Search in sources :

Example 16 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class UpdateCapabilityPropertyValueProcessor method process.

@Override
@SneakyThrows
public void process(Csar csar, Topology topology, UpdateCapabilityPropertyValueOperation operation) {
    String propertyName = operation.getPropertyName();
    Object propertyValue = operation.getPropertyValue();
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
    Capability capability = nodeTemplate.getCapabilities().get(operation.getCapabilityName());
    CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
    if (!capabilityType.getProperties().containsKey(propertyName)) {
        throw new NotFoundException("Property <" + propertyName + "> doesn't exists for node <" + operation.getNodeName() + "> of type <" + capabilityType + ">");
    }
    log.debug("Updating property [ {} ] of the capability [ {} ] for the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", propertyName, capability.getType(), operation.getNodeName(), topology.getId(), capabilityType.getProperties().get(propertyName), propertyValue);
    try {
        propertyService.setCapabilityPropertyValue(capability, capabilityType.getProperties().get(propertyName), propertyName, propertyValue);
    } catch (ConstraintFunctionalException e) {
        throw new PropertyValueException("Error when setting node " + operation.getNodeName() + " property.", e, propertyName, propertyValue);
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) SneakyThrows(lombok.SneakyThrows)

Example 17 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class SetNodeCapabilityPropertyAsInputProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodeCapabilityPropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
    Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} does not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
    PropertyDefinition inputPropertyDefinition = getOrFail(topology.getInputs(), operation.getInputName(), "Input {} not found in topology", operation.getInputName());
    CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
    PropertyDefinition capabilityPropertyDefinition = getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
    // Check that the property definition of the input is indeed compatible with the property definition of the capability.
    inputPropertyDefinition.checkIfCompatibleOrFail(capabilityPropertyDefinition);
    FunctionPropertyValue getInput = new FunctionPropertyValue();
    getInput.setFunction(ToscaFunctionConstants.GET_INPUT);
    getInput.setParameters(Arrays.asList(operation.getInputName()));
    capabilityTemplate.getProperties().put(operation.getPropertyName(), getInput);
    log.debug("Associate the property [ {} ] of capability template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 18 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class SetNodeCapabilityPropertyAsOutputProcessor method check.

private void check(SetNodeCapabilityPropertyAsOutputOperation operation, Topology topology, NodeTemplate nodeTemplate) {
    if (nodeTemplate.getCapabilities() == null || nodeTemplate.getCapabilities().get(operation.getCapabilityName()) == null) {
        throw new NotFoundException("Capability " + operation.getCapabilityName() + " not found in node template " + operation.getNodeName());
    }
    Capability capabilityTemplate = nodeTemplate.getCapabilities().get(operation.getCapabilityName());
    CapabilityType indexedCapabilityType = EditionContextManager.get().getToscaContext().getElement(CapabilityType.class, capabilityTemplate.getType(), true);
    if (indexedCapabilityType.getProperties() == null || !indexedCapabilityType.getProperties().containsKey(operation.getPropertyName())) {
        throw new NotFoundException("Property " + operation.getPropertyName() + " not found in capability " + operation.getCapabilityName() + " of node " + operation.getNodeName());
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException)

Example 19 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class UnsetNodeCapabilityPropertyAsInputProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodeCapabilityPropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
    Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} do not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
    // check if the node property value is a get_input
    AbstractPropertyValue currentValue = capabilityTemplate.getProperties().get(operation.getPropertyName());
    if (!isGetInput(currentValue)) {
        throw new NotFoundException("Property {} of node {} is not associated to an input.", operation.getPropertyName(), operation.getNodeName());
    }
    CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
    PropertyDefinition capabilityPropertyDefinition = getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(capabilityPropertyDefinition);
    capabilityTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove association from property [ {} ] of capability template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 20 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class NodeFilterValidationService method validateNodeFilterCapabilities.

private void validateNodeFilterCapabilities(NodeFilter nodeFilter, NodeTemplate target, NodeType targetType, Map<String, CapabilityType> capabilityTypes, NodeFilterToSatisfy nodeFilterToSatisfy, boolean skipInputs) {
    if (nodeFilter.getCapabilities() == null || nodeFilter.getCapabilities().isEmpty()) {
        return;
    }
    Map<String, FilterDefinition> capabilities = nodeFilter.getCapabilities();
    for (Map.Entry<String, FilterDefinition> filterDefinitionEntry : capabilities.entrySet()) {
        String capabilityName = filterDefinitionEntry.getKey();
        CapabilityDefinition definition = getCapabilityDefinition(targetType, capabilityName);
        if (definition == null) {
            nodeFilterToSatisfy.getMissingCapabilities().add(capabilityName);
            continue;
        }
        CapabilityType capabilityType = capabilityTypes.get(definition.getType());
        List<Violations> violations = validatePropertyFilters(filterDefinitionEntry.getValue().getProperties(), target.getCapabilities().get(definition.getId()).getProperties(), capabilityType.getProperties(), skipInputs);
        violations.forEach(violation -> violation.capabilityName = capabilityName);
        if (nodeFilterToSatisfy.getViolations() == null) {
            nodeFilterToSatisfy.setViolations(violations);
        } else {
            nodeFilterToSatisfy.getViolations().addAll(violations);
        }
    }
}
Also used : FilterDefinition(org.alien4cloud.tosca.model.definitions.FilterDefinition) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Violations(alien4cloud.topology.task.NodeFilterToSatisfy.Violations) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) Map(java.util.Map)

Aggregations

CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)48 Capability (org.alien4cloud.tosca.model.templates.Capability)25 NodeType (org.alien4cloud.tosca.model.types.NodeType)21 Set (java.util.Set)20 Test (org.junit.Test)18 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)14 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)13 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)13 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)10 Map (java.util.Map)9 Csar (org.alien4cloud.tosca.model.Csar)8 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)8 NotFoundException (alien4cloud.exception.NotFoundException)7 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)5 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)5 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)5 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)4 List (java.util.List)3 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)3 MatchingFilterDefinition (alien4cloud.model.deployment.matching.MatchingFilterDefinition)2