Search in sources :

Example 1 with PropertiesTask

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

the class TopologyValidationService method doValidate.

private TopologyValidationResult doValidate(Topology topology) {
    TopologyValidationResult dto = new TopologyValidationResult();
    if (MapUtils.isEmpty(topology.getNodeTemplates())) {
        dto.addTask(new EmptyTask());
        dto.setValid(false);
        return dto;
    }
    // validate the workflows
    dto.addTasks(workflowBuilderService.validateWorkflows(topology));
    // validate abstract relationships
    dto.addTasks(topologyAbstractRelationshipValidationService.validateAbstractRelationships(topology));
    // validate requirements lowerBounds
    dto.addTasks(topologyRequirementBoundsValidationServices.validateRequirementsLowerBounds(topology));
    // validate the node filters for all relationships
    dto.addTasks(nodeFilterValidationService.validateStaticRequirementFilters(topology));
    // validate that all artifacts has been filled
    dto.addTasks(topologyArtifactsValidationService.validate(topology));
    // Add warning for deprecated nodes.
    dto.addWarnings(deprecatedNodeTypesValidationService.validate(topology));
    // validate required properties (properties of NodeTemplate, Relationship and Capability)
    List<PropertiesTask> validateProperties = topologyPropertiesValidationService.validateStaticProperties(topology);
    // List<PropertiesTask> validateProperties = null;
    if (hasOnlyPropertiesWarnings(validateProperties)) {
        dto.addWarnings(validateProperties);
    } else {
        dto.addTasks(validateProperties);
    }
    dto.setValid(isValidTaskList(dto.getTaskList()));
    return dto;
}
Also used : PropertiesTask(alien4cloud.topology.task.PropertiesTask) EmptyTask(alien4cloud.topology.task.EmptyTask)

Example 2 with PropertiesTask

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

the class TopologyPropertiesValidationService method validateProperties.

/**
 * Validate properties.
 *
 * @param topology
 * @param skipInputProperties whether to skip input properties validation or not. This is in case inputs are not yet processed
 * @return
 */
private List<PropertiesTask> validateProperties(Topology topology, boolean skipInputProperties) {
    List<PropertiesTask> toReturnTaskList = Lists.newArrayList();
    Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
    // create task by nodetemplate
    for (Map.Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
        NodeTemplate nodeTemplate = nodeTempEntry.getValue();
        NodeType relatedIndexedNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
        // do pass if abstract node
        if (relatedIndexedNodeType.isAbstract()) {
            continue;
        }
        validateNodeTemplate(toReturnTaskList, relatedIndexedNodeType, nodeTemplate, nodeTempEntry.getKey(), skipInputProperties);
    }
    return toReturnTaskList.isEmpty() ? null : toReturnTaskList;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PropertiesTask(alien4cloud.topology.task.PropertiesTask) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map)

Example 3 with PropertiesTask

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

the class TopologyPropertiesValidationService method validateNodeTemplate.

