Class 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 Detail

      • deploymentId

        private java.lang.String deploymentId
      • portKeys

        private java.util.List<java.lang.String> portKeys
      • process

        private java.lang.Process process
      • processDir

        private java.io.File processDir
      • serviceProtocol

        private java.lang.String serviceProtocol
      • adminAddr

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

        private Server server
    • Constructor Detail

      • 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​(java.lang.String id,
                                               java.lang.String applicationId,
                                               java.lang.String name,
                                               java.lang.String description,
                                               de.iip_ecosphere.platform.support.iip_aas.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 Detail

      • 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

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

        SpringCloudServiceDescriptor instantiate​(java.lang.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.
        Parameters:
        sId - the service id
        Returns:
        the instantiated service
      • setState

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

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

        private de.iip_ecosphere.platform.support.net.ManagedServerAddress registerPort​(de.iip_ecosphere.platform.support.net.NetworkManager mgr,
                                                                                        java.lang.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
      • setEnsembleLeader

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

        public java.lang.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>
      • createDeploymentRequest

        org.springframework.cloud.deployer.spi.core.AppDeploymentRequest createDeploymentRequest​(SpringCloudServiceSetup config,
                                                                                                 java.util.List<java.lang.String> cmdArgs)
                                                                                          throws java.util.concurrent.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
        Returns:
        the deployment request, may be null if this service is an ensemble follower and should not be started individually
        Throws:
        java.util.concurrent.ExecutionException - when preparing the service fails for some reason
      • collectCmdArguments

        java.util.List<java.lang.String> collectCmdArguments​(SpringCloudServiceSetup config,
                                                             int port,
                                                             java.lang.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 java.lang.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
      • waitForAdminServer

        void waitForAdminServer​(int waitingTime)
        Waits that the server on adminAddr becomes available.
        Parameters:
        waitingTime - maximum waiting time in ms
      • 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 java.util.concurrent.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:
        java.util.concurrent.ExecutionException - when preparing the service fails for some reason
      • getStreamingNetmanagerKey

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

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

        void setDeploymentId​(java.lang.String id)
        Sets the Spring cloud deployer deployment id.
        Parameters:
        id - the deployment id
      • getDeploymentId

        java.lang.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
      • toFunctionDefinition

        public static java.lang.String toFunctionDefinition​(java.util.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