Search in sources :

Example 6 with TopologyValidationResult

use of alien4cloud.topology.TopologyValidationResult in project alien4cloud by alien4cloud.

the class DeploymentTopologyDTOBuilder method build.

/**
 * Create a deployment topology dto from the context of the execution of a deployment flow.
 *
 * @param executionContext The deployment flow execution context.
 * @return The deployment topology.
 */
private DeploymentTopologyDTO build(FlowExecutionContext executionContext) {
    // re-create the deployment topology object for api compatibility purpose
    DeploymentTopology deploymentTopology = new DeploymentTopology();
    ReflectionUtil.mergeObject(executionContext.getTopology(), deploymentTopology);
    deploymentTopology.setInitialTopologyId(executionContext.getTopology().getId());
    deploymentTopology.setEnvironmentId(executionContext.getEnvironmentContext().get().getEnvironment().getId());
    deploymentTopology.setVersionId(executionContext.getEnvironmentContext().get().getEnvironment().getTopologyVersion());
    DeploymentTopologyDTO deploymentTopologyDTO = new DeploymentTopologyDTO();
    topologyDTOBuilder.initTopologyDTO(deploymentTopology, deploymentTopologyDTO);
    // Convert log result to validation result.
    TopologyValidationResult validationResult = new TopologyValidationResult();
    for (AbstractTask task : executionContext.getLog().getInfos()) {
        validationResult.addInfo(task);
    }
    for (AbstractTask task : executionContext.getLog().getWarnings()) {
        validationResult.addWarning(task);
    }
    for (AbstractTask task : executionContext.getLog().getErrors()) {
        validationResult.addTask(task);
    }
    validationResult.setValid(validationResult.getTaskList() == null || validationResult.getTaskList().isEmpty());
    deploymentTopologyDTO.setValidation(validationResult);
    Optional<PreconfiguredInputsConfiguration> preconfiguredInputsConfiguration = executionContext.getConfiguration(PreconfiguredInputsConfiguration.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
    if (!preconfiguredInputsConfiguration.isPresent()) {
        deploymentTopology.setPreconfiguredInputProperties(Maps.newHashMap());
    } else {
        deploymentTopology.setPreconfiguredInputProperties(preconfiguredInputsConfiguration.get().getInputs());
    }
    Optional<DeploymentInputs> inputsOptional = executionContext.getConfiguration(DeploymentInputs.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
    if (!inputsOptional.isPresent()) {
        deploymentTopology.setDeployerInputProperties(Maps.newHashMap());
        deploymentTopology.setUploadedInputArtifacts(Maps.newHashMap());
    } else {
        deploymentTopology.setDeployerInputProperties(inputsOptional.get().getInputs());
        deploymentTopology.setUploadedInputArtifacts(inputsOptional.get().getInputArtifacts());
    }
    Optional<DeploymentMatchingConfiguration> matchingConfigurationOptional = executionContext.getConfiguration(DeploymentMatchingConfiguration.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
    if (!matchingConfigurationOptional.isPresent()) {
        return deploymentTopologyDTO;
    }
    DeploymentMatchingConfiguration matchingConfiguration = matchingConfigurationOptional.get();
    deploymentTopology.setOrchestratorId(matchingConfiguration.getOrchestratorId());
    deploymentTopology.setLocationGroups(matchingConfiguration.getLocationGroups());
    deploymentTopologyDTO.setLocationPolicies(matchingConfiguration.getLocationIds());
    // Good enough approximation as it doesn't contains just the location dependencies.
    deploymentTopology.setLocationDependencies(executionContext.getTopology().getDependencies());
    DeploymentSubstitutionConfiguration substitutionConfiguration = new DeploymentSubstitutionConfiguration();
    substitutionConfiguration.setSubstitutionTypes(new LocationResourceTypes());
    // fill DTO with policies substitution stuffs
    fillDTOWithPoliciesSubstitutionConfiguration(executionContext, deploymentTopology, deploymentTopologyDTO, matchingConfiguration, substitutionConfiguration);
    // fill DTO with nodes substitution stuffs
    fillDTOWithNodesSubstitutionConfiguration(executionContext, deploymentTopology, deploymentTopologyDTO, matchingConfiguration, substitutionConfiguration);
    deploymentTopologyDTO.setAvailableSubstitutions(substitutionConfiguration);
    ApplicationEnvironment environment = executionContext.getEnvironmentContext().get().getEnvironment();
    OrchestratorDeploymentProperties orchestratorDeploymentProperties = executionContext.getConfiguration(OrchestratorDeploymentProperties.class, this.getClass().getSimpleName()).orElse(new OrchestratorDeploymentProperties(environment.getTopologyVersion(), environment.getId(), matchingConfiguration.getOrchestratorId()));
    deploymentTopology.setProviderDeploymentProperties(orchestratorDeploymentProperties.getProviderDeploymentProperties());
    deploymentTopologyDTO.setSecretCredentialInfos((List<SecretCredentialInfo>) executionContext.getExecutionCache().get(FlowExecutionContext.SECRET_CREDENTIAL));
    return deploymentTopologyDTO;
}
Also used : AbstractTask(alien4cloud.topology.task.AbstractTask) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) PreconfiguredInputsConfiguration(org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration) SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo) DeploymentSubstitutionConfiguration(alien4cloud.deployment.model.DeploymentSubstitutionConfiguration) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) OrchestratorDeploymentProperties(org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties) TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) LocationResourceTypes(alien4cloud.orchestrators.locations.services.LocationResourceTypes) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)