public void validateNodeTemplate(List<PropertiesTask> toReturnTaskList, NodeType relatedIndexedNodeType, NodeTemplate nodeTemplate, String nodeTempalteName, boolean skipInputProperties) {
    // Define a task regarding properties
    PropertiesTask task = new PropertiesTask();
    task.setNodeTemplateName(nodeTempalteName);
    task.setComponent(relatedIndexedNodeType);
    task.setCode(TaskCode.PROPERTIES);
    task.setProperties(Maps.newHashMap());
    // Check the properties of node template
    if (MapUtils.isNotEmpty(nodeTemplate.getProperties())) {
        addRequiredPropertyIdToTaskProperties(null, nodeTemplate.getProperties(), relatedIndexedNodeType.getProperties(), task, skipInputProperties);
    }
    // Check relationships PD
    for (Map.Entry<String, RelationshipTemplate> relationshipEntry : safe(nodeTemplate.getRelationships()).entrySet()) {
        RelationshipTemplate relationship = relationshipEntry.getValue();
        if (relationship.getProperties() == null || relationship.getProperties().isEmpty()) {
            continue;
        }
        addRequiredPropertyIdToTaskProperties("relationships[" + relationshipEntry.getKey() + "]", relationship.getProperties(), safe(ToscaContext.getOrFail(RelationshipType.class, relationshipEntry.getValue().getType()).getProperties()), task, skipInputProperties);
    }
    for (Map.Entry<String, Capability> capabilityEntry : safe(nodeTemplate.getCapabilities()).entrySet()) {
        Capability capability = capabilityEntry.getValue();
        if (capability.getProperties() == null || capability.getProperties().isEmpty()) {
            continue;
        }
        addRequiredPropertyIdToTaskProperties("capabilities[" + capabilityEntry.getKey() + "]", capability.getProperties(), safe(ToscaContext.getOrFail(CapabilityType.class, capabilityEntry.getValue().getType()).getProperties()), task, skipInputProperties);
        if (capability.getType().equals(NormativeCapabilityTypes.SCALABLE)) {
            Map<String, AbstractPropertyValue> scalableProperties = capability.getProperties();
            verifyScalableProperties(scalableProperties, toReturnTaskList, nodeTempalteName, skipInputProperties);
        }
    }
    if (MapUtils.isNotEmpty(task.getProperties())) {
        toReturnTaskList.add(task);
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) PropertiesTask(alien4cloud.topology.task.PropertiesTask) Capability(org.alien4cloud.tosca.model.templates.Capability) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 4 with PropertiesTask

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

the class OrchestratorPropertiesValidationService method validate.

public PropertiesTask validate(OrchestratorDeploymentProperties orchestratorDeploymentProperties) {
    if (orchestratorDeploymentProperties == null || StringUtils.isBlank(orchestratorDeploymentProperties.getOrchestratorId())) {
        return null;
    }
    Map<String, PropertyDefinition> deploymentProperties = orchestratorDeploymentService.getDeploymentPropertyDefinitions(orchestratorDeploymentProperties.getOrchestratorId());
    if (MapUtils.isEmpty(deploymentProperties)) {
        return null;
    }
    Map<String, String> properties = orchestratorDeploymentProperties.getProviderDeploymentProperties();
    if (properties == null) {
        properties = Maps.newHashMap();
    }
    PropertiesTask task = null;
    List<String> required = Lists.newArrayList();
    for (Entry<String, PropertyDefinition> entry : deploymentProperties.entrySet()) {
        if (entry.getValue().isRequired()) {
            String value = properties.get(entry.getKey());
            if (StringUtils.isBlank(value)) {
                required.add(entry.getKey());
            }
        }
    }
    if (CollectionUtils.isNotEmpty(required)) {
        task = new PropertiesTask(Maps.<TaskLevel, List<String>>newHashMap());
        task.setCode(TaskCode.ORCHESTRATOR_PROPERTY);
        task.getProperties().put(TaskLevel.REQUIRED, required);
    }
    return task;
}
Also used : PropertiesTask(alien4cloud.topology.task.PropertiesTask) TaskLevel(alien4cloud.topology.task.TaskLevel) List(java.util.List) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 5 with PropertiesTask

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

the class NodeInstanceService method checkRequired.

/**
 * Performs validation of the node instance. Note that based on the actual node state the validation is more or less strict.
 *
 * When the node state is initial the validation checks that all elements defined in the node template or node instance attributes matches the definition of
 * the node
 * type. It however does not check if the type has all required properties configured.
 *
 * When the node state is anything else the validation performs above validation and also checks that all required properties are defined.
 *
 * @param nodeType The node type against which to perform validation of the node instance.
 * @param nodeInstance The actual node instance to validate
 */
@ToscaContextual
public void checkRequired(NodeType nodeType, NodeInstance nodeInstance) {
    List<PropertiesTask> errors = Lists.newArrayList();
    topologyPropertiesValidationService.validateNodeTemplate(errors, nodeType, nodeInstance.getNodeTemplate(), "", false);
    if (!errors.isEmpty()) {
        Set<String> errorProperties = Sets.newHashSet();
        for (PropertiesTask task : errors) {
            for (List<String> properties : task.getProperties().values()) {
                errorProperties.addAll(properties);
            }
        }
        throw new InstanceRequiredPropertiesException("Some required properties are not defined.", errorProperties);
    }
}
Also used : InstanceRequiredPropertiesException(org.alien4cloud.alm.service.exceptions.InstanceRequiredPropertiesException) PropertiesTask(alien4cloud.topology.task.PropertiesTask) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

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