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 ofTargetService
.- Author:
- avasquez
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
TargetServiceImpl.CustomConfigFileFilter
-
Field Summary
Fields Modifier and Type Field Description static String
APPLICATION_CONTEXT_FILENAME_FORMAT
protected org.springframework.core.io.Resource
baseTargetContextOverrideResource
protected org.springframework.core.io.Resource
baseTargetContextResource
protected org.springframework.core.io.Resource
baseTargetYamlConfigOverrideResource
protected org.springframework.core.io.Resource
baseTargetYamlConfigResource
static String
CONFIG_BEAN_NAME
static String
CONFIG_PROPERTY_SOURCE_NAME
protected org.craftercms.commons.config.EncryptionAwareConfigurationReader
configurationReader
protected Set<Target>
currentTargets
protected String
defaultTargetConfigTemplateName
protected DeploymentPipelineFactory
deploymentPipelineFactory
protected org.springframework.context.ApplicationContext
mainApplicationContext
protected ProcessedCommitsStore
processedCommitsStore
static String
TARGET_ENV_MODEL_KEY
static String
TARGET_ID_MODEL_KEY
static String
TARGET_SITE_NAME_MODEL_KEY
protected File
targetConfigFolder
protected com.github.jknack.handlebars.Handlebars
targetConfigTemplateEngine
protected TargetLifecycleHooksResolver
targetLifecycleHooksResolver
protected ExecutorService
taskExecutor
protected org.springframework.scheduling.TaskScheduler
taskScheduler
protected org.craftercms.commons.upgrade.UpgradeManager<Target>
upgradeManager
static String
YAML_FILE_EXTENSION
-
Constructor Summary
Constructors Constructor Description TargetServiceImpl(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
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)
Target
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
findLoadedTargetById(String id)
List<Target>
getAllTargets()
Returns all targets.Target
getTarget(String env, String siteName)
Returns the current target with the given IDprotected Collection<File>
getTargetConfigFiles()
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 Elasticsearch index for a given targetprotected Target
resolveTargetFromConfigFile(File configFile, boolean create)
List<Target>
resolveTargets()
Scans for target configurations, loading targets with new/modified configuration and unloading targets with no configuration.protected void
startInit(Target target)
boolean
targetExists(String env, String siteName)
Returns true if the target associated to the env and site name exists.
-
-
-
Field Detail
-
YAML_FILE_EXTENSION
public static final String YAML_FILE_EXTENSION
- See Also:
- Constant Field Values
-
APPLICATION_CONTEXT_FILENAME_FORMAT
public static final String APPLICATION_CONTEXT_FILENAME_FORMAT
- See Also:
- Constant Field Values
-
CONFIG_PROPERTY_SOURCE_NAME
public static final String CONFIG_PROPERTY_SOURCE_NAME
- See Also:
- Constant Field Values
-
CONFIG_BEAN_NAME
public static final String CONFIG_BEAN_NAME
- See Also:
- Constant Field Values
-
TARGET_ENV_MODEL_KEY
public static final String TARGET_ENV_MODEL_KEY
- See Also:
- Constant Field Values
-
TARGET_SITE_NAME_MODEL_KEY
public static final String TARGET_SITE_NAME_MODEL_KEY
- See Also:
- Constant Field Values
-
TARGET_ID_MODEL_KEY
public static final String TARGET_ID_MODEL_KEY
- See Also:
- Constant Field Values
-
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
-
-
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 interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
DeployerException
-
onApplicationEvent
public void onApplicationEvent(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
public List<Target> getAllTargets()
Description copied from interface:TargetService
Returns all targets.- Specified by:
getAllTargets
in interfaceTargetService
- 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 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
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 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
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 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, 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 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
public void recreateIndex(String env, String siteName) throws TargetNotFoundException
Description copied from interface:TargetService
Recreates the underlying Elasticsearch 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
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
-
executeCreateHooks
protected void executeCreateHooks(Target target) throws Exception
- Throws:
Exception
-
startInit
protected void startInit(Target target)
-
-