Search in sources :

Example 1 with TopologyValidationResult

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;
}
Also used : RestResponse(alien4cloud.rest.model.RestResponse) NotFoundException(alien4cloud.exception.NotFoundException) Deployment(alien4cloud.model.deployment.Deployment) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) RestError(alien4cloud.rest.model.RestError) Application(alien4cloud.model.application.Application) DeferredResult(org.springframework.web.context.request.async.DeferredResult) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with TopologyValidationResult

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);
}
Also used : TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) InputArtifactTask(alien4cloud.topology.task.InputArtifactTask) Then(cucumber.api.java.en.Then)

Example 3 with TopologyValidationResult

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);
}
Also used : TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) And(cucumber.api.java.en.And)

Example 4 with TopologyValidationResult

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);
    }
}
Also used : TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) TaskCode(alien4cloud.topology.task.TaskCode) UnavailableLocationTask(alien4cloud.topology.task.UnavailableLocationTask) And(cucumber.api.java.en.And)

Example 5 with TopologyValidationResult

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

Aggregations

TopologyValidationResult (alien4cloud.topology.TopologyValidationResult)11 And (cucumber.api.java.en.And)4 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)2 NotFoundException (alien4cloud.exception.NotFoundException)2 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 RestError (alien4cloud.rest.model.RestError)2 AbstractTask (alien4cloud.topology.task.AbstractTask)2 InputArtifactTask (alien4cloud.topology.task.InputArtifactTask)2 PropertiesTask (alien4cloud.topology.task.PropertiesTask)2 ApiOperation (io.swagger.annotations.ApiOperation)2 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)2 OrchestratorDeploymentProperties (org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties)2 Topology (org.alien4cloud.tosca.model.templates.Topology)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 DeploymentSubstitutionConfiguration (alien4cloud.deployment.model.DeploymentSubstitutionConfiguration)1 SecretProviderCredentials (alien4cloud.deployment.model.SecretProviderCredentials)1 Application (alien4cloud.model.application.Application)1 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)1