Class LxcContainerManager

  • All Implemented Interfaces:
    de.iip_ecosphere.platform.ecsRuntime.ContainerManager, de.iip_ecosphere.platform.ecsRuntime.ContainerOperations

    public class LxcContainerManager
    extends de.iip_ecosphere.platform.ecsRuntime.AbstractContainerManager<LxcContainerDescriptor>
    Implements a lxc-based container manager for IIP-Ecosphere.
    Author:
    Luca Schulz, SSE
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  LxcContainerManager.FactoryDescriptor
      Implements the factory descriptor for hooking the LXC container manager into the ECS factory.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static LxcSetup config  
      private static org.slf4j.Logger LOGGER  
      • Fields inherited from interface de.iip_ecosphere.platform.ecsRuntime.ContainerOperations

        EXC_ALREADY_KNOWN
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String addContainer​(java.net.URI location)
      Adds a container from a selected repository that was defined in a YAML-File to the local repository.
      java.lang.String addContainerFromTarball​(java.net.URI location)
      Adds a container from a tarball that can be created with distrobuilder and a template or via exporting an image.
      void copyImageFromRemote​(au.com.jcloud.lxd.enums.RemoteServer remote, java.lang.String remoteImage, java.lang.String imageAlias)
      Copy/import an image from a remote server that is defined in and set up on localhost.
      void createSnapshot​(java.lang.String containerName, java.lang.String snapshot)
      Creates a snapshot of a container with given name.
      void deleteContainer​(java.lang.String name)
      Deletes an existing container with given name.
      void exportImage​(java.lang.String imageAlias)
      Exports an existing image as a tarball to the users home directory.
      void freezeContainer​(java.lang.String name)
      Freezes an existing container with given name.
      java.lang.String getContainerSystemName()
      Returns the ContainerSystemName.
      java.lang.String getContainerSystemVersion()
      Returns the ContainerSystemVersion.
      private java.lang.String getImageAlias​(LxcContainerDescriptor desc)
      Validates and returns the LXC image file name.
      au.com.jcloud.lxd.service.ILxdService getLxcClient()
      Returns a LXC API Client.
      private java.lang.String getLxcId​(LxcContainerDescriptor desc)
      Validates and returns the LXC image file name.
      java.lang.String getLxcName​(java.lang.String name)
      Returns an name of a LXC container with a given name.
      java.lang.String getRuntimeName()  
      private java.lang.String getZip​(LxcContainerDescriptor desc)
      Validates and returns the LXC image file name.
      void importImage​(java.lang.String tarball, java.lang.String imageAlias)
      Imports an image from an existing tarball to the local server.
      void publishImage​(java.lang.String containerName, java.lang.String snapshot, java.lang.String imageAlias, boolean isPublic)
      Publishes an container and the corresponding snapshot as an image to the local server.
      void startContainer​(java.lang.String name)
      Starts an existing container with given name.
      void stopContainer​(java.lang.String name)
      Stops an existing container with given name.
      void unfreezeContainer​(java.lang.String name)
      Unfreezes an existing container with given name.
      void updateContainer​(java.lang.String id, java.net.URI location)
      This method is not relevant for LXC.
      • Methods inherited from class de.iip_ecosphere.platform.ecsRuntime.AbstractContainerManager

        addContainer, checkId, getContainer, getContainer, getContainers, getId, getIds, getState, migrateContainer, resolveUri, setState, throwExecutionException, throwExecutionException, undeployContainer
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface de.iip_ecosphere.platform.ecsRuntime.ContainerManager

        getVersion
    • Field Detail

      • config

        private static LxcSetup config
      • LOGGER

        private static final org.slf4j.Logger LOGGER
    • Constructor Detail

      • LxcContainerManager

        public LxcContainerManager()
    • Method Detail

      • addContainer

        public java.lang.String addContainer​(java.net.URI location)
                                      throws java.util.concurrent.ExecutionException
        Adds a container from a selected repository that was defined in a YAML-File to the local repository.
        Parameters:
        location - the location where the Yaml with container info is
        Returns:
        containerName, name of the created container
        Throws:
        java.util.concurrent.ExecutionException - if adding the container failed
      • addContainerFromTarball

        public java.lang.String addContainerFromTarball​(java.net.URI location)
                                                 throws java.util.concurrent.ExecutionException
        Adds a container from a tarball that can be created with distrobuilder and a template or via exporting an image.
        Parameters:
        location - the location where the Yaml with container info is
        Returns:
        containerName, the name of the created container
        Throws:
        java.util.concurrent.ExecutionException - if adding the container failed
        See Also:
        add function to create tarball with distrobuilder in this method
      • getImageAlias

        private java.lang.String getImageAlias​(LxcContainerDescriptor desc)
        Validates and returns the LXC image file name.
        Parameters:
        desc - the descriptor to return the name from
        Returns:
        the image name, potentially turned to lower cases
      • getZip

        private java.lang.String getZip​(LxcContainerDescriptor desc)
        Validates and returns the LXC image file name.
        Parameters:
        desc - the descriptor to return the name from
        Returns:
        the image zip file name, potentially turned to lower cases
      • getLxcId

        private java.lang.String getLxcId​(LxcContainerDescriptor desc)
        Validates and returns the LXC image file name.
        Parameters:
        desc - the descriptor to return the name from
        Returns:
        the image zip file name, potentially turned to lower cases
      • getLxcClient

        public au.com.jcloud.lxd.service.ILxdService getLxcClient()
        Returns a LXC API Client. If there is not running LXC daemon on the host it returns null.
        Returns:
        LxcClient or null if no LXC daemon is running or if the lxc lxcHost in the configuration setup cannot be applied, e.g., a Linux socket path
      • startContainer

        public void startContainer​(java.lang.String name)
                            throws java.util.concurrent.ExecutionException
        Starts an existing container with given name.
        Parameters:
        name - the name of the container
        Throws:
        java.util.concurrent.ExecutionException - if starting the container failed
      • stopContainer

        public void stopContainer​(java.lang.String name)
                           throws java.util.concurrent.ExecutionException
        Stops an existing container with given name.
        Parameters:
        name - the name of the container
        Throws:
        java.util.concurrent.ExecutionException - if stopping the container failed
      • deleteContainer

        public void deleteContainer​(java.lang.String name)
                             throws java.util.concurrent.ExecutionException
        Deletes an existing container with given name.
        Parameters:
        name - the name of the container
        Throws:
        java.util.concurrent.ExecutionException - if deleting the container failed
      • freezeContainer

        public void freezeContainer​(java.lang.String name)
                             throws java.util.concurrent.ExecutionException
        Freezes an existing container with given name.
        Parameters:
        name - the name of the container
        Throws:
        java.util.concurrent.ExecutionException - if freezing the container failed
      • unfreezeContainer

        public void unfreezeContainer​(java.lang.String name)
                               throws java.util.concurrent.ExecutionException
        Unfreezes an existing container with given name.
        Parameters:
        name - the name of the container
        Throws:
        java.util.concurrent.ExecutionException - if unfreezing the container failed
      • createSnapshot

        public void createSnapshot​(java.lang.String containerName,
                                   java.lang.String snapshot)
                            throws java.util.concurrent.ExecutionException
        Creates a snapshot of a container with given name.
        Parameters:
        containerName - the name of the container
        snapshot - the name that the snapshot is going to get
        Throws:
        java.util.concurrent.ExecutionException - if creating the snapshot failed
      • publishImage

        public void publishImage​(java.lang.String containerName,
                                 java.lang.String snapshot,
                                 java.lang.String imageAlias,
                                 boolean isPublic)
                          throws java.util.concurrent.ExecutionException
        Publishes an container and the corresponding snapshot as an image to the local server.
        Parameters:
        containerName - the name of the container
        snapshot - the name of the corresponding snapshot
        imageAlias - the name that the image is going to get
        isPublic - defines if the image should be public or not
        Throws:
        java.util.concurrent.ExecutionException - if publishing the image failed
      • exportImage

        public void exportImage​(java.lang.String imageAlias)
                         throws java.util.concurrent.ExecutionException
        Exports an existing image as a tarball to the users home directory.
        Parameters:
        imageAlias - the name the image that is going to be exported
        Throws:
        java.util.concurrent.ExecutionException - if expoerting the image failed
      • importImage

        public void importImage​(java.lang.String tarball,
                                java.lang.String imageAlias)
                         throws java.util.concurrent.ExecutionException
        Imports an image from an existing tarball to the local server.
        Parameters:
        tarball - the path to the tarball/gzip file
        imageAlias - the name that the image is going to get
        Throws:
        java.util.concurrent.ExecutionException - if importing the container failed
      • copyImageFromRemote

        public void copyImageFromRemote​(au.com.jcloud.lxd.enums.RemoteServer remote,
                                        java.lang.String remoteImage,
                                        java.lang.String imageAlias)
                                 throws java.util.concurrent.ExecutionException
        Copy/import an image from a remote server that is defined in and set up on localhost.
        Parameters:
        remote - the RemoteServer where the wanted image is stored
        remoteImage - the name of the image that is going to be copied
        imageAlias - the name that the image is going to get
        Throws:
        java.util.concurrent.ExecutionException - if copying the image failed
      • getContainerSystemName

        public java.lang.String getContainerSystemName()
        Returns the ContainerSystemName.
        Returns:
        ContainerSystemName e.g. "LXC"
      • getRuntimeName

        public java.lang.String getRuntimeName()
      • getContainerSystemVersion

        public java.lang.String getContainerSystemVersion()
        Returns the ContainerSystemVersion.
        Returns:
        ContainerSystemVersion
      • updateContainer

        public void updateContainer​(java.lang.String id,
                                    java.net.URI location)
                             throws java.util.concurrent.ExecutionException
        This method is not relevant for LXC.
        Throws:
        java.util.concurrent.ExecutionException
      • getLxcName

        public java.lang.String getLxcName​(java.lang.String name)
                                    throws java.util.concurrent.ExecutionException
        Returns an name of a LXC container with a given name.
        Parameters:
        name - container's name
        Returns:
        LXC container id/NULL
        Throws:
        java.util.concurrent.ExecutionException - if connecting to LXC API Client failed