Search in sources :

Example 1 with DeploymentMatchingConfiguration

use of org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration in project alien4cloud by alien4cloud.

the class PreDeploymentTopologyValidator method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    DeploymentMatchingConfiguration matchingConfiguration = context.getConfiguration(DeploymentMatchingConfiguration.class, PreDeploymentTopologyValidator.class.getSimpleName()).orElseThrow(() -> new NotFoundException("Failed to find deployment configuration for pre-deployment validation."));
    OrchestratorDeploymentProperties orchestratorDeploymentProperties = context.getConfiguration(OrchestratorDeploymentProperties.class, PreDeploymentTopologyValidator.class.getSimpleName()).orElse(new OrchestratorDeploymentProperties(matchingConfiguration.getVersionId(), matchingConfiguration.getEnvironmentId(), matchingConfiguration.getOrchestratorId()));
    TopologyValidationResult validationResult = deploymentTopologyValidationService.validateProcessedDeploymentTopology(topology, matchingConfiguration, orchestratorDeploymentProperties);
    for (AbstractTask task : safe(validationResult.getTaskList())) {
        context.log().error(task);
    }
    for (AbstractTask task : safe(validationResult.getInfoList())) {
        context.log().info(task);
    }
    for (AbstractTask task : safe(validationResult.getWarningList())) {
        context.log().warn(task);
    }
}
Also used : TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) AbstractTask(alien4cloud.topology.task.AbstractTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) NotFoundException(alien4cloud.exception.NotFoundException) OrchestratorDeploymentProperties(org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties)

Example 2 with DeploymentMatchingConfiguration

use of org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration 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 DeploymentMatchingConfiguration

use of org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration in project alien4cloud by alien4cloud.

the class LocationMatchingModifier method processLocationMatching.

private void processLocationMatching(Topology topology, FlowExecutionContext context) {
    // The configuration has already been loaded by a previous topology modifier.
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, LocationMatchingModifier.class.getSimpleName());
    if (!configurationOptional.isPresent()) {
        return;
    }
    DeploymentMatchingConfiguration matchingConfiguration = configurationOptional.get();
    // If some of the locations defined does not exist anymore then just reset the deployment matching configuration
    Map<String, String> locationIds = matchingConfiguration.getLocationIds();
    if (MapUtils.isEmpty(locationIds)) {
        return;
    }
    // returns null if at least one of the expected location is missing.
    Map<String, Location> locations = getLocations(locationIds);
    if (locations == null) {
        // TODO Add an info log to explain that previous location does not exist anymore
        // Reset and save the configuration
        resetMatchingConfiguration(context);
        return;
    }
    context.getExecutionCache().put(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY, locations);
    // Now we must check that the selected locations are still valid choices for deployment
    // Somehow if the initial topology and none of the previous modifiers had changed then we could assume that the choice is still valid.
    // We had an approximation for that in the past that was not correct enough as we checked only initial topology and location. Actually inputs and
    // potential snapshot substitution merged through composition may also impact this. We know always re-process location matching here.
    // We have to fetch valid location matches anyway to know if the location is a potential valid match.
    List<ILocationMatch> locationMatches = locationMatchingService.match(topology, context.getEnvironmentContext().get().getEnvironment());
    context.getExecutionCache().put(FlowExecutionContext.LOCATION_MATCH_CACHE_KEY, locationMatches);
    Map<String, ILocationMatch> locationMatchMap = Maps.newHashMap();
    // Check that current choices exist in actual location matches
    for (ILocationMatch match : safe(locationMatches)) {
        locationMatchMap.put(match.getLocation().getId(), match);
    }
    for (String locationId : locationIds.values()) {
        if (!locationMatchMap.containsKey(locationId)) {
            // A matched location is not a valid choice anymore.
            resetMatchingConfiguration(context);
            // TODO info log the reason why the location is no more a valid match
            return;
        }
    }
    // update the TOSCA context with the new dependencies so that next step runs with an up-to-date context
    ToscaContext.get().resetDependencies(topology.getDependencies());
}
Also used : ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) Location(alien4cloud.model.orchestrators.locations.Location)

Example 4 with DeploymentMatchingConfiguration

use of org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration in project alien4cloud by alien4cloud.

the class LocationMatchingModifier method resetMatchingConfiguration.

private void resetMatchingConfiguration(FlowExecutionContext context) {
    ApplicationEnvironment environment = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context.")).getEnvironment();
    context.saveConfiguration(new DeploymentMatchingConfiguration(environment.getTopologyVersion(), environment.getId()));
}
Also used : DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Example 5 with DeploymentMatchingConfiguration

use of org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration 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)

Aggregations

DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)23 LocationPolicyTask (alien4cloud.topology.task.LocationPolicyTask)10 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)8 Map (java.util.Map)8 List (java.util.List)7 NotFoundException (alien4cloud.exception.NotFoundException)6 Location (alien4cloud.model.orchestrators.locations.Location)5 Set (java.util.Set)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)4 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)3 Maps (com.google.common.collect.Maps)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 ITopologyModifier (org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier)3 NodeMatchingConfigAutoSelectModifier (org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier)3 NodePropsOverride (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride)3 OrchestratorDeploymentProperties (org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties)3 Csar (org.alien4cloud.tosca.model.Csar)3 MapUtils (org.apache.commons.collections4.MapUtils)3