Class QueryService


  • public class QueryService
    extends Object
    Query service for getting image and container information from the docker dameon
    • 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 null if 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 null if 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 Container objects
        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 up
        all - if true, fetch stopped containers as well as running containers.
        Returns:
        list of Container objects
        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 Image objects
        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 up
        all - if true, fetch stopped containers as well as running containers.
        Returns:
        container or null if 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 null if given containers is 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