Search in sources :

Example 6 with PolicyType

use of org.alien4cloud.tosca.model.types.PolicyType 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 7 with PolicyType

use of org.alien4cloud.tosca.model.types.PolicyType 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)

Example 8 with PolicyType

use of org.alien4cloud.tosca.model.types.PolicyType in project alien4cloud by alien4cloud.

the class LocationResourceService method duplicatePolicyTemplate.

@Override
public LocationResourceTemplateWithDependencies duplicatePolicyTemplate(String resourceId) {
    PolicyLocationResourceTemplate policyLocationResourceTemplate = getOrFail(resourceId);
    policyLocationResourceTemplate.setId(UUID.randomUUID().toString());
    policyLocationResourceTemplate.setName(policyLocationResourceTemplate.getName() + "_" + "copy");
    Location location = locationService.getOrFail(policyLocationResourceTemplate.getLocationId());
    PolicyType resourceType = csarRepoSearchService.getRequiredElementInDependencies(PolicyType.class, policyLocationResourceTemplate.getTemplate().getType(), location.getDependencies());
    publishCreatedEventAndSaveResource(location, policyLocationResourceTemplate, resourceType);
    return new LocationResourceTemplateWithDependencies(policyLocationResourceTemplate, Sets.newHashSet(location.getDependencies()));
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) LocationResourceTemplateWithDependencies(alien4cloud.model.orchestrators.locations.LocationResourceTemplateWithDependencies) PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) Location(alien4cloud.model.orchestrators.locations.Location)

Example 9 with PolicyType

use of org.alien4cloud.tosca.model.types.PolicyType in project alien4cloud by alien4cloud.

the class LocationResourceService method fillPoliciesLocationResourceTypes.

private void fillPoliciesLocationResourceTypes(Collection<String> exposedTypes, LocationResourceTypes locationResourceTypes, Set<CSARDependency> dependencies) {
    fillLocationResourceTypes(exposedTypes, locationResourceTypes, dependencies, (exposedType) -> {
        PolicyType policyType = csarRepoSearchService.getRequiredElementInDependencies(PolicyType.class, exposedType, dependencies);
        locationResourceTypes.getPolicyTypes().put(policyType.getElementId(), policyType);
    });
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType)

Example 10 with PolicyType

use of org.alien4cloud.tosca.model.types.PolicyType 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)

Aggregations

PolicyType (org.alien4cloud.tosca.model.types.PolicyType)15 PolicyTemplate (org.alien4cloud.tosca.model.templates.PolicyTemplate)7 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)5 Set (java.util.Set)5 Csar (org.alien4cloud.tosca.model.Csar)4 NodeType (org.alien4cloud.tosca.model.types.NodeType)4 Test (org.junit.Test)4 PolicyLocationResourceTemplate (alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate)3 List (java.util.List)2 Topology (org.alien4cloud.tosca.model.templates.Topology)2 ILocationMatch (alien4cloud.model.deployment.matching.ILocationMatch)1 Location (alien4cloud.model.orchestrators.locations.Location)1 LocationResourceTemplateWithDependencies (alien4cloud.model.orchestrators.locations.LocationResourceTemplateWithDependencies)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 ParsingError (alien4cloud.tosca.parser.ParsingError)1 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)1 TagUtil (alien4cloud.utils.TagUtil)1