use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class TemplateDeploymentArtifactPostProcessor method postProcessArtifactRef.
@Override
protected void postProcessArtifactRef(Node node, String artifactReference) {
if (artifactReference == null) {
Node referenceNode = ParsingContextExecution.getObjectToNodeMap().get(artifactReference);
if (referenceNode == null) {
referenceNode = node;
}
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNRESOLVED_ARTIFACT, "Deployment artifact", node.getStartMark(), "No artifact reference is defined, user will have to define / override in order to make ", node.getEndMark(), null));
}
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class OccurrencesParser method parse.
@Override
public List<String> parse(Node node, ParsingContextExecution context) {
Object parent = context.getParent();
List<String> result = (List<String>) listParser.parse(node, context);
if (result.size() != 2) {
context.getParsingErrors().add(new ParsingError(ErrorCode.SYNTAX_ERROR, null, node.getStartMark(), null, node.getEndMark(), null));
return result;
}
if (parent instanceof LowerBoundedDefinition) {
((LowerBoundedDefinition) parent).setLowerBound(Integer.parseInt(result.get(0)));
}
if (parent instanceof UpperBoundedDefinition) {
((UpperBoundedDefinition) parent).setUpperBound(Integer.parseInt(result.get(1)));
}
return result;
}
use of alien4cloud.tosca.parser.ParsingError 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 alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class SustitutionMappingParser method parseSubstitutionTargets.
private Map<String, SubstitutionTarget> parseSubstitutionTargets(Node valueNode, ParsingContextExecution context) {
if (!(valueNode instanceof MappingNode)) {
// we expect a MappingNode
context.getParsingErrors().add(new ParsingError(ErrorCode.YAML_MAPPING_NODE_EXPECTED, null, valueNode.getStartMark(), null, valueNode.getEndMark(), null));
return null;
}
Map<String, SubstitutionTarget> result = Maps.newHashMap();
MappingNode mappingNode = ((MappingNode) valueNode);
List<NodeTuple> nodeTuples = mappingNode.getValue();
for (NodeTuple nodeTuple : nodeTuples) {
String key = scalarParser.parse(nodeTuple.getKeyNode(), context);
SubstitutionTarget target = parseSubstitutionTarget(nodeTuple.getValueNode(), context);
if (target != null) {
result.put(key, target);
}
}
return result;
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class DerivedFromPostProcessor method process.
private void process(Map<AbstractInheritableToscaType, String> processed, Map<AbstractInheritableToscaType, String> processing, AbstractInheritableToscaType instance, Map<String, ? extends AbstractInheritableToscaType> instances) {
if (processed.containsKey(instance)) {
// Already processed
return;
}
if (processing.containsKey(instance)) {
// Cyclic dependency as parent is currently being processed...
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.CYCLIC_DERIVED_FROM, "Cyclic derived from has been detected", node.getStartMark(), "The type specified as parent or one of it's parent type refers the current type as parent, invalid cycle detected.", node.getEndMark(), instance.getElementId()));
processing.remove(instance);
return;
}
List<String> derivedFrom = instance.getDerivedFrom();
if (derivedFrom != null && derivedFrom.size() > 1) {
// The type has been already processed.
return;
}
if (derivedFrom == null || derivedFrom.isEmpty()) {
// If the user forgot to derive from Root, automatically do it but make an alert
String defaultDerivedFrom = null;
if (instance instanceof NodeType && !NormativeTypesConstant.ROOT_NODE_TYPE.equals(instance.getElementId())) {
defaultDerivedFrom = NormativeTypesConstant.ROOT_NODE_TYPE;
} else if (instance instanceof RelationshipType && !NormativeTypesConstant.ROOT_RELATIONSHIP_TYPE.equals(instance.getElementId())) {
defaultDerivedFrom = NormativeTypesConstant.ROOT_RELATIONSHIP_TYPE;
} else if (instance instanceof DataType && !NormativeTypesConstant.ROOT_DATA_TYPE.equals(instance.getElementId())) {
defaultDerivedFrom = NormativeTypesConstant.ROOT_DATA_TYPE;
} else if (instance instanceof CapabilityType && !NormativeCapabilityTypes.ROOT.equals(instance.getElementId())) {
defaultDerivedFrom = NormativeCapabilityTypes.ROOT;
} else if (instance instanceof ArtifactType && !NormativeTypesConstant.ROOT_ARTIFACT_TYPE.equals(instance.getElementId())) {
defaultDerivedFrom = NormativeTypesConstant.ROOT_ARTIFACT_TYPE;
}
if (defaultDerivedFrom != null) {
derivedFrom = new ArrayList<>();
derivedFrom.add(defaultDerivedFrom);
instance.setDerivedFrom(derivedFrom);
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.DERIVED_FROM_NOTHING, defaultDerivedFrom, node.getStartMark(), "The " + instance.getClass().getSimpleName() + " " + instance.getElementId() + " derives from nothing, default " + defaultDerivedFrom + " will be set as parent type.", node.getEndMark(), instance.getElementId()));
} else {
// Non managed default parent type then returns
return;
}
}
String parentElementType = derivedFrom.get(0);
// Merge the type with it's parent except for primitive data types.
if (instance instanceof DataType && ToscaTypes.isSimple(parentElementType)) {
if (instance instanceof PrimitiveDataType) {
log.debug("Do not merge data type instance with parent as it extends from a primitive type.");
} else {
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
// type has not been parsed as primitive because it has some properties
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.SYNTAX_ERROR, "Primitive types cannot define properties.", node.getStartMark(), "The defined type inherit from a primitive type but defines some properties.", node.getEndMark(), parentElementType));
}
return;
}
AbstractInheritableToscaType parent = instances.get(parentElementType);
if (parent == null) {
parent = ToscaContext.get(instance.getClass(), parentElementType);
} else {
// first process the parent type
processing.put(instance, null);
process(processed, processing, parent, instances);
processing.remove(instance);
}
if (parent == null) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.TYPE_NOT_FOUND, "Derived_from type not found", node.getStartMark(), "The type specified as parent is not found neither in the archive or its dependencies.", node.getEndMark(), parentElementType));
return;
}
// Merge with parent type
IndexedModelUtils.mergeInheritableIndex(parent, instance);
processed.put(instance, null);
}
Aggregations