Class DescriptorUtils
- java.lang.Object
-
- de.iip_ecosphere.platform.services.spring.DescriptorUtils
-
public class DescriptorUtils extends java.lang.ObjectDescriptor and artifact utility functions that may be used standalone.- Author:
- Holger Eichelberger, SSE
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDescriptorUtils.AccessibleJarLauncher
-
Constructor Summary
Constructors Constructor Description DescriptorUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddEndpointArgs(java.util.List<java.lang.String> cmdLine, Endpoint endpoint, int port, java.lang.String host)Adds commandline args for a givenendpoint.static voidaddEndpointArgs(java.util.List<java.lang.String> cmdLine, Endpoint endpoint, de.iip_ecosphere.platform.support.ServerAddress addr)Adds commandline args for a givenendpoint.private static voidaddUrlSafe(java.util.List<java.net.URL> urls, java.io.File file)Adds the URL offiletourls.static java.lang.ClassLoadercreateClassLoader(java.io.File jarFile)Creates a class loader for a JAR file, in particular an executable Spring-packaged Jar file.static java.util.List<java.lang.String>createStandaloneCommandArgs(java.io.File jar, int brokerPort, java.lang.String brokerHost, int adminPort, java.lang.String serviceProtocol)Creates command line args for executing the (Spring) fat JAR in standalone/debugging manner requesting the spring web server to be executed on an ephemeral port by default.static java.util.List<java.lang.String>createStandaloneCommandArgs(java.io.File jar, int brokerPort, java.lang.String brokerHost, int adminPort, java.lang.String serviceProtocol, int springPort)Creates command line args for executing the (Spring) fat JAR in standalone/debugging manner.static java.lang.ClassLoaderdetermineArtifactClassLoader(SpringCloudArtifactDescriptor artifact, java.io.File homeDir)Determines the class loader of theartifact.static java.lang.ClassLoaderdetermineArtifactClassLoader(SpringCloudServiceDescriptor service)Determines the class loader of the artifact ofservice.private static java.lang.StringgetDescriptorName()Returns the deployment descriptor file name to use.private static org.slf4j.LoggergetLogger()Returns the logger.static YamlArtifactreadFromClasspath()Reads the YAML deployment descriptor fromfile.static YamlArtifactreadFromFile(java.io.File file)Reads the YAML deployment descriptor fromfile.static voidthrowExecutionException(java.lang.String action, java.lang.String message)Throws an execution exception for the given message and logs an error in the same step.static voidthrowExecutionException(java.lang.String action, java.lang.Throwable th)Throws an execution exception for the given throwable and logs an error in the same step.
-
-
-
Method Detail
-
readFromFile
public static YamlArtifact readFromFile(java.io.File file) throws java.util.concurrent.ExecutionException
Reads the YAML deployment descriptor fromfile.- Parameters:
file- the file to read from- Returns:
- the parsed descriptor
- Throws:
java.util.concurrent.ExecutionException- if reading fails for some reason
-
getDescriptorName
private static java.lang.String getDescriptorName()
Returns the deployment descriptor file name to use.- Returns:
- the descriptor file name
-
readFromClasspath
public static YamlArtifact readFromClasspath() throws java.util.concurrent.ExecutionException
Reads the YAML deployment descriptor fromfile.- Returns:
- the parsed descriptor
- Throws:
java.util.concurrent.ExecutionException- if reading fails for some reason
-
throwExecutionException
public static void throwExecutionException(java.lang.String action, java.lang.Throwable th) throws java.util.concurrent.ExecutionExceptionThrows an execution exception for the given throwable and logs an error in the same step.- Parameters:
action- the actual action to logth- the throwable- Throws:
java.util.concurrent.ExecutionException- the exception based onth
-
throwExecutionException
public static void throwExecutionException(java.lang.String action, java.lang.String message) throws java.util.concurrent.ExecutionExceptionThrows an execution exception for the given message and logs an error in the same step.- Parameters:
action- the actual action to logmessage- the message for the exception- Throws:
java.util.concurrent.ExecutionException- the exception based onmessage
-
addEndpointArgs
public static void addEndpointArgs(java.util.List<java.lang.String> cmdLine, Endpoint endpoint, de.iip_ecosphere.platform.support.ServerAddress addr)Adds commandline args for a givenendpoint.- Parameters:
cmdLine- the command line arguments to modify as a side effectendpoint- the endpoint to turn into command line argumentsaddr- the address containing port number and host (for substitution in results delivered byendpoint)
-
addEndpointArgs
public static void addEndpointArgs(java.util.List<java.lang.String> cmdLine, Endpoint endpoint, int port, java.lang.String host)Adds commandline args for a givenendpoint.- Parameters:
cmdLine- the command line arguments to modify as a side effectendpoint- the endpoint to turn into command line argumentsport- the port number (for substitution in results delivered byendpoint)host- the host name (for substitution in results delivered byendpoint)
-
createStandaloneCommandArgs
public static java.util.List<java.lang.String> createStandaloneCommandArgs(java.io.File jar, int brokerPort, java.lang.String brokerHost, int adminPort, java.lang.String serviceProtocol) throws java.io.IOException, java.util.concurrent.ExecutionExceptionCreates command line args for executing the (Spring) fat JAR in standalone/debugging manner requesting the spring web server to be executed on an ephemeral port by default.- Parameters:
jar- the JAR file to readbrokerPort- the port where the transport broker is runningbrokerHost- the host where the transport broker is running (usually "localhost")adminPort- the port where to run the AAS command server, for -1 an emphemeral port will be usedserviceProtocol- the protocol to run for the AAS command server (seeAasFactory)- Returns:
- the list of command line args to use
- Throws:
java.io.IOException- ifjarcannot be found or readingjarfailsjava.util.concurrent.ExecutionException- if extracting process artifacts fails
-
createStandaloneCommandArgs
public static java.util.List<java.lang.String> createStandaloneCommandArgs(java.io.File jar, int brokerPort, java.lang.String brokerHost, int adminPort, java.lang.String serviceProtocol, int springPort) throws java.io.IOException, java.util.concurrent.ExecutionExceptionCreates command line args for executing the (Spring) fat JAR in standalone/debugging manner.- Parameters:
jar- the JAR file to readbrokerPort- the port where the transport broker is runningbrokerHost- the host where the transport broker is running (usually "localhost")adminPort- the port where to run the AAS command server, for -1 an emphemeral port will be usedserviceProtocol- the protocol to run for the AAS command server (seeAasFactory)springPort- the port to run the spring application server on, usually 8080, if negative an ephemeral port will be used- Returns:
- the list of command line args to use
- Throws:
java.io.IOException- ifjarcannot be found or readingjarfailsjava.util.concurrent.ExecutionException- if extracting process artifacts fails
-
createClassLoader
public static java.lang.ClassLoader createClassLoader(java.io.File jarFile) throws java.lang.ExceptionCreates a class loader for a JAR file, in particular an executable Spring-packaged Jar file.- Parameters:
jarFile- the jar file- Returns:
- the class loader
- Throws:
java.lang.Exception- if the class loader cannot be constructed
-
determineArtifactClassLoader
public static java.lang.ClassLoader determineArtifactClassLoader(SpringCloudArtifactDescriptor artifact, java.io.File homeDir)
Determines the class loader of theartifact.- Parameters:
artifact- the artifact to determine the class loader forhomeDir- process home dir to use for unpacking, may be null for none/unknown- Returns:
- the class loader
-
addUrlSafe
private static void addUrlSafe(java.util.List<java.net.URL> urls, java.io.File file)Adds the URL offiletourls. Emits a warning if URL problems occur.- Parameters:
urls- the URL list to be modified as a side effectfile- the file to take the URL from
-
determineArtifactClassLoader
public static java.lang.ClassLoader determineArtifactClassLoader(SpringCloudServiceDescriptor service)
Determines the class loader of the artifact ofservice.- Parameters:
service- the service to determine the class loader for- Returns:
- the class loader
-
getLogger
private static org.slf4j.Logger getLogger()
Returns the logger.- Returns:
- the logger
-
-