Search in sources :

Example 6 with ToscaTypeLoader

use of alien4cloud.tosca.container.ToscaTypeLoader 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)

Aggregations

ToscaTypeLoader (alien4cloud.tosca.container.ToscaTypeLoader)6 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)2 NotFoundException (alien4cloud.exception.NotFoundException)1 VersionConflictException (alien4cloud.exception.VersionConflictException)1 ICsarDependencyLoader (org.alien4cloud.tosca.catalog.index.ICsarDependencyLoader)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 PolicyTemplate (org.alien4cloud.tosca.model.templates.PolicyTemplate)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1 SubstitutionTarget (org.alien4cloud.tosca.model.templates.SubstitutionTarget)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1 PolicyType (org.alien4cloud.tosca.model.types.PolicyType)1 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)1 Before (org.junit.Before)1