use of org.alien4cloud.tosca.model.templates.PolicyTemplate in project alien4cloud by alien4cloud.
the class TemplateBuilder method buildPolicyTemplate.
public static PolicyTemplate buildPolicyTemplate(PolicyType policyType) {
policyType = CloneUtil.clone(policyType);
PolicyTemplate policyTemplate = new PolicyTemplate();
fillAbstractTemplate(policyTemplate, policyType, null, false);
return policyTemplate;
}
use of org.alien4cloud.tosca.model.templates.PolicyTemplate in project alien4cloud by alien4cloud.
the class PolicyTemplatePostProcessor method process.
@Override
public void process(final PolicyTemplate instance) {
// ensure type exists
referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getType(), PolicyType.class));
final PolicyType policyType = ToscaContext.get(PolicyType.class, instance.getType());
if (policyType == null) {
// error managed by the reference post processor.
return;
}
final Topology topology = ((ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance()).getTopology();
// check that the targets are exiting node templates
// TODO should we also check the type of the target, see if it matches with one provided in PolicyType.getTargets() ?
safe(instance.getTargets()).forEach(target -> {
if (!safe((topology.getNodeTemplates())).containsKey(target)) {
// Dispatch an error.
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance.getTargets());
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.POLICY_TARGET_NOT_FOUND, instance.getName(), node.getStartMark(), null, node.getEndMark(), target));
}
});
// Merge the policy template with data coming from the type (default values etc.).
PolicyTemplate tempObject = TemplateBuilder.buildPolicyTemplate(policyType, instance, false);
instance.setProperties(tempObject.getProperties());
propertyValueChecker.checkProperties(policyType, instance.getProperties(), instance.getName());
}
use of org.alien4cloud.tosca.model.templates.PolicyTemplate in project alien4cloud by alien4cloud.
the class AbstractPolicyProcessor method process.
@Override
public void process(Csar csar, Topology topology, T operation) {
PolicyTemplate policyTemplate = AlienUtils.getOrFail(topology.getPolicies(), operation.getPolicyName(), "The policy with name [ {} ] cannot be found in the topology.", operation.getPolicyName());
process(csar, topology, operation, policyTemplate);
}
use of org.alien4cloud.tosca.model.templates.PolicyTemplate in project alien4cloud by alien4cloud.
the class PolicyMatchingReplaceModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
super.process(topology, context);
for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) {
PolicyType policyType = ToscaContext.getOrFail(PolicyType.class, policyTemplate.getType());
String policyImplMeta = TagUtil.getTagValue(policyType.getTags(), "a4c_policy_impl");
if (policyImplMeta == null) {
context.log().warn("Matched policy {} for {} does not define an alien topology modifier implementation, it may not be taken in account.", policyTemplate.getType(), policyTemplate.getName());
continue;
}
String[] policyImpl = policyImplMeta.split(":");
if (policyImpl.length != 3) {
context.log().error("Matched policy {} for policy {} defines an invalid modifier implementation {}, format should be policy_plugin_id:policy_plugin_bean:injection_phase", policyTemplate.getType(), policyTemplate.getName(), policyImplMeta);
}
try {
ITopologyModifier modifier = pluginModifierRegistry.getPluginBean(policyImpl[0], policyImpl[1]);
List<ITopologyModifier> phaseModifiers = (List<ITopologyModifier>) context.getExecutionCache().computeIfAbsent(policyImpl[2], s -> Lists.<ITopologyModifier>newArrayList());
// No need to add a modifier more than once for a phase
if (!phaseModifiers.contains(modifier)) {
phaseModifiers.add(modifier);
}
} catch (MissingPluginException e) {
context.log().error("Implementation specified for policy type {} that refers to plugin bean {}, {} cannot be found.", policyTemplate.getType(), policyImpl[0], policyImpl[1]);
}
}
}
use of org.alien4cloud.tosca.model.templates.PolicyTemplate in project alien4cloud by alien4cloud.
the class LocationResourceService method addPolicyLocationResourceTemplate.
private PolicyLocationResourceTemplate addPolicyLocationResourceTemplate(Location location, String resourceName, String resourceTypeName) {
PolicyLocationResourceTemplate policyLocationResourceTemplate = new PolicyLocationResourceTemplate();
PolicyType resourceType = csarRepoSearchService.getRequiredElementInDependencies(PolicyType.class, resourceTypeName, location.getDependencies());
PolicyTemplate policyTemplate = TemplateBuilder.buildPolicyTemplate(resourceType);
fillAndSaveLocationResourceTemplate(location, resourceName, policyLocationResourceTemplate, resourceType, policyTemplate);
return policyLocationResourceTemplate;
}
Aggregations