Class SpringCloudServiceManager
- java.lang.Object
-
- de.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
-
- de.iip_ecosphere.platform.services.spring.SpringCloudServiceManager
-
- All Implemented Interfaces:
de.iip_ecosphere.platform.services.ServiceManager,de.iip_ecosphere.platform.services.ServiceOperations
@Component @Import(SpringCloudServiceSetup.class) public class SpringCloudServiceManager extends de.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
Service manager for Spring Cloud Stream. RequiresSpringInstancesset correctly before use.- Author:
- Holger Eichelberger, SSE
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSpringCloudServiceManager.SpringCloudServiceFactoryDescriptorDescriptor for creating the service manager instance.
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Predicate<de.iip_ecosphere.platform.services.TypedDataConnectorDescriptor>availableprivate static org.slf4j.LoggerLOGGERprivate java.util.function.Supplier<de.iip_ecosphere.platform.support.net.NetworkManager>networkManagerSupplierstatic java.lang.StringOPT_SERVICE_PREFIXprivate static java.lang.StringPROGRESS_COMPONENT_IDprivate java.util.Map<SpringCloudServiceDescriptor,de.iip_ecosphere.platform.support.Server>runningServers
-
Constructor Summary
Constructors Modifier Constructor Description privateSpringCloudServiceManager()Prevents external creation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddAppId(java.lang.String serviceId, java.util.List<java.lang.String> cmdArgs)Turns the application (instance) id into a command line argument.java.lang.StringaddArtifact(java.net.URI location)private voidcheckErrors(java.util.List<java.lang.String> errors)Checks the given errors list.voidclear()voidcloneArtifact(java.lang.String artifactId, java.net.URI location)private java.util.List<java.lang.String>determineBindingServiceArgs(java.lang.String... serviceIds)Determines the command line arguments to adjust service connections from "internal" to "external" binder.private java.lang.StringdetermineCloudFunctionArg(java.lang.String... serviceIds)Determines the cloud function argument for the given services.static java.util.List<java.lang.String>determineSpringConditionals(de.iip_ecosphere.platform.services.ServiceManager mgr, java.lang.String... serviceIds)Determines the command line values for the spring component conditionals.protected java.util.function.Predicate<de.iip_ecosphere.platform.services.TypedDataConnectorDescriptor>getAvailablePredicate()private static java.util.Set<java.lang.String>getThisDeviceHostIds()String returns the host names/ids to be considered equal for this (the executing) device.private voidhandleFamilyProcesses(java.lang.String[] serviceIds, boolean start)Prepares the processes of the family members.private static voidhandleOptionEnsemble(java.lang.String opt, java.lang.String[] serviceIds, de.iip_ecosphere.platform.services.ServiceManager mgr)Handles the ensemble option for service start.static voidhandleOptions(java.util.Map<java.lang.String,java.lang.String> options, de.iip_ecosphere.platform.services.ServiceManager mgr, java.lang.String... serviceIds)Handles service start options.private voidhandleOptions(java.util.Map<java.lang.String,java.lang.String> options, java.lang.String[] serviceIds)Handles service start options.protected SpringCloudServiceDescriptorinstantiateFromTemplate(SpringCloudServiceDescriptor template, java.lang.String serviceId)private de.iip_ecosphere.platform.support.net.NetworkManagermarkServerUse(boolean started, SpringCloudServiceDescriptor service, boolean register, de.iip_ecosphere.platform.support.net.NetworkManager netClient)Marks the use of a server by a service.voidmigrateService(java.lang.String serviceId, java.lang.String resourceId)private static voidreconfigure(SpringCloudServiceDescriptor service, boolean started, java.util.Map<java.lang.String,java.lang.String> options)Reconfiguresserviceifstartedwith .voidremoveArtifact(java.lang.String artifactId)private java.lang.String[]serviceAndEnsemble(java.lang.String id, java.lang.String[] serviceIds)Returns the lead and ensemble services of serviceid(viewingidas potential ensemble leader) from a given set of services.java.util.function.Supplier<de.iip_ecosphere.platform.support.net.NetworkManager>setNetworkManagerClientSupplier(java.util.function.Supplier<de.iip_ecosphere.platform.support.net.NetworkManager> supplier)Changes the network manager supplier.protected voidsetState(de.iip_ecosphere.platform.services.ServiceDescriptor service, de.iip_ecosphere.platform.services.environment.ServiceState state)protected voidsetStateSafe(de.iip_ecosphere.platform.services.ServiceDescriptor service, de.iip_ecosphere.platform.services.environment.ServiceState state)CallssetState(ServiceDescriptor, ServiceState)logging exceptions.private voidstartServers(java.util.Map<java.lang.String,java.lang.String> options)Starting server instances.voidstartService(java.lang.String... serviceIds)voidstartService(java.util.Map<java.lang.String,java.lang.String> options, java.lang.String... serviceIds)private voidstopServers()Stopping server instances.voidstopService(java.lang.String... serviceIds)voidswitchToService(java.lang.String serviceId, java.lang.String target)voidupdateService(java.lang.String serviceId, java.net.URI location)private org.springframework.cloud.deployer.spi.app.DeploymentStatewaitFor(java.lang.String id, org.springframework.cloud.deployer.spi.app.DeploymentState initState, java.util.function.Predicate<org.springframework.cloud.deployer.spi.app.DeploymentState> endCond)Waits for completing a deployer operation.-
Methods inherited from class de.iip_ecosphere.platform.services.AbstractServiceManager
activateService, addArtifact, checkId, checkServiceInstances, determineExternalConnections, determineFunctionalConnections, determineInternalConnections, getArtifact, getArtifactDescriptor, getArtifactIds, getArtifacts, getInputDataConnectors, getOutputDataConnectors, getParameters, getService, getServiceDescriptor, getServiceIds, getServiceInstanceCount, getServices, getServiceState, getStub, isValidId, isValidIdBut, passivateService, pruneServers, reconfigureService, setServiceState, sortByDependency, sortByDependency, topLevel
-
-
-
-
Field Detail
-
OPT_SERVICE_PREFIX
public static final java.lang.String OPT_SERVICE_PREFIX
- See Also:
- Constant Field Values
-
PROGRESS_COMPONENT_ID
private static final java.lang.String PROGRESS_COMPONENT_ID
- See Also:
- Constant Field Values
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
available
private java.util.function.Predicate<de.iip_ecosphere.platform.services.TypedDataConnectorDescriptor> available
-
runningServers
private java.util.Map<SpringCloudServiceDescriptor,de.iip_ecosphere.platform.support.Server> runningServers
-
networkManagerSupplier
private java.util.function.Supplier<de.iip_ecosphere.platform.support.net.NetworkManager> networkManagerSupplier
-
-
Method Detail
-
setNetworkManagerClientSupplier
public java.util.function.Supplier<de.iip_ecosphere.platform.support.net.NetworkManager> setNetworkManagerClientSupplier(java.util.function.Supplier<de.iip_ecosphere.platform.support.net.NetworkManager> supplier)
Changes the network manager supplier. [testing]- Parameters:
supplier- the new supplier, ignored if null- Returns:
- the supplier before applying this function/changing the actual value
-
getAvailablePredicate
protected java.util.function.Predicate<de.iip_ecosphere.platform.services.TypedDataConnectorDescriptor> getAvailablePredicate()
- Specified by:
getAvailablePredicatein classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
-
addArtifact
public java.lang.String addArtifact(java.net.URI location) throws java.util.concurrent.ExecutionException- Throws:
java.util.concurrent.ExecutionException
-
determineBindingServiceArgs
private java.util.List<java.lang.String> determineBindingServiceArgs(java.lang.String... serviceIds)
Determines the command line arguments to adjust service connections from "internal" to "external" binder.- Parameters:
serviceIds- the services to determine the arguments for- Returns:
- the command line arguments
- See Also:
AbstractServiceManager.determineExternalConnections(ServiceManager, String...)
-
determineCloudFunctionArg
private java.lang.String determineCloudFunctionArg(java.lang.String... serviceIds)
Determines the cloud function argument for the given services.- Parameters:
serviceIds- the services to determine the arguments for- Returns:
- the command line arguments
- See Also:
AbstractServiceManager.determineFunctionalConnections(ServiceManager, String...)
-
determineSpringConditionals
public static java.util.List<java.lang.String> determineSpringConditionals(de.iip_ecosphere.platform.services.ServiceManager mgr, java.lang.String... serviceIds)Determines the command line values for the spring component conditionals. [public, static for testing]- Parameters:
mgr- the manager instanceserviceIds- the services to determine the arguments for- Returns:
- the arguments
-
serviceAndEnsemble
private java.lang.String[] serviceAndEnsemble(java.lang.String id, java.lang.String[] serviceIds)Returns the lead and ensemble services of serviceid(viewingidas potential ensemble leader) from a given set of services.- Parameters:
id- the service to return the lead/ensemble services forserviceIds- the services to project the result from- Returns:
idand connected ensemble services stated inserviceIds
-
startService
public void startService(java.lang.String... serviceIds) throws java.util.concurrent.ExecutionException- Throws:
java.util.concurrent.ExecutionException
-
handleOptions
private void handleOptions(java.util.Map<java.lang.String,java.lang.String> options, java.lang.String[] serviceIds)Handles service start options.- Parameters:
options- the optionsserviceIds- the service ids to start
-
handleOptions
public static void handleOptions(java.util.Map<java.lang.String,java.lang.String> options, de.iip_ecosphere.platform.services.ServiceManager mgr, java.lang.String... serviceIds)Handles service start options. [public, static for testing]- Parameters:
options- the optionsserviceIds- the service ids to startmgr- the service manager
-
handleOptionEnsemble
private static void handleOptionEnsemble(java.lang.String opt, java.lang.String[] serviceIds, de.iip_ecosphere.platform.services.ServiceManager mgr)Handles the ensemble option for service start.- Parameters:
opt- the option as JSON stringserviceIds- the service ids to startmgr- the service manager
-
addAppId
public static void addAppId(java.lang.String serviceId, java.util.List<java.lang.String> cmdArgs)Turns the application (instance) id into a command line argument.- Parameters:
serviceId- the service id to take the application (instance) id fromcmdArgs- the command line arguments
-
getThisDeviceHostIds
private static java.util.Set<java.lang.String> getThisDeviceHostIds()
String returns the host names/ids to be considered equal for this (the executing) device.- Returns:
- the ids
-
startServers
private void startServers(java.util.Map<java.lang.String,java.lang.String> options)
Starting server instances.- Parameters:
options- optional map of optional options to be passed to the service manager, {@see #startService(Map, String...)}- See Also:
getThisDeviceHostIds()
-
stopServers
private void stopServers()
Stopping server instances.
-
markServerUse
private de.iip_ecosphere.platform.support.net.NetworkManager markServerUse(boolean started, SpringCloudServiceDescriptor service, boolean register, de.iip_ecosphere.platform.support.net.NetworkManager netClient)Marks the use of a server by a service.- Parameters:
started- was the service started; if not, ignore callservice- the service to markregister- register or unregister the server usenetClient- the network client used for marking, may be null- Returns:
- the network client used for marking, for instance reuse, may be null
-
reconfigure
private static void reconfigure(SpringCloudServiceDescriptor service, boolean started, java.util.Map<java.lang.String,java.lang.String> options) throws java.util.concurrent.ExecutionException
Reconfiguresserviceifstartedwith .- Parameters:
service- the service to be reconfiguredstarted- whether it was (just) startedoptions- the options to reconfigure (serviceId/name/value)- Throws:
java.util.concurrent.ExecutionException- if reconfiguration failed
-
startService
public void startService(java.util.Map<java.lang.String,java.lang.String> options, java.lang.String... serviceIds) throws java.util.concurrent.ExecutionException- Throws:
java.util.concurrent.ExecutionException
-
instantiateFromTemplate
protected SpringCloudServiceDescriptor instantiateFromTemplate(SpringCloudServiceDescriptor template, java.lang.String serviceId)
- Specified by:
instantiateFromTemplatein classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
-
handleFamilyProcesses
private void handleFamilyProcesses(java.lang.String[] serviceIds, boolean start) throws java.util.concurrent.ExecutionExceptionPrepares the processes of the family members.- Parameters:
serviceIds- the service ids of the top-level services to be startedstart- do startup or shutdown of the family services- Throws:
java.util.concurrent.ExecutionException- when preparing the service fails for some reason
-
checkErrors
private void checkErrors(java.util.List<java.lang.String> errors) throws java.util.concurrent.ExecutionExceptionChecks the given errors list. If there are errors, composes a message and throws an exception.- Parameters:
errors- the errors to check for- Throws:
java.util.concurrent.ExecutionException- an exception if there are errors
-
waitFor
private org.springframework.cloud.deployer.spi.app.DeploymentState waitFor(java.lang.String id, org.springframework.cloud.deployer.spi.app.DeploymentState initState, java.util.function.Predicate<org.springframework.cloud.deployer.spi.app.DeploymentState> endCond)Waits for completing a deployer operation.- Parameters:
id- the service id to wait forinitState- the initial deployment state, may be null for noneendCond- the end condition when to stop waiting, anyway at longestSpringCloudServiceSetup.getWaitingTime().- Returns:
- the service state at the end of waiting
-
stopService
public void stopService(java.lang.String... serviceIds) throws java.util.concurrent.ExecutionException- Throws:
java.util.concurrent.ExecutionException
-
migrateService
public void migrateService(java.lang.String serviceId, java.lang.String resourceId) throws java.util.concurrent.ExecutionException- Specified by:
migrateServicein interfacede.iip_ecosphere.platform.services.ServiceOperations- Overrides:
migrateServicein classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>- Throws:
java.util.concurrent.ExecutionException
-
removeArtifact
public void removeArtifact(java.lang.String artifactId) throws java.util.concurrent.ExecutionException- Specified by:
removeArtifactin interfacede.iip_ecosphere.platform.services.ServiceOperations- Overrides:
removeArtifactin classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>- Throws:
java.util.concurrent.ExecutionException
-
updateService
public void updateService(java.lang.String serviceId, java.net.URI location) throws java.util.concurrent.ExecutionException- Throws:
java.util.concurrent.ExecutionException
-
switchToService
public void switchToService(java.lang.String serviceId, java.lang.String target) throws java.util.concurrent.ExecutionException- Specified by:
switchToServicein interfacede.iip_ecosphere.platform.services.ServiceOperations- Overrides:
switchToServicein classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>- Throws:
java.util.concurrent.ExecutionException
-
cloneArtifact
public void cloneArtifact(java.lang.String artifactId, java.net.URI location) throws java.util.concurrent.ExecutionException- Throws:
java.util.concurrent.ExecutionException
-
setStateSafe
protected void setStateSafe(de.iip_ecosphere.platform.services.ServiceDescriptor service, de.iip_ecosphere.platform.services.environment.ServiceState state)CallssetState(ServiceDescriptor, ServiceState)logging exceptions.- Parameters:
service- the service to changestate- the new state
-
setState
protected void setState(de.iip_ecosphere.platform.services.ServiceDescriptor service, de.iip_ecosphere.platform.services.environment.ServiceState state) throws java.util.concurrent.ExecutionException- Overrides:
setStatein classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>- Throws:
java.util.concurrent.ExecutionException
-
clear
public void clear()
- Overrides:
clearin classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
-
-