Class Starter
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.Starter
-
public class Starter extends java.lang.ObjectService environment starter reading command server information from the command line.- Author:
- Holger Eichelberger, SSE
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringARG_AAS_NOTIFICATIONprivate static de.iip_ecosphere.platform.support.aas.ProtocolServerBuilderbuilderprotected static java.util.function.Function<EnvironmentSetup,de.iip_ecosphere.platform.transport.connectors.TransportSetup>DFLT_LOCAL_TRANSPORT_SETUP_SUPPLIERDefault supplier for the local transport setup.static java.lang.StringIIP_APP_PREFIXstatic java.lang.StringIIP_TEST_PREFIXprivate static java.util.function.Function<EnvironmentSetup,de.iip_ecosphere.platform.transport.connectors.TransportSetup>localTransportSetupSupplierDefines the supplier for the local transport setup.private static java.util.Map<java.lang.String,Service>mappedServicesprivate static booleanonServiceAutostartAttachShutdownHookstatic java.lang.StringPARAM_IIP_APP_IDstatic java.lang.StringPARAM_IIP_PORTstatic java.lang.StringPARAM_IIP_PROTOCOLstatic java.lang.StringPARAM_IIP_TEST_AAS_PORTstatic java.lang.StringPARAM_IIP_TEST_AASREG_PORTstatic java.lang.StringPARAM_IIP_TEST_SERVICE_AUTOSTARTstatic java.lang.StringPARAM_IIP_TEST_TRANSPORT_PORTstatic java.lang.StringPARAM_IIP_TRANSPORT_GLOBALstatic java.lang.StringPROPERTY_JAVA8private static de.iip_ecosphere.platform.support.Serverserverprivate static booleanserviceAutostartprivate static java.util.Map<java.lang.String,java.lang.Integer>servicePortsprivate static EnvironmentSetupsetupprivate static booleantransportGlobalprivate static java.lang.StringtransportHostprivate static inttransportPort
-
Constructor Summary
Constructors Constructor Description Starter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddAppEnvironment(java.util.List<java.lang.String> args)Adds all environment properties starting withIIP_APP_PREFIXorIIP_TEST_PREFIXto the command line of the service to be started.static java.lang.StringcomposeArgument(java.lang.String argName, java.lang.Object value)Composes a command line argument for the starter.static voidconsiderInstalledDependencies()Considers installed dependencies properties, -D"iip.test.java8".protected static booleanenablesLocalTransport(de.iip_ecosphere.platform.transport.connectors.TransportSetup globalSetup)Returns whetherglobalSetupenables local transport.static java.io.FileextractProcessArtifacts(java.lang.String sId, ProcessSpec pSpec, java.io.File artFile, java.io.File processBaseDir)Extracts artifacts that are required for a service being realized of external processes.static java.io.InputStreamgetApplicationSetupAsStream()Returns the application setup as stream.private static org.slf4j.LoggergetLogger()Returns the logger instance.static ServicegetMappedService(java.lang.String serviceId)Returns service mapped by this starter.static de.iip_ecosphere.platform.support.aas.ProtocolServerBuildergetProtocolBuilder()Returns the protocol builder for mapping services.static java.lang.StringgetServiceCommandNetworkMgrKey(java.lang.String serviceId)Returns the network manager key used by this descriptor to allocate dynamic network ports for service commands.static ServiceMappergetServiceMapper()Returns the service mapper linked togetProtocolBuilder().static intgetServicePort(java.lang.String serviceId)Returns a service port obtained inparse(String...).static java.lang.StringgetServicePortName(java.lang.String serviceId)Returns the argument name carrying the delegation port ofserviceId.static java.lang.StringgetServiceProcessNetworkMgrKey(java.lang.String serviceId)Returns the network manager key used by this descriptor to allocate dynamic network ports for a non-Java realization process.static EnvironmentSetupgetSetup()Returns the environment setup.static voidmain(java.lang.String[] args)Simple default start main program without mapping any services before startup.static voidmapService(Service service)Maps a service through the default mapper and the default metrics client.static voidmapService(ServiceMapper mapper, Service service, boolean enableAutostart)Maps a service through a given mapper and metrics client.static voidmapService(Service service, boolean enableAutostart)Maps a service through the default mapper and the default metrics client.static java.lang.StringnormalizeServiceId(java.lang.String serviceId)Returns the normalized service id.static voidparse(java.lang.String... args)Parses command line arguments.static de.iip_ecosphere.platform.support.iip_aas.ActiveAasBase.NotificationModesetAasNotificationMode(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.protected static voidsetLocalTransportSetupSupplier(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.static voidsetOnServiceAutostartAttachShutdownHook(boolean hook)Enables/disable shutdown hooks on service autostarts for service autostops.static voidsetServiceAutostart(boolean autostart)Enables service autostart for the next services to be mapped.static voidshutdown()Terminates running server instances.static voidstart()Starts the server instance(s).static voidtransferArgsToEnvironment(java.lang.String[] args)TransfersIIP_APP_PREFIXas system property or usual command line argument to the system properties if not already set.
-
-
-
Field Detail
-
PARAM_IIP_PROTOCOL
public static final java.lang.String PARAM_IIP_PROTOCOL
- See Also:
- Constant Field Values
-
PARAM_IIP_PORT
public static final java.lang.String PARAM_IIP_PORT
- 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
-
PROPERTY_JAVA8
public static final java.lang.String PROPERTY_JAVA8
- See Also:
- Constant Field Values
-
IIP_APP_PREFIX
public static final java.lang.String IIP_APP_PREFIX
- See Also:
- Constant Field Values
-
IIP_TEST_PREFIX
public static final java.lang.String IIP_TEST_PREFIX
- 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
-
setup
private static EnvironmentSetup setup
-
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.
-
localTransportSetupSupplier
private static java.util.function.Function<EnvironmentSetup,de.iip_ecosphere.platform.transport.connectors.TransportSetup> localTransportSetupSupplier
Defines the supplier for the local transport setup. Called only ingetSetup()ifa need for a separation of global/local transportwas detected. Specific service execution implementations may override this usingsetLocalTransportSetupSupplier(Function). Default isDFLT_LOCAL_TRANSPORT_SETUP_SUPPLIER.
-
-
Method Detail
-
addAppEnvironment
public static void addAppEnvironment(java.util.List<java.lang.String> args)
Adds all environment properties starting withIIP_APP_PREFIXorIIP_TEST_PREFIXto 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 argumentsdflt- 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)
TransfersIIP_APP_PREFIXas 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 namevalue- 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 ofserviceId. Arguments of this kind will be collected forgetServicePort(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 inparse(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-trueenables autostart,falsedisables 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-trueenables creation of shutdown hooks,falsedisables 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 forgetServicePort(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
-
getServiceMapper
public static ServiceMapper getServiceMapper()
Returns the service mapper linked togetProtocolBuilder().- 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 eitherservice,mapperorgetProtocolBuilder()is null. The specific mapping for the metrics will only take place ifmetricsClientis 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.IOExceptionExtracts artifacts that are required for a service being realized of external processes.- Parameters:
sId- the service idpSpec- the process specificationartFile- the ZIP/JAR service artifactprocessBaseDir- the base directory to be used to create a process home directory within ifProcessSpec.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 whetherglobalSetupenables local transport.- Parameters:
globalSetup- the global setup- Returns:
truefor enabled,falsefor 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 throughgetProtocolBuilder()andgetServiceMapper().- Parameters:
args- the command line arguments
-
-