Search in sources :

Example 1 with PropertyValueException

use of org.alien4cloud.tosca.editor.exception.PropertyValueException 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 2 with PropertyValueException

use of org.alien4cloud.tosca.editor.exception.PropertyValueException in project alien4cloud by alien4cloud.

the class UpdateNodePropertyValueProcessor method process.

@Override
public void process(Csar csar, Topology topology, UpdateNodePropertyValueOperation operation) {
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    NodeTemplate nodeTemp = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
    String propertyName = operation.getPropertyName();
    Object propertyValue = operation.getPropertyValue();
    NodeType node = ToscaContext.getOrFail(NodeType.class, nodeTemp.getType());
    PropertyDefinition propertyDefinition = node.getProperties().get(propertyName);
    if (propertyDefinition == null) {
        throw new NotFoundException("Property <" + propertyName + "> doesn't exists for node <" + operation.getNodeName() + "> of type <" + nodeTemp.getType() + ">");
    }
    log.debug("Updating property [ {} ] of the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", propertyName, operation.getNodeName(), topology.getId(), nodeTemp.getProperties().get(propertyName), propertyValue);
    try {
        propertyService.setPropertyValue(nodeTemp, propertyDefinition, 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) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 3 with PropertyValueException

use of org.alien4cloud.tosca.editor.exception.PropertyValueException in project alien4cloud by alien4cloud.

the class UpdatePolicyPropertyValueProcessor method process.

@Override
protected void process(Csar csar, Topology topology, UpdatePolicyPropertyValueOperation operation, PolicyTemplate policyTemplate) {
    PolicyType policyType = ToscaContext.getOrFail(PolicyType.class, policyTemplate.getType());
    PropertyDefinition propertyDefinition = AlienUtils.getOrFail(policyType.getProperties(), operation.getPropertyName(), "Property [ {} ] doesn't exists in type [ {} ] for policy [ {} ].", operation.getPropertyName(), policyTemplate.getType(), operation.getPolicyName());
    log.debug("Updating property [ {} ] of the policy template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", operation.getPropertyName(), operation.getPolicyName(), topology.getId(), policyTemplate.getProperties().get(operation.getPropertyName()), operation.getPropertyValue());
    try {
        propertyService.setPropertyValue(policyTemplate, propertyDefinition, operation.getPropertyName(), operation.getPropertyValue());
    } catch (ConstraintFunctionalException e) {
        throw new PropertyValueException("Error when setting policy " + operation.getPolicyName() + " property.", e, operation.getPropertyName(), operation.getPropertyValue());
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) PolicyType(org.alien4cloud.tosca.model.types.PolicyType) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 4 with PropertyValueException

use of org.alien4cloud.tosca.editor.exception.PropertyValueException 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)

Aggregations

PropertyValueException (org.alien4cloud.tosca.editor.exception.PropertyValueException)4 ConstraintFunctionalException (org.alien4cloud.tosca.exceptions.ConstraintFunctionalException)4 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 NotFoundException (alien4cloud.exception.NotFoundException)2 SneakyThrows (lombok.SneakyThrows)1 Capability (org.alien4cloud.tosca.model.templates.Capability)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 PolicyType (org.alien4cloud.tosca.model.types.PolicyType)1 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)1