Class ClasspathJavaCommandBuilder

  • All Implemented Interfaces:
    org.springframework.cloud.deployer.spi.local.CommandBuilder

    public class ClasspathJavaCommandBuilder
    extends org.springframework.cloud.deployer.spi.local.JavaCommandBuilder
    A command builder that excepts classpath-based Spring service starting for ZIP service artifacts as well as JAR service artifacts. Unfortunately, the Spring deployers cannot easily be extended through regular mechanisms, so we hook in via reflection (ugly). Unfortunately, the local deployer does not even pass on the work directory, so we have to "guess" it. The work folder in turn is needed as the services JVM will be started within and we need the JAR files of the application unpacked there.
    Author:
    Holger Eichelberger, SSE
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String curDeployerId  
      static java.lang.String PROP_ZIP_CLASSPATH  
      private org.springframework.cloud.deployer.spi.local.LocalDeployerProperties properties  
    • Constructor Summary

      Constructors 
      Constructor Description
      ClasspathJavaCommandBuilder​(org.springframework.cloud.deployer.spi.local.LocalDeployerProperties properties)
      Creates the command builder.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String add​(java.lang.String classpath, org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request, java.io.File workDir, boolean asWildcard)
      Adds shared libraries to the classpath.
      protected void addJavaExecutionOptions​(java.util.List<java.lang.String> commands, org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request)  
      java.lang.ProcessBuilder buildExecutionCommand​(org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request, java.util.Map<java.lang.String,​java.lang.String> appInstanceEnv, java.lang.String deployerId, java.util.Optional<java.lang.Integer> appInstanceNumber, org.springframework.cloud.deployer.spi.local.LocalDeployerProperties localDeployerProperties, java.util.Optional<org.springframework.cloud.deployer.spi.local.DebugAddress> debugAddressOption)  
      private boolean checkCpFile​(java.io.File cpFile, org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request, java.io.File workDir)
      Checks/rewrites a classpath file.
      private static void cleanWorkdirs​(org.springframework.cloud.deployer.spi.local.LocalDeployerProperties properties)
      Tries to clean up workdirs created by the local deployer that are left over from the last time, e.g., after issuing CTRL+C.
      private boolean copySharedLibs​(java.io.File sharedLibs, java.io.File target)
      Copy shared JAR-files (non-recursive).
      private java.io.File findWorkingDirectory()
      Guess the working directory.
      private static org.slf4j.Logger getLogger()
      Returns the logger of this class.
      (package private) static void installInto​(org.springframework.cloud.deployer.spi.app.AppDeployer deployer)
      Installs an instance of this builder into deployer.
      • Methods inherited from class org.springframework.cloud.deployer.spi.local.JavaCommandBuilder

        addJavaOptions, bindDeploymentProperties, getBaseUrl, getPortSuggestion
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.springframework.cloud.deployer.spi.local.CommandBuilder

        getJdwpOptions
    • Field Detail

      • PROP_ZIP_CLASSPATH

        public static final java.lang.String PROP_ZIP_CLASSPATH
        See Also:
        Constant Field Values
      • properties

        private final org.springframework.cloud.deployer.spi.local.LocalDeployerProperties properties
      • curDeployerId

        private java.lang.String curDeployerId
    • Constructor Detail

      • ClasspathJavaCommandBuilder

        public ClasspathJavaCommandBuilder​(org.springframework.cloud.deployer.spi.local.LocalDeployerProperties properties)
        Creates the command builder.
        Parameters:
        properties - the local properties as setup of the local deployer
    • Method Detail

      • buildExecutionCommand

        public java.lang.ProcessBuilder buildExecutionCommand​(org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request,
                                                              java.util.Map<java.lang.String,​java.lang.String> appInstanceEnv,
                                                              java.lang.String deployerId,
                                                              java.util.Optional<java.lang.Integer> appInstanceNumber,
                                                              org.springframework.cloud.deployer.spi.local.LocalDeployerProperties localDeployerProperties,
                                                              java.util.Optional<org.springframework.cloud.deployer.spi.local.DebugAddress> debugAddressOption)
        Specified by:
        buildExecutionCommand in interface org.springframework.cloud.deployer.spi.local.CommandBuilder
        Overrides:
        buildExecutionCommand in class org.springframework.cloud.deployer.spi.local.JavaCommandBuilder
      • findWorkingDirectory

        private java.io.File findWorkingDirectory()
        Guess the working directory. Start with the root from properties, find folders that contain only of numbers and contain curDeployerId as sub-folder. Then sort according to the creation timestamp (we may also take the folder name as it is a timestamp) and return the contained folder with curDeployerId.
        Returns:
        returns the working directory or as last resort a temporary one where the execution probably will fail
      • getLogger

        private static org.slf4j.Logger getLogger()
        Returns the logger of this class.
        Returns:
        the logger
      • copySharedLibs

        private boolean copySharedLibs​(java.io.File sharedLibs,
                                       java.io.File target)
        Copy shared JAR-files (non-recursive).
        Parameters:
        sharedLibs - the shared libs folder
        target - the target folder
        Returns:
        true if JAR-files were copied, false else
      • add

        private java.lang.String add​(java.lang.String classpath,
                                     org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request,
                                     java.io.File workDir,
                                     boolean asWildcard)
        Adds shared libraries to the classpath.
        Parameters:
        classpath - the base classpath
        request - the deployment request
        workDir - the work directory
        asWildcard - adds shared libraries as wildcard or by individual files to the classpath
        Returns:
        the modified classpath
      • checkCpFile

        private boolean checkCpFile​(java.io.File cpFile,
                                    org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request,
                                    java.io.File workDir)
        Checks/rewrites a classpath file.
        Parameters:
        cpFile - the (existing) file to check
        request - the deployment request object
        workDir - the work directory
        Returns:
        true if the file was modified without problems, false if the wildcard classpath shall be used
      • addJavaExecutionOptions

        protected void addJavaExecutionOptions​(java.util.List<java.lang.String> commands,
                                               org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request)
        Overrides:
        addJavaExecutionOptions in class org.springframework.cloud.deployer.spi.local.JavaCommandBuilder
      • cleanWorkdirs

        private static void cleanWorkdirs​(org.springframework.cloud.deployer.spi.local.LocalDeployerProperties properties)
        Tries to clean up workdirs created by the local deployer that are left over from the last time, e.g., after issuing CTRL+C. We recommend setting up a dedicated workdir, e.g., a folder within temp.
        Parameters:
        properties - the local deployer properties
      • installInto

        static void installInto​(org.springframework.cloud.deployer.spi.app.AppDeployer deployer)
        Installs an instance of this builder into deployer.
        Parameters:
        deployer - the deployer instance, may be null