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
,ReconfigurableDescribable<Node>
,Saveable
,SearchableModelObject
,SearchItem
,AccessControlled
,Serializable
,OnMaster
,org.jenkinsci.plugins.cloudstats.TrackedItem
public class DockerTransientNode extends AbstractCloudSlave implements org.jenkinsci.plugins.cloudstats.TrackedItem
AAbstractCloudSlave
node designed to be used only once for a build.- Author:
- Nicolas De Loof
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DockerTransientNode.DockerTransientNodeDescriptor
-
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
Constructors Constructor Description DockerTransientNode(String nodeName, String containerId, String workdir)
Preferred constructor.DockerTransientNode(String nodeName, String containerId, String workdir, ComputerLauncher launcher)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
_terminate(TaskListener listener)
DockerComputer
createComputer()
DockerCloud
getCloud()
String
getCloudId()
String
getContainerId()
String
getDisplayName()
DockerAPI
getDockerAPI()
org.jenkinsci.plugins.cloudstats.ProvisioningActivity.Id
getId()
org.jenkinsci.plugins.cloudstats.ProvisioningActivity.Id
getProvisioningId()
int
getStopTimeout()
boolean
isAcceptingTasks()
boolean
isRemoveVolumes()
void
robustlyAddToJenkins()
Robustly adds this node to Jenkins.void
robustlyRemoveFromJenkins()
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, getFileSystemProvisioner, getLabelCloud, getNodeProperty, getNodeProperty, getNodePropertyDescriptors, getSearchUrl, getSelfLabel, getTemporaryOfflineCause, isHoldOffLaunchUntilSave, reconfigure, save, toComputer
-
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, 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 Detail
-
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 Detail
-
isAcceptingTasks
public boolean isAcceptingTasks()
- Overrides:
isAcceptingTasks
in classNode
-
setAcceptingTasks
public void setAcceptingTasks(boolean acceptingTasks)
-
getContainerId
@NonNull public String getContainerId()
-
setDockerAPI
public void setDockerAPI(DockerAPI dockerAPI)
-
getDisplayName
public String 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
public String getCloudId()
-
setCloudId
public void setCloudId(String cloudId)
-
getProvisioningId
public org.jenkinsci.plugins.cloudstats.ProvisioningActivity.Id getProvisioningId()
-
setProvisioningId
public void setProvisioningId(org.jenkinsci.plugins.cloudstats.ProvisioningActivity.Id provisioningId)
-
createComputer
public DockerComputer 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
public DockerCloud getCloud()
-
robustlyAddToJenkins
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void robustlyAddToJenkins() throws IOException
Robustly 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:
- Nodes.java addNode method
-
robustlyRemoveFromJenkins
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void robustlyRemoveFromJenkins() throws IOException
Reverse ofrobustlyAddToJenkins()
.- Throws:
IOException
- if it all failed horribly.
-
-