Search in sources :

Example 1 with LocationPlacementPolicy

use of org.alien4cloud.tosca.model.templates.LocationPlacementPolicy 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 2 with LocationPlacementPolicy

use of org.alien4cloud.tosca.model.templates.LocationPlacementPolicy in project alien4cloud by alien4cloud.

the class GroupPolicyParser method buildPolicy.

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;
}
Also used : GenericPolicy(org.alien4cloud.tosca.model.templates.GenericPolicy) AbstractPolicy(org.alien4cloud.tosca.model.templates.AbstractPolicy) HaPolicy(org.alien4cloud.tosca.model.templates.HaPolicy) LocationPlacementPolicy(org.alien4cloud.tosca.model.templates.LocationPlacementPolicy)

Aggregations

LocationPlacementPolicy (org.alien4cloud.tosca.model.templates.LocationPlacementPolicy)2 Location (alien4cloud.model.orchestrators.locations.Location)1 OnMatchedLocationChangedEvent (org.alien4cloud.alm.deployment.configuration.events.OnMatchedLocationChangedEvent)1 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)1 AbstractPolicy (org.alien4cloud.tosca.model.templates.AbstractPolicy)1 GenericPolicy (org.alien4cloud.tosca.model.templates.GenericPolicy)1 HaPolicy (org.alien4cloud.tosca.model.templates.HaPolicy)1 NodeGroup (org.alien4cloud.tosca.model.templates.NodeGroup)1