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

    • PLUGIN_ID

      public static final String PLUGIN_ID
      See Also:
    • OPT_SERVICE_PREFIX

      public static final String OPT_SERVICE_PREFIX
      See Also:
    • LOGGER

      private static final de.iip_ecosphere.platform.support.logging.Logger LOGGER
    • serverManager

      private ServerManager serverManager
    • available

      private Predicate<de.iip_ecosphere.platform.services.TypedDataConnectorDescriptor> available
    • networkManagerSupplier

      private Supplier<de.iip_ecosphere.platform.support.net.NetworkManager> 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:
      getAvailablePredicate in class de.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
    • addArtifact

      public String addArtifact(URI location) throws ExecutionException
      Throws:
      ExecutionException
    • updatePlugins

      private void updatePlugins(File jarFile)
      Resolves/updates the plugins required by the application artifact jarFile.
      Parameters:
      jarFile - update
    • determineBindingServiceArgs

      private List<String> determineBindingServiceArgs(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 String determineCloudFunctionArg(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 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 instance
      serviceIds - the services to determine the arguments for
      Returns:
      the arguments
    • serviceAndEnsemble

      private String[] serviceAndEnsemble(String id, 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(String... serviceIds) throws ExecutionException
      Throws:
      ExecutionException
    • handleOptions

      private void handleOptions(Map<String,String> options, String[] serviceIds)
      Handles service start options.
      Parameters:
      options - the options
      serviceIds - 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 options
      mgr - the service manager
      serviceIds - the service ids to start
    • replaceAll

      private static Map<Object,Object> replaceAll(Map<?,?> optMap, Map<String,String> subst)
      Replaces all keys/values in optMap by substitutes given in subst.
      Parameters:
      optMap - the option map
      subst - the substitution table (original-substitute)
      Returns:
      the copied, substituted optMap
    • substitute

      private static Object substitute(Object val, Map<String,String> subst)
      Substitutes val by the corresponding value in subst.
      Parameters:
      val - the value, may be null
      subst - the substitution table (original-substitute)
      Returns:
      the substituted value, may be null if val was null
    • createServiceAppIdSubstitution

      private static Map<String,String> createServiceAppIdSubstitution(String... serviceIds)
      Creates a default substitution mapping for serviceIds, 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 string
      serviceIds - the service ids to start
      mgr - the service manager
    • addAppId

      public static void addAppId(String serviceId, List<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
    • 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, Map<String,String> options) throws ExecutionException
      Reconfigures service if started with params.
      Parameters:
      service - the service to be reconfigured
      started - whether it was (just) started
      options - the options to reconfigure (serviceId/name/value)
      Throws:
      ExecutionException - if reconfiguration failed
    • registerNetworkPorts

      private String[] registerNetworkPorts(String[] serviceIds)
      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:
      instantiateFromTemplate in class de.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
    • handleInstantiatedServices

      protected void handleInstantiatedServices(Iterable<String> sId)
      Overrides:
      handleInstantiatedServices in class de.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
    • getMemLimit

      private String getMemLimit(Map<String,String> options, String... sIds)
      Returns the specified memory limit of sIds given in service descriptors or options.
      Parameters:
      options - the service start options
      sIds - 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

      private void handleFamilyProcesses(String[] serviceIds, boolean start) throws 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:
      ExecutionException - when preparing the service fails for some reason
    • checkErrors

      private void checkErrors(List<String> errors) throws 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:
      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 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(String... serviceIds) throws ExecutionException
      Throws:
      ExecutionException
    • migrateService

      public void migrateService(String serviceId, String resourceId) throws 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:
      ExecutionException
    • removeArtifact

      public void removeArtifact(String artifactId) throws 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:
      ExecutionException
    • updateService

      public void updateService(String serviceId, URI location) throws ExecutionException
      Throws:
      ExecutionException
    • switchToService

      public void switchToService(String serviceId, String target) throws 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:
      ExecutionException
    • cloneArtifact

      public void cloneArtifact(String artifactId, URI location) throws ExecutionException
      Throws:
      ExecutionException
    • setState

      protected void setState(de.iip_ecosphere.platform.services.ServiceDescriptor service, de.iip_ecosphere.platform.services.environment.ServiceState state) throws ExecutionException
      Overrides:
      setState in class de.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
      Throws:
      ExecutionException
    • clear

      public void clear()
      Overrides:
      clear in class de.iip_ecosphere.platform.services.AbstractServiceManager<SpringCloudArtifactDescriptor,SpringCloudServiceDescriptor>
    • isLoggable

      private boolean isLoggable(SpringCloudServiceDescriptor desc)
      Returns whether desc is loggable, i.e., shomehow running and depoyed.
      Parameters:
      desc - the descriptor
      Returns:
      true for loggable, false else
    • streamLog

      public String streamLog(String serviceId, de.iip_ecosphere.platform.services.ServiceOperations.StreamLogMode mode) throws ExecutionException
      Throws:
      ExecutionException
    • isLogStreamCloseable

      private static boolean isLogStreamCloseable(String key)
      Returns whether key is a log stream closeable.
      Parameters:
      key - the key
      Returns:
      true for is a closeable, false else
    • 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 instance
      field - the field to attach to
      mode - the streaming mode
      desc - the service descriptor
      result - the result