use of org.alien4cloud.tosca.model.templates.NodeGroup in project alien4cloud by alien4cloud.
the class LocationMatchService method setLocationPolicy.
public void setLocationPolicy(ApplicationEnvironment environment, String orchestratorId, Map<String, String> groupsLocationsMapping) {
if (MapUtils.isEmpty(groupsLocationsMapping)) {
return;
}
DeploymentMatchingConfiguration configuration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(environment.getTopologyVersion(), environment.getId()));
if (configuration == null) {
configuration = new DeploymentMatchingConfiguration(environment.getTopologyVersion(), environment.getId());
} else if (configuration.getLocationGroups() == null) {
configuration.setLocationGroups(Maps.newHashMap());
}
Map<String, String> currentConfiguration = configuration.getLocationIds();
// TODO For now, we only support one location policy for all nodes. So we have a group _A4C_ALL that represents all compute nodes in the topology
// To improve later on for multiple groups support
// throw an exception if multiple location policies provided: not yet supported
// throw an exception if group name is not _A4C_ALL
checkGroups(groupsLocationsMapping);
boolean updated = false;
for (Entry<String, String> matchEntry : groupsLocationsMapping.entrySet()) {
String current = currentConfiguration.get(matchEntry.getKey());
if (current != null && current.equals(matchEntry.getValue())) {
continue;
}
updated = true;
String locationId = matchEntry.getValue();
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();
group.setName(matchEntry.getKey());
group.setPolicies(Lists.<AbstractPolicy>newArrayList());
group.getPolicies().add(locationPolicy);
groups.put(matchEntry.getKey(), group);
}
if (!updated) {
// nothing has changed.
return;
}
configuration.setOrchestratorId(orchestratorId);
configuration.setMatchedLocationResources(Maps.newHashMap());
configuration.setMatchedNodesConfiguration(Maps.newHashMap());
publisher.publishEvent(new OnMatchedLocationChangedEvent(this, environment, orchestratorId, groupsLocationsMapping));
deploymentConfigurationDao.save(configuration);
}
use of org.alien4cloud.tosca.model.templates.NodeGroup in project alien4cloud by alien4cloud.
the class NodeMatchingCandidateModifier method getAvailableSubstitutions.
private Map<String, List<LocationResourceTemplate>> getAvailableSubstitutions(Topology topology, Map<String, NodeGroup> locationGroups, Map<String, Location> locationByIds, String environmentId) {
// Fetch all node types for templates in the topology
Map<String, NodeType> nodeTypes = getNodeTypes(topology);
Map<String, List<LocationResourceTemplate>> availableSubstitutions = Maps.newHashMap();
// Based on our model nodes may come from various locations actually.
for (final Map.Entry<String, NodeGroup> locationGroupEntry : locationGroups.entrySet()) {
String groupName = locationGroupEntry.getKey();
final NodeGroup locationNodeGroup = locationGroupEntry.getValue();
Map<String, NodeTemplate> nodesToMatch = Maps.newHashMap();
if (MapUtils.isNotEmpty(topology.getNodeTemplates())) {
if (AlienConstants.GROUP_ALL.equals(groupName)) {
locationNodeGroup.setMembers(topology.getNodeTemplates().keySet());
nodesToMatch = topology.getNodeTemplates();
} else {
nodesToMatch = Maps.filterEntries(topology.getNodeTemplates(), input -> locationNodeGroup.getMembers().contains(input.getKey()));
}
}
availableSubstitutions.putAll(nodeMatcherService.match(nodeTypes, nodesToMatch, locationByIds.get(groupName), environmentId));
}
return availableSubstitutions;
}
use of org.alien4cloud.tosca.model.templates.NodeGroup in project alien4cloud by alien4cloud.
the class RenameGroupProcessor method process.
@Override
public void process(Csar csar, Topology topology, RenameGroupOperation operation) {
if (operation.getNewGroupName() == null || !operation.getNewGroupName().matches("\\w+")) {
throw new InvalidNameException("groupName", operation.getGroupName(), "\\w+");
}
if (topology.getGroups() == null) {
throw new NotFoundException("Group with name [" + operation.getGroupName() + "] does not exists and cannot be renamed.");
}
if (topology.getGroups().containsKey(operation.getNewGroupName())) {
throw new AlreadyExistException("Group with name [" + operation.getNewGroupName() + "] already exists, please choose another name");
}
NodeGroup nodeGroup = topology.getGroups().remove(operation.getGroupName());
if (nodeGroup == null) {
throw new NotFoundException("Group with name [" + operation.getGroupName() + "] does not exists and cannot be renamed.");
}
nodeGroup.setName(operation.getNewGroupName());
Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
for (NodeTemplate nodeTemplate : nodeTemplates.values()) {
if (nodeTemplate.getGroups() != null) {
if (nodeTemplate.getGroups().remove(operation.getGroupName())) {
nodeTemplate.getGroups().add(operation.getNewGroupName());
}
}
}
topology.getGroups().put(operation.getNewGroupName(), nodeGroup);
}
use of org.alien4cloud.tosca.model.templates.NodeGroup in project alien4cloud by alien4cloud.
the class TopologyUtils method getAvailableGroupIndex.
public static int getAvailableGroupIndex(Topology topology) {
if (topology == null || topology.getGroups() == null) {
return 0;
}
Collection<NodeGroup> nodeGroups = topology.getGroups().values();
LinkedHashSet<Integer> indexSet = new LinkedHashSet<>(nodeGroups.size());
for (int i = 0; i < nodeGroups.size(); i++) {
indexSet.add(i);
}
for (NodeGroup nodeGroup : nodeGroups) {
indexSet.remove(nodeGroup.getIndex());
}
if (indexSet.isEmpty()) {
return nodeGroups.size();
}
return indexSet.iterator().next();
}
Aggregations