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. Requires
SpringInstances set correctly before use.- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDescriptor for creating the service manager instance.Nested classes/interfaces inherited from class de.iip_ecosphere.platform.services.AbstractServiceManager
de.iip_ecosphere.platform.services.AbstractServiceManager.TypedDataConnectionNested classes/interfaces inherited from interface de.iip_ecosphere.platform.services.ServiceOperations
de.iip_ecosphere.platform.services.ServiceOperations.StreamLogMode -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Predicate<de.iip_ecosphere.platform.services.TypedDataConnectorDescriptor> private static final de.iip_ecosphere.platform.support.logging.Loggerprivate Supplier<de.iip_ecosphere.platform.support.net.NetworkManager> static final Stringstatic final Stringprivate ServerManagerFields 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 TypeMethodDescriptionstatic voidTurns the application (instance) id into a command line argument.addArtifact(URI location) private voidattachTailer(org.springframework.cloud.deployer.spi.app.AppInstanceStatus inst, String field, de.iip_ecosphere.platform.services.ServiceOperations.StreamLogMode mode, SpringCloudServiceDescriptor desc, List<URI> result) Attaches a tailer to an app instance.private voidcheckErrors(List<String> errors) Checks the given errors list.voidclear()voidcloneArtifact(String artifactId, URI location) createServiceAppIdSubstitution(String... serviceIds) Creates a default substitution mapping forserviceIds, i.e., from the simple id to the full id with application id and application instance id only if both application ids are given.determineBindingServiceArgs(String... serviceIds) Determines the command line arguments to adjust service connections from "internal" to "external" binder.private StringdetermineCloudFunctionArg(String... serviceIds) Determines the cloud function argument for the given services.determineSpringConditionals(de.iip_ecosphere.platform.services.ServiceManager mgr, String... serviceIds) Determines the command line values for the spring component conditionals.protected Predicate<de.iip_ecosphere.platform.services.TypedDataConnectorDescriptor> private StringgetMemLimit(Map<String, String> options, String... sIds) Returns the specified memory limit ofsIdsgiven in service descriptors oroptions.private voidhandleFamilyProcesses(String[] serviceIds, boolean start) Prepares the processes of the family members.protected voidprivate static voidhandleOptionEnsemble(String opt, String[] serviceIds, de.iip_ecosphere.platform.services.ServiceManager mgr) Handles the ensemble option for service start.static voidhandleOptions(Map<String, String> options, de.iip_ecosphere.platform.services.ServiceManager mgr, String... serviceIds) Handles service start options.private voidhandleOptions(Map<String, String> options, String[] serviceIds) Handles service start options.protected SpringCloudServiceDescriptorinstantiateFromTemplate(SpringCloudServiceDescriptor template, String serviceId) private booleanReturns whetherdescis loggable, i.e., shomehow running and depoyed.private static booleanReturns whetherkeyis a log stream closeable.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(String serviceId, String resourceId) private static voidreconfigure(SpringCloudServiceDescriptor service, boolean started, Map<String, String> options) Reconfiguresserviceifstartedwithparams.private String[]registerNetworkPorts(String[] serviceIds) Registers/pre-allocates the network ports for all given services.voidremoveArtifact(String artifactId) replaceAll(Map<?, ?> optMap, Map<String, String> subst) Replaces all keys/values inoptMapby substitutes given insubst.private String[]serviceAndEnsemble(String id, String[] serviceIds) Returns the lead and ensemble services of serviceid(viewingidas potential ensemble leader) from a given set of services.Supplier<de.iip_ecosphere.platform.support.net.NetworkManager> setNetworkManagerClientSupplier(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) voidstartService(String... serviceIds) voidstartService(Map<String, String> options, String... serviceIds) voidstopService(String... serviceIds) streamLog(String serviceId, de.iip_ecosphere.platform.services.ServiceOperations.StreamLogMode mode) private static Objectsubstitute(Object val, Map<String, String> subst) Substitutesvalby the corresponding value insubst.voidswitchToService(String serviceId, String target) private voidupdatePlugins(File jarFile) Resolves/updates the plugins required by the application artifactjarFile.voidupdateService(String serviceId, URI location) private org.springframework.cloud.deployer.spi.app.DeploymentStatewaitFor(String id, org.springframework.cloud.deployer.spi.app.DeploymentState initState, 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 Details
-
PLUGIN_ID
- See Also:
-
OPT_SERVICE_PREFIX
- See Also:
-
LOGGER
private static final de.iip_ecosphere.platform.support.logging.Logger LOGGER -
serverManager
-
available
-
networkManagerSupplier
-
-
Constructor Details
-
SpringCloudServiceManager
private SpringCloudServiceManager()Prevents external creation.
-
-
Method Details
-
setNetworkManagerClientSupplier
public Supplier<de.iip_ecosphere.platform.support.net.NetworkManager> setNetworkManagerClientSupplier(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 Predicate<de.iip_ecosphere.platform.services.TypedDataConnectorDescriptor> getAvailablePredicate()- Specified by:
getAvailablePredicatein classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
-
addArtifact
- Throws:
ExecutionException
-
updatePlugins
Resolves/updates the plugins required by the application artifactjarFile.- Parameters:
jarFile- update
-
determineBindingServiceArgs
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:
-
determineCloudFunctionArg
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:
-
determineSpringConditionals
public static List<String> determineSpringConditionals(de.iip_ecosphere.platform.services.ServiceManager mgr, 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
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
- Throws:
ExecutionException
-
handleOptions
Handles service start options.- Parameters:
options- the optionsserviceIds- the service ids to start
-
handleOptions
public static void handleOptions(Map<String, String> options, de.iip_ecosphere.platform.services.ServiceManager mgr, String... serviceIds) Handles service start options. [public, static for testing]- Parameters:
options- the optionsmgr- the service managerserviceIds- the service ids to start
-
replaceAll
Replaces all keys/values inoptMapby substitutes given insubst.- Parameters:
optMap- the option mapsubst- the substitution table (original-substitute)- Returns:
- the copied, substituted
optMap
-
substitute
Substitutesvalby the corresponding value insubst.- Parameters:
val- the value, may be nullsubst- the substitution table (original-substitute)- Returns:
- the substituted value, may be null if
valwas null
-
createServiceAppIdSubstitution
Creates a default substitution mapping forserviceIds, i.e., from the simple id to the full id with application id and application instance id only if both application ids are given.- Parameters:
serviceIds- the service ids to create the substitution for- Returns:
- the substitution mapping
- See Also:
-
handleOptionEnsemble
private static void handleOptionEnsemble(String opt, 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
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
-
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, Map<String, String> options) throws ExecutionExceptionReconfiguresserviceifstartedwithparams.- Parameters:
service- the service to be reconfiguredstarted- whether it was (just) startedoptions- the options to reconfigure (serviceId/name/value)- Throws:
ExecutionException- if reconfiguration failed
-
registerNetworkPorts
Registers/pre-allocates the network ports for all given services.- Parameters:
serviceIds- the service ids- Returns:
serviceIds- See Also:
-
startService
public void startService(Map<String, String> options, String... serviceIds) throws ExecutionException- Throws:
ExecutionException
-
instantiateFromTemplate
protected SpringCloudServiceDescriptor instantiateFromTemplate(SpringCloudServiceDescriptor template, String serviceId) - Specified by:
instantiateFromTemplatein classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
-
handleInstantiatedServices
- Overrides:
handleInstantiatedServicesin classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
-
getMemLimit
Returns the specified memory limit ofsIdsgiven in service descriptors oroptions.- Parameters:
options- the service start optionssIds- the service ids of the service and the (optional) ensemble services- Returns:
- the memory limit in Mebibytes (i.e., "m"), may be null for none
-
handleFamilyProcesses
Prepares 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:
ExecutionException- when preparing the service fails for some reason
-
checkErrors
Checks the given errors list. If there are errors, composes a message and throws an exception.- Parameters:
errors- the errors to check for- Throws:
ExecutionException- an exception if there are errors
-
waitFor
private org.springframework.cloud.deployer.spi.app.DeploymentState waitFor(String id, org.springframework.cloud.deployer.spi.app.DeploymentState initState, 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
- Throws:
ExecutionException
-
migrateService
- Specified by:
migrateServicein interfacede.iip_ecosphere.platform.services.ServiceOperations- Overrides:
migrateServicein classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor> - Throws:
ExecutionException
-
removeArtifact
- Specified by:
removeArtifactin interfacede.iip_ecosphere.platform.services.ServiceOperations- Overrides:
removeArtifactin classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor> - Throws:
ExecutionException
-
updateService
- Throws:
ExecutionException
-
switchToService
- Specified by:
switchToServicein interfacede.iip_ecosphere.platform.services.ServiceOperations- Overrides:
switchToServicein classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor> - Throws:
ExecutionException
-
cloneArtifact
- Throws:
ExecutionException
-
setState
protected void setState(de.iip_ecosphere.platform.services.ServiceDescriptor service, de.iip_ecosphere.platform.services.environment.ServiceState state) throws ExecutionException - Overrides:
setStatein classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor> - Throws:
ExecutionException
-
clear
public void clear()- Overrides:
clearin classde.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
-
isLoggable
Returns whetherdescis loggable, i.e., shomehow running and depoyed.- Parameters:
desc- the descriptor- Returns:
truefor loggable,falseelse
-
streamLog
public String streamLog(String serviceId, de.iip_ecosphere.platform.services.ServiceOperations.StreamLogMode mode) throws ExecutionException - Throws:
ExecutionException
-
isLogStreamCloseable
Returns whetherkeyis a log stream closeable.- Parameters:
key- the key- Returns:
truefor is a closeable,falseelse
-
attachTailer
private void attachTailer(org.springframework.cloud.deployer.spi.app.AppInstanceStatus inst, String field, de.iip_ecosphere.platform.services.ServiceOperations.StreamLogMode mode, SpringCloudServiceDescriptor desc, List<URI> result) Attaches a tailer to an app instance.- Parameters:
inst- the instancefield- the field to attach tomode- the streaming modedesc- the service descriptorresult- the result
-