Search in sources :

Example 76 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class SetRelationshipPropertyAsInputProcessor method processRelationshipOperation.

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

Example 77 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class UpdateRelationshipPropertyValueProcessor method process.

@Override
public void process(Csar csar, Topology topology, UpdateRelationshipPropertyValueOperation operation) {
    NodeTemplate nodeTemplate = AlienUtils.getOrFail(topology.getNodeTemplates(), operation.getNodeName(), "The node with name [ {} ] cannot be found in the topology.", operation.getNodeName());
    RelationshipTemplate relationshipTemplate = AlienUtils.getOrFail(nodeTemplate.getRelationships(), operation.getRelationshipName(), "The relationship with name [ {} ] cannot be found in the node [ {} ].", operation.getRelationshipName(), operation.getNodeName());
    RelationshipType relationshipType = ToscaContext.getOrFail(RelationshipType.class, relationshipTemplate.getType());
    PropertyDefinition propertyDefinition = AlienUtils.getOrFail(relationshipType.getProperties(), operation.getPropertyName(), "Property [ {} ] doesn't exists in type [ {} ] for relationship [ {} ] of node [ {} ].", operation.getPropertyName(), relationshipTemplate.getType(), operation.getRelationshipName(), operation.getNodeName());
    log.debug("Updating property [ {} ] of the relationship [ {} ] for the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", operation.getPropertyName(), relationshipType, operation.getNodeName(), topology.getId(), relationshipType.getProperties().get(operation.getPropertyName()), operation.getPropertyValue());
    try {
        propertyService.setPropertyValue(relationshipTemplate, propertyDefinition, operation.getPropertyName(), operation.getPropertyValue());
    } catch (ConstraintFunctionalException e) {
        throw new PropertyValueException("Error when setting relationship " + operation.getNodeName() + "." + operation.getRelationshipName() + " property.", e, operation.getPropertyName(), operation.getPropertyValue());
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 78 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class SetRelationshipPropertyAsSecretProcessor method processRelationshipOperation.

@Override
protected void processRelationshipOperation(Csar csar, Topology topology, SetRelationshipPropertyAsSecretOperation operation, NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate) {
    RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
    PropertyDefinition relationshipPropertyDefinition = getOrFail(relationshipType.getProperties(), operation.getPropertyName(), "Property {} do not exist for relationship {} of node {}", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName());
    FunctionPropertyValue secretFunction = new FunctionPropertyValue();
    secretFunction.setFunction(ToscaFunctionConstants.GET_SECRET);
    secretFunction.setParameters(Arrays.asList(operation.getSecretPath()));
    relationshipTemplate.getProperties().put(operation.getPropertyName(), secretFunction);
    log.debug("Associate the property [ {} ] of relationship template [ {} ] of node [ {} ] to secret <path: {} > of the topology [ {} ].", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName(), operation.getSecretPath(), topology.getId());
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 79 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class UnsetNodePropertyAsSecretProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodePropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
    // check if the node property value is a get_secret
    AbstractPropertyValue currentValue = nodeTemplate.getProperties().get(operation.getPropertyName());
    if (currentValue != null && !isGetSecret(currentValue)) {
        throw new NotFoundException("Property {} of node {} is not associated to an secret.", operation.getPropertyName(), operation.getNodeName());
    }
    NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
    PropertyDefinition nodePropertyDefinition = getOrFail(nodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(nodePropertyDefinition);
    nodeTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove secret property [ {} ] of the node template [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), topology.getId());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 80 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class ToscaTypeConverterTest method convert_time_to_property_value.

@Test
public void convert_time_to_property_value() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.TIME);
    PropertyValue propertyValue = converter.toPropertyValue("2 d", propertyDefinition);
    Object time = ToscaTypes.fromYamlTypeName(propertyDefinition.getType()).parse(propertyValue.getValue().toString());
    assertThat(time).isInstanceOf(Time.class);
    assertThat(time).isEqualTo(new Time(2, TimeUnit.D));
}
Also used : ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) Time(org.alien4cloud.tosca.normative.primitives.Time) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Aggregations

PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)101 Test (org.junit.Test)42 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)23 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)20 Map (java.util.Map)19 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)17 NodeType (org.alien4cloud.tosca.model.types.NodeType)15 NotFoundException (alien4cloud.exception.NotFoundException)13 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)13 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)11 MinLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint)11 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)10 MaxLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint)10 Capability (org.alien4cloud.tosca.model.templates.Capability)10 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)10 DataType (org.alien4cloud.tosca.model.types.DataType)9 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)8 Set (java.util.Set)8 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)8 LengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint)8