Class ServicesAasClient
java.lang.Object
de.iip_ecosphere.platform.support.iip_aas.SubmodelClient
de.iip_ecosphere.platform.support.iip_aas.SubmodelElementsCollectionClient
de.iip_ecosphere.platform.services.ServicesAasClient
- All Implemented Interfaces:
ServiceOperations,ServicesClient
public class ServicesAasClient
extends de.iip_ecosphere.platform.support.iip_aas.SubmodelElementsCollectionClient
implements ServicesClient
A client for
ServicesAas for accessing the operations provided by a certain resource.- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
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.ServiceOperations
EXC_ALREADY_KNOWN, OPTION_ARGS, OPTION_ENSEMBLE, OPTION_MEMLIMITS, OPTION_PARAMS, OPTION_SERVERS -
Constructor Summary
ConstructorsConstructorDescriptionServicesAasClient(String resourceId) Creates a client instance based on a deployed IIP-AAS fromAasPartRegistrybased on a submodel withresources.ServicesAasClient(String resourceId, String appId) Creates a client instance based on a deployed IIP-AAS fromAasPartRegistrybased on a submodel withresources. -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateService(String serviceId) Activates the service.addArtifact(URI location) Adds an artifact (and transitively the contained services) to the management domain of this instance, e.g., by downloading it from an artifact/service store.addArtifactAsTask(String taskId, URI location) Adds an artifact (and transitively the contained services) to the management domain of this instance, e.g., by downloading it from an artifact/service store.private static booleanReturns whetherarraycontainselt.de.iip_ecosphere.platform.support.aas.SubmodelElementCollectionReturns the collection with all artifacts of the resources this client was created for.de.iip_ecosphere.platform.support.aas.SubmodelElementCollectionReturns the collection with all relations of the resources this client was created for.intgetServiceInstanceCount(String serviceId) Returns the number of service instances of the same service in the same application.de.iip_ecosphere.platform.support.aas.SubmodelElementCollectionReturns the collection with all services of the resources this client was created for.private voidgetServices(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection coll, String artifactId, List<String> serviceIds, boolean topLevelOnly) Collects the services associated to a givenartifactId.String[]getServices(String artifactId, boolean topLevelOnly) Returns the services associated to a givenartifactId.de.iip_ecosphere.platform.services.environment.ServiceStategetServiceState(String serviceId) Returns the state of the service.private intgetServiceStateCount(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection resource, de.iip_ecosphere.platform.services.environment.ServiceState state) Requests the number of services in the givenstateon the service manager submodel elements collectionresource.protected de.iip_ecosphere.platform.support.aas.SubmodelElementCollectionvoidmigrateService(String serviceId, String resourceId) Migrates a service.voidpassivateService(String serviceId) Passivates the service.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.voidremoveArtifactAsTask(String taskId, 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.voidstartService(String... serviceId) Starts one or multiple service.voidstartService(Map<String, String> options, String... serviceId) Starts one or multiple service.voidstartServiceAsTask(String taskId, String... serviceId) LikeServiceOperations.startService(String...)but reporting on the giventaskId.voidLikeServiceOperations.startService(Map, String...)but reporting on the giventaskId.voidstopService(String... serviceId) Stops one or multiple services.voidstopServiceAsTask(String taskId, String... serviceId) LikeServiceOperations.stopService(String...)but reporting on the giventaskId.streamLog(String serviceId, ServiceOperations.StreamLogMode mode) Tries to attach the logs ofserviceIdto a sender determined byTransportConverterFactory.voidswitchToService(String serviceId, String targetId) Switches to an interface-compatible service.voidupdateService(String serviceId, URI location) Updates the service by the service in the givenlocation.Methods inherited from class de.iip_ecosphere.platform.support.iip_aas.SubmodelElementsCollectionClient
getLogger, getOperation, getPropertyMethods inherited from class de.iip_ecosphere.platform.support.iip_aas.SubmodelClient
checkNotNull, checkString, clear, getOperation, getProperty, getPropertyStringValue, getSubmodel, requestRefresh
-
Field Details
-
appId
-
-
Constructor Details
-
ServicesAasClient
Creates a client instance based on a deployed IIP-AAS fromAasPartRegistrybased on a submodel withresources.- Parameters:
resourceId- the id used as key inServicesAas.NAME_SUBMODEL_RESOURCESto denote the resource to operate on- Throws:
IOException- if retrieving the IIP-AAS or the respective submodel fails
-
ServicesAasClient
Creates a client instance based on a deployed IIP-AAS fromAasPartRegistrybased on a submodel withresources.- Parameters:
resourceId- the id used as key inServicesAas.NAME_SUBMODEL_RESOURCESto denote the resource to operate onappId- optional app id to select the service manager to use, may be empty or null for the first/fallback manager- Throws:
IOException- if retrieving the IIP-AAS or the respective submodel fails
-
-
Method Details
-
getSubmodelElementCollection
protected de.iip_ecosphere.platform.support.aas.SubmodelElementCollection getSubmodelElementCollection()- Overrides:
getSubmodelElementCollectionin classde.iip_ecosphere.platform.support.iip_aas.SubmodelElementsCollectionClient
-
contains
Returns whetherarraycontainselt.- Parameters:
array- the array to searchelt- the element to search for- Returns:
trueif contained,falseelse
-
addArtifact
Description copied from interface:ServiceOperationsAdds an artifact (and transitively the contained services) to the management domain of this instance, e.g., by downloading it from an artifact/service store. This defines theidof the service within the management domain of this instance. After a successful execution, the artifactidis returned, artifact and service(s) shall be available and the service(s) shall be in stateServiceState.AVAILABLE.- Specified by:
addArtifactin interfaceServiceOperations- Parameters:
location- the location from where to download the service, e.g., an URL- Returns:
- the id of the artifact
- Throws:
ExecutionException- in case that adding the service fails for some reason
-
addArtifactAsTask
Description copied from interface:ServicesClientAdds an artifact (and transitively the contained services) to the management domain of this instance, e.g., by downloading it from an artifact/service store. This defines theidof the service within the management domain of this instance. After a successful execution, the artifactidis returned, artifact and service(s) shall be available and the service(s) shall be in stateServiceState.AVAILABLE.- Specified by:
addArtifactAsTaskin interfaceServicesClient- Parameters:
taskId- the task id to report on (may be null, leads toServiceOperations.addArtifact(URI))location- the location from where to download the service, e.g., an URL- Returns:
- the id of the artifact
- Throws:
ExecutionException- in case that adding the service fails for some reason
-
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
-
removeArtifactAsTask
Description copied from interface:ServicesClientRemoves 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:
removeArtifactAsTaskin interfaceServicesClient- Parameters:
taskId- the task id to report on (may be null, leads toServiceOperations.removeArtifact(String))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
-
updateService
Description copied from interface:ServiceOperationsUpdates the service by the service in the givenlocation. This operation is responsible for stopping the running service (if needed), replacing it, starting the new service.- Specified by:
updateServicein interfaceServiceOperations- Parameters:
serviceId- the id of the service to be updatedlocation- the location of the new service, e.g., an URL- Throws:
ExecutionException- if the given service cannot be updated for some reason, e.g., because the replacement service is not an evolved version of the running service
-
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
-
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
-
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
-
startService
Description copied from interface:ServiceOperationsStarts one or multiple service. The service implementation must be already within the management domain of this instance byServiceOperations.addArtifact(URI). The service(s) shall after some time be in stateServiceState.STARTING,ServiceState.RUNNINGorServiceState.FAILED.- Specified by:
startServicein interfaceServiceOperations- Parameters:
serviceId- the id(s) of the service(s)- Throws:
ExecutionException- in case that starting the service fails for some reason
-
startService
Description copied from interface:ServiceOperationsStarts one or multiple service. The service implementation must be already within the management domain of this instance byServiceOperations.addArtifact(URI). The service(s) shall after some time be in stateServiceState.STARTING,ServiceState.RUNNINGorServiceState.FAILED.- Specified by:
startServicein interfaceServiceOperations- Parameters:
options- optional map of optional options to be passed to the service manager, may modify the service descriptors, e.g., to change services to be started together on demand, may be empty for none; options are a name-value mapping with values that come either as primitive values or as JSON structures. For pre-defined names, seeServiceOperations.OPTION_ARGS,ServiceOperations.OPTION_ENSEMBLE,ServiceOperations.OPTION_PARAMS,ServiceOperations.OPTION_SERVERS, orServiceOperations.OPTION_MEMLIMITS. The service manager is responsible for correct JSON de-serialization.serviceId- the id(s) of the service(s)- Throws:
ExecutionException- in case that starting the service fails for some reason- See Also:
-
stopService
Description copied from interface:ServiceOperationsStops one or multiple services. The service shall afterwards be in stateServiceState.STOPPED.- Specified by:
stopServicein interfaceServiceOperations- Parameters:
serviceId- the id(s) of the service(s) to stop- Throws:
ExecutionException- if stopping the service fails
-
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
-
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
-
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
-
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
-
streamLog
public String streamLog(String serviceId, ServiceOperations.StreamLogMode mode) throws ExecutionException Description copied from interface:ServiceOperationsTries to attach the logs ofserviceIdto a sender determined byTransportConverterFactory.- Specified by:
streamLogin interfaceServiceOperations- Parameters:
serviceId- the service idmode- the mode- Returns:
- the URIs where to find the (streamed) log as JSON list or empty
- Throws:
ExecutionException- if attaching fails
-
getServices
Description copied from interface:ServicesClientReturns the services associated to a givenartifactId.- Specified by:
getServicesin interfaceServicesClient- Parameters:
artifactId- the artifactId to search fortopLevelOnly- whether only top-level services or all shall be returned- Returns:
- the associated service ids, empty if none was found
-
getServices
private void getServices(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection coll, String artifactId, List<String> serviceIds, boolean topLevelOnly) Collects the services associated to a givenartifactId.- Parameters:
coll- the collection containing the servicesartifactId- the artifactId to search forserviceIds- the service ids to be modified as a side effecttopLevelOnly- whether only top-level services or all services shall be returned
-
getArtifacts
public de.iip_ecosphere.platform.support.aas.SubmodelElementCollection getArtifacts()Description copied from interface:ServicesClientReturns the collection with all artifacts of the resources this client was created for.- Specified by:
getArtifactsin interfaceServicesClient- Returns:
- the artifacts collection, may be null for none
-
getServices
public de.iip_ecosphere.platform.support.aas.SubmodelElementCollection getServices()Description copied from interface:ServicesClientReturns the collection with all services of the resources this client was created for.- Specified by:
getServicesin interfaceServicesClient- Returns:
- the services collection, may be null for none
-
getRelations
public de.iip_ecosphere.platform.support.aas.SubmodelElementCollection getRelations()Returns the collection with all relations of the resources this client was created for.- Returns:
- the relations collection, may be null for none
-
startServiceAsTask
Description copied from interface:ServicesClientLikeServiceOperations.startService(String...)but reporting on the giventaskId.- Specified by:
startServiceAsTaskin interfaceServicesClient- Parameters:
taskId- the task id to report on (may be null, leads toServiceOperations.startService(String...))serviceId- the id(s) of the service(s)- Throws:
ExecutionException- in case that starting the service fails for some reason
-
startServiceAsTask
public void startServiceAsTask(String taskId, Map<String, String> options, String... serviceId) throws ExecutionExceptionDescription copied from interface:ServicesClientLikeServiceOperations.startService(Map, String...)but reporting on the giventaskId.- Specified by:
startServiceAsTaskin interfaceServicesClient- Parameters:
taskId- the task id to report on (may be null, leads toServiceOperations.startService(Map, String...))options- optional map of optional options, seeServiceOperations.startService(Map, String...)serviceId- the id(s) of the service(s)- Throws:
ExecutionException- in case that starting the service fails for some reason
-
stopServiceAsTask
Description copied from interface:ServicesClientLikeServiceOperations.stopService(String...)but reporting on the giventaskId.- Specified by:
stopServiceAsTaskin interfaceServicesClient- Parameters:
taskId- the task id to report on (may be null, leads toServiceOperations.stopService(String...))serviceId- the id(s) of the service(s) to stop- Throws:
ExecutionException- if stopping the service fails
-
getServiceStateCount
private int getServiceStateCount(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection resource, de.iip_ecosphere.platform.services.environment.ServiceState state) Requests the number of services in the givenstateon the service manager submodel elements collectionresource.- Parameters:
resource- the submodel elements collection representing a service managerstate- the state to query for- Returns:
- the number of service instances
-
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
-