Class SpringCloudServiceDescriptor
java.lang.Object
de.iip_ecosphere.platform.services.AbstractServiceDescriptor<SpringCloudArtifactDescriptor>
de.iip_ecosphere.platform.services.spring.SpringCloudServiceDescriptor
- All Implemented Interfaces:
de.iip_ecosphere.platform.services.ServiceDescriptor
public class SpringCloudServiceDescriptor
extends de.iip_ecosphere.platform.services.AbstractServiceDescriptor<SpringCloudArtifactDescriptor>
Specific descriptor implementation for spring cloud streams. [public for testing]
Relies on parameter functions from
Starter.- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.iip_ecosphere.platform.services.ServiceDescriptor
de.iip_ecosphere.platform.services.ServiceDescriptor.Action -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionSpringCloudServiceDescriptor(Service service, TypeResolver resolver) Creates an instance.protectedSpringCloudServiceDescriptor(String id, String applicationId, String name, String description, de.iip_ecosphere.platform.support.Version version) Creates an instance. -
Method Summary
Modifier and TypeMethodDescription(package private) voidattachCloseable(String key, Closeable closeable) Attaches a closable.(package private) voidAttaches a service stub to directly interact with the service ifadminAddrhas been set bycreateDeploymentRequest(SpringCloudServiceSetup, List, String)before.(package private) voidcloseCloseables(Predicate<String> predKey, Predicate<Closeable> predCl) Closes attached closeables.collectCmdArguments(SpringCloudServiceSetup config, int port, String protocol) Collects basic command line arguments.(package private) org.springframework.cloud.deployer.spi.core.AppDeploymentRequestcreateDeploymentRequest(SpringCloudServiceSetup config, List<String> cmdArgs, String memLimit) Creates the deployment request for the Spring deployer.(package private) static SpringCloudServiceDescriptorCreates a temporary descriptor for the given server spec instance.(package private) voidDetaches an attached service stub.(package private) StringReturns theNetworkManagerkey for the AAS command connection to an external process.(package private) de.iip_ecosphere.platform.support.net.ManagedServerAddressReturns the address for the admin service/asset.protected Class<SpringCloudArtifactDescriptor> (package private) StringReturns the Spring cloud deployer deployment id.getGroup()Returns the deployment group.de.iip_ecosphere.platform.support.aas.InvocablesCreatorlongReturns the desired memory for instances of this service.If the service represents a server, return the server specification.private StringReturns theNetworkManagerkey for the streaming connection to an external process.getSvc()Returns the YAML descriptor.private StringReturns the actual transport host.private intReturns the actual transport port.instantiate(String sId) Instantiates this service as a template to represent an instance service with idserviceId.(package private) voidIterates over attached closeables.private voiditerCloseables(Predicate<String> predKey, Predicate<Closeable> predCl, Consumer<Closeable> consumer, Consumer<Iterator<?>> iterHandler) Iterates over attached closeables.(package private) de.iip_ecosphere.platform.support.net.ManagedServerAddressRegisters the network ports for the underlying service using theNetworkManager.private de.iip_ecosphere.platform.support.net.ManagedServerAddressregisterPort(de.iip_ecosphere.platform.support.net.NetworkManager mgr, String key) Obtains a network port and registers it if necessary for release insetState(ServiceState).private voidrelease()(package private) voidSets the Spring cloud deployer deployment id.(package private) voidsetEnsembleLeader(SpringCloudServiceDescriptor ensembleLeader) Defines the ensemble leader.voidsetState(de.iip_ecosphere.platform.services.environment.ServiceState state) (package private) intstartProcess(SpringCloudServiceSetup config, ProcessSpec pSpec) Starts the non-Java execution process if needed.static StringtoFunctionDefinition(Set<de.iip_ecosphere.platform.services.AbstractServiceManager.TypedDataConnection> conn) Turns typed data connections into a Spring cloud function definition argument.(package private) booleanwaitForAdminServer(int waitingTime) Waits that the server onadminAddrbecomes available.Methods inherited from class de.iip_ecosphere.platform.services.AbstractServiceDescriptor
addInputDataConnector, addOutputDataConnector, addParameter, attachAction, connectorIds, ensemble, ensembleConnectorNames, executeAction, getAdditionalArguments, getApplicationId, getArtifact, getDataConnectors, getDescription, getId, getInputDataConnectors, getKind, getName, getOutputDataConnectors, getParameters, getState, getStub, getVersion, instantiateFrom, instantiateFrom, internalConnectorNames, isDeployable, isTopLevel, setAdditionalArguments, setArtifact, setClassification, setStubMethods 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.ServiceDescriptor
getApplicationInstanceId, getServiceId
-
Field Details
-
service
-
ensembleLeader
-
deploymentId
-
portKeys
-
process
-
processDir
-
serviceProtocol
-
adminAddr
private de.iip_ecosphere.platform.support.net.ManagedServerAddress adminAddr -
server
-
closeables
-
-
Constructor Details
-
SpringCloudServiceDescriptor
Creates an instance.- Parameters:
service- the service deployment specification objectresolver- the (artifact) type resolver- See Also:
-
SpringCloudServiceDescriptor
protected SpringCloudServiceDescriptor(String id, String applicationId, String name, String description, de.iip_ecosphere.platform.support.Version version) Creates an instance. CallAbstractServiceDescriptor.setClassification(ServiceKind, boolean, boolean)afterwards.- Parameters:
id- the service idapplicationId- the application id, may be empty for default application/legacyname- the name of this servicedescription- the description of the serviceversion- the version
-
-
Method Details
-
createFor
Creates a temporary descriptor for the given server spec instance.- Parameters:
server- the server spec instance- Returns:
- the descriptor
-
getServer
If the service represents a server, return the server specification. [public for testing]- Returns:
- the server specification, may be null
-
instantiate
Instantiates this service as a template to represent an instance service with idserviceId. Typically, the application instance id changes compared to existing service descriptors. [public for testing]- Parameters:
sId- the service id- Returns:
- the instantiated service
-
getArtifactDescriptorClass
- Specified by:
getArtifactDescriptorClassin classde.iip_ecosphere.platform.services.AbstractServiceDescriptor<SpringCloudArtifactDescriptor>
-
setState
public void setState(de.iip_ecosphere.platform.services.environment.ServiceState state) throws ExecutionException - Specified by:
setStatein interfacede.iip_ecosphere.platform.services.ServiceDescriptor- Overrides:
setStatein classde.iip_ecosphere.platform.services.AbstractServiceDescriptor<SpringCloudArtifactDescriptor>- Throws:
ExecutionException
-
release
private void release() -
attachCloseable
Attaches a closable.- Parameters:
key- the key to identify the closeable latercloseable- the closable (may be null, ignored then)
-
iterClosables
void iterClosables(Predicate<String> predKey, Predicate<Closeable> predCl, Consumer<Closeable> consumer) Iterates over attached closeables.- Parameters:
predKey- the predicate to select the closeables by key (may be null for all)predCl- the predicate to select the closeables by instance (may be null for all)consumer- on identified closeables, for closing them usecloseCloseables(Predicate, Predicate)
-
iterCloseables
private void iterCloseables(Predicate<String> predKey, Predicate<Closeable> predCl, Consumer<Closeable> consumer, Consumer<Iterator<?>> iterHandler) Iterates over attached closeables.- Parameters:
predKey- the predicate to select the closeables by key (may be null for all)predCl- the predicate to select the closeables by instance (may be null for all)consumer- on identified closeables, for closing them usecloseCloseables(Predicate, Predicate).iterHandler- for actions on the internal closeables iterator
-
closeCloseables
Closes attached closeables.- Parameters:
predKey- the predicate to select the closeables by key (may be null for all)predCl- the predicate to select the closeables by instance (may be null for all)
-
registerPort
private de.iip_ecosphere.platform.support.net.ManagedServerAddress registerPort(de.iip_ecosphere.platform.support.net.NetworkManager mgr, String key) Obtains a network port and registers it if necessary for release insetState(ServiceState).- Parameters:
mgr- the network manager instancekey- the key to obtain the network address- Returns:
- the obtained address, may be invalid for ensemble members
-
setEnsembleLeader
Defines the ensemble leader.- Parameters:
ensembleLeader- optional ensemble leader some information shall be taken from/synchronized with
-
getGroup
Returns the deployment group.- Returns:
- the deployment group
-
getEnsembleLeader
- Specified by:
getEnsembleLeaderin interfacede.iip_ecosphere.platform.services.ServiceDescriptor- Overrides:
getEnsembleLeaderin classde.iip_ecosphere.platform.services.AbstractServiceDescriptor<SpringCloudArtifactDescriptor>
-
registerNetworkPorts
de.iip_ecosphere.platform.support.net.ManagedServerAddress registerNetworkPorts()Registers the network ports for the underlying service using theNetworkManager. Does not register network ports twice. Also allocatesadminAddrif not already done.- Returns:
- the spring managed server address
-
getAdminAddr
de.iip_ecosphere.platform.support.net.ManagedServerAddress getAdminAddr()Returns the address for the admin service/asset.registerNetworkPorts()must have been called before or anensembleLeadermust have been set.- Returns:
- the admin address, may be null if not assigned before
-
createDeploymentRequest
org.springframework.cloud.deployer.spi.core.AppDeploymentRequest createDeploymentRequest(SpringCloudServiceSetup config, List<String> cmdArgs, String memLimit) throws ExecutionException Creates the deployment request for the Spring deployer.- Parameters:
config- the service manager configuration instancecmdArgs- further command line arguments to be considered, may be null or empty for nonememLimit- optional memory limit in MBytes as String, viaUtils.formatToMeBi(long)- Returns:
- the deployment request, may be null if this service is an ensemble follower and should not be started individually
- Throws:
ExecutionException- when preparing the service fails for some reason
-
collectCmdArguments
Collects basic command line arguments.- Parameters:
config- the configurationport- the network port to substitute in the service command line argumentsprotocol- the protocol, may be empty for none- Returns:
- the command line arguments
-
getTransportHost
Returns the actual transport host. [legacy fallback, due to testing]- Parameters:
setup- the instance to take the information from- Returns:
- the host
-
getTransportPort
Returns the actual transport port. [legacy fallback, due to testing]- Parameters:
setup- the instance to take the information from- Returns:
- the port
-
attachStub
void attachStub()Attaches a service stub to directly interact with the service ifadminAddrhas been set bycreateDeploymentRequest(SpringCloudServiceSetup, List, String)before. -
waitForAdminServer
boolean waitForAdminServer(int waitingTime) Waits that the server onadminAddrbecomes available.- Parameters:
waitingTime- maximum waiting time in ms- Returns:
trueif available,falseelse
-
detachStub
void detachStub()Detaches an attached service stub. -
getInvocablesCreator
public de.iip_ecosphere.platform.support.aas.InvocablesCreator getInvocablesCreator() -
startProcess
Starts the non-Java execution process if needed.- Parameters:
config- the service manager configuration instancepSpec- the specification of the service to start- Returns:
- the process port, valid if positive
- Throws:
ExecutionException- when preparing the service fails for some reason
-
getStreamingNetmanagerKey
Returns theNetworkManagerkey for the streaming connection to an external process.- Returns:
- the key
-
getAasNetmanagerKey
String getAasNetmanagerKey()Returns theNetworkManagerkey for the AAS command connection to an external process.- Returns:
- the key
-
setDeploymentId
Sets the Spring cloud deployer deployment id.- Parameters:
id- the deployment id
-
getDeploymentId
String getDeploymentId()Returns the Spring cloud deployer deployment id.- Returns:
- the deployment id, may be null for not deployed
-
getSvc
Returns the YAML descriptor. [for testing]- Returns:
- the YAML descriptor
-
getMemory
public long getMemory()Returns the desired memory for instances of this service.- Returns:
- the desired memory in Mebibytes (i.e., "m"), ignored if not positive
-
toFunctionDefinition
public static String toFunctionDefinition(Set<de.iip_ecosphere.platform.services.AbstractServiceManager.TypedDataConnection> conn) Turns typed data connections into a Spring cloud function definition argument.- Parameters:
conn- the connections- Returns:
- the composed function definition argument
-