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);
}
}
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());
}
}
}
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());
}
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()));
}
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);
}
Aggregations