use of org.eclipse.winery.repository.patterndetection.model.TNodeTemplateExtended 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++;
}
}
use of org.eclipse.winery.repository.patterndetection.model.TNodeTemplateExtended in project winery by eclipse.
the class Detection method searchForKeywords.
/**
* 1. step: search for keywords using predefined keywords in enums
*/
private void searchForKeywords(TTopologyTemplate tTopologyTemplate) {
List<TNodeTemplate> tNodeTemplateList = ModelUtilities.getAllNodeTemplates(tTopologyTemplate);
List<Server> serverList = new ArrayList<>(EnumSet.allOf(Server.class));
List<Service> serviceList = new ArrayList<>(EnumSet.allOf(Service.class));
List<VirtualHardware> virtualHardwareList = new ArrayList<>(EnumSet.allOf(VirtualHardware.class));
List<OperatingSystem> operatingSystemList = new ArrayList<>(EnumSet.allOf(OperatingSystem.class));
List<Messaging> messagingList = new ArrayList<>(EnumSet.allOf(Messaging.class));
List<Storage> storageList = new ArrayList<>(EnumSet.allOf(Storage.class));
for (TNodeTemplate tNodeTemplate : tNodeTemplateList) {
for (Server server : serverList) {
if (tNodeTemplate.getName().toLowerCase().contains(server.toString().toLowerCase())) {
// add the matching keyword
matchedKeywords.add(server.toString());
// create a new TNodeTemplateExtended with the detected keyword and set the according label
TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelServer, server.toString());
// add this object to the list with labeled NodeTemplates
labeledNodeTemplates.add(temp);
isPaaS = true;
}
}
for (Service service : serviceList) {
if (tNodeTemplate.getName().toLowerCase().contains(service.toString().toLowerCase())) {
matchedKeywords.add(service.toString());
TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelService, service.toString());
labeledNodeTemplates.add(temp);
isPaaS = true;
}
}
for (VirtualHardware virtualHardware : virtualHardwareList) {
if (tNodeTemplate.getName().toLowerCase().contains(virtualHardware.toString().toLowerCase())) {
matchedKeywords.add(virtualHardware.toString());
TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelVirtualHardware, virtualHardware.toString());
labeledNodeTemplates.add(temp);
isIaaS = true;
}
}
for (OperatingSystem operatingSystem : operatingSystemList) {
if (tNodeTemplate.getName().toLowerCase().contains(operatingSystem.toString().toLowerCase())) {
matchedKeywords.add(operatingSystem.toString());
TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelOS, operatingSystem.toString());
labeledNodeTemplates.add(temp);
isPaaS = true;
}
}
for (Messaging messaging : messagingList) {
if (tNodeTemplate.getName().toLowerCase().contains(messaging.toString().toLowerCase())) {
matchedKeywords.add(messaging.toString());
TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelMessaging, messaging.toString());
labeledNodeTemplates.add(temp);
isPaaS = true;
}
}
for (Storage storage : storageList) {
if (tNodeTemplate.getName().toLowerCase().contains(storage.toString().toLowerCase())) {
matchedKeywords.add(storage.toString());
TNodeTemplateExtended temp = new TNodeTemplateExtended(tNodeTemplate, labelStorage, storage.toString());
labeledNodeTemplates.add(temp);
isPaaS = true;
}
}
}
// create all taxonomies
paasGraph = paas.getPaasTaxonomie();
iaasGraph = iaas.getIaasTaxonomie();
// set propabilities for possible patterns according to detected keywords only if any keywords matched the node template names
if (!matchedKeywords.isEmpty()) {
// for each specific keyowrds like beanstalk or mysql, probabilities are set in the pattern taxonomy graph
for (String keyword : matchedKeywords) {
DefaultWeightedEdge tempEdge;
if (keyword.equals(keywordBeanstalk)) {
detectedPattern.add(patternPaaS);
tempEdge = paasGraph.getEdge(paas.getElasticPlatform(), paas.getEnvBasedAv());
// set 100% probability of the pattern this edge is pointing to
paasGraph.setEdgeWeight(tempEdge, 0.99);
tempEdge = paasGraph.getEdge(paas.getElasticPlatform(), paas.getElasticLoadBalancer());
paasGraph.setEdgeWeight(tempEdge, 0.99);
tempEdge = paasGraph.getEdge(paas.getElasticPlatform(), paas.getElasticityManager());
paasGraph.setEdgeWeight(tempEdge, 0.99);
} else if (keyword.equals(keywordOpenstack) || keyword.equals(keywordEC2)) {
tempEdge = iaasGraph.getEdge(iaas.getIaas(), iaas.getElasticInfrastructure());
iaasGraph.setEdgeWeight(tempEdge, 0.75);
} else if (keyword.equals(keywordMySQL)) {
tempEdge = paasGraph.getEdge(paas.getPaas(), paas.getRelationalDatabase());
paasGraph.setEdgeWeight(tempEdge, 0.99);
tempEdge = paasGraph.getEdge(paas.getPaas(), paas.getKeyValueStorage());
paasGraph.setEdgeWeight(tempEdge, 0.0);
} else if (keyword.equals(keywordJava) || keyword.equals(keywordPython) || keyword.equals(keywordTomcat) || keyword.equals(keywordApache)) {
tempEdge = paasGraph.getEdge(paas.getPaas(), paas.getExecEnvironment());
paasGraph.setEdgeWeight(tempEdge, 0.75);
} else if (keyword.equals(keywordMongoDB)) {
tempEdge = paasGraph.getEdge(paas.getPaas(), paas.getKeyValueStorage());
paasGraph.setEdgeWeight(tempEdge, 0.99);
tempEdge = paasGraph.getEdge(paas.getPaas(), paas.getRelationalDatabase());
paasGraph.setEdgeWeight(tempEdge, 0.0);
}
}
// this case indicates only IaaS keywords and no detected PaaS keywords -> IaaS is assumed, therefore PaaS is added to impossible patterns
if (isIaaS && !isPaaS) {
detectedPattern.add(patternIaaS);
impossiblePattern.add(patternPaaS);
impossiblePattern.add(patternElasticPlatform);
Set<DefaultWeightedEdge> edgeSet = iaasGraph.edgeSet();
Iterator iterator2 = edgeSet.iterator();
// iterate through the IaaS taxonomy and check the weight of each edge -> add the target nodes to the according pattern list
while (iterator2.hasNext()) {
DefaultWeightedEdge edge = (DefaultWeightedEdge) iterator2.next();
double weight = iaasGraph.getEdgeWeight(edge);
if (weight == 0.75) {
patternProbabilityHigh.add(iaasGraph.getEdgeTarget(edge));
} else if (weight == 0.5) {
patternProbabilityMedium.add(iaasGraph.getEdgeTarget(edge));
} else if (weight == 0.25) {
patternProbabilityLow.add(iaasGraph.getEdgeTarget(edge));
} else if (weight == 0.99) {
detectedPattern.add(iaasGraph.getEdgeTarget(edge));
} else if (weight == 0.0) {
impossiblePattern.add(iaasGraph.getEdgeTarget(edge));
} else if (weight == 1.0) {
// for all other patterns add low probability, 1.0 is default edge value
patternProbabilityLow.add(iaasGraph.getEdgeTarget(edge));
}
}
// this case occurs if IaaS and PaaS keywords are detected or just PaaS keywords -> PaaS is assumed and excludes IaaS
} else {
detectedPattern.add(patternPaaS);
impossiblePattern.add(patternIaaS);
impossiblePattern.add(patternElasticInfrastructure);
Set<DefaultWeightedEdge> edgeSet;
edgeSet = paasGraph.edgeSet();
Iterator iterator = edgeSet.iterator();
// iterate through the IaaS taxonomy and check the weight of each edge -> add the target nodes to the according pattern list
while (iterator.hasNext()) {
DefaultWeightedEdge edge = (DefaultWeightedEdge) iterator.next();
double weight = paasGraph.getEdgeWeight(edge);
if (weight == 0.75) {
patternProbabilityHigh.add(paasGraph.getEdgeTarget(edge));
} else if (weight == 0.5) {
patternProbabilityMedium.add(paasGraph.getEdgeTarget(edge));
} else if (weight == 0.25) {
patternProbabilityLow.add(paasGraph.getEdgeTarget(edge));
} else if (weight == 0.99) {
detectedPattern.add(paasGraph.getEdgeTarget(edge));
} else if (weight == 0.0) {
impossiblePattern.add(paasGraph.getEdgeTarget(edge));
} else if (weight == 1.0) {
// for all other patterns add low probability, 1.0 is default edge value
patternProbabilityLow.add(paasGraph.getEdgeTarget(edge));
}
}
}
}
}
Aggregations