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
  • Field Details

    • service

      private Service service
    • ensembleLeader

      private SpringCloudServiceDescriptor ensembleLeader
    • deploymentId

      private String deploymentId
    • portKeys

      private List<String> portKeys
    • process

      private Process process
    • processDir

      private File processDir
    • serviceProtocol

      private String serviceProtocol
    • adminAddr

      private de.iip_ecosphere.platform.support.net.ManagedServerAddress adminAddr
    • server

      private Server server
    • closeables

      private Map<String,Closeable> closeables
  • Constructor Details

    • SpringCloudServiceDescriptor

      public SpringCloudServiceDescriptor(Service service, TypeResolver resolver)
      Creates an instance.
      Parameters:
      service - the service deployment specification object
      resolver - the (artifact) type resolver
      See Also:
      • AbstractServiceDescriptor.setClassification(de.iip_ecosphere.platform.services.environment.ServiceKind, boolean, boolean)
    • SpringCloudServiceDescriptor

      protected SpringCloudServiceDescriptor(String id, String applicationId, String name, String description, de.iip_ecosphere.platform.support.Version version)
      Creates an instance. Call AbstractServiceDescriptor.setClassification(ServiceKind, boolean, boolean) afterwards.
      Parameters:
      id - the service id
      applicationId - the application id, may be empty for default application/legacy
      name - the name of this service
      description - the description of the service
      version - the version
  • Method Details

    • createFor

      static SpringCloudServiceDescriptor createFor(Server server)
      Creates a temporary descriptor for the given server spec instance.
      Parameters:
      server - the server spec instance
      Returns:
      the descriptor
    • getServer

      public Server getServer()
      If the service represents a server, return the server specification. [public for testing]
      Returns:
      the server specification, may be null
    • instantiate

      public SpringCloudServiceDescriptor instantiate(String sId)
      Instantiates this service as a template to represent an instance service with id serviceId. Typically, the application instance id changes compared to existing service descriptors. [public for testing]
      Parameters:
      sId - the service id
      Returns:
      the instantiated service
    • getArtifactDescriptorClass

      protected Class<SpringCloudArtifactDescriptor> getArtifactDescriptorClass()
      Specified by:
      getArtifactDescriptorClass in class de.iip_ecosphere.platform.services.AbstractServiceDescriptor<SpringCloudArtifactDescriptor>
    • setState

      public void setState(de.iip_ecosphere.platform.services.environment.ServiceState state) throws ExecutionException
      Specified by:
      setState in interface de.iip_ecosphere.platform.services.ServiceDescriptor
      Overrides:
      setState in class de.iip_ecosphere.platform.services.AbstractServiceDescriptor<SpringCloudArtifactDescriptor>
      Throws:
      ExecutionException
    • release

      private void release()
      Releases the process as well as the ports in portKeys.
    • attachCloseable

      void attachCloseable(String key, Closeable closeable)
      Attaches a closable.
      Parameters:
      key - the key to identify the closeable later
      closeable - 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 use closeCloseables(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 use closeCloseables(Predicate, Predicate).
      iterHandler - for actions on the internal closeables iterator
    • closeCloseables

      void closeCloseables(Predicate<String> predKey, Predicate<Closeable> predCl)
      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 in setState(ServiceState).
      Parameters:
      mgr - the network manager instance
      key - the key to obtain the network address
      Returns:
      the obtained address, may be invalid for ensemble members
    • setEnsembleLeader

      void setEnsembleLeader(SpringCloudServiceDescriptor ensembleLeader)
      Defines the ensemble leader.
      Parameters:
      ensembleLeader - optional ensemble leader some information shall be taken from/synchronized with
    • getGroup

      public String getGroup()
      Returns the deployment group.
      Returns:
      the deployment group
    • getEnsembleLeader

      public SpringCloudServiceDescriptor getEnsembleLeader()
      Specified by:
      getEnsembleLeader in interface de.iip_ecosphere.platform.services.ServiceDescriptor
      Overrides:
      getEnsembleLeader in class de.iip_ecosphere.platform.services.AbstractServiceDescriptor<SpringCloudArtifactDescriptor>
    • registerNetworkPorts

      de.iip_ecosphere.platform.support.net.ManagedServerAddress registerNetworkPorts()
      Registers the network ports for the underlying service using the NetworkManager. Does not register network ports twice. Also allocates adminAddr if 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 an ensembleLeader must 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 instance
      cmdArgs - further command line arguments to be considered, may be null or empty for none
      memLimit - optional memory limit in MBytes as String, via Utils.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

      List<String> collectCmdArguments(SpringCloudServiceSetup config, int port, String protocol)
      Collects basic command line arguments.
      Parameters:
      config - the configuration
      port - the network port to substitute in the service command line arguments
      protocol - the protocol, may be empty for none
      Returns:
      the command line arguments
    • getTransportHost

      private String getTransportHost(SpringCloudServiceSetup setup)
      Returns the actual transport host. [legacy fallback, due to testing]
      Parameters:
      setup - the instance to take the information from
      Returns:
      the host
    • getTransportPort

      private int getTransportPort(SpringCloudServiceSetup setup)
      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 if adminAddr has been set by createDeploymentRequest(SpringCloudServiceSetup, List, String) before.
    • waitForAdminServer

      boolean waitForAdminServer(int waitingTime)
      Waits that the server on adminAddr becomes available.
      Parameters:
      waitingTime - maximum waiting time in ms
      Returns:
      true if available, false else
    • detachStub

      void detachStub()
      Detaches an attached service stub.
    • getInvocablesCreator

      public de.iip_ecosphere.platform.support.aas.InvocablesCreator getInvocablesCreator()
    • startProcess

      int startProcess(SpringCloudServiceSetup config, ProcessSpec pSpec) throws ExecutionException
      Starts the non-Java execution process if needed.
      Parameters:
      config - the service manager configuration instance
      pSpec - 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

      private String getStreamingNetmanagerKey()
      Returns the NetworkManager key for the streaming connection to an external process.
      Returns:
      the key
    • getAasNetmanagerKey

      String getAasNetmanagerKey()
      Returns the NetworkManager key for the AAS command connection to an external process.
      Returns:
      the key
    • setDeploymentId

      void setDeploymentId(String id)
      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

      public Service 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