Search in sources :

Example 11 with TRelationshipTemplate

use of org.eclipse.winery.model.tosca.TRelationshipTemplate in project winery by eclipse.

the class TOSCAModelHelper method addEdge.

public static TOSCAEdge addEdge(TOSCAGraph graph, TOSCANode source, TOSCANode target, String id, String name) {
    TOSCAEdge edge = graph.getEdgeFactory().createEdge(source, target);
    edge.setId(id);
    graph.addEdge(source, target, edge);
    TRelationshipTemplate template = new TRelationshipTemplate();
    template.setName(name);
    edge.setTemplate(template);
    return edge;
}
Also used : TOSCAEdge(org.eclipse.winery.compliance.model.TOSCAEdge) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate)

Example 12 with TRelationshipTemplate

use of org.eclipse.winery.model.tosca.TRelationshipTemplate in project winery by eclipse.

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ServiceTemplateId id) {
    // We have to use a HashSet to ensure that no duplicate ids are added
    // E.g., there may be multiple relationship templates having the same type
    Collection<DefinitionsChildId> ids = new HashSet<>();
    TServiceTemplate serviceTemplate = this.getElement(id);
    // add included things to export queue
    TBoundaryDefinitions boundaryDefs;
    if ((boundaryDefs = serviceTemplate.getBoundaryDefinitions()) != null) {
        TBoundaryDefinitions.Policies policies = boundaryDefs.getPolicies();
        if (policies != null) {
            for (TPolicy policy : policies.getPolicy()) {
                PolicyTypeId policyTypeId = new PolicyTypeId(policy.getPolicyType());
                ids.add(policyTypeId);
                PolicyTemplateId policyTemplateId = new PolicyTemplateId(policy.getPolicyRef());
                ids.add(policyTemplateId);
            }
        }
    // reqs and caps don't have to be exported here as they are references to existing reqs/caps (of nested node templates)
    }
    if (serviceTemplate.getTopologyTemplate() != null) {
        for (TEntityTemplate entityTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
            QName qname = entityTemplate.getType();
            if (entityTemplate instanceof TNodeTemplate) {
                ids.add(new NodeTypeId(qname));
                TNodeTemplate n = (TNodeTemplate) entityTemplate;
                // crawl through deployment artifacts
                TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
                if (deploymentArtifacts != null) {
                    List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
                    for (TDeploymentArtifact da : das) {
                        ids.add(new ArtifactTypeId(da.getArtifactType()));
                        if ((qname = da.getArtifactRef()) != null) {
                            ids.add(new ArtifactTemplateId(qname));
                        }
                    }
                }
                // crawl through reqs/caps
                TNodeTemplate.Requirements requirements = n.getRequirements();
                if (requirements != null) {
                    for (TRequirement req : requirements.getRequirement()) {
                        QName type = req.getType();
                        RequirementTypeId rtId = new RequirementTypeId(type);
                        ids.add(rtId);
                    }
                }
                TNodeTemplate.Capabilities capabilities = n.getCapabilities();
                if (capabilities != null) {
                    for (TCapability cap : capabilities.getCapability()) {
                        QName type = cap.getType();
                        CapabilityTypeId ctId = new CapabilityTypeId(type);
                        ids.add(ctId);
                    }
                }
                // crawl through policies
                org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
                if (policies != null) {
                    for (TPolicy pol : policies.getPolicy()) {
                        QName type = pol.getPolicyType();
                        PolicyTypeId ctId = new PolicyTypeId(type);
                        ids.add(ctId);
                        QName template = pol.getPolicyRef();
                        if (template != null) {
                            PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
                            ids.add(policyTemplateId);
                        }
                    }
                }
            } else {
                assert (entityTemplate instanceof TRelationshipTemplate);
                ids.add(new RelationshipTypeId(qname));
            }
        }
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) TCapability(org.eclipse.winery.model.tosca.TCapability) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) TPolicy(org.eclipse.winery.model.tosca.TPolicy) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Example 13 with TRelationshipTemplate

use of org.eclipse.winery.model.tosca.TRelationshipTemplate in project winery by eclipse.

the class Detection method getLowestNode.

/**
 * Get the lowest node in a topology, this is the only node with any outgoing relation
 */
private void getLowestNode(TNodeTemplate baseNodeTemplate, List<TRelationshipTemplate> tRelationshipTemplateList) {
    List<TRelationshipTemplate> outgoing = new ArrayList<>();
    List<TRelationshipTemplate> incoming = new ArrayList<>();
    for (TRelationshipTemplate tRelationshipTemplate : tRelationshipTemplateList) {
        if (baseNodeTemplate.equals((tRelationshipTemplate.getSourceElement().getRef()))) {
            outgoing.add(tRelationshipTemplate);
            getLowestNode((TNodeTemplate) tRelationshipTemplate.getTargetElement().getRef(), tRelationshipTemplateList);
            break;
        } else {
            incoming.add(tRelationshipTemplate);
        }
    }
    if (outgoing.isEmpty()) {
        // lowestNode is set
        basisNodeTemplate = baseNodeTemplate;
    }
}
Also used : TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate)

