Package io.jenkins.docker
Class DockerTransientNode
java.lang.Object
hudson.model.AbstractModelObject
hudson.model.Node
hudson.model.Slave
hudson.slaves.AbstractCloudSlave
io.jenkins.docker.DockerTransientNode
- All Implemented Interfaces:
ExtensionPoint
,Describable<Node>
,ModelObject
,PersistenceRoot
,ReconfigurableDescribable<Node>
,Saveable
,SearchableModelObject
,SearchItem
,AccessControlled
,Serializable
,OnMaster
,org.jenkinsci.plugins.cloudstats.TrackedItem
public class DockerTransientNode
extends AbstractCloudSlave
implements org.jenkinsci.plugins.cloudstats.TrackedItem
A
AbstractCloudSlave
node designed to be used only once for a build.- Author:
- Nicolas De Loof
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Nested classes/interfaces inherited from class hudson.model.Slave
Slave.JnlpJar, Slave.SlaveDescriptor
Nested classes/interfaces inherited from class hudson.model.Node
Node.InternalComputerListener, Node.Mode
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
Field Summary
Fields inherited from class hudson.model.Node
holdOffLaunchUntilSave, SKIP_BUILD_CHECK_ON_FLYWEIGHTS
-
Constructor Summary
ConstructorDescriptionDockerTransientNode
(String nodeName, String containerId, String workdir) Preferred constructor.DockerTransientNode
(String nodeName, String containerId, String workdir, ComputerLauncher launcher) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoid
_terminate
(TaskListener listener) getCloud()
org.jenkinsci.plugins.cloudstats.ProvisioningActivity.Id
getId()
org.jenkinsci.plugins.cloudstats.ProvisioningActivity.Id
int
boolean
boolean
void
Robustly adds this node to Jenkins.void
Reverse ofrobustlyAddToJenkins()
.void
setAcceptingTasks
(boolean acceptingTasks) void
setCloudId
(String cloudId) void
setDockerAPI
(DockerAPI dockerAPI) void
setProvisioningId
(org.jenkinsci.plugins.cloudstats.ProvisioningActivity.Id provisioningId) void
setRemoveVolumes
(boolean removeVolumes) void
setStopTimeout
(int timeout) static boolean
stopAndRemoveContainer
(DockerAPI api, org.slf4j.Logger logger, String containerDescription, boolean removeVolumes, String containerId, boolean containerAlreadyStopped) Utility method that gracefully terminates a docker container (preferably one that we started).void
terminate
(org.slf4j.Logger logger) Tries to remove all trace of this node, logging anything that goes wrong.Methods inherited from class hudson.slaves.AbstractCloudSlave
terminate
Methods inherited from class hudson.model.Slave
createLauncher, equals, getClockDifferenceCallable, getComputer, getDescriptor, getLabelAtomSet, getLabelString, getLauncher, getMode, getNodeDescription, getNodeName, getNodeProperties, getNumExecutors, getRemoteFS, getRetentionStrategy, getRootPath, getUserId, getWorkspaceFor, getWorkspaceRoot, hashCode, readResolve, setLabelString, setLauncher, setMode, setNodeDescription, setNodeName, setNodeProperties, setNumExecutors, setRetentionStrategy, setUserId, toString
Methods inherited from class hudson.model.Node
canTake, canTake, createPath, getACL, getAssignedLabels, getChannel, getClockDifference, getConfigFile, getFileSystemProvisioner, getLabelCloud, getNodeProperty, getNodeProperty, getNodePropertyDescriptors, getRootDir, getSearchUrl, getSelfLabel, getTemporaryOfflineCause, isHoldOffLaunchUntilSave, onLoad, reconfigure, reconfigure, save, toComputer
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError, sendError, sendError, sendError
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface hudson.security.AccessControlled
checkAnyPermission, checkPermission, hasAnyPermission, hasPermission, hasPermission, hasPermission2
-
Constructor Details
-
DockerTransientNode
@Deprecated public DockerTransientNode(@NonNull String nodeName, @NonNull String containerId, String workdir, ComputerLauncher launcher) throws Descriptor.FormException, IOException Deprecated.- Parameters:
nodeName
- Passed toDockerTransientNode(String, String, String)
.containerId
- Passed toDockerTransientNode(String, String, String)
.workdir
- Passed toDockerTransientNode(String, String, String)
.launcher
- Passed toSlave.setLauncher(ComputerLauncher)
- Throws:
Descriptor.FormException
- SeeDockerTransientNode(String, String, String)
.IOException
- SeeDockerTransientNode(String, String, String)
.
-
DockerTransientNode
public DockerTransientNode(@NonNull String nodeName, @NonNull String containerId, String workdir) throws Descriptor.FormException, IOException Preferred constructor. Note that, unless this is a JNLP node, callers will later have to callSlave.setLauncher(ComputerLauncher)
.- Parameters:
nodeName
- Name of the node; passed toAbstractCloudSlave(String, String, ComputerLauncher)
.containerId
- Docker container id.workdir
- remoteFs home dir; passed toAbstractCloudSlave(String, String, ComputerLauncher)
.- Throws:
Descriptor.FormException
- SeeAbstractCloudSlave(String, String, ComputerLauncher)
.IOException
- SeeAbstractCloudSlave(String, String, ComputerLauncher)
.
-
-
Method Details
-
isAcceptingTasks
public boolean isAcceptingTasks()- Overrides:
isAcceptingTasks
in classNode
-
setAcceptingTasks
public void setAcceptingTasks(boolean acceptingTasks) -
getContainerId
-
setDockerAPI
-
getDockerAPI
- Returns:
- The
DockerAPI
for our cloud.
-
getDisplayName
- Specified by:
getDisplayName
in interfaceModelObject
- Overrides:
getDisplayName
in classNode
-
isRemoveVolumes
public boolean isRemoveVolumes() -
setRemoveVolumes
public void setRemoveVolumes(boolean removeVolumes) -
getStopTimeout
public int getStopTimeout() -
setStopTimeout
public void setStopTimeout(int timeout) -
getCloudId
-
setCloudId
-
getProvisioningId
public org.jenkinsci.plugins.cloudstats.ProvisioningActivity.Id getProvisioningId() -
setProvisioningId
public void setProvisioningId(org.jenkinsci.plugins.cloudstats.ProvisioningActivity.Id provisioningId) -
createComputer
- Specified by:
createComputer
in classAbstractCloudSlave
-
getId
@Nullable public org.jenkinsci.plugins.cloudstats.ProvisioningActivity.Id getId()- Specified by:
getId
in interfaceorg.jenkinsci.plugins.cloudstats.TrackedItem
-
_terminate
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void _terminate(TaskListener listener) - Specified by:
_terminate
in classAbstractCloudSlave
-
terminate
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void terminate(org.slf4j.Logger logger) Tries to remove all trace of this node, logging anything that goes wrong.Note: This is not intended for use outside the plugin.
- Parameters:
logger
- Where to log any progress messages, exceptions etc.
-
stopAndRemoveContainer
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean stopAndRemoveContainer(DockerAPI api, org.slf4j.Logger logger, String containerDescription, boolean removeVolumes, String containerId, boolean containerAlreadyStopped) Utility method that gracefully terminates a docker container (preferably one that we started). Intended to only be used when we do not have a correspondingDockerTransientNode
- if we have aDockerTransientNode
then callterminate(Logger)
instead.- Parameters:
api
- TheDockerAPI
which we are to use.logger
- Where to log progress/results to.containerDescription
- What the container was, e.g. "for node 'docker-1234'" or "for non-existent node". Used in logs.removeVolumes
- If true then we'll ask docker to remove the container's volumes as well.containerId
- The ID of the container to be terminated.containerAlreadyStopped
- If true then we will assume that the container is already stopped and not try to stop it again (which helps prevent verbose warnings from appearing in the Jenkins log outside our control). If you're not sure, pass in false.- Returns:
- true if the container is now stopped and removed. false if we could not remove it (in which case we will have logged the reason why).
-
getCloud
-
robustlyAddToJenkins
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void robustlyAddToJenkins() throws IOExceptionRobustly adds this node to Jenkins. This works around for Jenkins core issue in Nodes.java's addNode method.. There's a line there saying "TODO there is a theoretical race whereby the node instance is updated/removed after lock release". When we're busy adding nodes this is not merely "theoretical"!- Throws:
IOException
- if it all failed horribly every time we tried.- See Also:
-
robustlyRemoveFromJenkins
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void robustlyRemoveFromJenkins() throws IOExceptionReverse ofrobustlyAddToJenkins()
.- Throws:
IOException
- if it all failed horribly.
-
DockerTransientNode(String, String, String)
thenSlave.setLauncher(ComputerLauncher)
.