Search in sources :

Example 6 with PropertiesTask

use of alien4cloud.topology.task.PropertiesTask 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 7 with PropertiesTask

use of alien4cloud.topology.task.PropertiesTask in project alien4cloud by alien4cloud.

the class InputValidationModifier method process.

/**
 * Validate all required input is provided with a non null value.
 *
 * @param topology The topology to process.
 * @param context The object that stores warnings and errors (tasks) associated with the execution flow. Note that the flow will end-up if an error
 */
@Override
public void process(Topology topology, FlowExecutionContext context) {
    Optional<DeploymentInputs> inputsOptional = context.getConfiguration(DeploymentInputs.class, InputValidationModifier.class.getSimpleName());
    PreconfiguredInputsConfiguration preconfiguredInputsConfiguration = context.getConfiguration(PreconfiguredInputsConfiguration.class, InputValidationModifier.class.getSimpleName()).orElseThrow(() -> new IllegalStateException("PreconfiguredInputsConfiguration must be in the context"));
    // Define a task regarding properties
    PropertiesTask task = new PropertiesTask();
    task.setCode(TaskCode.INPUT_PROPERTY);
    task.setProperties(Maps.newHashMap());
    task.getProperties().put(TaskLevel.REQUIRED, Lists.newArrayList());
    Map<String, AbstractPropertyValue> inputValues = safe(inputsOptional.orElse(new DeploymentInputs()).getInputs());
    Map<String, PropertyValue> predefinedInputValues = safe(preconfiguredInputsConfiguration.getInputs());
    // override deployer inputValues with predefinedInputValues
    inputValues = Maps.newHashMap(inputValues);
    inputValues.putAll(predefinedInputValues);
    for (Entry<String, PropertyDefinition> propDef : safe(topology.getInputs()).entrySet()) {
        if (propDef.getValue().isRequired() && inputValues.get(propDef.getKey()) == null) {
            task.getProperties().get(TaskLevel.REQUIRED).add(propDef.getKey());
        }
    }
    if (CollectionUtils.isNotEmpty(task.getProperties().get(TaskLevel.REQUIRED))) {
        context.log().error(task);
    }
    // Check input artifacts
    deploymentInputArtifactValidationService.validate(topology, inputsOptional.orElse(new DeploymentInputs())).forEach(inputArtifactTask -> context.log().error(inputArtifactTask));
}
Also used : PropertiesTask(alien4cloud.topology.task.PropertiesTask) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) PreconfiguredInputsConfiguration(org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 8 with PropertiesTask

use of alien4cloud.topology.task.PropertiesTask 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)

Aggregations

PropertiesTask (alien4cloud.topology.task.PropertiesTask)8 TopologyValidationResult (alien4cloud.topology.TopologyValidationResult)2 Map (java.util.Map)2 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)2 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)2 EmptyTask (alien4cloud.topology.task.EmptyTask)1 TaskLevel (alien4cloud.topology.task.TaskLevel)1 ToscaContextual (alien4cloud.tosca.context.ToscaContextual)1 And (cucumber.api.java.en.And)1 List (java.util.List)1 DeploymentInputs (org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs)1 PreconfiguredInputsConfiguration (org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration)1 InstanceRequiredPropertiesException (org.alien4cloud.alm.service.exceptions.InstanceRequiredPropertiesException)1 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)1 Capability (org.alien4cloud.tosca.model.templates.Capability)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)1