use of org.elasticsearch.annotation.ESObject in project alien4cloud by alien4cloud.
the class FlowExecutionContext method getConfiguration.
/**
* Get a configuration object related to the deployment flow.
*
* This operation also updates the lastFlowParamUpdate that may be used by later processor to skip some processing when nothing has changed.
*
* The operation is also caching aware to avoid requesting multiple times the same object from elasticsearch.
*
* The configuration object is not annotated with {@link ESObject}, no request to elasticsearch will be made.
*
* @param cfgClass The class of the configuration object.
* @param modifierName Name of the modifier that tries to access a deployment configuration object (related to the environment).
* @param <T> The type of the configuration object.
* @return An instance of the requested configuration object.
*/
public <T extends AbstractDeploymentConfig> Optional<T> getConfiguration(Class<T> cfgClass, String modifierName) {
environmentContext.orElseThrow(() -> new EnvironmentContextRequiredException(modifierName));
ApplicationEnvironment env = environmentContext.get().getEnvironment();
String cfgId = AbstractDeploymentConfig.generateId(env.getTopologyVersion(), env.getId());
String configCacheId = cfgClass.getSimpleName() + "/" + cfgId;
T config = (T) executionCache.get(configCacheId);
// If the config object is annotated with ESObject then it may be cached in ElasticSearch
if (config == null && cfgClass.isAnnotationPresent(ESObject.class)) {
config = deploymentConfigurationDao.findById(cfgClass, cfgId);
executionCache.put(configCacheId, config);
}
if (config == null) {
return Optional.empty();
}
if (lastFlowParamUpdate.before(config.getLastUpdateDate())) {
lastFlowParamUpdate = config.getLastUpdateDate();
}
return Optional.of(config);
}
Aggregations