Example 14 with TRelationshipTemplate

use of org.eclipse.winery.model.tosca.TRelationshipTemplate in project winery by eclipse.

the class Detection method detectPattern.

/**
 * 2. step: Create all subgraphs of the topology graph and test for isomorphism with pattern graphs
 *
 * @param tTopologyTemplate: the TOSCA topology will be labeled
 */
private void detectPattern(TTopologyTemplate tTopologyTemplate) {
    abstractTopology = new AbstractTopology(tTopologyTemplate, labeledNodeTemplates);
    List<TNodeTemplate> tNodeTemplateList = ModelUtilities.getAllNodeTemplates(tTopologyTemplate);
    List<TRelationshipTemplate> tRelationshipTemplateList = ModelUtilities.getAllRelationshipTemplates(tTopologyTemplate);
    getLowestNode(tNodeTemplateList.get(0), tRelationshipTemplateList);
    Set<TNodeTemplateExtended> allNodes = abstractTopology.getGraph().vertexSet();
    TNodeTemplateExtended baseNodeExtended = new TNodeTemplateExtended();
    Iterator iterator = allNodes.iterator();
    // search for the lowest node in the abstract topology graph, this is used to copy the lowest node from the original Topology to the AbstractTopology
    while (iterator.hasNext()) {
        TNodeTemplateExtended temp = (TNodeTemplateExtended) iterator.next();
        if (temp.getNodeTemplate().getId().equals(basisNodeTemplate.getId())) {
            baseNodeExtended = temp;
            break;
        }
    }
    // map the topology outgoing from the given base node
    abstractTopology.map(baseNodeExtended);
    // in the patternList all graphs of the pattern objects are added
    List<DirectedGraph<PatternComponent, RelationshipEdge>> patternList = new ArrayList<>();
    HashMap<Integer, String> patternNames = new HashMap<>();
    // create objects of all known patterns
    ExecutionEnvironmentPattern executionEnvironmentPattern = new ExecutionEnvironmentPattern();
    NodeBasedAvailabilityPattern nodeBasedAvailabilityPattern = new NodeBasedAvailabilityPattern();
    ElasticityManagerPattern elasticityManagerPattern = new ElasticityManagerPattern();
    ElasticLoadBalancerPattern elasticLoadBalancerPattern = new ElasticLoadBalancerPattern();
    ElasticQueuePattern elasticQueuePattern = new ElasticQueuePattern();
    EnvironmentBasedAvailabilityPattern environmentBasedAvailabilityPattern = new EnvironmentBasedAvailabilityPattern();
    MessageOrientedMiddlewarePattern messageOrientedMiddlewarePattern = new MessageOrientedMiddlewarePattern();
    RelationalDatabasePattern relationalDatabasePattern = new RelationalDatabasePattern();
    KeyValueStoragePattern keyValueStoragePattern = new KeyValueStoragePattern();
    ExecutionEnvironmentPattern2 executionEnvironmentPattern2 = new ExecutionEnvironmentPattern2();
    // to receive the right pattern name for the current counter, pattern names are associated with numbers
    patternNames.put(0, patternExecEnv);
    patternNames.put(1, patternNodeBasedAvail);
    patternNames.put(2, patternElasticityManager);
    patternNames.put(3, patternElasticLoadBalancer);
    patternNames.put(4, patternElasticQueue);
    patternNames.put(5, patternEnvBasedAvail);
    patternNames.put(6, patternMessageMiddleware);
    patternNames.put(7, patternRelationalDatabase);
    patternNames.put(8, patternKeyValueStorage);
    patternNames.put(9, patternExecEnv);
    // pattern are added in order
    patternList.add(executionEnvironmentPattern.getPatternGraph());
    patternList.add(nodeBasedAvailabilityPattern.getPatternGraph());
    patternList.add(elasticityManagerPattern.getPatternGraph());
    patternList.add(elasticLoadBalancerPattern.getPatternGraph());
    patternList.add(elasticQueuePattern.getPatternGraph());
    patternList.add(environmentBasedAvailabilityPattern.getPatternGraph());
    patternList.add(messageOrientedMiddlewarePattern.getPatternGraph());
    patternList.add(relationalDatabasePattern.getPatternGraph());
    patternList.add(keyValueStoragePattern.getPatternGraph());
    patternList.add(executionEnvironmentPattern2.getPatternGraph());
    int countIndex = 0;
    // abstractTopology represents the base graph, for each pattern graph search for a subgraph isomorphism between base graph & pattern graph
    for (DirectedGraph<PatternComponent, RelationshipEdge> pattern : patternList) {
        VF2SubgraphIsomorphismInspector<TNodeTemplateExtended, RelationshipEdge> inspector = new VF2SubgraphIsomorphismInspector(abstractTopology.getGraph(), pattern);
        if (inspector.isomorphismExists()) {
            Iterator it = inspector.getMappings();
            while (it.hasNext()) {
                IsomorphicGraphMapping mapping = (IsomorphicGraphMapping) it.next();
                // list for counting all matches between pattern nodes and base graph nodes, must be true for all
                List<Boolean> matched = new ArrayList<>();
                // this graph holds the nodes of the base graph in which the pattern occurs
                DirectedGraph<TNodeTemplateExtended, RelationshipEdge> originGraph = new SimpleDirectedGraph<>(RelationshipEdge.class);
                // each node of the pattern graph is compared to the according node in the GraphMapping
                for (PatternComponent p : pattern.vertexSet()) {
                    // check if matched subgraph and topology have the same components, get the correspondent vertex in the mapping for a node
                    TNodeTemplateExtended v = (TNodeTemplateExtended) mapping.getVertexCorrespondence(p, false);
                    // if the names equal, the node is added to the originGraph and a boolean with value true is added to the matched list
                    if (p.getName().equals(v.getLabel())) {
                        matched.add(true);
                        originGraph.addVertex(v);
                    } else {
                        matched.add(false);
                    }
                }
                // correspondent to the countIndex, the pattern name is retrieved
                if (!matched.contains(false) && !impossiblePattern.contains(patternNames.get(countIndex))) {
                    // add a new pattern position: the pattern name & the subgraph in which it occurs, this graph was built up in the previous step
                    PatternPosition temp = new PatternPosition(patternNames.get(countIndex), originGraph);
                    patternPositions.add(temp);
                    detectedPattern.add(patternNames.get(countIndex));
                    // sett some additional probabilities
                    if (patternNames.get(countIndex).equals(patternEnvBasedAvail)) {
                        patternProbabilityHigh.add(patternPublicCloud);
                    } else if (patternNames.get(countIndex).equals(patternEnvBasedAvail)) {
                        impossiblePattern.add(patternNodeBasedAvail);
                    } else if (patternNames.get(countIndex).equals(patternNodeBasedAvail)) {
                        impossiblePattern.add(patternEnvBasedAvail);
                    }
                }
            }
        }
        countIndex++;
    }
}
Also used : IsomorphicGraphMapping(org.jgrapht.alg.isomorphism.IsomorphicGraphMapping) DirectedGraph(org.jgrapht.DirectedGraph) SimpleDirectedGraph(org.jgrapht.graph.SimpleDirectedGraph) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) VF2SubgraphIsomorphismInspector(org.jgrapht.alg.isomorphism.VF2SubgraphIsomorphismInspector) SimpleDirectedGraph(org.jgrapht.graph.SimpleDirectedGraph)

