Search in sources :

Example 6 with PolicyTemplate

use of org.alien4cloud.tosca.model.templates.PolicyTemplate in project alien4cloud by alien4cloud.

the class PolicyMatcherService method match.

/**
 * Perform matching of policies from a topology.
 *
 * @param policyTemplates The policy templates to match.
 * @param location The location against which to match policies.
 * @return A Map of available matches for every policy template.
 */
public Map<String, List<PolicyLocationResourceTemplate>> match(Map<String, PolicyTemplate> policyTemplates, Map<String, PolicyType> policyTypes, Location location, String environmentId) {
    if (MapUtils.isEmpty(policyTemplates)) {
        return Maps.newHashMap();
    }
    Map<String, List<PolicyLocationResourceTemplate>> matches = Maps.newHashMap();
    // fetch location resources
    LocationResources locationResources = locationResourceService.getLocationResources(location);
    // Authorization filtering of location resources
    locationResources.getPolicyTemplates().removeIf(securedResource -> !locationSecurityService.isAuthorised(securedResource, environmentId));
    for (Entry<String, PolicyTemplate> policyTemplateEntry : policyTemplates.entrySet()) {
        PolicyType policyType = policyTypes.get(policyTemplateEntry.getValue().getType());
        matches.put(policyTemplateEntry.getKey(), policyMatcher.match(policyTemplateEntry.getValue(), policyType, locationResources.getPolicyTemplates(), locationResources.getPolicyTypes(), locationResources, null));
    }
    return matches;
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) LocationResources(alien4cloud.model.orchestrators.locations.LocationResources) List(java.util.List) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 7 with PolicyTemplate

use of org.alien4cloud.tosca.model.templates.PolicyTemplate in project alien4cloud by alien4cloud.

the class TopologyService method initializeTypeLoader.

private ToscaTypeLoader initializeTypeLoader(Topology topology, boolean failOnTypeNotFound) {
    // FIXME we should use ToscaContext here, and why not allowing the caller to pass ona Context?
    ToscaTypeLoader loader = new ToscaTypeLoader(csarDependencyLoader);
    Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, false, failOnTypeNotFound);
    Map<String, RelationshipType> relationshipTypes = topologyServiceCore.getIndexedRelationshipTypesFromTopology(topology, failOnTypeNotFound);
    Map<String, PolicyType> policyTypes = topologyServiceCore.getPolicyTypesFromTopology(topology, failOnTypeNotFound);
    for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
        NodeType nodeType = nodeTypes.get(nodeTemplate.getType());
        // just load found types: the type might be null when failOnTypeNotFound is set to false.
        if (nodeType != null) {
            loader.loadType(nodeTemplate.getType(), csarDependencyLoader.buildDependencyBean(nodeType.getArchiveName(), nodeType.getArchiveVersion()));
        }
        for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
            RelationshipType relationshipType = relationshipTypes.get(relationshipTemplate.getType());
            // just load found types: the type might be null when failOnTypeNotFound is set to false.
            if (relationshipType != null) {
                loader.loadType(relationshipTemplate.getType(), csarDependencyLoader.buildDependencyBean(relationshipType.getArchiveName(), relationshipType.getArchiveVersion()));
            }
        }
    }
    for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) {
        PolicyType policyType = policyTypes.get(policyTemplate.getType());
        if (policyType != null) {
            loader.loadType(policyTemplate.getType(), csarDependencyLoader.buildDependencyBean(policyType.getArchiveName(), policyType.getArchiveVersion()));
        }
    }
    if (topology.getSubstitutionMapping() != null && topology.getSubstitutionMapping().getSubstitutionType() != null) {
        NodeType substitutionType = nodeTypes.get(topology.getSubstitutionMapping().getSubstitutionType());
        loader.loadType(substitutionType.getElementId(), csarDependencyLoader.buildDependencyBean(substitutionType.getArchiveName(), substitutionType.getArchiveVersion()));
        for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getCapabilities()).values()) {
            initializeSubstitutionTarget(loader, relationshipTypes, substitutionTarget);
        }
        for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getRequirements()).values()) {
            initializeSubstitutionTarget(loader, relationshipTypes, substitutionTarget);
        }
    }
    return loader;
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) ToscaTypeLoader(alien4cloud.tosca.container.ToscaTypeLoader) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 8 with PolicyTemplate

use of org.alien4cloud.tosca.model.templates.PolicyTemplate in project alien4cloud by alien4cloud.

the class PolicyMatchingCandidateModifier method getPolicyTypes.

private Map<String, PolicyType> getPolicyTypes(Topology topology) {
    Map<String, PolicyType> policyTypes = Maps.newHashMap();
    for (PolicyTemplate template : safe(topology.getPolicies()).values()) {
        if (!policyTypes.containsKey(template.getType())) {
            PolicyType policyType = ToscaContext.getOrFail(PolicyType.class, template.getType());
            policyTypes.put(policyType.getElementId(), policyType);
        }
    }
    return policyTypes;
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 9 with PolicyTemplate

use of org.alien4cloud.tosca.model.templates.PolicyTemplate in project alien4cloud by alien4cloud.

the class AddPolicyProcessor method process.

@Override
public void process(Csar csar, Topology topology, AddPolicyOperation operation) {
    NameValidationUtils.validate("policy", operation.getPolicyName());
    AlienUtils.failIfExists(topology.getPolicies(), operation.getPolicyName(), "A policy with the given name {} already exists in the topology {}.", operation.getPolicyName(), topology.getId());
    PolicyType policyType = toscaTypeSearchService.findByIdOrFail(PolicyType.class, operation.getPolicyTypeId());
    if (topology.getPolicies() == null) {
        topology.setPolicies(new LinkedHashMap<>());
    }
    PolicyTemplate policyTemplate = TemplateBuilder.buildPolicyTemplate(policyType);
    policyTemplate.setName(operation.getPolicyName());
    log.debug("Adding a new policy template <" + operation.getPolicyName() + "> of type <" + operation.getPolicyTypeId() + "> to the topology <" + topology.getId() + "> .");
    topologyService.loadType(topology, policyType);
    topology.getPolicies().put(operation.getPolicyName(), policyTemplate);
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 10 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, PolicyTemplate templateToMerge, boolean adaptToType) {
    policyType = CloneUtil.clone(policyType);
    PolicyTemplate policyTemplate = new PolicyTemplate();
    fillAbstractTemplate(policyTemplate, policyType, templateToMerge, !adaptToType);
    return policyTemplate;
}
Also used : 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