Class DescriptorUtils


  • public class DescriptorUtils
    extends java.lang.Object
    Descriptor and artifact utility functions that may be used standalone.
    Author:
    Holger Eichelberger, SSE
    • Constructor Summary

      Constructors 
      Constructor Description
      DescriptorUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addEndpointArgs​(java.util.List<java.lang.String> cmdLine, Endpoint endpoint, int port, java.lang.String host)
      Adds commandline args for a given endpoint.
      static void addEndpointArgs​(java.util.List<java.lang.String> cmdLine, Endpoint endpoint, de.iip_ecosphere.platform.support.ServerAddress addr)
      Adds commandline args for a given endpoint.
      private static void addUrlSafe​(java.util.List<java.net.URL> urls, java.io.File file)
      Adds the URL of file to urls.
      static java.lang.ClassLoader createClassLoader​(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.ClassLoader determineArtifactClassLoader​(SpringCloudArtifactDescriptor artifact, java.io.File homeDir)
      Determines the class loader of the artifact.
      static java.lang.ClassLoader determineArtifactClassLoader​(SpringCloudServiceDescriptor service)
      Determines the class loader of the artifact of service.
      private static java.lang.String getDescriptorName()
      Returns the deployment descriptor file name to use.
      private static org.slf4j.Logger getLogger()
      Returns the logger.
      static YamlArtifact readFromClasspath()
      Reads the YAML deployment descriptor from file.
      static YamlArtifact readFromFile​(java.io.File file)
      Reads the YAML deployment descriptor from file.
      static void throwExecutionException​(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 void throwExecutionException​(java.lang.String action, java.lang.Throwable th)
      Throws an execution exception for the given throwable and logs an error in the same step.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DescriptorUtils

        public DescriptorUtils()
    • Method Detail

      • readFromFile

        public static YamlArtifact readFromFile​(java.io.File file)
                                         throws java.util.concurrent.ExecutionException
        Reads the YAML deployment descriptor from file.
        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 from file.
        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.ExecutionException
        Throws an execution exception for the given throwable and logs an error in the same step.
        Parameters:
        action - the actual action to log
        th - the throwable
        Throws:
        java.util.concurrent.ExecutionException - the exception based on th
      • throwExecutionException

        public static void throwExecutionException​(java.lang.String action,
                                                   java.lang.String message)
                                            throws java.util.concurrent.ExecutionException
        Throws an execution exception for the given message and logs an error in the same step.
        Parameters:
        action - the actual action to log
        message - the message for the exception
        Throws:
        java.util.concurrent.ExecutionException - the exception based on message
      • 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 given endpoint.
        Parameters:
        cmdLine - the command line arguments to modify as a side effect
        endpoint - the endpoint to turn into command line arguments
        addr - the address containing port number and host (for substitution in results delivered by endpoint)
      • 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 given endpoint.
        Parameters:
        cmdLine - the command line arguments to modify as a side effect
        endpoint - the endpoint to turn into command line arguments
        port - the port number (for substitution in results delivered by endpoint)
        host - the host name (for substitution in results delivered by endpoint)
      • 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.ExecutionException
        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.
        Parameters:
        jar - the JAR file to read
        brokerPort - the port where the transport broker is running
        brokerHost - 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 used
        serviceProtocol - the protocol to run for the AAS command server (see AasFactory)
        Returns:
        the list of command line args to use
        Throws:
        java.io.IOException - if jar cannot be found or reading jar fails
        java.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.ExecutionException
        Creates command line args for executing the (Spring) fat JAR in standalone/debugging manner.
        Parameters:
        jar - the JAR file to read
        brokerPort - the port where the transport broker is running
        brokerHost - 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 used
        serviceProtocol - the protocol to run for the AAS command server (see AasFactory)
        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 - if jar cannot be found or reading jar fails
        java.util.concurrent.ExecutionException - if extracting process artifacts fails
      • createClassLoader

        public static java.lang.ClassLoader createClassLoader​(java.io.File jarFile)
                                                       throws java.lang.Exception
        Creates 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 the artifact.
        Parameters:
        artifact - the artifact to determine the class loader for
        homeDir - 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 of file to urls. Emits a warning if URL problems occur.
        Parameters:
        urls - the URL list to be modified as a side effect
        file - the file to take the URL from
      • determineArtifactClassLoader

        public static java.lang.ClassLoader determineArtifactClassLoader​(SpringCloudServiceDescriptor service)
        Determines the class loader of the artifact of service.
        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