Search in sources :

Example 6 with NodeGroup

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);
}
Also used : OnMatchedLocationChangedEvent(org.alien4cloud.alm.deployment.configuration.events.OnMatchedLocationChangedEvent) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) LocationPlacementPolicy(org.alien4cloud.tosca.model.templates.LocationPlacementPolicy) Location(alien4cloud.model.orchestrators.locations.Location) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Example 7 with NodeGroup

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;
}
Also used : MapUtils(org.apache.commons.collections4.MapUtils) NodeMatcherService(alien4cloud.deployment.matching.services.nodes.NodeMatcherService) NodeType(org.alien4cloud.tosca.model.types.NodeType) Maps(com.google.common.collect.Maps) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Location(alien4cloud.model.orchestrators.locations.Location) Inject(javax.inject.Inject) AlienConstants(alien4cloud.utils.AlienConstants) List(java.util.List) Component(org.springframework.stereotype.Component) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) Map(java.util.Map) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Optional(java.util.Optional) Topology(org.alien4cloud.tosca.model.templates.Topology) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) ToscaContext(alien4cloud.tosca.context.ToscaContext) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) List(java.util.List) Map(java.util.Map) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Example 8 with NodeGroup

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);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) InvalidNameException(alien4cloud.exception.InvalidNameException) NotFoundException(alien4cloud.exception.NotFoundException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Example 9 with 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();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Aggregations

NodeGroup (org.alien4cloud.tosca.model.templates.NodeGroup)9 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)6 Map (java.util.Map)3 AlreadyExistException (alien4cloud.exception.AlreadyExistException)2 Location (alien4cloud.model.orchestrators.locations.Location)2 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)2 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)2 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)2 NodeMatcherService (alien4cloud.deployment.matching.services.nodes.NodeMatcherService)1 InvalidNameException (alien4cloud.exception.InvalidNameException)1 NotFoundException (alien4cloud.exception.NotFoundException)1 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)1 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)1 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)1 PaaSTopology (alien4cloud.paas.model.PaaSTopology)1 TopologyDTO (alien4cloud.topology.TopologyDTO)1 LocationPolicyTask (alien4cloud.topology.task.LocationPolicyTask)1 ToscaContext (alien4cloud.tosca.context.ToscaContext)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 ParsingError (alien4cloud.tosca.parser.ParsingError)1