Example 7 with TopologyValidationResult

use of alien4cloud.topology.TopologyValidationResult in project alien4cloud by alien4cloud.

the class DeploymentTopologyValidationService method validateProcessedDeploymentTopology.

/**
 * Perform validation of a deployment topology where all inputs have been processed.
 *
 * @param topology The deployment topology to check.
 * @return A DeploymentTopologyValidationResult with a list of errors and/or warnings er steps.
 */
public TopologyValidationResult validateProcessedDeploymentTopology(Topology topology, DeploymentMatchingConfiguration matchingConfiguration, OrchestratorDeploymentProperties orchestratorDeploymentProperties) {
    TopologyValidationResult dto = new TopologyValidationResult();
    if (topology.getNodeTemplates() == null || topology.getNodeTemplates().size() < 1) {
        dto.setValid(false);
        return dto;
    }
    // Node filters validation is performed twice, once at the editor times to check that the edition does not contains any values that breaks filters
    // And one post matching (below) after all properties are filled-in (inputs and location provided).
    dto.addTasks(nodeFilterValidationService.validateAllRequirementFilters(topology));
    // Display warning if operations from the topology are overriden by service provided operations.
    dto.addWarnings(topologyServiceInterfaceOverrideCheckerService.findWarnings(topology));
    // validate workflows
    dto.addTasks(workflowBuilderService.validateWorkflows(topology));
    // validate abstract node types
    dto.addTasks(topologyAbstractNodeValidationService.findReplacementForAbstracts(topology, matchingConfiguration.getMatchedLocationResources()));
    // TODO Perform here validation of policies
    // If a policy is not matched on the location this is a warning as we allow deployment but some features may be missing
    // If a policy requires a configuration or cannot be applied du to any reason the policy implementation itself can trigger some errors (see Orchestrator
    // plugins)
    // validate required properties (properties of NodeTemplate, Relationship and Capability)
    // check also location / ENVIRONMENT meta properties
    List<PropertiesTask> validateProperties = topologyPropertiesValidationService.validateAllProperties(topology);
    // validate orchestrator properties
    PropertiesTask orchestratorValidation = orchestratorPropertiesValidationService.validate(orchestratorDeploymentProperties);
    if (orchestratorValidation != null) {
        dto.addTasks(Lists.newArrayList(orchestratorValidation));
    }
    if (TopologyValidationService.hasOnlyPropertiesWarnings(validateProperties)) {
        dto.addWarnings(validateProperties);
    } else {
        dto.addTasks(validateProperties);
    }
    dto.setValid(TopologyValidationService.isValidTaskList(dto.getTaskList()));
    return dto;
}
Also used : TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) PropertiesTask(alien4cloud.topology.task.PropertiesTask)

Example 8 with TopologyValidationResult

use of alien4cloud.topology.TopologyValidationResult in project alien4cloud by alien4cloud.

the class DeploymentSetupValidationStepDefinitions method theMissingOrchestratorPropertiesShouldBe.