Example 15 with TRelationshipTemplate

use of org.eclipse.winery.model.tosca.TRelationshipTemplate in project winery by eclipse.

the class ProviderRepository method breadthFirstSearch.

private List<TEntityTemplate> breadthFirstSearch(TNodeTemplate nodeTemplate, TTopologyTemplate topologyTemplate) {
    List<TEntityTemplate> topologyFragmentElements = new ArrayList<>();
    topologyFragmentElements.add(nodeTemplate);
    List<TRelationshipTemplate> outgoingRelationships = ModelUtilities.getOutgoingRelationshipTemplates(topologyTemplate, nodeTemplate);
    for (TRelationshipTemplate outgoingRelationship : outgoingRelationships) {
        Object successor = outgoingRelationship.getTargetElement().getRef();
        if (successor instanceof TNodeTemplate) {
            topologyFragmentElements.add(outgoingRelationship);
            topologyFragmentElements.addAll(breadthFirstSearch((TNodeTemplate) successor, topologyTemplate));
        }
    }
    return topologyFragmentElements;
}
Also used : TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Aggregations

TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)15 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)10 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)6 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 QName (javax.xml.namespace.QName)4 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)4 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)4 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)4 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)4 HashSet (java.util.HashSet)3 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)3 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)3 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)3 PolicyTypeId (org.eclipse.winery.common.ids.definitions.PolicyTypeId)3 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)3 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)3 TOSCAEdge (org.eclipse.winery.compliance.model.TOSCAEdge)3 TCapability (org.eclipse.winery.model.tosca.TCapability)3