Class DockerCloud
- java.lang.Object
-
- hudson.model.AbstractModelObject
-
- hudson.model.Actionable
-
- hudson.slaves.Cloud
-
- com.nirima.jenkins.plugins.docker.DockerCloud
-
- All Implemented Interfaces:
ExtensionPoint
,Describable<Cloud>
,ModelObject
,SearchableModelObject
,SearchItem
,AccessControlled
,ModelObjectWithContextMenu
public class DockerCloud extends Cloud
Docker Cloud configuration. Contains connection configuration,DockerTemplate
contains configuration for running docker image.- Author:
- magnayn
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DockerCloud.DescriptorImpl
-
Nested classes/interfaces inherited from class hudson.slaves.Cloud
Cloud.CloudState
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
Nested classes/interfaces inherited from interface jenkins.model.ModelObjectWithContextMenu
ModelObjectWithContextMenu.ContextMenu, ModelObjectWithContextMenu.ContextMenuVisibility, ModelObjectWithContextMenu.MenuItem, ModelObjectWithContextMenu.MenuItemType
-
-
Constructor Summary
Constructors Constructor Description DockerCloud(String name, DockerCloud source)
DockerCloud(String name, DockerAPI dockerApi, List<DockerTemplate> templates)
DockerCloud(String name, List<DockerTemplate> templates, String serverUrl, int containerCap, int connectTimeout, int readTimeout, String credentialsId, String version, String dockerHostname)
Deprecated.DockerCloud(String name, List<DockerTemplate> templates, String serverUrl, String containerCapStr, int connectTimeout, int readTimeout, String credentialsId, String version, String dockerHostname)
Deprecated.DockerCloud(String name, List<DockerTemplate> templates, org.jenkinsci.plugins.docker.commons.credentials.DockerServerEndpoint dockerHost, int containerCap, int connectTimeout, int readTimeout, String version, String dockerHostname)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addJobTemplate(long jobId, DockerTemplate template)
Adds a template which is temporary provided and bound to a specific job.void
addTemplate(DockerTemplate t)
Add a new template to the cloudboolean
canProvision(Label label)
int
countContainersInDocker(String imageName)
Counts the number of instances currently running in Docker that are using the specified image.int
countContainersInProgress(DockerTemplate template)
boolean
equals(Object o)
static com.github.dockerjava.api.model.AuthConfig
getAuthConfig(org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint registry, ItemGroup context)
com.github.dockerjava.api.DockerClient
getClient()
Deprecated.UsegetDockerApi()
and thenDockerAPI.getClient()
to get the client, followed by a call toDockerClient.close()
.static DockerCloud
getCloudByName(String name)
int
getConnectTimeout()
Deprecated.int
getContainerCap()
String
getContainerCapStr()
Deprecated.DockerDisabled
getDisabled()
DockerAPI
getDockerApi()
org.jenkinsci.plugins.docker.commons.credentials.DockerServerEndpoint
getDockerHost()
Deprecated.String
getDockerHostname()
Deprecated.Integer
getErrorDuration()
String
getServerUrl()
Deprecated.DockerTemplate
getTemplate(Label label)
Gets firstDockerTemplate
that has the matchingLabel
.DockerTemplate
getTemplate(String template)
List<DockerTemplate>
getTemplates()
List<DockerTemplate>
getTemplates(Label label)
Multiple amis can have the same label.int
hashCode()
static List<DockerCloud>
instances()
boolean
isExposeDockerHost()
boolean
isTriton()
Collection<NodeProvisioner.PlannedNode>
provision(Label label, int numberOfExecutorsRequired)
protected Object
readResolve()
void
removeJobTemplate(long jobId)
Removes a template which is bound to a specific job.void
removeTemplate(DockerTemplate t)
Remove Docker templatestatic String
runContainer(DockerTemplateBase dockerTemplateBase, com.github.dockerjava.api.DockerClient dockerClient)
protected String
sanitizeUrl(String url)
void
setContainerCap(int containerCap)
void
setDisabled(DockerDisabled disabled)
void
setErrorDuration(Integer errorDuration)
void
setExposeDockerHost(boolean exposeDockerHost)
static void
setRegistryAuthentication(com.github.dockerjava.api.command.PullImageCmd cmd, org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint registry, ItemGroup context)
static void
setRegistryAuthentication(com.github.dockerjava.api.command.PushImageCmd cmd, org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint registry, ItemGroup context)
String
toString()
-
Methods inherited from class hudson.slaves.Cloud
all, canProvision, doConfigSubmit, doDoDelete, getACL, getDescriptor, getDisplayName, getIcon, getIconAltText, getIconClassName, getSearchUrl, getUrl, provision, reconfigure, registerPermissions
-
Methods inherited from class hudson.model.Actionable
addAction, addOrReplaceAction, doContextMenu, getAction, getAction, getActions, getActions, getAllActions, getDynamic, removeAction, removeActions, replaceAction, replaceActions
-
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
-
-
-
-
Field Detail
-
credentialsId
@Deprecated public transient String credentialsId
Deprecated.
-
-
Constructor Detail
-
DockerCloud
@DataBoundConstructor public DockerCloud(String name, DockerAPI dockerApi, List<DockerTemplate> templates)
-
DockerCloud
public DockerCloud(@NonNull String name, @NonNull DockerCloud source)
-
DockerCloud
@Deprecated public DockerCloud(String name, List<DockerTemplate> templates, org.jenkinsci.plugins.docker.commons.credentials.DockerServerEndpoint dockerHost, int containerCap, int connectTimeout, int readTimeout, String version, String dockerHostname)
Deprecated.
-
DockerCloud
@Deprecated public DockerCloud(String name, List<DockerTemplate> templates, String serverUrl, int containerCap, int connectTimeout, int readTimeout, String credentialsId, String version, String dockerHostname)
Deprecated.
-
DockerCloud
@Deprecated public DockerCloud(String name, List<DockerTemplate> templates, String serverUrl, String containerCapStr, int connectTimeout, int readTimeout, String credentialsId, String version, String dockerHostname)
Deprecated.
-
-
Method Detail
-
getDockerApi
public DockerAPI getDockerApi()
-
getConnectTimeout
@Deprecated public int getConnectTimeout()
Deprecated.
-
getDockerHost
@Deprecated public org.jenkinsci.plugins.docker.commons.credentials.DockerServerEndpoint getDockerHost()
Deprecated.
-
getServerUrl
@Deprecated public String getServerUrl()
Deprecated.
-
getDockerHostname
@Deprecated public String getDockerHostname()
Deprecated.
-
getContainerCapStr
@Deprecated public String getContainerCapStr()
Deprecated.- Returns:
getContainerCap()
as aString
.
-
getContainerCap
public int getContainerCap()
-
setContainerCap
@DataBoundSetter public void setContainerCap(int containerCap)
-
getClient
@Deprecated public com.github.dockerjava.api.DockerClient getClient()
Deprecated.UsegetDockerApi()
and thenDockerAPI.getClient()
to get the client, followed by a call toDockerClient.close()
.Connects to Docker. NOTE: This should not be used for any long-running operations as the client it returns is not protected from closure.- Returns:
- Docker client.
-
countContainersInProgress
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public int countContainersInProgress(DockerTemplate template)
-
provision
public Collection<NodeProvisioner.PlannedNode> provision(Label label, int numberOfExecutorsRequired)
-
runContainer
public static String runContainer(DockerTemplateBase dockerTemplateBase, com.github.dockerjava.api.DockerClient dockerClient)
-
canProvision
public boolean canProvision(Label label)
- Overrides:
canProvision
in classCloud
-
getTemplate
@CheckForNull public DockerTemplate getTemplate(String template)
-
getTemplate
@CheckForNull public DockerTemplate getTemplate(Label label)
Gets firstDockerTemplate
that has the matchingLabel
.- Parameters:
label
- The label we're looking to match.- Returns:
- The first
DockerTemplate
that has the matchingLabel
, or null if not found.
-
addTemplate
public void addTemplate(DockerTemplate t)
Add a new template to the cloud- Parameters:
t
- The template to be added.
-
addJobTemplate
public void addJobTemplate(long jobId, DockerTemplate template)
Adds a template which is temporary provided and bound to a specific job.- Parameters:
jobId
- Unique id (per master) of the job to which the template is bound.template
- The template to bound to a specific job.
-
removeJobTemplate
public void removeJobTemplate(long jobId)
Removes a template which is bound to a specific job.- Parameters:
jobId
- Id of the job.
-
getTemplates
public List<DockerTemplate> getTemplates()
-
getTemplates
public List<DockerTemplate> getTemplates(Label label)
Multiple amis can have the same label.- Parameters:
label
- The label to be matched, or null if no label was provided.- Returns:
- Templates matched to requested label assuming agent Mode
-
removeTemplate
public void removeTemplate(DockerTemplate t)
Remove Docker template- Parameters:
t
- The template to be removed.
-
countContainersInDocker
public int countContainersInDocker(String imageName) throws Exception
Counts the number of instances currently running in Docker that are using the specified image.WARNING: This method can be slow so it should be called sparingly.
- Parameters:
imageName
- If null, then all instances belonging to this Jenkins instance are counted. Otherwise, only those started with the specified image are counted.- Returns:
- The number of containers.
- Throws:
Exception
- if anything went wrong.
-
getCloudByName
@CheckForNull public static DockerCloud getCloudByName(String name)
-
readResolve
protected Object readResolve()
-
isTriton
public boolean isTriton()
-
isExposeDockerHost
public boolean isExposeDockerHost()
-
setExposeDockerHost
@DataBoundSetter public void setExposeDockerHost(boolean exposeDockerHost)
-
getDisabled
public DockerDisabled getDisabled()
-
setDisabled
@DataBoundSetter public void setDisabled(DockerDisabled disabled)
-
getErrorDuration
@CheckForNull public Integer getErrorDuration()
-
setErrorDuration
@DataBoundSetter public void setErrorDuration(Integer errorDuration)
-
instances
@NonNull public static List<DockerCloud> instances()
-
setRegistryAuthentication
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static void setRegistryAuthentication(com.github.dockerjava.api.command.PullImageCmd cmd, org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint registry, ItemGroup context)
-
setRegistryAuthentication
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static void setRegistryAuthentication(com.github.dockerjava.api.command.PushImageCmd cmd, org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint registry, ItemGroup context)
-
getAuthConfig
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static com.github.dockerjava.api.model.AuthConfig getAuthConfig(org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint registry, ItemGroup context)
-
-