Class TargetServiceImpl

java.lang.Object
org.craftercms.deployer.impl.TargetServiceImpl
All Implemented Interfaces:
EventListener, TargetService, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationReadyEvent>

@Component("targetService") @DependsOn("crafter.cacheStoreAdapter") public class TargetServiceImpl extends Object implements TargetService, org.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationReadyEvent>, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
Default implementation of TargetService.
Author:
avasquez
  • Field Details

    • YAML_FILE_EXTENSION

      public static final String YAML_FILE_EXTENSION
      See Also:
    • APPLICATION_CONTEXT_FILENAME_FORMAT

      public static final String APPLICATION_CONTEXT_FILENAME_FORMAT
      See Also:
    • CONFIG_PROPERTY_SOURCE_NAME

      public static final String CONFIG_PROPERTY_SOURCE_NAME
      See Also:
    • CONFIG_BEAN_NAME

      public static final String CONFIG_BEAN_NAME
      See Also:
    • TARGET_ENV_MODEL_KEY

      public static final String TARGET_ENV_MODEL_KEY
      See Also:
    • TARGET_SITE_NAME_MODEL_KEY

      public static final String TARGET_SITE_NAME_MODEL_KEY
      See Also:
    • TARGET_ID_MODEL_KEY

      public static final String TARGET_ID_MODEL_KEY
      See Also:
    • targetConfigFolder

      protected final File targetConfigFolder
    • baseTargetYamlConfigResource

      protected final org.springframework.core.io.Resource baseTargetYamlConfigResource
    • baseTargetYamlConfigOverrideResource

      protected final org.springframework.core.io.Resource baseTargetYamlConfigOverrideResource
    • baseTargetContextResource

      protected final org.springframework.core.io.Resource baseTargetContextResource
    • baseTargetContextOverrideResource

      protected final org.springframework.core.io.Resource baseTargetContextOverrideResource
    • defaultTargetConfigTemplateName

      protected final String defaultTargetConfigTemplateName
    • targetConfigTemplateEngine

      protected final com.github.jknack.handlebars.Handlebars targetConfigTemplateEngine
    • mainApplicationContext

      protected final org.springframework.context.ApplicationContext mainApplicationContext
    • deploymentPipelineFactory

      protected final DeploymentPipelineFactory deploymentPipelineFactory
    • taskScheduler

      protected final org.springframework.scheduling.TaskScheduler taskScheduler
    • taskExecutor

      protected final ExecutorService taskExecutor
    • processedCommitsStore

      protected final ProcessedCommitsStore processedCommitsStore
    • targetLifecycleHooksResolver

      protected final TargetLifecycleHooksResolver targetLifecycleHooksResolver
    • configurationReader

      protected final org.craftercms.commons.config.EncryptionAwareConfigurationReader configurationReader
    • upgradeManager

      protected final org.craftercms.commons.upgrade.UpgradeManager<Target> upgradeManager
    • currentTargets

      protected final Set<Target> currentTargets
  • Constructor Details

    • TargetServiceImpl

      public TargetServiceImpl(@Value("${deployer.main.targets.config.folderPath}") File targetConfigFolder, @Value("${deployer.main.targets.config.baseYaml.location}") org.springframework.core.io.Resource baseTargetYamlConfigResource, @Value("${deployer.main.targets.config.baseYaml.overrideLocation}") org.springframework.core.io.Resource baseTargetYamlConfigOverrideResource, @Value("${deployer.main.targets.config.baseContext.location}") org.springframework.core.io.Resource baseTargetContextResource, @Value("${deployer.main.targets.config.baseContext.overrideLocation}") org.springframework.core.io.Resource baseTargetContextOverrideResource, @Value("${deployer.main.targets.config.templates.default}") String defaultTargetConfigTemplateName, @Autowired com.github.jknack.handlebars.Handlebars targetConfigTemplateEngine, @Autowired org.springframework.context.ApplicationContext mainApplicationContext, @Autowired DeploymentPipelineFactory deploymentPipelineFactory, @Autowired org.springframework.scheduling.TaskScheduler taskScheduler, @Autowired ExecutorService taskExecutor, @Autowired ProcessedCommitsStore processedCommitsStore, @Autowired TargetLifecycleHooksResolver targetLifecycleHooksResolver, @Autowired org.craftercms.commons.config.EncryptionAwareConfigurationReader configurationReader, @Autowired org.craftercms.commons.upgrade.UpgradeManager<Target> upgradeManager)
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet() throws DeployerException
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      DeployerException
    • onApplicationEvent

      public void onApplicationEvent(@NonNull org.springframework.boot.context.event.ApplicationReadyEvent event)
      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationReadyEvent>
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
    • getAllTargets

      public List<Target> getAllTargets()
      Description copied from interface: TargetService
      Returns all targets.
      Specified by:
      getAllTargets in interface TargetService
      Returns:
      the list of targets
    • targetExists

      public boolean targetExists(String env, String siteName)
      Description copied from interface: TargetService
      Returns true if the target associated to the env and site name exists.
      Specified by:
      targetExists in interface TargetService
      Parameters:
      env - the target's environment (e.g. dev)
      siteName - the target's site name (e.g. mysite)
      Returns:
      true if the target exists, false otherwise
    • getTarget

      public Target getTarget(String env, String siteName) throws TargetNotFoundException
      Description copied from interface: TargetService
      Returns the current target with the given ID
      Specified by:
      getTarget in interface TargetService
      Parameters:
      env - the target's environment (e.g. dev)
      siteName - the target's site name (e.g. mysite)
      Returns:
      the target info
      Throws:
      TargetNotFoundException - if the target for the specified env and site name doesn't exist
    • resolveTargets

      public List<Target> resolveTargets() throws TargetServiceException
      Description copied from interface: TargetService
      Scans for target configurations, loading targets with new/modified configuration and unloading targets with no configuration. This method triggers no lifecycle hooks.
      Specified by:
      resolveTargets in interface TargetService
      Returns:
      existing targets, after being loaded
      Throws:
      TargetServiceException - if a general error occurs
    • createTarget

      public Target createTarget(String env, String siteName, boolean replace, String templateName, Map<String,Object> templateParams) throws TargetAlreadyExistsException, TargetServiceException
      Description copied from interface: TargetService
      Creates a new target with it's own configuration. Creating a target also triggers its create lifecycle hooks.
      Specified by:
      createTarget in interface TargetService
      Parameters:
      env - the target's environment (e.g. dev)
      siteName - the target's site name (e.g. mysite)
      replace - indicates that if there's a target with the same name, the target config should be replaced.
      templateName - the name of the template used to create the target configuration (can be null).
      templateParams - the parameters that the template needs.
      Returns:
      the created target
      Throws:
      TargetAlreadyExistsException - if the target for the specified env and site name already exists
      TargetServiceException - if a general error occurs
    • deleteTarget

      public void deleteTarget(String env, String siteName) throws TargetNotFoundException, TargetServiceException
      Description copied from interface: TargetService
      Deletes a target with the given ID. Deleting the target also triggers its delete lifecycle hooks.
      Specified by:
      deleteTarget in interface TargetService
      Parameters:
      env - the target's environment (e.g. dev)
      siteName - the target's site name (e.g. mysite)
      Throws:
      TargetNotFoundException - if the target for the specified env and site name doesn't exist
      TargetServiceException - if a general error occurs
    • recreateIndex

      public void recreateIndex(String env, String siteName) throws TargetNotFoundException
      Description copied from interface: TargetService
      Recreates the underlying OpenSearch index for a given target
      Specified by:
      recreateIndex in interface TargetService
      Parameters:
      env - the target's environment (e.g. dev)
      siteName - the target's site name (e.g. mysite)
      Throws:
      TargetNotFoundException - if the target for the specified env and site name doesn't exist
    • getTargetConfigFiles

      protected Collection<File> getTargetConfigFiles() throws TargetServiceException
      Throws:
      TargetServiceException
    • closeTargetsWithNoConfigFile

      protected void closeTargetsWithNoConfigFile(Collection<File> configFiles)
    • resolveTargetFromConfigFile

      protected Target resolveTargetFromConfigFile(File configFile, boolean create) throws TargetServiceException
      Throws:
      TargetServiceException
    • buildTarget

      protected TargetImpl buildTarget(File configFile, File contextFile) throws Exception
      Throws:
      Exception
    • loadTarget

      protected Target loadTarget(File configFile, File contextFile, boolean create) throws TargetServiceException
      Throws:
      TargetServiceException
    • loadConfiguration

      protected org.apache.commons.configuration2.HierarchicalConfiguration loadConfiguration(File configFile) throws org.craftercms.commons.config.ConfigurationException
      Throws:
      org.craftercms.commons.config.ConfigurationException
    • loadApplicationContext

      protected org.springframework.context.ConfigurableApplicationContext loadApplicationContext(org.apache.commons.configuration2.HierarchicalConfiguration config, File contextFile) throws org.craftercms.commons.config.ConfigurationException
      Throws:
      org.craftercms.commons.config.ConfigurationException
    • createConfigFromTemplate

      protected void createConfigFromTemplate(String env, String siteName, String targetId, String templateName, Map<String,Object> templateParameters, File configFile) throws TargetServiceException
      Throws:
      TargetServiceException
    • processConfigTemplate

      protected void processConfigTemplate(String templateName, Object templateModel, Writer out) throws TargetServiceException
      Throws:
      TargetServiceException
    • findLoadedTargetByConfigFile

      protected Target findLoadedTargetByConfigFile(File configFile)
    • findLoadedTargetById

      protected Target findLoadedTargetById(String id)
    • executeCreateHooks

      protected void executeCreateHooks(Target target) throws Exception
      Throws:
      Exception
    • startInit

      protected void startInit(Target target)