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());
}
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());
}
}
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());
}
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());
}
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));
}
Aggregations