Class LxcContainerDescriptor

  • All Implemented Interfaces:
    de.iip_ecosphere.platform.ecsRuntime.ContainerDescriptor

    public class LxcContainerDescriptor
    extends de.iip_ecosphere.platform.ecsRuntime.BasicContainerDescriptor
    Implements a container descriptor for lxc-based container management.
    Author:
    Luca Schulz, SSE
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        LxcContainerDescriptor()
      Creates a container descriptor instance.
      protected LxcContainerDescriptor​(java.lang.String id, java.lang.String name, de.iip_ecosphere.platform.support.iip_aas.Version version, java.net.URI uri)
      Creates a container descriptor instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.ArrayList<java.lang.String> getEnv()
      Returns the plain environment settings to start the container.
      java.util.ArrayList<java.lang.String> getExposedPorts()
      Returns the ports exposed by the container.
      java.lang.String getId()
      Returns the LXC container's id for LXC its the fingerprint in specific.
      java.lang.String getLxcImageAlias()
      Returns the name of the LXC image.
      java.lang.String getLxcZip()
      Returns the name of the LXC image zip.
      java.lang.String getNetKey()
      Returns the key for the network manager.
      java.lang.String getNetKey1()
      Returns the key for the network manager.
      java.lang.String getNetworkMode()
      Returns the network mode.
      static java.lang.String getRegistry​(java.lang.String imgName)
      Turns a full container image name with optional registry, repository and version into its repository/name.
      static java.lang.String getRepository​(java.lang.String imgName)
      Turns a full container image name with optional registry, repository and version into its repository/name.
      static java.lang.String getTag​(java.lang.String imgName)
      Turns a full container image name with optional registry, repository and version into its (version) tag.
      java.util.List<java.lang.String> instantiateEnv​(int port, int port1)
      Returns the substituted environment variable settings to start the container.
      static void main​(java.lang.String[] args)
      Tests reading a Docker container file.
      static LxcContainerDescriptor readFromYaml​(java.io.InputStream in, java.net.URI uri)
      Returns a LxcContainerDescriptor with a information from a yaml file.
      static LxcContainerDescriptor readFromYamlFile​(java.io.File file)
      Returns a LxcContainerDescriptor with a information from a yaml file.
      boolean requiresPort​(java.lang.String placeholder)
      Returns whether a dynamic port for a placeholder is required.
      void setEnv​(java.util.ArrayList<java.lang.String> env)
      Defines the environment settings to start the container.
      void setExposedPorts​(java.util.ArrayList<java.lang.String> exposedPorts)
      Defines the exposed ports.
      void setId​(java.lang.String lxcId)
      Defines the LXC container's id for LXC its the fingerprint in specific.
      void setLxcImageAlias​(java.lang.String lxcImageAlias)
      Defines the name of the LXC image.
      void setLxcZip​(java.lang.String lxcZip)
      Defines the name of the LXC image zip.
      void setNetworkMode​(java.lang.String networkMode)
      Defines the network mode.
      • Methods inherited from class de.iip_ecosphere.platform.ecsRuntime.BasicContainerDescriptor

        getDockerImageZipfile, getImageFile, getName, getState, getUri, getVersion, setDockerImageZipfile, setImageFile, setName, setState, setUri, setVersion
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PORT_PLACEHOLDER

        public static final java.lang.String PORT_PLACEHOLDER
        See Also:
        Constant Field Values
      • PORT_PLACEHOLDER_1

        public static final java.lang.String PORT_PLACEHOLDER_1
        See Also:
        Constant Field Values
      • instanceCount

        private static int instanceCount
      • instance

        private int instance
      • lxcId

        private java.lang.String lxcId
      • lxcImageAlias

        private java.lang.String lxcImageAlias
      • lxcZip

        private java.lang.String lxcZip
      • networkMode

        private java.lang.String networkMode
      • exposedPorts

        private java.util.ArrayList<java.lang.String> exposedPorts
      • env

        private java.util.ArrayList<java.lang.String> env
    • Constructor Detail

      • LxcContainerDescriptor

        public LxcContainerDescriptor()
        Creates a container descriptor instance.
      • LxcContainerDescriptor

        protected LxcContainerDescriptor​(java.lang.String id,
                                         java.lang.String name,
                                         de.iip_ecosphere.platform.support.iip_aas.Version version,
                                         java.net.URI uri)
        Creates a container descriptor instance.
        Parameters:
        id - the container id
        name - the (file) name of the container
        version - the version of the container
        uri - the URI where the descriptor was loaded from
        Throws:
        java.lang.IllegalArgumentException - if id, name, version or uri is invalid, e.g., null or empty
    • Method Detail

      • setId

        public void setId​(java.lang.String lxcId)
        Defines the LXC container's id for LXC its the fingerprint in specific.
        Overrides:
        setId in class de.iip_ecosphere.platform.ecsRuntime.BasicContainerDescriptor
        Parameters:
        lxcId -
      • getId

        public java.lang.String getId()
        Returns the LXC container's id for LXC its the fingerprint in specific.
        Specified by:
        getId in interface de.iip_ecosphere.platform.ecsRuntime.ContainerDescriptor
        Overrides:
        getId in class de.iip_ecosphere.platform.ecsRuntime.BasicContainerDescriptor
        Returns:
        lxcId
      • setLxcImageAlias

        public void setLxcImageAlias​(java.lang.String lxcImageAlias)
        Defines the name of the LXC image.
        Parameters:
        lxcImageAlias -
      • getLxcImageAlias

        public java.lang.String getLxcImageAlias()
        Returns the name of the LXC image.
        Returns:
        lxcImageAlias
      • getLxcZip

        public java.lang.String getLxcZip()
        Returns the name of the LXC image zip.
        Returns:
        lxcZip
      • setLxcZip

        public void setLxcZip​(java.lang.String lxcZip)
        Defines the name of the LXC image zip.
        Parameters:
        lxcZip -
      • setExposedPorts

        public void setExposedPorts​(java.util.ArrayList<java.lang.String> exposedPorts)
        Defines the exposed ports.
        Parameters:
        exposedPorts - the exposed ports
      • getExposedPorts

        public java.util.ArrayList<java.lang.String> getExposedPorts()
        Returns the ports exposed by the container.
        Returns:
        exposedPorts, the exposed ports
      • setEnv

        public void setEnv​(java.util.ArrayList<java.lang.String> env)
        Defines the environment settings to start the container.
        Parameters:
        env - the environment settings, may contain PORT_PLACEHOLDER to be replaced by the dynamic port of the AAS implementation server of the service manager
      • getNetworkMode

        public java.lang.String getNetworkMode()
        Returns the network mode.
        Returns:
        networkMode, the network mode, may be null for none
      • getEnv

        public java.util.ArrayList<java.lang.String> getEnv()
        Returns the plain environment settings to start the container.
        Returns:
        the environment settings, may contain PORT_PLACEHOLDER}
      • setNetworkMode

        public void setNetworkMode​(java.lang.String networkMode)
        Defines the network mode. [snakeyaml]
        Parameters:
        networkMode - the network mode, may be null for none
      • instantiateEnv

        public java.util.List<java.lang.String> instantiateEnv​(int port,
                                                               int port1)
        Returns the substituted environment variable settings to start the container.
        Parameters:
        port - the port to substitute PORT_PLACEHOLDER
        port1 - the port to substitute PORT_PLACEHOLDER_1
        Returns:
        result, the instantiated environment variable settings
      • requiresPort

        public boolean requiresPort​(java.lang.String placeholder)
        Returns whether a dynamic port for a placeholder is required.
        Parameters:
        placeholder - the name of the placeholder
        Returns:
        result, true for dynamic port, false else
      • getNetKey

        public java.lang.String getNetKey()
        Returns the key for the network manager.
        Returns:
        the key
      • getNetKey1

        public java.lang.String getNetKey1()
        Returns the key for the network manager.
        Returns:
        the key
      • readFromYamlFile

        public static LxcContainerDescriptor readFromYamlFile​(java.io.File file)
        Returns a LxcContainerDescriptor with a information from a yaml file.
        Parameters:
        file - yaml file
        Returns:
        LxcContainerDescriptor (may be null)
      • readFromYaml

        public static LxcContainerDescriptor readFromYaml​(java.io.InputStream in,
                                                          java.net.URI uri)
        Returns a LxcContainerDescriptor with a information from a yaml file.
        Parameters:
        in - an inout stream with Yaml contents (may be null)
        uri - the URI the descriptor was read from
        Returns:
        LxcContainerDescriptor (may be null)
      • getRepository

        public static java.lang.String getRepository​(java.lang.String imgName)
        Turns a full container image name with optional registry, repository and version into its repository/name.
        Parameters:
        imgName - the image name
        Returns:
        the repository
      • getRegistry

        public static java.lang.String getRegistry​(java.lang.String imgName)
        Turns a full container image name with optional registry, repository and version into its repository/name.
        Parameters:
        imgName - the image name
        Returns:
        the repository
      • getTag

        public static java.lang.String getTag​(java.lang.String imgName)
        Turns a full container image name with optional registry, repository and version into its (version) tag.
        Parameters:
        imgName - the image name
        Returns:
        the tag, may be empty
      • main

        public static void main​(java.lang.String[] args)
        Tests reading a Docker container file.
        Parameters:
        args - arguments, first is taken as file name