public class RunService extends Object
Constructor and Description |
---|
RunService(DockerAccess docker,
QueryService queryService,
ContainerTracker tracker,
LogOutputSpecFactory logConfig,
Logger log) |
Modifier and Type | Method and Description |
---|---|
void |
addShutdownHookForStoppingContainers(boolean keepContainer,
boolean removeVolumes,
boolean removeCustomNetworks)
Add a shutdown hook in order to stop all registered containers
|
String |
createAndStartContainer(ImageConfiguration imageConfig,
PortMapping portMapping,
GavLabel gavLabel,
Properties properties,
File baseDir,
String defaultContainerNamePattern,
Date buildTimestamp)
Create and start a container with the given image configuration.
|
void |
createCustomNetworkIfNotExistant(String customNetwork) |
PortMapping |
createPortMapping(RunImageConfiguration runConfig,
Properties properties)
Create port mapping for a specific configuration as it can be used when creating containers
|
List<String> |
createVolumesAsPerVolumeBinds(ServiceHub hub,
List<String> binds,
List<VolumeConfiguration> volumes)
Creates a Volume if a volume is referred to during startup in bind mount mapping and
a VolumeConfiguration exists
|
String |
execInContainer(String containerId,
String command,
ImageConfiguration imageConfiguration)
Create and start a Exec container with the given image configuration.
|
List<StartOrderResolver.Resolvable> |
getImagesConfigsInOrder(QueryService queryService,
List<ImageConfiguration> images)
Get the proper order for images to start
|
String |
lookupContainer(String lookup)
Lookup a container that has been started
|
void |
removeCustomNetworks(Collection<Network> networks) |
void |
stopContainer(String containerId,
ImageConfiguration imageConfig,
boolean keepContainer,
boolean removeVolumes)
Stop a container immediately by id.
|
void |
stopPreviouslyStartedContainer(String containerId,
boolean keepContainer,
boolean removeVolumes)
Lookup up whether a certain has been already started and registered.
|
void |
stopStartedContainers(boolean keepContainer,
boolean removeVolumes,
boolean removeCustomNetworks,
GavLabel gavLabel)
Stop all registered container
|
public RunService(DockerAccess docker, QueryService queryService, ContainerTracker tracker, LogOutputSpecFactory logConfig, Logger log)
public String execInContainer(String containerId, String command, ImageConfiguration imageConfiguration) throws DockerAccessException, ExecException
containerId
- container id to run exec command againstcommand
- command to executeimageConfiguration
- configuration of the container's imageDockerAccessException
- if access to the docker backend failsExecException
public String createAndStartContainer(ImageConfiguration imageConfig, PortMapping portMapping, GavLabel gavLabel, Properties properties, File baseDir, String defaultContainerNamePattern, Date buildTimestamp) throws DockerAccessException
imageConfig
- image configuration holding the run information and the image nameportMapping
- container port mappinggavLabel
- label to tag the started container withproperties
- properties to fill in with dynamically assigned portsdefaultContainerNamePattern
- pattern to use for naming containers. Can be null in which case a default pattern is usedbuildTimestamp
- date which should be used as the timestamp when calculating container namesDockerAccessException
- if access to the docker backend failspublic void stopContainer(String containerId, ImageConfiguration imageConfig, boolean keepContainer, boolean removeVolumes) throws DockerAccessException, ExecException
containerId
- the container to stopimageConfig
- image configuration for this containerkeepContainer
- whether to keep container or to remove them after stoppingsremoveVolumes
- whether to remove volumes after stoppingDockerAccessException
ExecException
public void stopPreviouslyStartedContainer(String containerId, boolean keepContainer, boolean removeVolumes) throws DockerAccessException, ExecException
containerId
- the container to stopkeepContainer
- whether to keep container or to remove them after stoppingsremoveVolumes
- whether to remove volumes after stoppingDockerAccessException
ExecException
public void stopStartedContainers(boolean keepContainer, boolean removeVolumes, boolean removeCustomNetworks, GavLabel gavLabel) throws DockerAccessException, ExecException
keepContainer
- whether to keep container or to remove them after stoppingremoveVolumes
- whether to remove volumes after stoppingDockerAccessException
- if during stopping of a container sth failsExecException
public String lookupContainer(String lookup)
lookup
- a container by id or aliasnull
otherwise.public List<StartOrderResolver.Resolvable> getImagesConfigsInOrder(QueryService queryService, List<ImageConfiguration> images)
images
- list of images for which the order should be createdpublic PortMapping createPortMapping(RunImageConfiguration runConfig, Properties properties)
runConfig
- the cun configurationproperties
- properties to lookup variablespublic void addShutdownHookForStoppingContainers(boolean keepContainer, boolean removeVolumes, boolean removeCustomNetworks)
public void createCustomNetworkIfNotExistant(String customNetwork) throws DockerAccessException
DockerAccessException
public void removeCustomNetworks(Collection<Network> networks) throws DockerAccessException
DockerAccessException
public List<String> createVolumesAsPerVolumeBinds(ServiceHub hub, List<String> binds, List<VolumeConfiguration> volumes) throws DockerAccessException
hub
- Service hubbinds
- volume binds present in ImageConfigurationvolumes
- VolumeConfigs presentDockerAccessException
Copyright © 2020. All rights reserved.