Class SpringCloudServiceManager

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  SpringCloudServiceManager.SpringCloudServiceFactoryDescriptor
      Descriptor for creating the service manager instance.
      • Nested classes/interfaces inherited from class de.iip_ecosphere.platform.services.AbstractServiceManager

        de.iip_ecosphere.platform.services.AbstractServiceManager.TypedDataConnection
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.function.Predicate<de.iip_ecosphere.platform.services.TypedDataConnectorDescriptor> available  
      private static org.slf4j.Logger LOGGER  
      private java.util.function.Supplier<de.iip_ecosphere.platform.support.net.NetworkManager> networkManagerSupplier  
      static java.lang.String OPT_SERVICE_PREFIX  
      private static java.lang.String PROGRESS_COMPONENT_ID  
      private java.util.Map<SpringCloudServiceDescriptor,​de.iip_ecosphere.platform.support.Server> runningServers  
      • Fields inherited from interface de.iip_ecosphere.platform.services.ServiceOperations

        EXC_ALREADY_KNOWN, OPTION_ARGS, OPTION_ENSEMBLE, OPTION_PARAMS, OPTION_SERVERS
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SpringCloudServiceManager()
      Prevents external creation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void addAppId​(java.lang.String serviceId, java.util.List<java.lang.String> cmdArgs)
      Turns the application (instance) id into a command line argument.
      java.lang.String addArtifact​(java.net.URI location)  
      private void checkErrors​(java.util.List<java.lang.String> errors)
      Checks the given errors list.
      void clear()  
      void cloneArtifact​(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.String determineCloudFunctionArg​(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 void handleFamilyProcesses​(java.lang.String[] serviceIds, boolean start)
      Prepares the processes of the family members.
      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.
      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.
      private void handleOptions​(java.util.Map<java.lang.String,​java.lang.String> options, java.lang.String[] serviceIds)
      Handles service start options.
      protected SpringCloudServiceDescriptor instantiateFromTemplate​(SpringCloudServiceDescriptor template, java.lang.String serviceId)  
      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.
      void migrateService​(java.lang.String serviceId, java.lang.String resourceId)  
      private static void reconfigure​(SpringCloudServiceDescriptor service, boolean started, java.util.Map<java.lang.String,​java.lang.String> options)
      Reconfigures service if started with .
      void removeArtifact​(java.lang.String artifactId)  
      private java.lang.String[] serviceAndEnsemble​(java.lang.String id, java.lang.String[] serviceIds)
      Returns the lead and ensemble services of service id (viewing id as 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 void setState​(de.iip_ecosphere.platform.services.ServiceDescriptor service, de.iip_ecosphere.platform.services.environment.ServiceState state)  
      protected void setStateSafe​(de.iip_ecosphere.platform.services.ServiceDescriptor service, de.iip_ecosphere.platform.services.environment.ServiceState state)
      private void startServers​(java.util.Map<java.lang.String,​java.lang.String> options)
      Starting server instances.
      void startService​(java.lang.String... serviceIds)  
      void startService​(java.util.Map<java.lang.String,​java.lang.String> options, java.lang.String... serviceIds)  
      private void stopServers()
      Stopping server instances.
      void stopService​(java.lang.String... serviceIds)  
      void switchToService​(java.lang.String serviceId, java.lang.String target)  
      void updateService​(java.lang.String serviceId, java.net.URI location)  
      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.
      • 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
      • networkManagerSupplier

        private java.util.function.Supplier<de.iip_ecosphere.platform.support.net.NetworkManager> networkManagerSupplier
    • Constructor Detail

      • SpringCloudServiceManager

        private SpringCloudServiceManager()
        Prevents external creation.
    • 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:
        getAvailablePredicate in class de.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 instance
        serviceIds - 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 service id (viewing id as potential ensemble leader) from a given set of services.
        Parameters:
        id - the service to return the lead/ensemble services for
        serviceIds - the services to project the result from
        Returns:
        id and connected ensemble services stated in serviceIds
      • 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 options
        serviceIds - 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 options
        serviceIds - the service ids to start
        mgr - 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 string
        serviceIds - the service ids to start
        mgr - 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 from
        cmdArgs - 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 call
        service - the service to mark
        register - register or unregister the server use
        netClient - 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
        Reconfigures service if started with .
        Parameters:
        service - the service to be reconfigured
        started - whether it was (just) started
        options - 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
      • handleFamilyProcesses

        private void handleFamilyProcesses​(java.lang.String[] serviceIds,
                                           boolean start)
                                    throws java.util.concurrent.ExecutionException
        Prepares the processes of the family members.
        Parameters:
        serviceIds - the service ids of the top-level services to be started
        start - 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.ExecutionException
        Checks 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 for
        initState - the initial deployment state, may be null for none
        endCond - the end condition when to stop waiting, anyway at longest SpringCloudServiceSetup.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:
        migrateService in interface de.iip_ecosphere.platform.services.ServiceOperations
        Overrides:
        migrateService in class de.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:
        removeArtifact in interface de.iip_ecosphere.platform.services.ServiceOperations
        Overrides:
        removeArtifact in class de.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:
        switchToService in interface de.iip_ecosphere.platform.services.ServiceOperations
        Overrides:
        switchToService in class de.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)
        Parameters:
        service - the service to change
        state - 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:
        setState in class de.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,​SpringCloudServiceDescriptor>
        Throws:
        java.util.concurrent.ExecutionException