Class ClasspathJavaCommandBuilder

java.lang.Object
org.springframework.cloud.deployer.spi.local.JavaCommandBuilder
de.iip_ecosphere.platform.services.spring.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 String
     
    static final String
     
    private final org.springframework.cloud.deployer.spi.local.LocalDeployerProperties
     
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    private String
    add(String classpath, org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request, File workDir, boolean asWildcard)
    Adds shared libraries to the classpath.
    protected void
    addJavaExecutionOptions(List<String> commands, org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request)
     
    buildExecutionCommand(org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request, Map<String,String> appInstanceEnv, String deployerId, Optional<Integer> appInstanceNumber, org.springframework.cloud.deployer.spi.local.LocalDeployerProperties localDeployerProperties, Optional<org.springframework.cloud.deployer.spi.local.DebugAddress> debugAddressOption)
     
    private boolean
    checkCpFile(File cpFile, org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request, 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(File sharedLibs, File target)
    Copy shared JAR-files (non-recursive).
    private File
    Guess the working directory.
    private static de.iip_ecosphere.platform.support.logging.Logger
    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 Details

    • PROP_ZIP_CLASSPATH

      public static final String PROP_ZIP_CLASSPATH
      See Also:
    • properties

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

      private String curDeployerId
  • Constructor Details

    • 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 Details

    • buildExecutionCommand

      public ProcessBuilder buildExecutionCommand(org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request, Map<String,String> appInstanceEnv, String deployerId, Optional<Integer> appInstanceNumber, org.springframework.cloud.deployer.spi.local.LocalDeployerProperties localDeployerProperties, 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 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 de.iip_ecosphere.platform.support.logging.Logger getLogger()
      Returns the logger of this class.
      Returns:
      the logger
    • copySharedLibs

      private boolean copySharedLibs(File sharedLibs, 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 String add(String classpath, org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request, 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(File cpFile, org.springframework.cloud.deployer.spi.core.AppDeploymentRequest request, 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(List<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