@And("^the missing orchestrator properties should be$")
public void theMissingOrchestratorPropertiesShouldBe(List<String> expectedInvalidOrchestratorProperties) throws Throwable {
    TopologyValidationResult topologyValidationResult = JsonUtil.read(Context.getInstance().getRestResponse(), DeploymentTopologyDTO.class, Context.getJsonMapper()).getData().getValidation();
    for (String expectedInvalidProp : expectedInvalidOrchestratorProperties) {
        boolean missingFound = topologyValidationResult.getTaskList().stream().anyMatch(task -> task.getCode().equals(TaskCode.ORCHESTRATOR_PROPERTY) && ((PropertiesTask) task).getProperties().get(TaskLevel.REQUIRED).contains(expectedInvalidProp));
        Assert.assertTrue(expectedInvalidProp + " does not appear in invalid orchestrators properties task list for the deployment topology", missingFound);
    }
}
Also used : TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) PropertiesTask(alien4cloud.topology.task.PropertiesTask) And(cucumber.api.java.en.And)

Example 9 with TopologyValidationResult

use of alien4cloud.topology.TopologyValidationResult in project alien4cloud by alien4cloud.

the class DeploymentSetupValidationStepDefinitions method theMissingInputsArtifactsShouldBe.

@And("^the missing inputs artifacts should be$")
public void theMissingInputsArtifactsShouldBe(DataTable expectedInputArtifactsTable) throws Throwable {
    TopologyValidationResult topologyValidationResult = JsonUtil.read(Context.getInstance().getRestResponse(), DeploymentTopologyDTO.class, Context.getJsonMapper()).getData().getValidation();
    for (List<String> expectedRow : expectedInputArtifactsTable.raw()) {
        boolean missingFound = topologyValidationResult.getTaskList().stream().anyMatch(task -> task instanceof InputArtifactTask && ((InputArtifactTask) task).getInputArtifactName().equals(expectedRow.get(0)));
        Assert.assertTrue(expectedRow.get(0) + " does not appear in the task list for the deployment topology", missingFound);
    }
}
Also used : TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) InputArtifactTask(alien4cloud.topology.task.InputArtifactTask) And(cucumber.api.java.en.And)

Example 10 with TopologyValidationResult

use of alien4cloud.topology.TopologyValidationResult in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method doDeploy.

private RestResponse<?> doDeploy(DeployApplicationRequest deployApplicationRequest, Application application, ApplicationEnvironment environment, Topology topology) {
    DeploymentTopologyDTO deploymentTopologyDTO = deploymentTopologyDTOBuilder.prepareDeployment(topology, application, environment);
    TopologyValidationResult validation = deploymentTopologyDTO.getValidation();
    // if not valid, then return validation errors
    if (!validation.isValid()) {
        return RestResponseBuilder.<TopologyValidationResult>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.")).data(validation).build();
    }
    User deployer = AuthorizationUtil.getCurrentUser();
    // commit and push the deployment configuration data
    GitLocation location = gitLocationDao.findDeploymentSetupLocation(application.getId(), environment.getId());
    localGitManager.commitAndPush(location, deployer.getUsername(), deployer.getEmail(), "Deployment " + DateTime.now(DateTimeZone.UTC));
    // the request contains secret provider credentials?
    SecretProviderCredentials secretProviderCredentials = null;
    if (deployApplicationRequest.getSecretProviderCredentials() != null && deployApplicationRequest.getSecretProviderPluginName() != null) {
        secretProviderCredentials = new SecretProviderCredentials();
        secretProviderCredentials.setCredentials(deployApplicationRequest.getSecretProviderCredentials());
        secretProviderCredentials.setPluginName(deployApplicationRequest.getSecretProviderPluginName());
    }
    // process with the deployment
    deployService.deploy(deployer, secretProviderCredentials, deploymentTopologyDTO.getTopology(), application);
    return RestResponseBuilder.<Void>builder().build();
}
Also used : TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) SecretProviderCredentials(alien4cloud.deployment.model.SecretProviderCredentials) User(alien4cloud.security.model.User) RestError(alien4cloud.rest.model.RestError) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) GitLocation(org.alien4cloud.git.model.GitLocation)

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