Class Starter
java.lang.Object
de.iip_ecosphere.platform.services.environment.Starter
Service environment starter reading command server information from the command line.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThe default plugin for displaying the help texts of the plugins.static interfaceDefines a starter plugin. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static Runnableprivate static Stringprivate static de.iip_ecosphere.platform.support.Serverstatic final Stringprivate static de.iip_ecosphere.platform.support.aas.ProtocolServerBuilderprivate static de.iip_ecosphere.platform.support.Serverprivate static Consumer<de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder> protected static final Function<EnvironmentSetup, de.iip_ecosphere.platform.transport.connectors.TransportSetup> Default supplier for the local transport setup.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprivate static Function<EnvironmentSetup, de.iip_ecosphere.platform.transport.connectors.TransportSetup> Defines the supplier for the local transport setup.private static booleanprivate static booleanstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprivate static Map<String, Starter.Plugin> static final Stringprivate static booleanprivate static EnvironmentSetupprivate static booleanprivate static Stringprivate static int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddAppEnvironment(List<String> args) Adds all environment properties starting withIIP_APP_PREFIXorIIP_TEST_PREFIXto the command line of the service to be started.static voidaddAppEnvironment(List<String> args, File pluginParent) Adds all environment properties starting withIIP_APP_PREFIXorIIP_TEST_PREFIXto the command line of the service to be started.static StringcomposeArgument(String argName, Object value) Composes a command line argument for the starter.private static voidconfigurePort(String[] args, String paramName, Consumer<Integer> consumer) Configures a port.static voidConsiders installed dependencies properties, -D"iip.test.java8".protected static final booleanenablesLocalTransport(de.iip_ecosphere.platform.transport.connectors.TransportSetup globalSetup) Returns whetherglobalSetupenables local transport.static booleanReturns whether the execution may expect a running AAS.static FileextractProcessArtifacts(String sId, ProcessSpec pSpec, File artFile, File processBaseDir) Extracts artifacts that are required for a service being realized of external processes.static InputStreamfindArtifact(File artFile, String artPath) Finds a file artifact within an application file/artifact.static StringgetAppId()Returns the application/application instance id passed in byPARAM_IIP_APP_ID.static InputStreamReturns the application setup as stream.private static de.iip_ecosphere.platform.support.logging.LoggerReturns the logger instance.static ServicegetMappedService(String serviceId) Returns service mapped by this starter.static de.iip_ecosphere.platform.support.aas.ProtocolServerBuilderReturns the protocol builder for mapping services.static StringgetServiceCommandNetworkMgrKey(String serviceId) Returns the network manager key used by this descriptor to allocate dynamic network ports for service commands.static StringgetServiceId(Service service) Returns the id ofservicetakinggetAppId()into account.static StringgetServiceId(String sId) Returns the completed service idsIdtakinggetAppId()into account.static ServiceMapperReturns the service mapper linked togetProtocolBuilder().static intgetServicePort(String serviceId) Returns a service port obtained inparse(String...).static StringgetServicePortName(String serviceId) Returns the argument name carrying the delegation port ofserviceId.static StringgetServiceProcessNetworkMgrKey(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 booleaninTest()Returns whether we are in test mode, i.e., system or env property "iip.test" istrue.static voidLoads the oktoflow plugins if present.static voidSimple 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 StringnormalizeServiceId(String serviceId) Returns the normalized service id.static voidParses command line arguments.static voidregisterAfterPluginInitializer(Runnable initializer) Sets an initializer to be executed after loading plugins inloadOktoPlugins().protected static voidRegisters the default plugins.protected static voidregisterPlugin(String name, Starter.Plugin plugin) Registers a functional plugin.protected static voidSelects the actual functional plugin via cmd line argument of "iip.test.plugin".static de.iip_ecosphere.platform.support.iip_aas.ActiveAasBase.NotificationModesetAasNotificationMode(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 voidsetCmdServerConfigurer(Consumer<de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder> configurer) Sets a configurer for the AAS asset command server.protected static voidsetLocalTransportSetupSupplier(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).protected static booleanstartServer(String[] args) Starts a server instance passed in byPARAM_IIP_START_SERVER.static voidtransferArgsToEnvironment(String[] args) TransfersIIP_APP_PREFIXas system property or usual command line argument to the system properties if not already set.
-
Field Details
-
PARAM_IIP_PROTOCOL
- See Also:
-
PARAM_IIP_PORT
- See Also:
-
PARAM_IIP_APP_ID
- See Also:
-
PARAM_IIP_APP_PLUGINS
- See Also:
-
PARAM_IIP_APP_PLUGINS_NO_PLUGINS
- See Also:
-
PARAM_IIP_TRANSPORT_GLOBAL
- See Also:
-
PARAM_IIP_START_SERVER
- See Also:
-
PARAM_IIP_START_SERVER_ONLY
- See Also:
-
IIP_APP_PREFIX
- See Also:
-
IIP_APP_NOAAS
- See Also:
-
PARAM_IIP_TEST_TRANSPORT_PORT
- See Also:
-
PARAM_IIP_TEST_AAS_PORT
- See Also:
-
PARAM_IIP_TEST_SM_PORT
- See Also:
-
PARAM_IIP_TEST_AASREG_PORT
- See Also:
-
PARAM_IIP_TEST_SMREG_PORT
- See Also:
-
PARAM_IIP_TEST_SERVICE_AUTOSTART
- See Also:
-
ARG_AAS_NOTIFICATION
- See Also:
-
PROPERTY_JAVA8
- See Also:
-
IIP_TEST
- See Also:
-
IIP_TEST_PREFIX
- See Also:
-
IIP_TEST_PLUGIN
- See Also:
-
builder
private static de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder builder -
cmdServer
private static de.iip_ecosphere.platform.support.Server cmdServer -
appServer
private static de.iip_ecosphere.platform.support.Server appServer -
servicePorts
-
mappedServices
-
serviceAutostart
private static boolean serviceAutostart -
onServiceAutostartAttachShutdownHook
private static boolean onServiceAutostartAttachShutdownHook -
transportPort
private static int transportPort -
transportHost
-
transportGlobal
private static boolean transportGlobal -
setup
-
appId
-
plugins
-
oktoPluginsLoaded
private static boolean oktoPluginsLoaded -
cmdServerConfigurer
private static Consumer<de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder> cmdServerConfigurer -
afterPluginInitializer
-
DFLT_LOCAL_TRANSPORT_SETUP_SUPPLIER
protected static final Function<EnvironmentSetup,de.iip_ecosphere.platform.transport.connectors.TransportSetup> DFLT_LOCAL_TRANSPORT_SETUP_SUPPLIERDefault 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 Function<EnvironmentSetup,de.iip_ecosphere.platform.transport.connectors.TransportSetup> localTransportSetupSupplierDefines 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.
-
-
Constructor Details
-
Starter
public Starter()
-
-
Method Details
-
registerPlugin
Registers a functional plugin.- Parameters:
name- the name (turned to lower case)plugin- the plugin instance
-
registerDefaultPlugins
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" istrue.- Returns:
truefor test mode,falseelse
-
addAppEnvironment
Adds all environment properties starting withIIP_APP_PREFIXorIIP_TEST_PREFIXto the command line of the service to be started. The plugin parent folder is taken from the system propertyPARAM_IIP_APP_PLUGINSwith unset default value"".- Parameters:
args- the arguments to add the application environment settings- See Also:
-
addAppEnvironment
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 settingspluginParent- 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 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
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
-
startServer
Starts a server instance passed in byPARAM_IIP_START_SERVER.- Parameters:
args- the command line arguments- Returns:
truefor handled,falsefor not handled
-
getAppId
Returns the application/application instance id passed in byPARAM_IIP_APP_ID.- Returns:
- the app/application instance id (separated by
ServiceBase.APPLICATION_SEPARATOR, may be empty
-
getServiceId
Returns the id ofservicetakinggetAppId()into account.- Parameters:
service- the service- Returns:
- the service including appId if known/specified
-
getServiceId
Returns the completed service idsIdtakinggetAppId()into account.- Parameters:
sId- the service id- Returns:
- the service including appId if known/specified
-
getServiceCommandNetworkMgrKey
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
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
Composes a command line argument for the starter.- Parameters:
argName- the argument namevalue- the value- Returns:
- the composed command line argument
-
getServicePortName
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
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
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
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
Configures a port.- Parameters:
args- the command line argumentsparamName- the parameter name to look forconsumer- the port consumer
-
expectAas
public static boolean expectAas()Returns whether the execution may expect a running AAS.- Returns:
truefor running AAS,falseelse
-
parse
Parses command line arguments. Collects information forgetServicePort(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
Returns the service mapper linked togetProtocolBuilder().- Returns:
- the service mapper, null if
parse(String[])was not called before
-
mapService
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 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 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:
IOException- if accessing files fails
-
findArtifact
Finds a file artifact within an application file/artifact.- Parameters:
artFile- the artifact fileartPath- the file artifact path withinartFile- Returns:
- the input stream (may be null for not found)
-
mapService
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
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
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
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
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
-
registerAfterPluginInitializer
Sets an initializer to be executed after loading plugins inloadOktoPlugins().- Parameters:
initializer- the initializer
-
loadOktoPlugins
public static void loadOktoPlugins()Loads the oktoflow plugins if present. Loads plugins only once. Needs args transferred to environment, i.e., after parse. Runs and clearsafterPluginInitializer.- See Also:
-
main
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
-