Search in sources :

Example 36 with FunctionPropertyValue

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

the class OuputsParser method parse.

@Override
public Void parse(Node node, ParsingContextExecution context) {
    Topology topology = (Topology) context.getParent();
    if (!(node instanceof MappingNode)) {
        context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.YAML_MAPPING_NODE_EXPECTED, null, node.getStartMark(), null, node.getEndMark(), null));
        return null;
    }
    MappingNode mappingNode = (MappingNode) node;
    Map<String, Set<String>> outputAttributes = null;
    Map<String, Set<String>> outputProperties = null;
    Map<String, Map<String, Set<String>>> ouputCapabilityProperties = null;
    List<NodeTuple> children = mappingNode.getValue();
    for (NodeTuple child : children) {
        Node childValueNode = child.getValueNode();
        if (!(childValueNode instanceof MappingNode)) {
            // not a mapping jut ignore the entry
            continue;
        }
        for (NodeTuple childChild : ((MappingNode) childValueNode).getValue()) {
            if (childChild.getKeyNode() instanceof ScalarNode && ((ScalarNode) childChild.getKeyNode()).getValue().equals("value")) {
                // we are only interested by the 'value' node
                Node outputValueNode = childChild.getValueNode();
                // now we have to parse this node
                INodeParser<?> p = context.getRegistry().get("tosca_function");
                FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) p.parse(outputValueNode, context);
                String functionName = functionPropertyValue.getFunction();
                List<String> params = functionPropertyValue.getParameters();
                if (params.size() == 2) {
                    // we need exactly 2 params to be able to do the job : node name & property or attribute name
                    String nodeTemplateName = params.get(0);
                    String nodeTemplatePropertyOrAttributeName = params.get(1);
                    // TODO: should we check they exist ?
                    switch(functionName) {
                        case "get_attribute":
                            outputAttributes = addToMapOfSet(nodeTemplateName, nodeTemplatePropertyOrAttributeName, outputAttributes);
                            break;
                        case "get_property":
                            outputProperties = addToMapOfSet(nodeTemplateName, nodeTemplatePropertyOrAttributeName, outputProperties);
                            break;
                        default:
                            context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.OUTPUTS_UNKNOWN_FUNCTION, null, outputValueNode.getStartMark(), null, outputValueNode.getEndMark(), functionName));
                    }
                } else if (params.size() == 3 && functionName.equals("get_property")) {
                    // in case of 3 parameters we only manage capabilities outputs for the moment
                    String nodeTemplateName = params.get(0);
                    String capabilityName = params.get(1);
                    String propertyName = params.get(2);
                    ouputCapabilityProperties = addToMapOfMapOfSet(nodeTemplateName, capabilityName, propertyName, ouputCapabilityProperties);
                } else {
                    context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.OUTPUTS_BAD_PARAMS_COUNT, null, outputValueNode.getStartMark(), null, outputValueNode.getEndMark(), null));
                }
            }
        }
    }
    topology.setOutputProperties(outputProperties);
    topology.setOutputAttributes(outputAttributes);
    topology.setOutputCapabilityProperties(ouputCapabilityProperties);
    return null;
}
Also used : ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) Topology(org.alien4cloud.tosca.model.templates.Topology) ParsingError(alien4cloud.tosca.parser.ParsingError) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple)

Example 37 with FunctionPropertyValue

use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project yorc-a4c-plugin by ystia.

the class BasicToscaParser method postProcessPropVal.

private void postProcessPropVal(AbstractPropertyValue value) {
    if (value instanceof ConcatPropertyValue) {
        ConcatPropertyValue concatPropertyValue = (ConcatPropertyValue) value;
        safe(concatPropertyValue.getParameters()).forEach(this::postProcessPropVal);
    } else if (value instanceof FunctionPropertyValue) {
        FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) value;
        if ("R_TARGET".equals(functionPropertyValue.getParameters().get(0))) {
            functionPropertyValue.getParameters().set(0, "TARGET");
        }
    }
}
Also used : FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)

Aggregations

FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)37 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)12 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)10 Map (java.util.Map)7 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)6 And (cucumber.api.java.en.And)5 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)5 When (cucumber.api.java.en.When)4 RestResponse (alien4cloud.rest.model.RestResponse)3 TopologyDTO (alien4cloud.topology.TopologyDTO)3 JavaType (com.fasterxml.jackson.databind.JavaType)3 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)3 Capability (org.alien4cloud.tosca.model.templates.Capability)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)3 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)3 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)2 NotFoundException (alien4cloud.exception.NotFoundException)2 ParsingError (alien4cloud.tosca.parser.ParsingError)2 ConstraintValueDoNotMatchPropertyTypeException (org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException)2