use of org.alien4cloud.tosca.model.templates.SubstitutionMapping in project alien4cloud by alien4cloud.
the class AddSubstitutionTypeProcessor method process.
@Override
public void process(Csar csar, Topology topology, AddSubstitutionTypeOperation operation) {
if (topology.getSubstitutionMapping() == null) {
topology.setSubstitutionMapping(new SubstitutionMapping());
}
NodeType nodeType = toscaTypeSearchService.getElementInDependencies(NodeType.class, operation.getElementId(), topology.getDependencies());
// if not null the node type exists in the dependencies, there is no choices for this type version
if (nodeType == null) {
// the node type does'nt exist in this topology dependencies
// we need to find the latest version of this component and use it as default
nodeType = toscaTypeSearchService.findMostRecent(NodeType.class, operation.getElementId());
if (nodeType == null) {
throw new NotFoundException("Node type with name <" + operation.getElementId() + "> cannot be found in the catalog.");
}
topologyService.loadType(topology, nodeType);
}
topology.getSubstitutionMapping().setSubstitutionType(operation.getElementId());
}
use of org.alien4cloud.tosca.model.templates.SubstitutionMapping in project alien4cloud by alien4cloud.
the class SustitutionMappingParser method parse.
@Override
public SubstitutionMapping parse(Node node, ParsingContextExecution context) {
Topology topology = (Topology) context.getParent();
if (!(node instanceof MappingNode)) {
// we expect a MappingNode
context.getParsingErrors().add(new ParsingError(ErrorCode.YAML_MAPPING_NODE_EXPECTED, null, node.getStartMark(), null, node.getEndMark(), null));
return null;
}
SubstitutionMapping result = new SubstitutionMapping();
MappingNode mappingNode = ((MappingNode) node);
List<NodeTuple> nodeTuples = mappingNode.getValue();
for (NodeTuple nodeTuple : nodeTuples) {
String key = scalarParser.parse(nodeTuple.getKeyNode(), context);
Node valueNode = nodeTuple.getValueNode();
switch(key) {
case NODE_TYPE:
String nodeTypeName = scalarParser.parse(valueNode, context);
result.setSubstitutionType(nodeTypeName);
break;
case CAPABILITIES:
result.setCapabilities(parseSubstitutionTargets(valueNode, context));
break;
case REQUIREMENTS:
result.setRequirements(parseSubstitutionTargets(valueNode, context));
break;
default:
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNRECOGNIZED_PROPERTY, null, valueNode.getStartMark(), "Key <" + key + "> is not recognized for substitution mapping.", valueNode.getEndMark(), "key"));
}
}
return result;
}
Aggregations