@Override Map<String, PolicyTemplate> getTemplates(Topology topology) { return topology.getPolicies(); }
@Override Map<String, PolicyTemplate> getTemplates(Topology topology) { return topology.getPolicies(); } }
@Override protected Map<String, PolicyTemplate> getTopologyTemplates(Topology topology) { return topology.getPolicies(); }
private <T extends Topology> Map<String, PolicyType> getPolicyTypes(T topology) { Map<String, PolicyType> types = Maps.newHashMap(); fillTypeMap(PolicyType.class, types, topology.getPolicies(), false, false); return types; }
private void removeNodeFromPolicies(String removedNode, Topology topology) { for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) { policyTemplate.getTargets().remove(removedNode); } }
/** * Get the policies that target this node template. */ public static Set<PolicyTemplate> getTargetedPolicies(Topology topology, NodeTemplate nodeTemplate) { return safe(topology.getPolicies()).values().stream() .filter(policyTemplate -> policyTemplate.getTargets() != null && policyTemplate.getTargets().contains(nodeTemplate.getName())) .collect(Collectors.toSet()); }
private static void updatePolicyMembers(Topology topology, String nodeName, String newName) { // Update the policy members when a node template is renamed. for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) { boolean removed = policyTemplate.getTargets().remove(nodeName); if (removed && newName != null) { policyTemplate.getTargets().add(newName); } } }
@Override public void process(Topology topology, FlowExecutionContext context) { for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) { if (ANTI_AFFINITY_POLICY.equals(policyTemplate.getType())) { apply(policyTemplate, topology, context); } } }
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; } }
private Map<String, List<PolicyLocationResourceTemplate>> getAvailableMatches(Topology topology, FlowExecutionContext context, Map<String, NodeGroup> locationGroups, Map<String, Location> locationByIds, String environmentId) { Map<String, List<PolicyLocationResourceTemplate>> availableSubstitutions = Maps.newHashMap(); if (locationGroups.size() > 1) { // Fail as not yet supported in alien4cloud. // Supporting policy management on multiple locations could have limitations based on the policy (need to be defined on both locations with // identical requirements / access to services etc.) // Unless defined on nodes that are all in the same location. context.log().warn("Policy are not supported when deployment is performed on multiple locations."); return availableSubstitutions; } // Fetch all policy types for templates in the topology Map<String, PolicyType> policyTypes = getPolicyTypes(topology); availableSubstitutions .putAll(policyMatcherService.match(topology.getPolicies(), policyTypes, locationByIds.get(AlienConstants.GROUP_ALL), environmentId)); return availableSubstitutions; }
public Map<String, PolicyType> getPolicyTypesFromTopology(Topology topology, boolean failOnTypeNotFound) { Map<String, PolicyType> types = Maps.newHashMap(); for (PolicyTemplate template : safe(topology.getPolicies()).values()) { types.put(template.getType(), getFromContextIfDefined(PolicyType.class, template.getType(), topology.getDependencies(), failOnTypeNotFound)); } return types; }
/** * @param topology * @param type * @param manageInheritance true if you also want to consider type hierarchy (ie. include that inherit the given type). * @return a set of nodes that are of the given type (or inherit the given type if <code>manageInheritance</code> is true). */ public static Set<PolicyTemplate> getPoliciesOfType(Topology topology, String type, boolean manageInheritance) { Set<PolicyTemplate> result = Sets.newHashSet(); for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) { if (policyTemplate.getType().equals(type)) { result.add(policyTemplate); } else if (manageInheritance) { PolicyType policyType = ToscaContext.get(PolicyType.class, policyTemplate.getType()); if (policyType.getDerivedFrom().contains(type)) { result.add(policyTemplate); } } } return result; }
@Override protected void process(Csar csar, Topology topology, RenamePolicyOperation operation, PolicyTemplate policyTemplate) { NameValidationUtils.validateNodeName(operation.getNewName()); AlienUtils.failIfExists(topology.getPolicies(), operation.getNewName(), "A node template with the given name {} already exists in the topology {}.", operation.getNewName(), topology.getId()); log.debug("Renaming policy template <" + operation.getPolicyName() + "> to <" + operation.getNewName() + "> in the topology <" + topology.getId() + "> ."); policyTemplate.setName(operation.getNewName()); topology.getPolicies().put(operation.getNewName(), policyTemplate); topology.getPolicies().remove(operation.getPolicyName()); } }
@Override protected void process(Csar csar, Topology topology, DeletePolicyOperation operation, PolicyTemplate policyTemplate) { log.debug("Removing policy template <" + operation.getPolicyName() + "> of type <" + policyTemplate.getType() + "> from the topology <" + topology.getId() + "> ."); topology.getPolicies().remove(operation.getPolicyName()); topologyService.unloadType(topology, policyTemplate.getType()); } }
protected abstract void process(Csar csar, Topology topology, T operation, PolicyTemplate policyTemplate); }
@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); } }
for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) { PolicyType policyType = ToscaContext.getOrFail(PolicyType.class, policyTemplate.getType()); String policyImplMeta = TagUtil.getTagValue(policyType.getTags(), "a4c_policy_impl");
safe(instance.getPolicies()).forEach((policyName, policyTemplate) -> {
for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) { PolicyType policyType = policyTypes.get(policyTemplate.getType()); if (policyType != null) {
assertEquals(1, archiveRoot.getTopology().getPolicies().size()); assertNotNull(archiveRoot.getTopology().getPolicies().get("anti_affinity_policy")); assertEquals("org.alien4cloud.sample.SamplePolicy", archiveRoot.getTopology().getPolicies().get("anti_affinity_policy").getType()); assertEquals(1, archiveRoot.getTopology().getPolicies().get("anti_affinity_policy").getProperties().size()); assertNotNull(archiveRoot.getTopology().getPolicies().get("anti_affinity_policy").getProperties().get("sample_property")); assertEquals(2, archiveRoot.getTopology().getPolicies().get("anti_affinity_policy").getTags().size());