Class Starter


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

      • PARAM_IIP_PROTOCOL

        public static final java.lang.String PARAM_IIP_PROTOCOL
        See Also:
        Constant Field Values
      • PARAM_IIP_APP_ID

        public static final java.lang.String PARAM_IIP_APP_ID
        See Also:
        Constant Field Values
      • PARAM_IIP_TRANSPORT_GLOBAL

        public static final java.lang.String PARAM_IIP_TRANSPORT_GLOBAL
        See Also:
        Constant Field Values
      • PARAM_IIP_TEST_TRANSPORT_PORT

        public static final java.lang.String PARAM_IIP_TEST_TRANSPORT_PORT
        See Also:
        Constant Field Values
      • PARAM_IIP_TEST_AAS_PORT

        public static final java.lang.String PARAM_IIP_TEST_AAS_PORT
        See Also:
        Constant Field Values
      • PARAM_IIP_TEST_AASREG_PORT

        public static final java.lang.String PARAM_IIP_TEST_AASREG_PORT
        See Also:
        Constant Field Values
      • PARAM_IIP_TEST_SERVICE_AUTOSTART

        public static final java.lang.String PARAM_IIP_TEST_SERVICE_AUTOSTART
        See Also:
        Constant Field Values
      • ARG_AAS_NOTIFICATION

        public static final java.lang.String ARG_AAS_NOTIFICATION
        See Also:
        Constant Field Values
      • builder

        private static de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder builder
      • server

        private static de.iip_ecosphere.platform.support.Server server
      • servicePorts

        private static java.util.Map<java.lang.String,​java.lang.Integer> servicePorts
      • mappedServices

        private static java.util.Map<java.lang.String,​Service> mappedServices
      • serviceAutostart

        private static boolean serviceAutostart
      • onServiceAutostartAttachShutdownHook

        private static boolean onServiceAutostartAttachShutdownHook
      • transportPort

        private static int transportPort
      • transportHost

        private static java.lang.String transportHost
      • transportGlobal

        private static boolean transportGlobal
      • DFLT_LOCAL_TRANSPORT_SETUP_SUPPLIER

        protected static final java.util.function.Function<EnvironmentSetup,​de.iip_ecosphere.platform.transport.connectors.TransportSetup> DFLT_LOCAL_TRANSPORT_SETUP_SUPPLIER
        Default supplier for the local transport setup. This basic implementation is a bit heuristic as it assumes the same authentication/port as the global setup, which may not work in certain container settings.
    • Constructor Detail

      • Starter

        public Starter()
    • Method Detail

      • addAppEnvironment

        public static void addAppEnvironment​(java.util.List<java.lang.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
      • setAasNotificationMode

        public static de.iip_ecosphere.platform.support.iip_aas.ActiveAasBase.NotificationMode setAasNotificationMode​(java.lang.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​(java.lang.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
      • getServiceCommandNetworkMgrKey

        public static java.lang.String getServiceCommandNetworkMgrKey​(java.lang.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 java.lang.String getServiceProcessNetworkMgrKey​(java.lang.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 java.lang.String composeArgument​(java.lang.String argName,
                                                       java.lang.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 java.lang.String getServicePortName​(java.lang.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​(java.lang.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 java.lang.String normalizeServiceId​(java.lang.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​(java.lang.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
      • parse

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

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

        private static org.slf4j.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
      • 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 java.io.File extractProcessArtifacts​(java.lang.String sId,
                                                           ProcessSpec pSpec,
                                                           java.io.File artFile,
                                                           java.io.File processBaseDir)
                                                    throws java.io.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:
        java.io.IOException - if accessing files fails
      • 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:
        getServiceMapper(), mapService(ServiceMapper, Service, boolean)
      • 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:
        getServiceMapper(), mapService(ServiceMapper, Service, boolean)
      • 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 java.io.InputStream getApplicationSetupAsStream()
        Returns the application setup as stream.
        Returns:
        the application setup as stream
      • setLocalTransportSetupSupplier

        protected static void setLocalTransportSetupSupplier​(java.util.function.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
      • main

        public static void main​(java.lang.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