java.lang.Object
de.iip_ecosphere.platform.services.environment.Starter

public class Starter extends Object
Service environment starter reading command server information from the command line.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • Starter

      public Starter()
  • Method Details

    • registerPlugin

      protected static void registerPlugin(String name, Starter.Plugin plugin)
      Registers a functional plugin.
      Parameters:
      name - the name (turned to lower case)
      plugin - the plugin instance
    • registerDefaultPlugins

      protected static void registerDefaultPlugins(Starter.Plugin dflt)
      Registers the default plugins.
      Parameters:
      dflt - the default plugin to be used if no command line argument is given for "iip.test.plugin".
    • inTest

      public static boolean inTest()
      Returns whether we are in test mode, i.e., system or env property "iip.test" is true.
      Returns:
      true for test mode, false else
    • addAppEnvironment

      public static void addAppEnvironment(List<String> args)
      Adds all environment properties starting with IIP_APP_PREFIX or IIP_TEST_PREFIX to the command line of the service to be started.
      Parameters:
      args - the arguments to add the application environment settings
    • addAppEnvironment

      public static void addAppEnvironment(List<String> args, File pluginParent)
      Adds all environment properties starting with IIP_APP_PREFIX or IIP_TEST_PREFIX to the command line of the service to be started.
      Parameters:
      args - the arguments to add the application environment settings
      pluginParent - the folder containing the "jars" and the "plugins" folder if the do exist
    • setAasNotificationMode

      public static de.iip_ecosphere.platform.support.iip_aas.ActiveAasBase.NotificationMode setAasNotificationMode(String[] args, de.iip_ecosphere.platform.support.iip_aas.ActiveAasBase.NotificationMode dflt)
      Retrieves the AAS notification mode from cmd line argument "iip.test.aas.notification" and sets this mode for AAS interactions. [testing]
      Parameters:
      args - the command line arguments
      dflt - the default value if no argument is present, may be null to keep the actual mode if not set explicitly
      Returns:
      the actual AAS notification mode, may be null for none
    • considerInstalledDependencies

      public static void considerInstalledDependencies()
      Considers installed dependencies properties, -D"iip.test.java8".
    • transferArgsToEnvironment

      public static void transferArgsToEnvironment(String[] args)
      Transfers IIP_APP_PREFIX as system property or usual command line argument to the system properties if not already set.
      Parameters:
      args - the arguments to be analyzed
    • startServer

      protected static boolean startServer(String[] args)
      Starts a server instance passed in by PARAM_IIP_START_SERVER.
      Parameters:
      args - the command line arguments
      Returns:
      true for handled, false for not handled
    • getAppId

      public static String getAppId()
      Returns the application/application instance id passed in by PARAM_IIP_APP_ID.
      Returns:
      the app/application instance id (separated by ServiceBase.APPLICATION_SEPARATOR, may be empty
    • getServiceId

      public static String getServiceId(Service service)
      Returns the id of service taking getAppId() into account.
      Parameters:
      service - the service
      Returns:
      the service including appId if known/specified
    • getServiceId

      public static String getServiceId(String sId)
      Returns the completed service id sId taking getAppId() into account.
      Parameters:
      sId - the service id
      Returns:
      the service including appId if known/specified
    • getServiceCommandNetworkMgrKey

      public static String getServiceCommandNetworkMgrKey(String serviceId)
      Returns the network manager key used by this descriptor to allocate dynamic network ports for service commands.
      Parameters:
      serviceId - the service id
      Returns:
      the key
    • getServiceProcessNetworkMgrKey

      public static String getServiceProcessNetworkMgrKey(String serviceId)
      Returns the network manager key used by this descriptor to allocate dynamic network ports for a non-Java realization process.
      Parameters:
      serviceId - the service id
      Returns:
      the key
    • composeArgument

      public static String composeArgument(String argName, Object value)
      Composes a command line argument for the starter.
      Parameters:
      argName - the argument name
      value - the value
      Returns:
      the composed command line argument
    • getServicePortName

      public static String getServicePortName(String serviceId)
      Returns the argument name carrying the delegation port of serviceId. Arguments of this kind will be collected for getServicePort(String)
      Parameters:
      serviceId - the service id (will be normalized to command line requirements)
      Returns:
      the argument name
    • getServicePort

      public static int getServicePort(String serviceId)
      Returns a service port obtained in parse(String...).
      Parameters:
      serviceId - the service id (will be normalized to command line requirements)
      Returns:
      the port number, negative if invalid or unknown
    • normalizeServiceId

      public static String normalizeServiceId(String serviceId)
      Returns the normalized service id.
      Parameters:
      serviceId - the service id
      Returns:
      the /normalized) service id
    • setServiceAutostart

      public static void setServiceAutostart(boolean autostart)
      Enables service autostart for the next services to be mapped. Disabled by default. Shall be called before #main(String[]). Usually done when needed by platform during service lifecycle. [testing]
      Parameters:
      autostart - true enables autostart, false disables autostart
    • setOnServiceAutostartAttachShutdownHook

      public static void setOnServiceAutostartAttachShutdownHook(boolean hook)
      Enables/disable shutdown hooks on service autostarts for service autostops. Enabled by default. Shall be called before #main(String[]). [testing]
      Parameters:
      hook - true enables creation of shutdown hooks, false disables shutdown hooks on autostart
    • getMappedService

      public static Service getMappedService(String serviceId)
      Returns service mapped by this starter. These are typically all services executed within the same JVM.
      Parameters:
      serviceId - the serviceId, ignored if null
      Returns:
      the service if known, null else
    • configurePort

      private static void configurePort(String[] args, String paramName, Consumer<Integer> consumer)
      Configures a port.
      Parameters:
      args - the command line arguments
      paramName - the parameter name to look for
      consumer - the port consumer
    • parse

      public static void parse(String... args)
      Parses command line arguments. Collects information for getServicePort(String).
      Parameters:
      args - the command line arguments
    • setCmdServerConfigurer

      protected static void setCmdServerConfigurer(Consumer<de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder> configurer)
      Sets a configurer for the AAS asset command server.
      Parameters:
      configurer - the configurer
    • start

      public static void start()
      Starts the server instance(s).
      See Also:
    • getLogger

      private static de.iip_ecosphere.platform.support.logging.Logger getLogger()
      Returns the logger instance.
      Returns:
      the logger instance
    • getProtocolBuilder

      public static de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder getProtocolBuilder()
      Returns the protocol builder for mapping services.
      Returns:
      the protocol builder, null if parse(String[]) was not called before
    • getServiceMapper

      public static ServiceMapper getServiceMapper()
      Returns the service mapper linked to getProtocolBuilder().
      Returns:
      the service mapper, null if parse(String[]) was not called before
    • mapService

      public static void mapService(ServiceMapper mapper, Service service, boolean enableAutostart)
      Maps a service through a given mapper and metrics client. No mapping will take place if either service, mapper or getProtocolBuilder() is null. The specific mapping for the metrics will only take place if metricsClient is not null.
      Parameters:
      mapper - the service mapper instance (may be null, no mapping will happen then)
      service - the service to be mapped (may be null, no mapping will happen then)
      enableAutostart - whether service autostart shall be performed if , e.g., not for family members
    • extractProcessArtifacts

      public static File extractProcessArtifacts(String sId, ProcessSpec pSpec, File artFile, File processBaseDir) throws IOException
      Extracts artifacts that are required for a service being realized of external processes.
      Parameters:
      sId - the service id
      pSpec - the process specification
      artFile - the ZIP/JAR service artifact
      processBaseDir - the base directory to be used to create a process home directory within if ProcessSpec.getHomePath() is null
      Returns:
      the folder into which the process has been extracted. May be ProcessSpec.getHomePath() or a temporary directory.
      Throws:
      IOException - if accessing files fails
    • findArtifact

      public static InputStream findArtifact(File artFile, String artPath)
      Finds a file artifact within an application file/artifact.
      Parameters:
      artFile - the artifact file
      artPath - the file artifact path within artFile
      Returns:
      the input stream (may be null for not found)
    • mapService

      public static void mapService(Service service, boolean enableAutostart)
      Maps a service through the default mapper and the default metrics client. [Convenience method for generation]
      Parameters:
      service - the service to be mapped (may be null, no mapping will happen then)
      enableAutostart - whether service autostart shall be performed if , e.g., not for family members
      See Also:
    • mapService

      public static void mapService(Service service)
      Maps a service through the default mapper and the default metrics client. [Convenience method for generation] By default, do autostart.
      Parameters:
      service - the service to be mapped (may be null, no mapping will happen then)
      See Also:
    • shutdown

      public static void shutdown()
      Terminates running server instances.
    • getSetup

      public static EnvironmentSetup getSetup()
      Returns the environment setup.
      Returns:
      the setup
    • enablesLocalTransport

      protected static final boolean enablesLocalTransport(de.iip_ecosphere.platform.transport.connectors.TransportSetup globalSetup)
      Returns whether globalSetup enables local transport.
      Parameters:
      globalSetup - the global setup
      Returns:
      true for enabled, false for local transport is sufficient, e.g., in local testing
    • getApplicationSetupAsStream

      public static InputStream getApplicationSetupAsStream()
      Returns the application setup as stream.
      Returns:
      the application setup as stream
    • setLocalTransportSetupSupplier

      protected static void setLocalTransportSetupSupplier(Function<EnvironmentSetup,de.iip_ecosphere.platform.transport.connectors.TransportSetup> supplier)
      Changes the local transport supplier determining the setup for the local transport.
      Parameters:
      supplier - the new supplier, may be null for none
    • runPlugin

      protected static void runPlugin(String[] args)
      Selects the actual functional plugin via cmd line argument of "iip.test.plugin". If none is given, start the default plugin.
      Parameters:
      args - command line arguments
    • loadOktoPlugins

      public static void loadOktoPlugins()
      Loads the oktoflow plugins if present. Loads plugins only once. Needs args transferred to environment, i.e., after parse.
      See Also:
    • main

      public static void main(String[] args)
      Simple default start main program without mapping any services before startup. This can be done on-demand through getProtocolBuilder() and getServiceMapper().
      Parameters:
      args - the command line arguments