use of org.eclipse.winery.repository.patterndetection.keywords.VirtualHardware 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