Package io.fabric8.maven.docker.service
Class QueryService
- java.lang.Object
-
- io.fabric8.maven.docker.service.QueryService
-
public class QueryService extends Object
Query service for getting image and container information from the docker dameon
-
-
Constructor Summary
Constructors Constructor Description QueryService(DockerAccess docker)Constructor which gets its dependencies as args)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ContainergetContainer(String containerIdOrName)Get a container running for a given container name.StringgetContainerName(String containerId)Get name for single container when the id is givenList<Container>getContainersForImage(String image, boolean all)Get all containers which are build from an image.StringgetImageId(String imageName)Finds the id of an image.ContainergetLatestContainer(List<Container> containers)Finds the latest container.ContainergetLatestContainerForImage(String image, boolean all)Get the id of the latest container started for an imageContainergetMandatoryContainer(String containerIdOrName)Get container by idNetworkgetNetworkByName(String networkName)Get a network for a given network name.Set<Network>getNetworks()Get all networks.booleanhasContainer(String containerName)Check whether a container with the given name existsbooleanhasImage(String name)Check whether the given Image is locally available.booleanhasNetwork(String networkName)Check whether a network with the given name existsList<Container>listContainers(boolean all)List all containers on the Docker server.List<Image>listImages(boolean all)Get all images on the Docker server.
-
-
-
Constructor Detail
-
QueryService
public QueryService(DockerAccess docker)
Constructor which gets its dependencies as args)- Parameters:
docker- remote access to docker daemon
-
-
Method Detail
-
getMandatoryContainer
public Container getMandatoryContainer(String containerIdOrName) throws DockerAccessException
Get container by id- Parameters:
containerIdOrName- container id or name- Returns:
- container found
- Throws:
DockerAccessException- if an error occurs or no container with this id or name exists
-
getContainer
public Container getContainer(String containerIdOrName) throws DockerAccessException
Get a container running for a given container name.- Parameters:
containerIdOrName- name of container to lookup- Returns:
- the container found or
nullif no container is available. - Throws:
DockerAccessException- in case of an remote error
-
getNetworkByName
public Network getNetworkByName(String networkName) throws DockerAccessException
Get a network for a given network name.- Parameters:
networkName- name of network to lookup- Returns:
- the network found or
nullif no network is available. - Throws:
DockerAccessException- in case of an remote error
-
getNetworks
public Set<Network> getNetworks() throws DockerAccessException
Get all networks.- Returns:
- the network found or
nullif no network is available. - Throws:
DockerAccessException- in case of an remote error
-
getContainerName
public String getContainerName(String containerId) throws DockerAccessException
Get name for single container when the id is given- Parameters:
containerId- id of container to lookup- Returns:
- the name of the container
- Throws:
DockerAccessException- if access to the docker daemon fails
-
listContainers
public List<Container> listContainers(boolean all) throws DockerAccessException
List all containers on the Docker server.- Parameters:
all- if true, list stopped containers as well as running containers.- Returns:
- list of
Containerobjects - Throws:
DockerAccessException- if the request fails
-
getContainersForImage
public List<Container> getContainersForImage(String image, boolean all) throws DockerAccessException
Get all containers which are build from an image. By default only the last containers are considered but this can be tuned with a global parameters.- Parameters:
image- for which its container are looked upall- if true, fetch stopped containers as well as running containers.- Returns:
- list of
Containerobjects - Throws:
DockerAccessException- if the request fails
-
listImages
public List<Image> listImages(boolean all) throws DockerAccessException
Get all images on the Docker server.- Parameters:
all- if true, fetch untagged images as well as tagged.- Returns:
- list of
Imageobjects - Throws:
DockerAccessException- if the request fails
-
getImageId
public String getImageId(String imageName) throws DockerAccessException
Finds the id of an image.- Parameters:
imageName- name of the image.- Returns:
- the id of the image
- Throws:
DockerAccessException- if the request fails
-
getLatestContainerForImage
public Container getLatestContainerForImage(String image, boolean all) throws DockerAccessException
Get the id of the latest container started for an image- Parameters:
image- for which its container are looked upall- if true, fetch stopped containers as well as running containers.- Returns:
- container or
nullif no container has been started for this image. - Throws:
DockerAccessException- if the request fails
-
getLatestContainer
public Container getLatestContainer(List<Container> containers)
Finds the latest container.- Parameters:
containers- containers to find the latest.- Returns:
- the latest container or
nullif givencontainersis empty.
-
hasContainer
public boolean hasContainer(String containerName) throws DockerAccessException
Check whether a container with the given name exists- Parameters:
containerName- container name- Returns:
- true if a container with this name exists, false otherwise.
- Throws:
DockerAccessException
-
hasNetwork
public boolean hasNetwork(String networkName) throws DockerAccessException
Check whether a network with the given name exists- Parameters:
networkName- network name- Returns:
- true if a network with this name exists, false otherwise.
- Throws:
DockerAccessException
-
hasImage
public boolean hasImage(String name) throws DockerAccessException
Check whether the given Image is locally available.- Parameters:
name- name of image to check, the image can contain a tag, otherwise 'latest' will be appended- Returns:
- true if the image is locally available or false if it must be pulled.
- Throws:
DockerAccessException- if the request fails
-
-