Package org.craftercms.deployer.impl
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
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
protected final org.springframework.core.io.Resource
protected final org.springframework.core.io.Resource
protected final org.springframework.core.io.Resource
protected final org.springframework.core.io.Resource
static final String
static final String
protected final org.craftercms.commons.config.EncryptionAwareConfigurationReader
protected final String
protected final DeploymentPipelineFactory
protected final org.springframework.context.ApplicationContext
protected final ProcessedCommitsStore
static final String
static final String
static final String
protected final File
protected final com.github.jknack.handlebars.Handlebars
protected final TargetLifecycleHooksResolver
protected final ExecutorService
protected final org.springframework.scheduling.TaskScheduler
protected final org.craftercms.commons.upgrade.UpgradeManager<Target>
static final String
-
Constructor Summary
ConstructorDescriptionTargetServiceImpl
(File targetConfigFolder, org.springframework.core.io.Resource baseTargetYamlConfigResource, org.springframework.core.io.Resource baseTargetYamlConfigOverrideResource, org.springframework.core.io.Resource baseTargetContextResource, org.springframework.core.io.Resource baseTargetContextOverrideResource, String defaultTargetConfigTemplateName, com.github.jknack.handlebars.Handlebars targetConfigTemplateEngine, org.springframework.context.ApplicationContext mainApplicationContext, DeploymentPipelineFactory deploymentPipelineFactory, org.springframework.scheduling.TaskScheduler taskScheduler, ExecutorService taskExecutor, ProcessedCommitsStore processedCommitsStore, TargetLifecycleHooksResolver targetLifecycleHooksResolver, org.craftercms.commons.config.EncryptionAwareConfigurationReader configurationReader, org.craftercms.commons.upgrade.UpgradeManager<Target> upgradeManager) -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected TargetImpl
buildTarget
(File configFile, File contextFile) protected void
closeTargetsWithNoConfigFile
(Collection<File> configFiles) protected void
createConfigFromTemplate
(String env, String siteName, String targetId, String templateName, Map<String, Object> templateParameters, File configFile) createTarget
(String env, String siteName, boolean replace, String templateName, Map<String, Object> templateParams) Creates a new target with it's own configuration.void
deleteTarget
(String env, String siteName) Deletes a target with the given ID.void
destroy()
protected void
executeCreateHooks
(Target target) protected Target
findLoadedTargetByConfigFile
(File configFile) protected Target
Returns all targets.Returns the current target with the given IDprotected Collection<File>
protected org.springframework.context.ConfigurableApplicationContext
loadApplicationContext
(org.apache.commons.configuration2.HierarchicalConfiguration config, File contextFile) protected org.apache.commons.configuration2.HierarchicalConfiguration
loadConfiguration
(File configFile) protected Target
loadTarget
(File configFile, File contextFile, boolean create) void
onApplicationEvent
(org.springframework.boot.context.event.ApplicationReadyEvent event) protected void
processConfigTemplate
(String templateName, Object templateModel, Writer out) void
recreateIndex
(String env, String siteName) Recreates the underlying OpenSearch index for a given targetprotected Target
resolveTargetFromConfigFile
(File configFile, boolean create) Scans for target configurations, loading targets with new/modified configuration and unloading targets with no configuration.protected void
boolean
targetExists
(String env, String siteName) Returns true if the target associated to the env and site name exists.
-
Field Details
-
YAML_FILE_EXTENSION
- See Also:
-
APPLICATION_CONTEXT_FILENAME_FORMAT
- See Also:
-
CONFIG_PROPERTY_SOURCE_NAME
- See Also:
-
CONFIG_BEAN_NAME
- See Also:
-
TARGET_ENV_MODEL_KEY
- See Also:
-
TARGET_SITE_NAME_MODEL_KEY
- See Also:
-
TARGET_ID_MODEL_KEY
- See Also:
-
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
-
targetConfigTemplateEngine
protected final com.github.jknack.handlebars.Handlebars targetConfigTemplateEngine -
mainApplicationContext
protected final org.springframework.context.ApplicationContext mainApplicationContext -
deploymentPipelineFactory
-
taskScheduler
protected final org.springframework.scheduling.TaskScheduler taskScheduler -
taskExecutor
-
processedCommitsStore
-
targetLifecycleHooksResolver
-
configurationReader
protected final org.craftercms.commons.config.EncryptionAwareConfigurationReader configurationReader -
upgradeManager
-
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
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
DeployerException
-
onApplicationEvent
public void onApplicationEvent(@NonNull org.springframework.boot.context.event.ApplicationReadyEvent event) - Specified by:
onApplicationEvent
in interfaceorg.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationReadyEvent>
-
destroy
public void destroy()- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
-
getAllTargets
Description copied from interface:TargetService
Returns all targets.- Specified by:
getAllTargets
in interfaceTargetService
- Returns:
- the list of targets
-
targetExists
Description copied from interface:TargetService
Returns true if the target associated to the env and site name exists.- Specified by:
targetExists
in interfaceTargetService
- 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
Description copied from interface:TargetService
Returns the current target with the given ID- Specified by:
getTarget
in interfaceTargetService
- 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
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 interfaceTargetService
- 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, TargetServiceExceptionDescription 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 interfaceTargetService
- 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 existsTargetServiceException
- 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 interfaceTargetService
- 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 existTargetServiceException
- if a general error occurs
-
recreateIndex
Description copied from interface:TargetService
Recreates the underlying OpenSearch index for a given target- Specified by:
recreateIndex
in interfaceTargetService
- 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
- Throws:
TargetServiceException
-
closeTargetsWithNoConfigFile
-
resolveTargetFromConfigFile
protected Target resolveTargetFromConfigFile(File configFile, boolean create) throws TargetServiceException - Throws:
TargetServiceException
-
buildTarget
- 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
-
findLoadedTargetById
-
executeCreateHooks
- Throws:
Exception
-
startInit
-