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]);
}
}
}
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;
}
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()));
}
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);
});
}
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;
}
Aggregations