Class DockerManager

  • All Implemented Interfaces:
    Manager

    public class DockerManager
    extends Object
    implements Manager
    Class providing connection between Patriot api and java-docker api.
    • Constructor Detail

      • DockerManager

        public DockerManager()
    • Method Detail

      • findIpAddress

        public String findIpAddress​(Container container,
                                    Network network)
        Description copied from interface: Manager
        Find ip address string.
        Specified by:
        findIpAddress in interface Manager
        Parameters:
        container - the container
        network - the network
        Returns:
        the string
      • buildImage

        public void buildImage​(File dockerfile,
                               Set<String> tag)
        Description copied from interface: Manager
        Build image.
        Specified by:
        buildImage in interface Manager
        Parameters:
        dockerfile - the dockerfile
        tag - the tag
      • deleteImage

        public void deleteImage​(String tag)
        Description copied from interface: Manager
        Delete image.
        Specified by:
        deleteImage in interface Manager
        Parameters:
        tag - the tag
      • createContainer

        public Container createContainer​(String name,
                                         String tag)
        Description copied from interface: Manager
        Create container container.
        Specified by:
        createContainer in interface Manager
        Parameters:
        name - the name
        tag - the tag
        Returns:
        the container
      • createContainer

        public Container createContainer​(String name,
                                         String tag,
                                         String volumePath,
                                         String bindPath)
        Create container container.
        Parameters:
        name - the name
        tag - the tag
        volumePath - the volume path
        bindPath - the bind path
        Returns:
        the container
      • createContainer

        public Container createContainer​(String name,
                                         String tag,
                                         String elasticIP,
                                         Integer logstashPort,
                                         List<String> environmentVariables)
        Create container container with elastic log hook.
        Parameters:
        name - the name
        tag - the tag
        elasticIP - the elastic ip
        logstashPort - the logshtash port
        Returns:
        the container
      • createNetwork

        public Network createNetwork​(String name,
                                     String subnet)
        Description copied from interface: Manager
        Create network network.
        Specified by:
        createNetwork in interface Manager
        Parameters:
        name - the name
        subnet - the subnet
        Returns:
        the network
      • listContainers

        public List<Container> listContainers()
        Method providing service for finding containers and return list of all created containers
        Specified by:
        listContainers in interface Manager
        Returns:
      • listNetworks

        public List<Network> listNetworks()
        Method providing service for finding networks and return list of all created networks
        Specified by:
        listNetworks in interface Manager
        Returns:
        returns all networks running in docker
      • connectContainerToNetwork

        public void connectContainerToNetwork​(Container container,
                                              Network network)
        Description copied from interface: Manager
        Connect container to network.
        Specified by:
        connectContainerToNetwork in interface Manager
        Parameters:
        container - the container
        network - the network
      • killContainer

        public void killContainer​(Container container)
        Description copied from interface: Manager
        Method stops container.
        Specified by:
        killContainer in interface Manager
      • destroyContainer

        public void destroyContainer​(Container container)
        Method which destroys docker network based on network id.
        Specified by:
        destroyContainer in interface Manager
        Parameters:
        container - container which needs to be destroyed
      • destroyNetwork

        public void destroyNetwork​(Network network)
        Method which destroys docker network based on network id.
        Specified by:
        destroyNetwork in interface Manager
        Parameters:
        network - network which needs to be destroyed
      • runCommand

        public void runCommand​(Container container,
                               String command)
        Method is providing execution of commands directly in running docker container.
        Specified by:
        runCommand in interface Manager
        Parameters:
        container - container in which will be command executed
        command - command which will be executed
      • startContainer

        public void startContainer​(Container container)
        Method which starts docker container based on container name.
        Specified by:
        startContainer in interface Manager
        Parameters:
        container - container which will be started
      • getDefaultGwNetworkIp

        public String getDefaultGwNetworkIp​(Container container)
      • getDefaultGwNetworkMask

        public Integer getDefaultGwNetworkMask​(Container container)
        Method gathers gateway's network mask.
        Parameters:
        container - container from which will generator gather gateway
        Returns:
        network mask (decimal)
      • convertToNetworkIp

        public String convertToNetworkIp​(String ip,
                                         int mask)
        Method converts host ip address to ip address of network or subnet. Docker api doesn't store ip address of network in containers config so we have to convert it from container's ip and mask. Convert uses logic AND function.
        Parameters:
        ip - IP Address of container in target network.
        mask - mask of containers ip addres in target network.
        Returns:
        Network IP Address
      • delDefaultGateway

        public void delDefaultGateway​(DockerContainer container)