Class AbstractContainerManager<C extends ContainerDescriptor>

java.lang.Object
de.iip_ecosphere.platform.ecsRuntime.AbstractContainerManager<C>
Type Parameters:
C - the actual type of container descriptor
All Implemented Interfaces:
ContainerManager, ContainerOperations

public abstract class AbstractContainerManager<C extends ContainerDescriptor> extends Object implements ContainerManager
A basic re-usable implementation of the container manager. Implementations shall override at least undeployContainer(String), migrateContainer(String, String) and call the implementation of this class to perform the changes.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • AbstractContainerManager

      public AbstractContainerManager()
  • Method Details

    • getIds

      public Set<String> getIds()
      Description copied from interface: ContainerManager
      Returns the ids of all available containers.
      Specified by:
      getIds in interface ContainerManager
      Returns:
      the ids
    • getContainers

      public Collection<C> getContainers()
      Description copied from interface: ContainerManager
      Returns the available (installed) containers independent of their state.
      Specified by:
      getContainers in interface ContainerManager
      Returns:
      the container descriptors
    • getContainer

      public C getContainer(String id)
      Description copied from interface: ContainerManager
      Returns a container descriptor.
      Specified by:
      getContainer in interface ContainerManager
      Parameters:
      id - the id of the container (may be null or invalid)
      Returns:
      the related container descriptor or null if the container is not known at all
    • getId

      public String getId(URI location)
      Description copied from interface: ContainerOperations
      Returns the container id for a given container location as used in ContainerOperations.addContainer(URI).
      Specified by:
      getId in interface ContainerOperations
      Parameters:
      location - the location
      Returns:
      the id of the container, may be empty or nullnull if there is none
    • getState

      public ContainerState getState(String id)
      Description copied from interface: ContainerOperations
      Returns the state of the container.
      Specified by:
      getState in interface ContainerOperations
      Parameters:
      id - the id/URI of the container
      Returns:
      the state of the container
    • addContainer

      protected String addContainer(String id, C descriptor) throws ExecutionException
      Adds a container.
      Parameters:
      id - the container id
      descriptor - the container descriptor
      Returns:
      id
      Throws:
      ExecutionException - in case that the id is invalid or already known
    • undeployContainer

      public void undeployContainer(String id) throws ExecutionException
      Description copied from interface: ContainerOperations
      Removes the container from the management domain of this instance. This operation shall only remove the implementation of a non-operational container and, thus, perform a state transition to ContainerState.UNDEPLOYING and ultimately the container shall be removed and its descriptor shall not be available anymore.
      Specified by:
      undeployContainer in interface ContainerOperations
      Parameters:
      id - the id of the container to remove, or as fallback the canonical URI of the container descriptor used for adding
      Throws:
      ExecutionException - if undeploying the container fails, e.g., because it is still running
    • setState

      protected void setState(BasicContainerDescriptor container, ContainerState state) throws ExecutionException
      Changes the container state and notifies EcsAas.
      Parameters:
      container - the container
      state - the new state
      Throws:
      ExecutionException - if changing the state fails
      See Also:
    • getContainer

      protected C getContainer(String id, String idText, String activityText) throws ExecutionException
      Returns a service descriptor.
      Parameters:
      id - the service id, or the URI used to add the container as fallback
      idText - the id text to be passed to checkId(String, String)
      activityText - a description of the activity the service is requested for to construct an exception if the service does not exist
      Returns:
      the service (not null)
      Throws:
      ExecutionException - if id is invalid or the service is unknown
    • checkId

      protected void checkId(String id, String text) throws ExecutionException
      Checks the given id for basic validity.
      Parameters:
      id - the id to check
      text - the text to include into the exception
      Throws:
      ExecutionException - if id is not considered valid
    • migrateContainer

      public void migrateContainer(String id, String resourceId) throws ExecutionException
      Description copied from interface: ContainerOperations
      Migrates the container.
      Specified by:
      migrateContainer in interface ContainerOperations
      Parameters:
      id - the id of the container
      resourceId - the target resource id, e.g., a device
      Throws:
      ExecutionException - if migration fails
    • throwExecutionException

      protected void throwExecutionException(String action, Throwable th) throws ExecutionException
      Throws an execution exception for the given throwable.
      Parameters:
      action - the actual action to log (may be null or empty)
      th - the throwable
      Throws:
      ExecutionException - the constructed exception
    • throwExecutionException

      protected void throwExecutionException(String action, String message) throws ExecutionException
      Throws an execution exception for the given message.
      Parameters:
      action - the actual action to log (may be null or empty)
      message - the message for the exception
      Throws:
      ExecutionException - the constructed exception
    • resolveUri

      protected File resolveUri(URI uri, File downloadDir) throws IOException
      Resolves an URI taking EcsSetup.getArtifactInfixes() into account.
      Parameters:
      uri - the default/base URI to be resolved
      downloadDir - the directory to store resolved files, may be null for temporary files
      Returns:
      the resolve file
      Throws:
      IOException - if the uri ultimately cannot be resolved