Search in sources :

Example 26 with RelationshipTemplate

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);
                    }
                }
            }
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Topology(org.alien4cloud.tosca.model.templates.Topology)

Example 27 with 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();
    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;
}
Also used : RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) ParsingError(alien4cloud.tosca.parser.ParsingError) INodeParser(alien4cloud.tosca.parser.INodeParser) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) MapParser(alien4cloud.tosca.parser.impl.base.MapParser) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 28 with 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;
}
Also used : RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) ParsingError(alien4cloud.tosca.parser.ParsingError) INodeParser(alien4cloud.tosca.parser.INodeParser) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) MapParser(alien4cloud.tosca.parser.impl.base.MapParser) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 29 with 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;
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) ToscaTypeLoader(alien4cloud.tosca.container.ToscaTypeLoader) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 30 with RelationshipTemplate

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);
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) RelationshipEntry(org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry)

Aggregations

RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)47 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)37 Map (java.util.Map)12 Capability (org.alien4cloud.tosca.model.templates.Capability)12 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)11 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7 NotFoundException (alien4cloud.exception.NotFoundException)6 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)4 LinkedHashMap (java.util.LinkedHashMap)4 Topology (org.alien4cloud.tosca.model.templates.Topology)4 AlreadyExistException (alien4cloud.exception.AlreadyExistException)3 ParsingError (alien4cloud.tosca.parser.ParsingError)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Interface (org.alien4cloud.tosca.model.definitions.Interface)3 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)3 Requirement (org.alien4cloud.tosca.model.templates.Requirement)3 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)3 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)3