use of alien4cloud.topology.TopologyValidationResult in project alien4cloud by alien4cloud.
the class ApplicationDeploymentController method updateDeployment.
@ApiOperation(value = "Update the active deployment for the given application on the given cloud.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+}/environments/{applicationEnvironmentId}/update-deployment", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public DeferredResult<RestResponse<Void>> updateDeployment(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId, @ApiParam(value = "The secret provider configuration and credentials.") @RequestBody SecretProviderCredentials secretProviderCredentials) {
final DeferredResult<RestResponse<Void>> result = new DeferredResult<>(15L * 60L * 1000L);
Application application = applicationService.checkAndGetApplication(applicationId);
// get the topology from the version and the cloud from the environment
ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(application.getId(), applicationEnvironmentId);
if (!environment.getApplicationId().equals(applicationId)) {
throw new NotFoundException("Unable to find environment with id <" + applicationEnvironmentId + "> for application <" + applicationId + ">");
}
AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.APPLICATION_USER);
// check that the environment is not already deployed
boolean isEnvironmentDeployed = applicationEnvironmentService.isDeployed(environment.getId());
if (!isEnvironmentDeployed) {
// the topology must be deployed in order to update it
throw new NotFoundException("Application <" + applicationId + "> is not deployed for environment with id <" + applicationEnvironmentId + ">, can't update it");
}
Deployment deployment = deploymentService.getActiveDeployment(environment.getId());
if (deployment == null) {
throw new NotFoundException("Unable to find deployment for environment with id <" + applicationEnvironmentId + "> application <" + applicationId + ">, can't update it");
}
ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
DeploymentTopologyDTO deploymentTopologyDTO = deploymentTopologyDTOBuilder.prepareDeployment(topology, application, environment);
TopologyValidationResult validation = deploymentTopologyDTO.getValidation();
deploymentService.checkDeploymentUpdateFeasibility(deployment, deploymentTopologyDTO.getTopology());
// if not valid, then return validation errors
if (!validation.isValid()) {
result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.INVALID_DEPLOYMENT_TOPOLOGY.getCode(), "The deployment topology for the application <" + application.getName() + "> on the environment <" + environment.getName() + "> is not valid.")).build());
}
// process with the deployment
deployService.update(secretProviderCredentials, deploymentTopologyDTO.getTopology(), application, deployment, new IPaaSCallback<Object>() {
@Override
public void onSuccess(Object data) {
result.setResult(RestResponseBuilder.<Void>builder().build());
}
@Override
public void onFailure(Throwable e) {
result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.UNCATEGORIZED_ERROR.getCode(), e.getMessage())).build());
}
});
return result;
}
use of alien4cloud.topology.TopologyValidationResult in project alien4cloud by alien4cloud.
the class DeploymentSetupValidationStepDefinitions method thereShouldBeNoMissingArtifactsTasks.
@Then("^there should be no missing artifacts tasks$")
public void thereShouldBeNoMissingArtifactsTasks() throws Throwable {
TopologyValidationResult topologyValidationResult = JsonUtil.read(Context.getInstance().getRestResponse(), DeploymentTopologyDTO.class, Context.getJsonMapper()).getData().getValidation();
boolean missingFound = topologyValidationResult.getTaskList().stream().anyMatch(task -> task instanceof InputArtifactTask);
Assert.assertFalse(" Expected NO missing artifacts tasks for the deployment topology", missingFound);
}
use of alien4cloud.topology.TopologyValidationResult in project alien4cloud by alien4cloud.
the class DeploymentSetupValidationStepDefinitions method thereShouldBeAMissingLocationPolicyTask.
@And("^there should be a missing location policy task$")
public void thereShouldBeAMissingLocationPolicyTask() throws Throwable {
TopologyValidationResult topologyValidationResult = JsonUtil.read(Context.getInstance().getRestResponse(), DeploymentTopologyDTO.class, Context.getJsonMapper()).getData().getValidation();
boolean missingFound = topologyValidationResult.getTaskList().stream().anyMatch(task -> task.getCode().equals(TaskCode.LOCATION_POLICY));
Assert.assertTrue(" Expected a task LOCATION_POLICY for the deployment setup", missingFound);
}
use of alien4cloud.topology.TopologyValidationResult in project alien4cloud by alien4cloud.
the class DeploymentSetupValidationStepDefinitions method thereShouldBeADisabledLocationPolicyTask.
@And("^there should be an unavailable location task with code \"([^\"]*)\" and the following orchestrators and locations$$")
public void thereShouldBeADisabledLocationPolicyTask(String taskCodeStr, Map<String, String> orchLocationCouple) throws Throwable {
TaskCode taskCode = TaskCode.valueOf(taskCodeStr);
TopologyValidationResult topologyValidationResult = JsonUtil.read(Context.getInstance().getRestResponse(), DeploymentTopologyDTO.class, Context.getJsonMapper()).getData().getValidation();
for (Entry<String, String> expectedEntry : orchLocationCouple.entrySet()) {
boolean missingFound = topologyValidationResult.getTaskList().stream().anyMatch(task -> task instanceof UnavailableLocationTask && task.getCode().equals(taskCode) && Objects.equals(((UnavailableLocationTask) task).getOrchestratorName(), expectedEntry.getKey()) && Objects.equals(((UnavailableLocationTask) task).getLocationName(), expectedEntry.getValue()));
Assert.assertTrue(" Expected a task " + taskCode + " for the deployment setup", missingFound);
}
}
use of alien4cloud.topology.TopologyValidationResult 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);
}
}
Aggregations