/** * 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; }
Location location = locationService.getOrFail(locationId); locationSecurityService.checkAuthorisation(location, environment.getId()); LocationPlacementPolicy locationPolicy = new LocationPlacementPolicy(locationId); locationPolicy.setName("Location policy"); Map<String, NodeGroup> groups = configuration.getLocationGroups(); NodeGroup group = new NodeGroup();
private AbstractPolicy buildPolicy(Map<String, Object> nodeMap, Node node, ParsingContextExecution context) { String type = (String) nodeMap.get(TYPE); AbstractPolicy result = null; if (type != null) { switch (type) { case HaPolicy.HA_POLICY: result = new HaPolicy(nodeMap); break; case LocationPlacementPolicy.LOCATION_PLACEMENT_POLICY: Object locationO = nodeMap.get(LocationPlacementPolicy.LOCATION_ID_PROPERTY); if (locationO instanceof String) { result = new LocationPlacementPolicy(); } else { context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.SYNTAX_ERROR, null, node.getStartMark(), "Location id should be a string.", node.getEndMark(), locationO.toString())); return null; } break; } } if (result == null) { result = new GenericPolicy(nodeMap); } return result; }
/** * 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; } }