Search in sources :

Example 1 with PolicyTemplate

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;
}
Also used : PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 2 with 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());
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) Node(org.yaml.snakeyaml.nodes.Node) Topology(org.alien4cloud.tosca.model.templates.Topology) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 3 with PolicyTemplate

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);
}
Also used : PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 4 with 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]);
        }
    }
}
Also used : TagUtil(alien4cloud.utils.TagUtil) Set(java.util.Set) PolicyType(org.alien4cloud.tosca.model.types.PolicyType) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) PluginModifierRegistry(org.alien4cloud.alm.deployment.configuration.flow.modifiers.PluginModifierRegistry) Map(java.util.Map) Topology(org.alien4cloud.tosca.model.templates.Topology) PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) ToscaContext(alien4cloud.tosca.context.ToscaContext) PolicyType(org.alien4cloud.tosca.model.types.PolicyType) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) List(java.util.List) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 5 with PolicyTemplate

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;
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Aggregations

PolicyTemplate (org.alien4cloud.tosca.model.templates.PolicyTemplate)10 PolicyType (org.alien4cloud.tosca.model.types.PolicyType)7 PolicyLocationResourceTemplate (alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate)2 List (java.util.List)2 Topology (org.alien4cloud.tosca.model.templates.Topology)2 ILocationMatch (alien4cloud.model.deployment.matching.ILocationMatch)1 LocationResources (alien4cloud.model.orchestrators.locations.LocationResources)1 MissingPluginException (alien4cloud.plugin.exception.MissingPluginException)1 ToscaTypeLoader (alien4cloud.tosca.container.ToscaTypeLoader)1 ToscaContext (alien4cloud.tosca.context.ToscaContext)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 ParsingError (alien4cloud.tosca.parser.ParsingError)1 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)1 TagUtil (alien4cloud.utils.TagUtil)1 Lists (com.google.common.collect.Lists)1 Map (java.util.Map)1 Set (java.util.Set)1 Inject (javax.inject.Inject)1 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)1 ITopologyModifier (org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier)1