use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class AbstractArchivePostProcessor method processArtifacts.
private void processArtifacts(final Path archive, ParsingResult<ArchiveRoot> parsedArchive) {
try (ArchivePathChecker archivePathResolver = createPathChecker(archive)) {
// Check if input artifacts are correctly set
processInputArtifact(archivePathResolver, parsedArchive);
// Process deployment artifact / implementation artifact for types
processTypes(archivePathResolver, parsedArchive.getResult().getNodeTypes(), parsedArchive);
processTypes(archivePathResolver, parsedArchive.getResult().getRelationshipTypes(), parsedArchive);
// Process topology
Topology topology = parsedArchive.getResult().getTopology();
if (topology != null && topology.getNodeTemplates() != null) {
for (NodeTemplate nodeTemplate : topology.getNodeTemplates().values()) {
processTemplate(archivePathResolver, nodeTemplate, parsedArchive);
if (nodeTemplate.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : nodeTemplate.getRelationships().values()) {
processTemplate(archivePathResolver, relationshipTemplate, parsedArchive);
}
}
}
}
}
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class RelationshipTemplateParser method parse.
@Override
public RelationshipTemplate parse(Node node, ParsingContextExecution context) {
// To parse a relationship template we actually get the parent node to retrieve the requirement name;
if (!(node instanceof MappingNode) || ((MappingNode) node).getValue().size() != 1) {
ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
}
MappingNode assignmentNode = (MappingNode) node;
RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
String relationshipId = scalarParser.parse(assignmentNode.getValue().get(0).getKeyNode(), context);
// The relationship's id which is used to identify the relationship within the source
relationshipTemplate.setName(relationshipId);
// By default the relationship id is the requirement name, it can be overridden with 'type_requirement'
relationshipTemplate.setRequirementName(relationshipId);
// Now parse the content of the relationship assignment.
node = assignmentNode.getValue().get(0).getValueNode();
if (node instanceof ScalarNode) {
// Short notation (host: compute)
relationshipTemplate.setTarget(scalarParser.parse(node, context));
} else if (node instanceof MappingNode) {
MappingNode mappingNode = (MappingNode) node;
for (NodeTuple nodeTuple : mappingNode.getValue()) {
String key = scalarParser.parse(nodeTuple.getKeyNode(), context);
switch(key) {
case "node":
relationshipTemplate.setTarget(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "capability":
relationshipTemplate.setTargetedCapabilityName(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "type_requirement":
relationshipTemplate.setRequirementName(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "relationship":
relationshipTemplate.setType(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "properties":
INodeParser<AbstractPropertyValue> propertyValueParser = context.getRegistry().get("node_template_property");
MapParser<AbstractPropertyValue> mapParser = baseParserFactory.getMapParser(propertyValueParser, "node_template_property");
relationshipTemplate.setProperties(mapParser.parse(nodeTuple.getValueNode(), context));
break;
case "interfaces":
INodeParser<Map<String, Interface>> interfacesParser = context.getRegistry().get("interfaces");
relationshipTemplate.setInterfaces(interfacesParser.parse(nodeTuple.getValueNode(), context));
break;
default:
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_ARTIFACT_KEY, null, node.getStartMark(), "Unrecognized key while parsing implementation artifact", node.getEndMark(), key));
}
}
} else {
ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
}
return relationshipTemplate;
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class RelationshipTemplateParser method parse.
@Override
public RelationshipTemplate parse(Node node, ParsingContextExecution context) {
// To parse a relationship template we actually get the parent node to retrieve the requirement name;
if (!(node instanceof MappingNode) || ((MappingNode) node).getValue().size() != 1) {
ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
}
MappingNode assignmentNode = (MappingNode) node;
RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
relationshipTemplate.setRequirementName(scalarParser.parse(assignmentNode.getValue().get(0).getKeyNode(), context));
// Now parse the content of the relationship assignment.
node = assignmentNode.getValue().get(0).getValueNode();
if (node instanceof ScalarNode) {
// Short notation (host: compute)
relationshipTemplate.setTarget(scalarParser.parse(node, context));
} else if (node instanceof MappingNode) {
MappingNode mappingNode = (MappingNode) node;
for (NodeTuple nodeTuple : mappingNode.getValue()) {
String key = scalarParser.parse(nodeTuple.getKeyNode(), context);
switch(key) {
case "node":
relationshipTemplate.setTarget(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "capability":
relationshipTemplate.setTargetedCapabilityName(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "relationship":
relationshipTemplate.setType(scalarParser.parse(nodeTuple.getValueNode(), context));
break;
case "properties":
INodeParser<AbstractPropertyValue> propertyValueParser = context.getRegistry().get("node_template_property");
MapParser<AbstractPropertyValue> mapParser = baseParserFactory.getMapParser(propertyValueParser, "node_template_property");
relationshipTemplate.setProperties(mapParser.parse(nodeTuple.getValueNode(), context));
break;
case "interfaces":
INodeParser<Map<String, Interface>> interfacesParser = context.getRegistry().get("interfaces");
relationshipTemplate.setInterfaces(interfacesParser.parse(nodeTuple.getValueNode(), context));
break;
default:
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_ARTIFACT_KEY, null, node.getStartMark(), "Unrecognized key while parsing implementation artifact", node.getEndMark(), key));
}
}
} else {
ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
}
return relationshipTemplate;
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class TopologyService method initializeTypeLoader.
private ToscaTypeLoader initializeTypeLoader(Topology topology, boolean failOnTypeNotFound) {
// FIXME we should use ToscaContext here, and why not allowing the caller to pass ona Context?
ToscaTypeLoader loader = new ToscaTypeLoader(csarDependencyLoader);
Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, false, failOnTypeNotFound);
Map<String, RelationshipType> relationshipTypes = topologyServiceCore.getIndexedRelationshipTypesFromTopology(topology, failOnTypeNotFound);
Map<String, PolicyType> policyTypes = topologyServiceCore.getPolicyTypesFromTopology(topology, failOnTypeNotFound);
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
NodeType nodeType = nodeTypes.get(nodeTemplate.getType());
// just load found types: the type might be null when failOnTypeNotFound is set to false.
if (nodeType != null) {
loader.loadType(nodeTemplate.getType(), csarDependencyLoader.buildDependencyBean(nodeType.getArchiveName(), nodeType.getArchiveVersion()));
}
for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
RelationshipType relationshipType = relationshipTypes.get(relationshipTemplate.getType());
// just load found types: the type might be null when failOnTypeNotFound is set to false.
if (relationshipType != null) {
loader.loadType(relationshipTemplate.getType(), csarDependencyLoader.buildDependencyBean(relationshipType.getArchiveName(), relationshipType.getArchiveVersion()));
}
}
}
for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) {
PolicyType policyType = policyTypes.get(policyTemplate.getType());
if (policyType != null) {
loader.loadType(policyTemplate.getType(), csarDependencyLoader.buildDependencyBean(policyType.getArchiveName(), policyType.getArchiveVersion()));
}
}
if (topology.getSubstitutionMapping() != null && topology.getSubstitutionMapping().getSubstitutionType() != null) {
NodeType substitutionType = nodeTypes.get(topology.getSubstitutionMapping().getSubstitutionType());
loader.loadType(substitutionType.getElementId(), csarDependencyLoader.buildDependencyBean(substitutionType.getArchiveName(), substitutionType.getArchiveVersion()));
for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getCapabilities()).values()) {
initializeSubstitutionTarget(loader, relationshipTypes, substitutionTarget);
}
for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getRequirements()).values()) {
initializeSubstitutionTarget(loader, relationshipTypes, substitutionTarget);
}
}
return loader;
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class TopologyService method processNodeTemplate.
/**
* Process a node template to retrieve filters for node replacements search.
*
* TODO cleanup this method, better return a filter for node rather than adding it to a parameter list.
*
* @param topology The topology for which to search filters.
* @param nodeTempEntry The node template for which to find replacement filter.
* @param nodeTemplatesToFilters The map of filters in which to add the filter for the new Node.
*/
public void processNodeTemplate(final Topology topology, final Entry<String, NodeTemplate> nodeTempEntry, Map<String, Map<String, Set<String>>> nodeTemplatesToFilters) {
String capabilityFilterKey = "capabilities.type";
String requirementFilterKey = "requirements.type";
NodeTemplate template = nodeTempEntry.getValue();
Map<String, RelationshipTemplate> relTemplates = template.getRelationships();
nodeTemplatesToFilters.put(nodeTempEntry.getKey(), null);
// process the node template source of relationships
if (relTemplates != null && !relTemplates.isEmpty()) {
for (RelationshipTemplate relationshipTemplate : relTemplates.values()) {
addFilters(nodeTempEntry.getKey(), requirementFilterKey, relationshipTemplate.getRequirementType(), nodeTemplatesToFilters);
}
}
// process the node template target of relationships
List<RelationshipEntry> targetRelationships = TopologyUtils.getTargetRelationships(nodeTempEntry.getKey(), topology.getNodeTemplates());
for (RelationshipEntry targetRelationshipEntry : targetRelationships) {
addFilters(nodeTempEntry.getKey(), capabilityFilterKey, targetRelationshipEntry.getRelationship().getRequirementType(), nodeTemplatesToFilters);
}
}
Aggregations