Class LxcContainerManager
- java.lang.Object
-
- de.iip_ecosphere.platform.ecsRuntime.AbstractContainerManager<LxcContainerDescriptor>
-
- de.iip_ecosphere.platform.ecsRuntime.lxc.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 classLxcContainerManager.FactoryDescriptorImplements the factory descriptor for hooking the LXC container manager into the ECS factory.
-
Constructor Summary
Constructors Constructor Description LxcContainerManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringaddContainer(java.net.URI location)Adds a container from a selected repository that was defined in a YAML-File to the local repository.java.lang.StringaddContainerFromTarball(java.net.URI location)Adds a container from a tarball that can be created with distrobuilder and a template or via exporting an image.voidcopyImageFromRemote(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.voidcreateSnapshot(java.lang.String containerName, java.lang.String snapshot)Creates a snapshot of a container with given name.voiddeleteContainer(java.lang.String name)Deletes an existing container with given name.voidexportImage(java.lang.String imageAlias)Exports an existing image as a tarball to the users home directory.voidfreezeContainer(java.lang.String name)Freezes an existing container with given name.java.lang.StringgetContainerSystemName()Returns the ContainerSystemName.java.lang.StringgetContainerSystemVersion()Returns the ContainerSystemVersion.private java.lang.StringgetImageAlias(LxcContainerDescriptor desc)Validates and returns the LXC image file name.au.com.jcloud.lxd.service.ILxdServicegetLxcClient()Returns a LXC API Client.private java.lang.StringgetLxcId(LxcContainerDescriptor desc)Validates and returns the LXC image file name.java.lang.StringgetLxcName(java.lang.String name)Returns an name of a LXC container with a givenname.java.lang.StringgetRuntimeName()private java.lang.StringgetZip(LxcContainerDescriptor desc)Validates and returns the LXC image file name.voidimportImage(java.lang.String tarball, java.lang.String imageAlias)Imports an image from an existing tarball to the local server.voidpublishImage(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.voidstartContainer(java.lang.String name)Starts an existing container with given name.voidstopContainer(java.lang.String name)Stops an existing container with given name.voidunfreezeContainer(java.lang.String name)Unfreezes an existing container with given name.voidupdateContainer(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
-
-
-
-
Field Detail
-
config
private static LxcSetup config
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
-
Method Detail
-
addContainer
public java.lang.String addContainer(java.net.URI location) throws java.util.concurrent.ExecutionExceptionAdds 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.ExecutionExceptionAdds 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
lxcHostin the configuration setup cannot be applied, e.g., a Linux socket path
-
startContainer
public void startContainer(java.lang.String name) throws java.util.concurrent.ExecutionExceptionStarts 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.ExecutionExceptionStops 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.ExecutionExceptionDeletes 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.ExecutionExceptionFreezes 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.ExecutionExceptionUnfreezes 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.ExecutionExceptionCreates a snapshot of a container with given name.- Parameters:
containerName- the name of the containersnapshot- 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.ExecutionExceptionPublishes an container and the corresponding snapshot as an image to the local server.- Parameters:
containerName- the name of the containersnapshot- the name of the corresponding snapshotimageAlias- the name that the image is going to getisPublic- 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.ExecutionExceptionExports 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.ExecutionExceptionImports an image from an existing tarball to the local server.- Parameters:
tarball- the path to the tarball/gzip fileimageAlias- 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.ExecutionExceptionCopy/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 storedremoteImage- the name of the image that is going to be copiedimageAlias- 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.ExecutionExceptionThis 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.ExecutionExceptionReturns an name of a LXC container with a givenname.- Parameters:
name- container's name- Returns:
- LXC container id/NULL
- Throws:
java.util.concurrent.ExecutionException- if connecting to LXC API Client failed
-
-