Class AbstractServiceManager<A extends AbstractArtifactDescriptor<S>,S extends AbstractServiceDescriptor<A>>
java.lang.Object
de.iip_ecosphere.platform.services.AbstractServiceManager<A,S>
- Type Parameters:
A- the actual type of the artifact descriptorS- the actual type of the service descriptor
- All Implemented Interfaces:
ServiceManager,ServiceOperations
public abstract class AbstractServiceManager<A extends AbstractArtifactDescriptor<S>,S extends AbstractServiceDescriptor<A>>
extends Object
implements ServiceManager
A basic re-usable implementation of the service manager. Implementations shall override at least
switchToService(String, String), migrateService(String, String)
and call the implementation of this class to perform the changes. Implementations shall call the notify methods
in ServicesAas.- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classWraps aTypedDataConnectorDescriptorto adjust the service (depending from the direction of traversal/creation).Nested classes/interfaces inherited from interface de.iip_ecosphere.platform.services.ServiceOperations
ServiceOperations.StreamLogMode -
Field Summary
FieldsFields inherited from interface de.iip_ecosphere.platform.services.ServiceManager
PROGRESS_COMPONENT_IDFields inherited from interface de.iip_ecosphere.platform.services.ServiceOperations
EXC_ALREADY_KNOWN, OPTION_ARGS, OPTION_ENSEMBLE, OPTION_MEMLIMITS, OPTION_PARAMS, OPTION_SERVERS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateService(String serviceId) Activates the service.protected StringaddArtifact(String artifactId, A descriptor) Adds an artifact.protected static voidChecks the givenidfor basic validity.checkServiceInstances(String[] sId) Checks for service instances regarding application id and application instance id.voidclear()Clears the internal data.private static final booleancontainsIdSafe(Collection<String> coll, String id) Returns whethercollcontainsid.determineExternalConnections(ServiceManager mgr, String... serviceIds) Determines the external connections of the given services.determineFunctionalConnections(ServiceManager mgr, String... serviceIds) Determines all connections characterizing the functional output/input services inserviceIds.determineInternalConnections(ServiceManager mgr, String... serviceIds) Determines all connections withinserviceIds.getArtifact(String artifactId) Returns an artifact descriptor.protected AgetArtifactDescriptor(String artifactId, String idText, String activityText) Returns a service descriptor.Returns the ids of all available artifacts.Returns the available (installed) artifacts.protected abstract Predicate<TypedDataConnectorDescriptor> Returns the available connector testing predicate.getInputDataConnectors(String serviceId) Returns all input connector information for the givenserviceId.getOutputDataConnectors(String serviceId) Returns all output connector information for the givenserviceId.getParameters(String serviceId) Returns all information about parameter for the givenserviceId.getService(String serviceId) Returns a service descriptor.protected SgetServiceDescriptor(String serviceId, String idText, String activityText) Returns a service descriptor.Returns the ids of all available services.intgetServiceInstanceCount(String serviceId) Returns the number of service instances of the same service in the same application.Returns the available (installed) services in all artifacts.de.iip_ecosphere.platform.services.environment.ServiceStategetServiceState(String serviceId) Returns the state of the service.protected de.iip_ecosphere.platform.services.environment.ServiceStubReturns the service stub for implementing the service operations.protected voidHandles the services instantiated incheckServiceInstances(String[])by adding them to the Services AAS.protected abstract SinstantiateFromTemplate(S template, String serviceId) Creates a service instance descriptor fromtemplate.protected static final booleanReturns whether the givenidis structurally valid, i.e., not null and not empty.protected static final booleanisValidIdBut(String id, String butId) Returns whether the givenidis structurally valid, i.e., not null and not empty, but notbutId.voidmigrateService(String serviceId, String resourceId) Migrates a service.voidpassivateService(String serviceId) Passivates the service.static String[]pruneServers(ServiceManager mgr, String... serviceIds) Returns only non-server services fromserviceIds, i.e., only instances that can be identified as server are pruned.voidreconfigureService(String serviceId, Map<String, String> values) Reconfigures the underlying service.voidremoveArtifact(String artifactId) Removes the artifact (and transitively its services) from the management domain of this instance.voidsetServiceState(String serviceId, de.iip_ecosphere.platform.services.environment.ServiceState state) Sets the state of the service.protected voidsetState(ServiceDescriptor service, de.iip_ecosphere.platform.services.environment.ServiceState state) Changes the service state and notifiesServicesAas.protected String[]sortByDependency(String[] serviceIds, boolean start) Sorts the given list by the dependencies specified in the deployment descriptor.static <S extends ServiceDescriptor>
List<S> sortByDependency(List<S> services, Collection<? extends ServiceDescriptor> localServices, Predicate<TypedDataConnectorDescriptor> available, boolean reverse) Sorts a list of services by their dependencies, considering prerequisite input nodes outside the own ensemble.voidswitchToService(String serviceId, String targetId) Switches to an interface-compatible service.static String[]topLevel(ServiceManager mgr, String... serviceIds) Returns only top-level services fromserviceIds.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.iip_ecosphere.platform.services.ServiceManager
cloneArtifactMethods inherited from interface de.iip_ecosphere.platform.services.ServiceOperations
addArtifact, startService, startService, stopService, streamLog, updateService
-
Field Details
-
artifacts
-
-
Constructor Details
-
AbstractServiceManager
public AbstractServiceManager()
-
-
Method Details
-
getAvailablePredicate
Returns the available connector testing predicate.- Returns:
- the predicate
-
getArtifactIds
Description copied from interface:ServiceManagerReturns the ids of all available artifacts.- Specified by:
getArtifactIdsin interfaceServiceManager- Returns:
- the ids
-
getArtifacts
Description copied from interface:ServiceManagerReturns the available (installed) artifacts.- Specified by:
getArtifactsin interfaceServiceManager- Returns:
- the services
-
getServiceIds
Description copied from interface:ServiceManagerReturns the ids of all available services.- Specified by:
getServiceIdsin interfaceServiceManager- Returns:
- the ids
-
getServices
Description copied from interface:ServiceManagerReturns the available (installed) services in all artifacts.- Specified by:
getServicesin interfaceServiceManager- Returns:
- the services
-
getArtifact
Description copied from interface:ServiceManagerReturns an artifact descriptor.- Specified by:
getArtifactin interfaceServiceManager- Parameters:
artifactId- the id of the service (may be null or invalid)- Returns:
- the related artifact descriptor or null if the artifact does not exist
-
getService
Description copied from interface:ServiceManagerReturns a service descriptor.- Specified by:
getServicein interfaceServiceManager- Parameters:
serviceId- the id of the service (may be null or invalid)- Returns:
- the related service descriptor or null if the service does not exist
-
getServiceState
public de.iip_ecosphere.platform.services.environment.ServiceState getServiceState(String serviceId) Description copied from interface:ServiceOperationsReturns the state of the service.- Specified by:
getServiceStatein interfaceServiceOperations- Parameters:
serviceId- the id of the running service- Returns:
- the state of the service
-
addArtifact
Adds an artifact.- Parameters:
artifactId- the artifact iddescriptor- the service descriptor- Returns:
artifactId- Throws:
ExecutionException- in case that the id is invalid or already known
-
removeArtifact
Description copied from interface:ServiceOperationsRemoves the artifact (and transitively its services) from the management domain of this instance. This operation shall only remove the implementation of non-operational services and, thus, perform a state transition toServiceState.UNDEPLOYINGand ultimately the service(s) shall be removed and their descriptors (including the artifact descriptor) shall not be available anymore.- Specified by:
removeArtifactin interfaceServiceOperations- Parameters:
artifactId- the id of the artifact to remove, or as fallback the canonical URI of the artifact- Throws:
ExecutionException- if removing the service fails, e.g., because it is still running
-
isValidId
Returns whether the givenidis structurally valid, i.e., not null and not empty.- Parameters:
id- the id to check- Returns:
trueifidis valid,falseelse
-
isValidIdBut
Returns whether the givenidis structurally valid, i.e., not null and not empty, but notbutId.- Parameters:
id- the id to checkbutId- the id to exclude- Returns:
trueifidis valid,falseelse
-
checkId
Checks the givenidfor basic validity.- Parameters:
id- the id to checktext- the text to include into the exception- Throws:
ExecutionException- ifidis not considered valid- See Also:
-
switchToService
Description copied from interface:ServiceOperationsSwitches to an interface-compatible service. This method cares for stopping the old service, performing a handover if adequate, starting thetargetservice. [adaptation]- Specified by:
switchToServicein interfaceServiceOperations- Parameters:
serviceId- the id of the running servicetargetId- the id of the target service- Throws:
ExecutionException- if switching the service cannot be performed for some reason
-
migrateService
Description copied from interface:ServiceOperationsMigrates a service. However, it may be required to migrate/move the containing artifact. [adaptation]- Specified by:
migrateServicein interfaceServiceOperations- Parameters:
serviceId- the id of the serviceresourceId- the target resource id, e.g., a device- Throws:
ExecutionException- if migration fails
-
passivateService
Description copied from interface:ServiceOperationsPassivates the service. [adaptation]- Specified by:
passivateServicein interfaceServiceOperations- Parameters:
serviceId- the id of the running service- Throws:
ExecutionException- in case that passivating fails, e.g., because the service is already passive
-
activateService
Description copied from interface:ServiceOperationsActivates the service. [adaptation]- Specified by:
activateServicein interfaceServiceOperations- Parameters:
serviceId- the id of the running service- Throws:
ExecutionException- in case that activating fails, e.g., because the service is already active
-
reconfigureService
public void reconfigureService(String serviceId, Map<String, String> values) throws ExecutionExceptionDescription copied from interface:ServiceOperationsReconfigures the underlying service. [adaptation]- Specified by:
reconfigureServicein interfaceServiceOperations- Parameters:
serviceId- the serviceId of the running servicevalues- the (service-specific) name-value mapping that shall lead to a reconfiguration of the service; values come either as primitive values or as JSON structures complying with the parameter descriptor. The service is responsible for correct JSON de-serialization according to the respectivedescriptor- Throws:
ExecutionException- if reconfiguration fails
-
getStub
Returns the service stub for implementing the service operations.- Parameters:
service- the service to return the stub for- Returns:
- the stub, may be null if the service is not running
-
getArtifactDescriptor
protected A getArtifactDescriptor(String artifactId, String idText, String activityText) throws ExecutionException Returns a service descriptor.- Parameters:
artifactId- the artifact ididText- the id text to be passed tocheckId(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
-
getServiceDescriptor
protected S getServiceDescriptor(String serviceId, String idText, String activityText) throws ExecutionException Returns a service descriptor.- Parameters:
serviceId- the service ididText- the id text to be passed tocheckId(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
-
setServiceState
public void setServiceState(String serviceId, de.iip_ecosphere.platform.services.environment.ServiceState state) throws ExecutionException Description copied from interface:ServiceOperationsSets the state of the service. [adaptation]- Specified by:
setServiceStatein interfaceServiceOperations- Parameters:
serviceId- the id of the running servicestate- the new state of the service- Throws:
ExecutionException- if changing to the target state is not possible
-
setState
protected void setState(ServiceDescriptor service, de.iip_ecosphere.platform.services.environment.ServiceState state) throws ExecutionException Changes the service state and notifiesServicesAas.- Parameters:
service- the servicestate- the new state- Throws:
ExecutionException- if changing the state fails
-
getParameters
Description copied from interface:ServiceManagerReturns all information about parameter for the givenserviceId. [adaptation]- Specified by:
getParametersin interfaceServiceManager- Parameters:
serviceId- the serviceId of the service- Returns:
- the descriptors for all supported parameters
-
getInputDataConnectors
Description copied from interface:ServiceManagerReturns all input connector information for the givenserviceId.- Specified by:
getInputDataConnectorsin interfaceServiceManager- Parameters:
serviceId- the serviceId of the service- Returns:
- the descriptors for all input data connectors
-
getOutputDataConnectors
Description copied from interface:ServiceManagerReturns all output connector information for the givenserviceId.- Specified by:
getOutputDataConnectorsin interfaceServiceManager- Parameters:
serviceId- the serviceId of the service- Returns:
- the descriptors for all output data connectors
-
sortByDependency
Sorts the given list by the dependencies specified in the deployment descriptor.- Parameters:
serviceIds- the service ids to sortstart- sequence for service start- Returns:
- the sorted service ids
-
sortByDependency
public static <S extends ServiceDescriptor> List<S> sortByDependency(List<S> services, Collection<? extends ServiceDescriptor> localServices, Predicate<TypedDataConnectorDescriptor> available, boolean reverse) Sorts a list of services by their dependencies, considering prerequisite input nodes outside the own ensemble. Ensemble nodes are simply listed after their ensemble leader. [public, static for testing]- Type Parameters:
S- the service type- Parameters:
services- the services to sortlocalServices- all known local services includingservicesavailable- the available predicatereverse- reverse the order (for stopping)- Returns:
- the list of sorted services
-
containsIdSafe
Returns whethercollcontainsid.- Parameters:
coll- the collection to search withinid- the id to search for, may be null or empty- Returns:
falseifthe id is not valid, whether it is contained incollelse
-
determineExternalConnections
public static Set<AbstractServiceManager.TypedDataConnection> determineExternalConnections(ServiceManager mgr, String... serviceIds) Determines the external connections of the given services.- Parameters:
mgr- the service managerserviceIds- the services to determine the connections for- Returns:
- the external connections
-
determineInternalConnections
public static Set<AbstractServiceManager.TypedDataConnection> determineInternalConnections(ServiceManager mgr, String... serviceIds) Determines all connections withinserviceIds.- Parameters:
mgr- the service managerserviceIds- the services to determine the connections for- Returns:
- the internal connections
-
determineFunctionalConnections
public static Set<AbstractServiceManager.TypedDataConnection> determineFunctionalConnections(ServiceManager mgr, String... serviceIds) Determines all connections characterizing the functional output/input services inserviceIds.- Parameters:
mgr- the service managerserviceIds- the services to determine the connections for- Returns:
- the internal connections
-
topLevel
Returns only top-level services fromserviceIds.- Parameters:
mgr- the service manager to take the descriptors fromserviceIds- the service ids to filter out- Returns:
serviceIdsor a subset ofserviceIds
-
pruneServers
Returns only non-server services fromserviceIds, i.e., only instances that can be identified as server are pruned.- Parameters:
mgr- the service manager to take the descriptors fromserviceIds- the service ids to filter out- Returns:
serviceIdsor a subset ofserviceIds
-
checkServiceInstances
Checks for service instances regarding application id and application instance id. If needed, creates instances using existing service descriptors as templates viainstantiateFromTemplate(AbstractServiceDescriptor, String). CallhandleInstantiatedServices(Iterable)on the result, immediately or after further initializations are done.- Parameters:
sId- service ids to check- Returns:
- the instantiated services
-
handleInstantiatedServices
Handles the services instantiated incheckServiceInstances(String[])by adding them to the Services AAS.- Parameters:
sId- the instantiated service ids, may be empty
-
instantiateFromTemplate
Creates a service instance descriptor fromtemplate. Application and application instance id shall matchtemplate.- Parameters:
template- the service descriptor templateserviceId- the service id, usually including application id and application instance id- Returns:
- the instantiated descriptor
-
clear
public void clear()Clears the internal data. [testing] -
getServiceInstanceCount
Description copied from interface:ServiceOperationsReturns the number of service instances of the same service in the same application.- Specified by:
getServiceInstanceCountin interfaceServiceOperations- Parameters:
serviceId- the service id, application instance id is ignored if not given- Returns:
- 0 if there is no other service instance, 1 if no applicationId is given in
serviceIdbut there is a service with the same id, the number of instances otherwise
-