Class 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 Detail

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

        protected final org.springframework.scheduling.TaskScheduler taskScheduler
      • 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 Detail

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

      • afterPropertiesSet

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

        public void onApplicationEvent​(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
      • 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
      • 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
      • closeTargetsWithNoConfigFile

        protected void closeTargetsWithNoConfigFile​(Collection<File> configFiles)
      • 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
      • findLoadedTargetByConfigFile

        protected Target findLoadedTargetByConfigFile​(File configFile)
      • findLoadedTargetById

        protected Target findLoadedTargetById​(String id)
      • startInit

        protected void startInit​(Target target)