Search in sources :

Example 1 with LocationPolicyTask

use of alien4cloud.topology.task.LocationPolicyTask in project alien4cloud by alien4cloud.

the class LocationPolicyValidationService method validateLocationPolicies.

public List<LocationPolicyTask> validateLocationPolicies(DeploymentMatchingConfiguration matchingConfiguration) {
    List<LocationPolicyTask> tasks = Lists.newArrayList();
    Location location = null;
    Orchestrator orchestrator = null;
    // TODO change this later, as now we only support one location policy and only for _A4C_ALL group
    String locationId = safe(matchingConfiguration.getLocationIds()).get(AlienConstants.GROUP_ALL);
    if (StringUtils.isBlank(locationId)) {
        tasks.add(new LocationPolicyTask());
    } else {
        location = locationService.getOrFail(locationId);
        orchestrator = orchestratorService.getOrFail(location.getOrchestratorId());
        try {
            // if a location already exists, then check the rigths on it
            locationSecurityService.checkAuthorisation(location, matchingConfiguration.getEnvironmentId());
            if (!Objects.equals(orchestrator.getState(), OrchestratorState.CONNECTED)) {
                UnavailableLocationTask task = new UnavailableLocationTask(location.getName(), orchestrator.getName());
                task.setCode(TaskCode.LOCATION_DISABLED);
                tasks.add(task);
            }
        } catch (AccessDeniedException e) {
            UnavailableLocationTask task = new UnavailableLocationTask(location.getName(), orchestrator.getName());
            task.setCode(TaskCode.LOCATION_UNAUTHORIZED);
            tasks.add(task);
        }
    }
    return tasks;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) UnavailableLocationTask(alien4cloud.topology.task.UnavailableLocationTask) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) Location(alien4cloud.model.orchestrators.locations.Location)

Example 2 with LocationPolicyTask

use of alien4cloud.topology.task.LocationPolicyTask in project alien4cloud by alien4cloud.

the class CfyMultirelationshipErrorModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    // Check if orchestrator is cloudify
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, LocationMatchingModifier.class.getSimpleName());
    if (!configurationOptional.isPresent()) {
        context.log().error(new LocationPolicyTask());
        return;
    }
    DeploymentMatchingConfiguration matchingConfiguration = configurationOptional.get();
    Orchestrator orchestrator = orchestratorService.getOrFail(matchingConfiguration.getOrchestratorId());
    if (!orchestrator.getPluginId().contains("cloudify")) {
        return;
    }
    // For every node check that there is not two relationships defined
    for (Entry<String, NodeTemplate> nodeTemplateEntry : safe(topology.getNodeTemplates()).entrySet()) {
        // Keep track of the relationship id
        Set<String> relationshipTargets = Sets.newHashSet();
        for (Entry<String, RelationshipTemplate> relationshipTemplateEntry : safe(nodeTemplateEntry.getValue().getRelationships()).entrySet()) {
            if (relationshipTargets.contains(relationshipTemplateEntry.getValue().getTarget())) {
                context.log().error(TaskCode.CFY_MULTI_RELATIONS, "Cloudify orchestrator does not support multiple relationships between the same source and target nodes. Topology defines more than one between " + nodeTemplateEntry.getKey() + " and " + relationshipTemplateEntry.getValue().getTarget() + ".");
                return;
            }
            relationshipTargets.add(relationshipTemplateEntry.getValue().getTarget());
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) Orchestrator(alien4cloud.model.orchestrators.Orchestrator)

Example 3 with LocationPolicyTask

use of alien4cloud.topology.task.LocationPolicyTask in project alien4cloud by alien4cloud.

the class OrchestratorPropertiesValidationModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, OrchestratorPropertiesValidationModifier.class.getSimpleName());
    if (!configurationOptional.isPresent()) {
        // we should not end-up here as location matching should be processed first
        context.log().error(new LocationPolicyTask());
        return;
    }
    ApplicationEnvironment environment = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context.")).getEnvironment();
    OrchestratorDeploymentProperties orchestratorDeploymentProperties = context.getConfiguration(OrchestratorDeploymentProperties.class, OrchestratorPropertiesValidationModifier.class.getSimpleName()).orElse(new OrchestratorDeploymentProperties(environment.getTopologyVersion(), environment.getId(), configurationOptional.get().getOrchestratorId()));
    orchestratorPropertiesValidationService.validate(orchestratorDeploymentProperties);
}
Also used : LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) OrchestratorDeploymentProperties(org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties)

