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