Search in sources :

Example 1 with MessageOrientedMiddlewarePattern

use of org.eclipse.winery.repository.patterndetection.model.patterns.MessageOrientedMiddlewarePattern 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<SimpleDirectedGraph<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 (SimpleDirectedGraph<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
                SimpleDirectedGraph<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 : ElasticLoadBalancerPattern(org.eclipse.winery.repository.patterndetection.model.patterns.ElasticLoadBalancerPattern) ExecutionEnvironmentPattern(org.eclipse.winery.repository.patterndetection.model.patterns.ExecutionEnvironmentPattern) HashMap(java.util.HashMap) PatternPosition(org.eclipse.winery.repository.patterndetection.model.PatternPosition) RelationshipEdge(org.eclipse.winery.repository.patterndetection.model.RelationshipEdge) AbstractTopology(org.eclipse.winery.repository.patterndetection.model.AbstractTopology) ArrayList(java.util.ArrayList) MessageOrientedMiddlewarePattern(org.eclipse.winery.repository.patterndetection.model.patterns.MessageOrientedMiddlewarePattern) NodeBasedAvailabilityPattern(org.eclipse.winery.repository.patterndetection.model.patterns.NodeBasedAvailabilityPattern) ElasticityManagerPattern(org.eclipse.winery.repository.patterndetection.model.patterns.ElasticityManagerPattern) IsomorphicGraphMapping(org.jgrapht.alg.isomorphism.IsomorphicGraphMapping) RelationalDatabasePattern(org.eclipse.winery.repository.patterndetection.model.patterns.RelationalDatabasePattern) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) Iterator(java.util.Iterator) ElasticQueuePattern(org.eclipse.winery.repository.patterndetection.model.patterns.ElasticQueuePattern) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ExecutionEnvironmentPattern2(org.eclipse.winery.repository.patterndetection.model.patterns.ExecutionEnvironmentPattern2) VF2SubgraphIsomorphismInspector(org.jgrapht.alg.isomorphism.VF2SubgraphIsomorphismInspector) SimpleDirectedGraph(org.jgrapht.graph.SimpleDirectedGraph) TNodeTemplateExtended(org.eclipse.winery.repository.patterndetection.model.TNodeTemplateExtended) KeyValueStoragePattern(org.eclipse.winery.repository.patterndetection.model.patterns.KeyValueStoragePattern) EnvironmentBasedAvailabilityPattern(org.eclipse.winery.repository.patterndetection.model.patterns.EnvironmentBasedAvailabilityPattern) PatternComponent(org.eclipse.winery.repository.patterndetection.model.PatternComponent)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)1 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)1 AbstractTopology (org.eclipse.winery.repository.patterndetection.model.AbstractTopology)1 PatternComponent (org.eclipse.winery.repository.patterndetection.model.PatternComponent)1 PatternPosition (org.eclipse.winery.repository.patterndetection.model.PatternPosition)1 RelationshipEdge (org.eclipse.winery.repository.patterndetection.model.RelationshipEdge)1 TNodeTemplateExtended (org.eclipse.winery.repository.patterndetection.model.TNodeTemplateExtended)1 ElasticLoadBalancerPattern (org.eclipse.winery.repository.patterndetection.model.patterns.ElasticLoadBalancerPattern)1 ElasticQueuePattern (org.eclipse.winery.repository.patterndetection.model.patterns.ElasticQueuePattern)1 ElasticityManagerPattern (org.eclipse.winery.repository.patterndetection.model.patterns.ElasticityManagerPattern)1 EnvironmentBasedAvailabilityPattern (org.eclipse.winery.repository.patterndetection.model.patterns.EnvironmentBasedAvailabilityPattern)1 ExecutionEnvironmentPattern (org.eclipse.winery.repository.patterndetection.model.patterns.ExecutionEnvironmentPattern)1 ExecutionEnvironmentPattern2 (org.eclipse.winery.repository.patterndetection.model.patterns.ExecutionEnvironmentPattern2)1 KeyValueStoragePattern (org.eclipse.winery.repository.patterndetection.model.patterns.KeyValueStoragePattern)1 MessageOrientedMiddlewarePattern (org.eclipse.winery.repository.patterndetection.model.patterns.MessageOrientedMiddlewarePattern)1 NodeBasedAvailabilityPattern (org.eclipse.winery.repository.patterndetection.model.patterns.NodeBasedAvailabilityPattern)1 RelationalDatabasePattern (org.eclipse.winery.repository.patterndetection.model.patterns.RelationalDatabasePattern)1