Example 4 with LocationPolicyTask

use of alien4cloud.topology.task.LocationPolicyTask in project alien4cloud by alien4cloud.

the class NodeMatchingCandidateModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, NodeMatchingCandidateModifier.class.getSimpleName());
    if (!configurationOptional.isPresent()) {
        // we should not end-up here as location matching should be processed first
        context.log().error(new LocationPolicyTask());
        return;
    }
    DeploymentMatchingConfiguration matchingConfiguration = configurationOptional.get();
    if (matchingConfiguration.getMatchedNodesConfiguration() == null) {
        matchingConfiguration.setMatchedNodesConfiguration(Maps.newHashMap());
    }
    if (matchingConfiguration.getMatchedLocationResources() == null) {
        matchingConfiguration.setMatchedLocationResources(Maps.newHashMap());
    }
    Map<String, Location> locationMap = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
    // TODO can we avoid update if the matching configuration is strickly younger than the context last conf update ?
    // Fetch available substitutions on the selected locations.
    Map<String, List<LocationResourceTemplate>> availableSubstitutions = getAvailableSubstitutions(topology, matchingConfiguration.getLocationGroups(), locationMap, context.getEnvironmentContext().get().getEnvironment().getId());
    context.getExecutionCache().put(FlowExecutionContext.MATCHED_NODE_LOCATION_TEMPLATES_BY_NODE_ID_MAP, availableSubstitutions);
}
Also used : LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) List(java.util.List) Map(java.util.Map) Location(alien4cloud.model.orchestrators.locations.Location)

Example 5 with LocationPolicyTask

use of alien4cloud.topology.task.LocationPolicyTask in project alien4cloud by alien4cloud.

the class PolicyMatchingCandidateModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, PolicyMatchingCandidateModifier.class.getSimpleName());
    if (!configurationOptional.isPresent()) {
        // we should not end-up here as location matching should be processed first
        context.log().error(new LocationPolicyTask());
        return;
    }
    DeploymentMatchingConfiguration matchingConfiguration = configurationOptional.get();
    if (matchingConfiguration.getMatchedPolicies() == null) {
        matchingConfiguration.setMatchedPolicies(Maps.newHashMap());
    }
    Map<String, Location> locationMap = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
    // TODO avoid update if the matching configuration is strickly younger than the context last conf update ?
    // Fetch available substitutions on the selected locations.
    Map<String, List<PolicyLocationResourceTemplate>> availableSubstitutions = getAvailableMatches(topology, context, matchingConfiguration.getLocationGroups(), locationMap, context.getEnvironmentContext().get().getEnvironment().getId());
    context.getExecutionCache().put(FlowExecutionContext.MATCHED_POLICY_LOCATION_TEMPLATES_BY_NODE_ID_MAP, availableSubstitutions);
}
Also used : LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) List(java.util.List) Map(java.util.Map) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

LocationPolicyTask (alien4cloud.topology.task.LocationPolicyTask)11 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)10 Map (java.util.Map)5 List (java.util.List)4 Location (alien4cloud.model.orchestrators.locations.Location)3 NotFoundException (alien4cloud.exception.NotFoundException)2 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 NodeMatchingConfigAutoSelectModifier (org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier)2 NodePropsOverride (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride)2 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 NodeMatchingTask (alien4cloud.topology.task.NodeMatchingTask)1 UnavailableLocationTask (alien4cloud.topology.task.UnavailableLocationTask)1 OrchestratorDeploymentProperties (org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties)1 ConstraintTechnicalException (org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)1 ConstraintValueDoNotMatchPropertyTypeException (org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException)1 ConstraintViolationException (org.alien4cloud.tosca.exceptions.ConstraintViolationException)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1