/** * Get the location ids out of the location groups settings. * * @return map of location group to location id */ public Map<String, String> getLocationIds() { Map<String, String> locationIds = Maps.newHashMap(); for (NodeGroup group : safe(locationGroups).values()) { for (AbstractPolicy policy : safe(group.getPolicies())) { if (policy instanceof LocationPlacementPolicy) { locationIds.put(group.getName(), ((LocationPlacementPolicy) policy).getLocationId()); } } } return locationIds; }
/** * Get the location on which a Deployment Topology should be deployed. * * @param deploymentTopology the deployment topology. * @return map of location group to location id */ public static Map<String, String> getLocationIds(DeploymentTopology deploymentTopology) { Map<String, String> locationIds = Maps.newHashMap(); if (MapUtils.isNotEmpty(deploymentTopology.getLocationGroups())) { for (NodeGroup group : deploymentTopology.getLocationGroups().values()) { for (AbstractPolicy policy : group.getPolicies()) { if (policy instanceof LocationPlacementPolicy) { locationIds.put(group.getName(), ((LocationPlacementPolicy) policy).getLocationId()); } } } } return locationIds; } }
@Override public void process(NodeGroup instance) { final ArchiveRoot archiveRoot = (ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance(); // ensure that member groups exists and add the group to the nodes. Iterator<String> groupMembers = instance.getMembers().iterator(); while (groupMembers.hasNext()) { String nodeTemplateId = groupMembers.next(); NodeTemplate nodeTemplate = archiveRoot.getTopology().getNodeTemplates().get(nodeTemplateId); if (nodeTemplate == null) { Node node = ParsingContextExecution.getObjectToNodeMap().get(instance); // add an error to the context ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKOWN_GROUP_MEMBER, null, node.getStartMark(), null, node.getEndMark(), nodeTemplateId)); // and remove the member groupMembers.remove(); } else { Set<String> groups = nodeTemplate.getGroups(); if (groups == null) { groups = Sets.newHashSet(); nodeTemplate.setGroups(groups); } groups.add(instance.getName()); } } } }