From 690fa1c9e5d40214add023c2716e0f50a6bab833 Mon Sep 17 00:00:00 2001 From: Nikolaus Huber <nikolaus.huber@uni-wuerzburg.de> Date: Thu, 6 Jun 2013 11:53:41 +0000 Subject: [PATCH] implemented a weighting function counting delta of active resources git-svn-id: https://se1.informatik.uni-wuerzburg.de/usvn/svn/code/code/DMM/trunk@11957 9e42b895-fcda-4063-8a3b-11be15eb1bbd --- edu.kit.ipd.descartes.adaptation/.classpath | 1 - .../META-INF/MANIFEST.MF | 6 +- .../actions/StartAdaptationAction.java | 5 +- .../weightingfunction/ResourceEfficiency.java | 82 +++++++++++++++++++ .../adaptation/ql/QueryEngineAdapter.java | 46 +++++++++++ 5 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/ResourceEfficiency.java create mode 100644 edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/ql/QueryEngineAdapter.java diff --git a/edu.kit.ipd.descartes.adaptation/.classpath b/edu.kit.ipd.descartes.adaptation/.classpath index bc141e96..ad32c83a 100644 --- a/edu.kit.ipd.descartes.adaptation/.classpath +++ b/edu.kit.ipd.descartes.adaptation/.classpath @@ -3,6 +3,5 @@ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/log4j"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/edu.kit.ipd.descartes.adaptation/META-INF/MANIFEST.MF b/edu.kit.ipd.descartes.adaptation/META-INF/MANIFEST.MF index 287afe1a..8a29ebc1 100644 --- a/edu.kit.ipd.descartes.adaptation/META-INF/MANIFEST.MF +++ b/edu.kit.ipd.descartes.adaptation/META-INF/MANIFEST.MF @@ -4,12 +4,14 @@ Bundle-Name: Adaptation Bundle-SymbolicName: edu.kit.ipd.descartes.adaptation;singleton:=true Bundle-Version: 1.0.0.qualifier Bundle-Activator: edu.kit.ipd.descartes.adaptation.Activator -Require-Bundle: org.eclipse.ui, +Require-Bundle: org.eclipse.osgi;bundle-version="3.8.2", + org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.ocl, edu.kit.ipd.descartes.mm.resourcelandscape;bundle-version="1.0.0", edu.kit.ipd.descartes.mm.adaptation;bundle-version="1.0.0", - edu.kit.ipd.descartes.ql.core.engine;bundle-version="1.0.0" + edu.kit.ipd.descartes.ql.core.engine;bundle-version="1.0.0", + org.apache.log4j;bundle-version="1.2.15" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Import-Package: edu.kit.ipd.descartes.ql.lang.descartesQL, diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/actions/StartAdaptationAction.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/actions/StartAdaptationAction.java index 6fb8cfab..c6d4442d 100644 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/actions/StartAdaptationAction.java +++ b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/actions/StartAdaptationAction.java @@ -34,10 +34,7 @@ public class StartAdaptationAction implements IWorkbenchWindowActionDelegate { MessageDialog.openInformation( window.getShell(), "External", - "Watch the console to see messages about the Adaptation Process"); - QueryEngineAdapter qea = new QueryEngineAdapter("/by_dmm-model/optimizationTest.pdr"); - System.out.println(qea.queryActiveServers()); - + "CURRENTLY NOT IMPLEMENTED!"); } /** diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/ResourceEfficiency.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/ResourceEfficiency.java new file mode 100644 index 00000000..298115fa --- /dev/null +++ b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/ResourceEfficiency.java @@ -0,0 +1,82 @@ +package edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction; + +import org.apache.log4j.Logger; +import org.eclipse.emf.common.util.EList; + +import edu.kit.ipd.descartes.adaptation.model.AbstractEcoreModelLoader; +import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.IPerformanceDataRepositoryHandler; +import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.PerformanceDataRepositoryHandler; +import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.PerformanceDataRepositoryModelLoader; +import edu.kit.ipd.descartes.adaptation.ql.QueryEngineAdapter; +import edu.kit.ipd.descartes.mm.adaptation.WeightedMetric; +import edu.kit.ipd.descartes.mm.adaptation.WeightedTactic; +import edu.kit.ipd.descartes.mm.adaptation.WeightingFunction; +import edu.kit.ipd.descartes.perfdatarepo.Impact; +import edu.kit.ipd.descartes.perfdatarepo.MetricValue; +import edu.kit.ipd.descartes.perfdatarepo.Result; + +public class ResourceEfficiency implements IWeightingFunction { + + private static final String UTIL_IDENTIFIER = "Util"; + private static final double THRESHOLD = 0.05; + private WeightingFunction function = null; + private static Logger logger = Logger.getLogger(ResourceEfficiency.class); + +// public ResourceEfficiency() { +// AbstractEcoreModelLoader loader = PerformanceDataRepositoryModelLoader.getInstance(); +// String pdrLocation = loader.getCurrentModelUri().toFileString(); +// logger.debug("Initializing query engine adaptor for performance data repository " + pdrLocation); +// qea = new QueryEngineAdapter(pdrLocation); +// } + + @Override + public void setWeightingFunction(WeightingFunction function) { + this.function = function; + } + + @Override + /* + * (non-Javadoc) + * + * @see + * edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.IWeightingFunction#calculateWeight + * (edu.kit.ipd.descartes.mm.adaptation.WeightedTactic) + */ + public double calculateWeight(WeightedTactic weightedTactic) { + double newWeight = 0.0; + Impact impact = weightedTactic.getLastImpact(); + Result before = impact.getBefore(); + Result after = impact.getAfter(); + + for (WeightedMetric wm : function.getWeightedMetrics()) { + double afterValue = WeightedSumWeightingFunctionHelper.getValueForMetricType(wm.getMetricType(), after); + double beforeValue = WeightedSumWeightingFunctionHelper.getValueForMetricType(wm.getMetricType(), before); + double delta = afterValue - beforeValue; + newWeight += delta * wm.getWeight(); + } + + int activeResourceDelta = calcActiveResourceDelta(impact); + logger.debug("Delta of active resources: " + activeResourceDelta); + + return activeResourceDelta; + } + + private int calcActiveResourceDelta(Impact impact) { + Result before = impact.getBefore(); + Result after = impact.getAfter(); + int activeResourcesBefore = getActiveResources(before); + int activeResourcesAfter = getActiveResources(after); + return activeResourcesAfter - activeResourcesBefore; + } + + private int getActiveResources(Result result) { + int counter = 0; + for (MetricValue v : result.getMetricValues()) { + // TODO parse with regexp or something more clever + if (v.getMetricType().getName().contains(UTIL_IDENTIFIER) && v.getValue() > THRESHOLD) + counter++; + } + return counter; + } + +} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/ql/QueryEngineAdapter.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/ql/QueryEngineAdapter.java new file mode 100644 index 00000000..437d2d27 --- /dev/null +++ b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/ql/QueryEngineAdapter.java @@ -0,0 +1,46 @@ +package edu.kit.ipd.descartes.adaptation.ql; + +import java.util.List; + +import org.apache.log4j.Logger; + +import edu.kit.ipd.descartes.perfdatarepo.MetricType; +import edu.kit.ipd.descartes.ql.core.engine.query.QueryExecutionEngine; +import edu.kit.ipd.descartes.ql.core.engine.query.QueryExecutionEngineImpl; +import edu.kit.ipd.descartes.ql.models.mapping.mapping.EntityMapping; + +public class QueryEngineAdapter { + + private static Logger logger = Logger.getLogger(QueryEngineAdapter.class); + private QueryExecutionEngine qee = new QueryExecutionEngineImpl(); + private String pdrLocation = null; + + public QueryEngineAdapter(String pdrLocation) { + this.pdrLocation = pdrLocation; + } + + public int queryActiveServers() { + String query = "LIST RESOURCES USING pdr@'" + pdrLocation + "';"; + List<EntityMapping> results = qee.execute(query); + return results.size(); + } + + public Double getValueForMetricType(MetricType metricType) { + // String pdrLocation = "/edu.kit.ipd.descartes.ql.lang.examples/PDR/optimizationTest.pdr"; + // String pdrLocation = "/by_dmm-model/optimizationTest.pdr"; + String query = "SELECT desc1." + metricType.getName() + " FOR RESOURCE '_uZslUK8HEeGqG9wdcmTqrg' AS desc1 " + + "USING pdr@'" + pdrLocation + "';"; + + logger.debug("Query: " + query); + List<EntityMapping> results = qee.execute(query); + + if (!qee.isValidQuery()) { + return Double.NaN; + } + + for (EntityMapping result : results) { + } + + return null; + } +} -- GitLab