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