diff --git a/edu.kit.ipd.descartes.adaptation/META-INF/MANIFEST.MF b/edu.kit.ipd.descartes.adaptation/META-INF/MANIFEST.MF index 1e3889adefe156d5324bcf054eb9a1e9535727b0..0e8a2d887219fdb378f577f1dbad3d5db464eb8e 100644 --- a/edu.kit.ipd.descartes.adaptation/META-INF/MANIFEST.MF +++ b/edu.kit.ipd.descartes.adaptation/META-INF/MANIFEST.MF @@ -4,20 +4,23 @@ 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, - org.eclipse.core.runtime, - org.eclipse.ocl, - edu.kit.ipd.descartes.mm.resourcelandscape;bundle-version="1.0.0", +Require-Bundle: 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", - org.eclipse.emf.ecore.change;bundle-version="2.8.0" + org.eclipse.emf.ecore.change;bundle-version="2.8.0", + org.eclipse.core.runtime;bundle-version="3.8.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Import-Package: edu.kit.ipd.descartes.ql.core.engine, +Import-Package: edu.kit.ipd.descartes.adaptation.evaluation.performance, + edu.kit.ipd.descartes.adaptation.modeladaptor, + edu.kit.ipd.descartes.adaptation.modeladaptor.dmm, + edu.kit.ipd.descartes.adaptation.modeladaptor.dmm.util, + edu.kit.ipd.descartes.adaptation.modelrepository, + edu.kit.ipd.descartes.ql.core.engine.query, edu.kit.ipd.descartes.ql.lang.descartesQL, edu.kit.ipd.descartes.ql.models.mapping.domain, edu.kit.ipd.descartes.ql.models.mapping.mapping, edu.kit.ipd.descartes.ql.models.repository, - org.eclipse.core.resources, - org.eclipse.emf.ecore.xmi.impl, - org.eclipse.ocl.ecore + org.apache.log4j;version="1.2.15", + org.eclipse.emf.ecore.xmi, + org.eclipse.emf.ecore.xmi.impl +Export-Package: edu.kit.ipd.descartes.adaptation diff --git a/edu.kit.ipd.descartes.adaptation/build.properties b/edu.kit.ipd.descartes.adaptation/build.properties index e9863e281eaccc5123e82ed75713bab3e8b87bbe..510cc5741076515f3b7e8789343c7ca59250c84b 100644 --- a/edu.kit.ipd.descartes.adaptation/build.properties +++ b/edu.kit.ipd.descartes.adaptation/build.properties @@ -1,5 +1,3 @@ source.. = src/ output.. = bin/ -bin.includes = META-INF/,\ - .,\ - plugin.xml +bin.includes = META-INF/,\ \ No newline at end of file diff --git a/edu.kit.ipd.descartes.adaptation/plugin.xml b/edu.kit.ipd.descartes.adaptation/plugin.xml deleted file mode 100644 index 59c69bbcc507026e00173c800e105bcfb2faca5c..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/plugin.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<?eclipse version="3.4"?> -<plugin> - <extension - point="org.eclipse.ui.actionSets"> - <actionSet - id="edu.kit.ipd.descartes.adaptation.adaptationFrameworkActionSet" - label="Adaptation Framework Action Set" - visible="true"> - <menu - id="adaptationFrameworkMenu" - label="Adaptation &Framework"> - <separator - name="edu.kit.ipd.descartes.adaptation.AdaptationSeparator"> - </separator> - </menu> - <action - class="edu.kit.ipd.descartes.adaptation.actions.StartAdaptationAction" - id="edu.kit.ipd.descartes.adaptation.actions.StartAdaptationAction" - label="Start &Adaptation" - menubarPath="adaptationFrameworkMenu/Adaptation Framework" - toolbarPath="Adaptation Framework" - tooltip="Starts the adaptation process"> - </action> - </actionSet> - </extension> - -</plugin> diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/Activator.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/Activator.java index 54c4fe423df5e3573f23637477659fbedffa6841..b26c561b61f678c7f7cbc2b9eda5654761123fc3 100644 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/Activator.java +++ b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/Activator.java @@ -1,50 +1,32 @@ package edu.kit.ipd.descartes.adaptation; -import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ -public class Activator extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "edu.kit.ipd.descartes.adaptation"; //$NON-NLS-1$ - - // The shared instance - private static Activator plugin; - - /** - * The constructor - */ - public Activator() { - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } +public class Activator implements BundleActivator { + private static BundleContext context; + + static BundleContext getContext() { + return context; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext bundleContext) throws Exception { + Activator.context = bundleContext; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext bundleContext) throws Exception { + Activator.context = null; + } } diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/AdaptationControl.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/AdaptationControl.java index 3c9db445f5065bf2886d2c7bdf4d50baf945fc96..2022075a85891ed8c66c5133f48ea5035542b7c4 100644 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/AdaptationControl.java +++ b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/AdaptationControl.java @@ -11,14 +11,14 @@ import org.apache.log4j.Logger; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.xmi.DanglingHREFException; -import edu.kit.ipd.descartes.adaptation.evaluation.IEvaluator; -import edu.kit.ipd.descartes.adaptation.evaluation.WeightingFunctionEvaluator; +import edu.kit.ipd.descartes.adaptation.evaluation.performance.IEvaluator; +import edu.kit.ipd.descartes.adaptation.evaluation.performance.WeightingFunctionEvaluator; import edu.kit.ipd.descartes.adaptation.event.EventTypeEnum; import edu.kit.ipd.descartes.adaptation.model.analysis.IModelAnalyzer; import edu.kit.ipd.descartes.adaptation.model.analysis.pcm.PcmModelAnalyzer; -import edu.kit.ipd.descartes.adaptation.model.dmm.AdaptationProcessModelLoader; -import edu.kit.ipd.descartes.adaptation.model.dmm.DmmModelActionHandler; -import edu.kit.ipd.descartes.adaptation.model.dmm.util.ObjectivesHelper; +import edu.kit.ipd.descartes.adaptation.modelrepository.AdaptationProcessModelLoader; +import edu.kit.ipd.descartes.adaptation.modeladaptor.dmm.DmmModelActionHandler; +import edu.kit.ipd.descartes.adaptation.modeladaptor.dmm.util.ObjectivesHelper; import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.IPerformanceDataRepositoryHandler; import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.PerformanceDataRepositoryHandlerFactory; import edu.kit.ipd.descartes.mm.adaptation.AdaptationProcess; @@ -63,7 +63,16 @@ public class AdaptationControl { * @throws IOException */ public static void main(String[] args) throws IOException { - prepare(args[0]); + String propertiesfile = args[0]; + LogManager.getRootLogger().setLevel(Level.DEBUG); + + AdaptationControl adaptationController = new AdaptationControl(); + // Initialize controller (load models, create Action perfDataRepoHandler, etc.) + adaptationController.init(propertiesfile); + Event triggeringEvent = adaptationController.findTriggeringEvent(); + + // trigger adaptation process + adaptationController.doAdaptation(triggeringEvent); } public void init(String propertiesFile) { @@ -93,19 +102,6 @@ public class AdaptationControl { } } - /* (non-Javadoc) refactor this after integration of QL Engine */ - private static void prepare(String propertiesfile) { - LogManager.getRootLogger().setLevel(Level.DEBUG); - - AdaptationControl adaptationController = new AdaptationControl(); - // Initialize controller (load models, create Action perfDataRepoHandler, etc.) - adaptationController.init(propertiesfile); - Event triggeringEvent = adaptationController.findTriggeringEvent(); - - // trigger adaptation process - adaptationController.doAdaptation(triggeringEvent); - } - public void doAdaptation(Event event) { // Determine the suitable strategy via the objective @@ -236,7 +232,8 @@ public class AdaptationControl { Properties properties = new Properties(); FileInputStream propFile = new FileInputStream(propertiesFilePath); properties.load(propFile); - logger.debug("Loaded properties of " + properties.getProperty(PROP_ADAPTATION_PROCESS_NAME)); + logger.debug("Loading properties file " + propertiesFilePath); + logger.debug("Adaptation process: " + properties.getProperty(PROP_ADAPTATION_PROCESS_NAME)); pdrMetamodelType = properties.getProperty(PROP_PERF_DATA_REPO_METAMODEL_TYPE); adaptationProcessXmiFilePath = properties.getProperty(PROP_ADAPTATION_PROCESS_XMI_FILE_PATH_NAME); performanceDataRepoXmiFilePath = properties.getProperty(PROP_PERF_DATA_REPO_XMI_FILE_PATH_NAME); @@ -247,7 +244,7 @@ public class AdaptationControl { } // Creates an "artifical event". Will be replaced later when integrated in the system - private Event findTriggeringEvent() { + public Event findTriggeringEvent() { EventTypeEnum type = EventTypeEnum.getEventType(eventType); if (type == null) { diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/IActionHandler.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/IActionHandler.java deleted file mode 100644 index 25e36625bc7f8e94ca6e240957ebcd53f6e64cf8..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/IActionHandler.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * - */ -package edu.kit.ipd.descartes.adaptation; - -import edu.kit.ipd.descartes.adaptation.exceptions.OperationNotPerformedException; -import edu.kit.ipd.descartes.mm.adaptation.AdaptationActionOperation; -import edu.kit.ipd.descartes.mm.adaptationpoints.AdaptationPoint; - -/** - * @author nhuber - * - * - * - */ -public interface IActionHandler { - - public void execute(AdaptationPoint point, AdaptationActionOperation adaptationOperation) throws OperationNotPerformedException; - - public void persistActions(); - -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/TacticExecutor.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/TacticExecutor.java index 7c5ca6f0de992a419eb2de3a74c3d43da5bc1375..1e96a1f2cd671e1ee4b1f64bb39aa2defbd4b2de 100644 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/TacticExecutor.java +++ b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/TacticExecutor.java @@ -10,9 +10,10 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.change.ChangeDescription; import edu.kit.ipd.descartes.adaptation.exceptions.InvalidAdaptationPlan; -import edu.kit.ipd.descartes.adaptation.exceptions.OperationNotPerformedException; -import edu.kit.ipd.descartes.adaptation.model.dmm.AdaptationProcessModelLoader; -import edu.kit.ipd.descartes.adaptation.model.dmm.util.OclEvaluationHelper; +import edu.kit.ipd.descartes.adaptation.modeladaptor.dmm.util.OclEvaluationHelper; +import edu.kit.ipd.descartes.adaptation.modeladaptor.IActionHandler; +import edu.kit.ipd.descartes.adaptation.modeladaptor.OperationNotPerformedException; +import edu.kit.ipd.descartes.adaptation.modelrepository.AdaptationProcessModelLoader; import edu.kit.ipd.descartes.adaptation.util.BlueYonderExperimentTracker; import edu.kit.ipd.descartes.adaptation.util.IObserver; import edu.kit.ipd.descartes.mm.adaptation.AbstractControlFlowElement; 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 deleted file mode 100644 index 48099199e1f8981d4bd27d96e08b7be3fbfefb98..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/actions/StartAdaptationAction.java +++ /dev/null @@ -1,64 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.IWorkbenchWindowActionDelegate; - -/** - * Our sample action implements workbench action delegate. - * The action proxy will be created by the workbench and - * shown in the UI. When the user tries to use the action, - * this delegate will be created and execution will be - * delegated to it. - * @see IWorkbenchWindowActionDelegate - */ -public class StartAdaptationAction implements IWorkbenchWindowActionDelegate { - private IWorkbenchWindow window; - /** - * The constructor. - */ - public StartAdaptationAction() { - } - - /** - * The action has been activated. The argument of the - * method represents the 'real' action sitting - * in the workbench UI. - * @see IWorkbenchWindowActionDelegate#run - */ - public void run(IAction action) { - MessageDialog.openInformation( - window.getShell(), - "External", - "CURRENTLY NOT IMPLEMENTED!"); - } - - /** - * Selection in the workbench has been changed. We - * can change the state of the 'real' action here - * if we want, but this can only happen after - * the delegate has been created. - * @see IWorkbenchWindowActionDelegate#selectionChanged - */ - public void selectionChanged(IAction action, ISelection selection) { - } - - /** - * We can use this method to dispose of any system - * resources we previously allocated. - * @see IWorkbenchWindowActionDelegate#dispose - */ - public void dispose() { - } - - /** - * We will cache window object in order to - * be able to provide parent shell for the message dialog. - * @see IWorkbenchWindowActionDelegate#init - */ - public void init(IWorkbenchWindow window) { - this.window = window; - } -} \ No newline at end of file diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/IEvaluator.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/IEvaluator.java deleted file mode 100644 index 3633d3f790fe37f3d79df40d2d315f8a9302ec0c..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/IEvaluator.java +++ /dev/null @@ -1,38 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.evaluation; - -import edu.kit.ipd.descartes.mm.adaptation.Objective; -import edu.kit.ipd.descartes.mm.adaptation.WeightedTactic; - -/** - * Evaluates a tactic. - * - * @author nhuber - * - */ -public interface IEvaluator { - - /** - * Evaluates the impact of a {@link WeightedTactic}. - * - * @param tactic - * The weighted tactic to evaluate - */ - public void evaluate(WeightedTactic tactic); - - /** - * Checks if any QoS property has degraded significantly, i.e. any {@link Objective}has been - * violated, after applying the tactic. - * - * @param tactic - * @return - */ - public boolean slaViolated(WeightedTactic tactic); - - /** - * Reduces the weight of the given tactic. - * - * @param tactic - */ - public void punishTactic(WeightedTactic tactic); - -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/WeightingFunctionEvaluator.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/WeightingFunctionEvaluator.java deleted file mode 100644 index 8e0aee1729fa1062f822a792c7d07c61130cc009..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/WeightingFunctionEvaluator.java +++ /dev/null @@ -1,86 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.evaluation; - -import org.apache.log4j.Logger; -import org.eclipse.emf.common.util.EList; - -import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.IWeightingFunction; -import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.WeightedSumWeightingFunctionHelper; -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; - -/** - * Evaluates a given {@link WeightedTactic} using the weighted tactic's {@link WeightingFunction}. - * - * @author nhuber - * - */ -public class WeightingFunctionEvaluator implements IEvaluator { - - private static final String RESPONSETIME_IDENTIFIER = "ResponseTime"; - private IWeightingFunction calculator = null; - private static Logger logger = Logger.getLogger(WeightingFunctionEvaluator.class); - - /* - * (non-Javadoc) - * - * @see edu.kit.ipd.descartes.adaptation.evaluation.IEvaluator#evaluate() - */ - @Override - public void evaluate(WeightedTactic tactic) { - WeightingFunction f = tactic.getParentStrategy().getWeightingFunction(); - - final String functionClassName = f.getWeightingFunctionImplementation(); - - Object o = null; - try { - o = Class.forName(functionClassName).newInstance(); - } catch (final ClassNotFoundException e) { - e.printStackTrace(); - } catch (final InstantiationException e) { - e.printStackTrace(); - } catch (final IllegalAccessException e) { - e.printStackTrace(); - } - - if (!IWeightingFunction.class.isInstance(o)) { - throw new RuntimeException("Expected a class implementing " + IWeightingFunction.class.getName()); - } - - calculator = (IWeightingFunction) o; - calculator.setWeightingFunction(f); - double newWeight = calculator.calculateWeight(tactic); - logger.debug("Setting new weight of " + tactic.getName() + " to " + newWeight); - tactic.setCurrentWeight(newWeight); - } - - public boolean slaViolated(WeightedTactic tactic) { - Impact impact = tactic.getLastImpact(); - Result before = impact.getBefore(); - Result after = impact.getAfter(); - EList<MetricValue> afterMetricValues = after.getMetricValues(); - - for (MetricValue afterMetricValue : afterMetricValues) { - // calculated delta=(after-before) - double afterValue = afterMetricValue.getValue(); - double beforeValue = WeightedSumWeightingFunctionHelper.getValueForMetricType( - afterMetricValue.getMetricType(), before); - - if (afterMetricValue.getMetricType().getName().contains(RESPONSETIME_IDENTIFIER) - && afterValue > beforeValue) { - return true; - } - } - - return false; - } - - @Override - public void punishTactic(WeightedTactic tactic) { - double weight = 0.0; - logger.info("Punishing tactic, setting weight to " + weight); - tactic.setCurrentWeight(weight); - } -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/BlueYonderResourceEfficiencyWeightingFunction.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/BlueYonderResourceEfficiencyWeightingFunction.java deleted file mode 100644 index 3d1ea4e0b89c61076038d3711c5db277a5f00fd6..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/BlueYonderResourceEfficiencyWeightingFunction.java +++ /dev/null @@ -1,78 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction; - -import org.apache.log4j.Logger; - -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 BlueYonderResourceEfficiencyWeightingFunction 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(BlueYonderResourceEfficiencyWeightingFunction.class); - -// public BlueYonderResourceEfficiencyWeightingFunction() { -// 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); - // TODO: Implement something more sophisticated - newWeight = activeResourceDelta; - - return newWeight; - } - - 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/evaluation/weightingfunction/IWeightingFunction.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/IWeightingFunction.java deleted file mode 100644 index 284d82a16836ac83dc6336db4146544b44ec9e66..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/IWeightingFunction.java +++ /dev/null @@ -1,33 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction; - -import edu.kit.ipd.descartes.mm.adaptation.Tactic; -import edu.kit.ipd.descartes.mm.adaptation.WeightedMetric; -import edu.kit.ipd.descartes.mm.adaptation.WeightedTactic; -import edu.kit.ipd.descartes.mm.adaptation.WeightingFunction; - -/** - * @author nhuber - * - */ -public interface IWeightingFunction { - - - /** - * Sets the {@link WeightingFunction} that can be used - * by the {@link WeightingFunction} to derive the - * {@link WeightedMetric}s used to calculate the weight. - * - * @param function - */ - void setWeightingFunction(WeightingFunction function); - - /** - * Calculates the new weight of the given {@link Tactic}. - * - * @param impact - * @return - */ - double calculateWeight(WeightedTactic weightedTactic); - - -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/RandomWeightsWeightingFunction.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/RandomWeightsWeightingFunction.java deleted file mode 100644 index ae2ade1149a4986b9780937f8985b6eae5a6f0e9..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/RandomWeightsWeightingFunction.java +++ /dev/null @@ -1,20 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction; - -import java.util.Random; - -import edu.kit.ipd.descartes.mm.adaptation.WeightedTactic; -import edu.kit.ipd.descartes.mm.adaptation.WeightingFunction; - -public class RandomWeightsWeightingFunction implements IWeightingFunction { - - @Override - public double calculateWeight(WeightedTactic weightedTactic) { - Random r = new Random(System.currentTimeMillis()); - return r.nextDouble(); - } - - @Override - public void setWeightingFunction(WeightingFunction function) { - // Left empty intentionally - } -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSum.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSum.java deleted file mode 100644 index 0491b2ce95100642e6f26ceb11e4e2e3eb854a27..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSum.java +++ /dev/null @@ -1,62 +0,0 @@ -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.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 WeightedSum implements IWeightingFunction { - - private Logger logger = Logger.getLogger(WeightedSum.class); - private WeightingFunction weightingFunction = null; - - public WeightedSum() { - } - - public WeightingFunction getWeightingFunction() { - return weightingFunction; - } - - @Override - public void setWeightingFunction(WeightingFunction weightingFunction) { - this.weightingFunction = weightingFunction; - } - - @Override - public double calculateWeight(WeightedTactic weightedtactic) { - - double newWeight = 0.0; - Impact impact = weightedtactic.getLastImpact(); - Result before = impact.getBefore(); - Result after = impact.getAfter(); - EList<MetricValue> afterMetricValues = after.getMetricValues(); - - for (MetricValue afterMetricValue : afterMetricValues) { - // calculated delta=(after-before) - double afterValue = afterMetricValue.getValue(); - double beforeValue = WeightedSumWeightingFunctionHelper - .getValueForMetricType(afterMetricValue.getMetricType(), before); - double delta = afterValue - beforeValue; - - // get the corresponding weight - double weightOfMetric = WeightedSumWeightingFunctionHelper.getWeightForMetricType(weightingFunction, - afterMetricValue.getMetricType()); - - if (Double.isNaN(weightOfMetric)) - logger.debug("WeightingFunction "+ weightingFunction.getName()+" has no weight specified for metric type " + afterMetricValue.getMetricType().getName() + ". Skipping..."); - else { - // add it - newWeight += weightOfMetric * delta; - logger.debug("Delta for metric type " + afterMetricValue.getMetricType().getName() + " was: " + delta - + " and weight is " + weightOfMetric); - } - } - - return newWeight; - } - -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumWeightingFunctionHelper.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumWeightingFunctionHelper.java deleted file mode 100644 index 98c0b27a68204b4f5d37b21663fdab8a9f047c50..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumWeightingFunctionHelper.java +++ /dev/null @@ -1,64 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction; - -import org.apache.log4j.Logger; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EcoreUtil; - -import edu.kit.ipd.descartes.mm.adaptation.WeightedMetric; -import edu.kit.ipd.descartes.mm.adaptation.WeightingFunction; -import edu.kit.ipd.descartes.perfdatarepo.MetricType; -import edu.kit.ipd.descartes.perfdatarepo.MetricValue; -import edu.kit.ipd.descartes.perfdatarepo.Result; - -public class WeightedSumWeightingFunctionHelper { - - static Logger logger = Logger.getLogger(WeightedSumWeightingFunctionHelper.class); - - /** - * - * @param function - * @param metricType - * @return Returns the weight of the {@code meticType} of the given {@code function}.<br> - * Returns {@code Double.NaN} if the {@code metricType} was not found. - */ - public static double getWeightForMetricType(WeightingFunction function, MetricType metricType) { - EList<WeightedMetric> weightedMetrics = function.getWeightedMetrics(); - - for (WeightedMetric weightedMetric : weightedMetrics) { - if (EcoreUtil.equals(weightedMetric.getMetricType(), metricType)) - return weightedMetric.getWeight(); - else if (weightedMetric.getMetricType().getName().equals(metricType.getName())) { - logger.debug("Could not find identical metric, using matching name instead"); - return weightedMetric.getWeight(); - } - } - - return Double.NaN; - } - - /** - * Searches the {@link MetricValue} of the given {@link MetricType} in the {@link Result} - * <code>resultBefore</code> - * - * @param metricType - * The type of the metric to find - * @param result - * The result to search - * @return - */ - public static double getValueForMetricType(MetricType metricType, Result result) { - EList<MetricValue> metricValues = result.getMetricValues(); - - for (MetricValue metricValue : metricValues) { - if (sameMetricType(metricValue, metricType)) - return metricValue.getValue(); - } - return Double.NaN; - } - - public static boolean sameMetricType(MetricValue metricValue, MetricType metricType) { -// return metricValue.getMetricType().equals(metricType); - return (metricValue.getMetricType().getName().equals(metricType.getName())); -// && metricValue.getMetricType().getId().equals(metricType.getId())); - } -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/exceptions/OperationNotPerformedException.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/exceptions/OperationNotPerformedException.java deleted file mode 100644 index f2a568f3ffc7da99c6c6d809c68a15aacac0c8a4..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/exceptions/OperationNotPerformedException.java +++ /dev/null @@ -1,14 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.exceptions; - -public class OperationNotPerformedException extends Exception { - - public OperationNotPerformedException(String message) { - super(message); - } - - /** - * - */ - private static final long serialVersionUID = 7144698514945329908L; - -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/AbstractEcoreModelLoader.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/AbstractEcoreModelLoader.java deleted file mode 100644 index 8f18ab65213f7d209cf92a8dbc64855df9442b3a..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/AbstractEcoreModelLoader.java +++ /dev/null @@ -1,124 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.model; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.log4j.Logger; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.xmi.XMIResource; - -public abstract class AbstractEcoreModelLoader { - - private static Logger logger = Logger.getLogger(AbstractEcoreModelLoader.class); - private ResourceSet resourceSet = null; - private URI currentUri = null; - private EObject loadedModel; - - protected ResourceSet getResourceSet() { - if (resourceSet == null) - throw new NullPointerException("INTITIALIZE RESOURCE SET FIRST! "); - return resourceSet; - } - - protected void setResourceSet(ResourceSet resourceSet) { - this.resourceSet = resourceSet; - } - - /**Implement this method to initialize your {@link ResourceSet}, e.g., - * if you load your models in a standalone application. - * - * @param resourceSet - */ - public abstract void initializeResourceSet(ResourceSet resourceSet); - - /** - * Loads the model specified by <code>uri</code>. - * - * @param uri - * @return - * @throws IOException - */ - public EObject load(URI uri) { - - if (null == uri) - throw new IllegalArgumentException("Missing file URI."); - - if (uri.equals(currentUri) && loadedModel != null) - return loadedModel; - - // Resource resource = resourceSet.createResource(fileURI); - Resource resource = resourceSet.getResource(uri, true); - try { - resource.load(null); - logger.info("Model from URI " + uri.toFileString() + " loaded."); - } catch (IOException e) { - logger.error("Error while loading model " + uri.toFileString(), e); - e.printStackTrace(); - } - currentUri = uri; - EcoreUtil.resolveAll(resourceSet); - loadedModel = resource.getContents().get(0); - return resource.getContents().get(0); - } - - /** - * Persists the specified <code>obj</code> at the given - * <code>uri</code>. - * - * @param uri - * @param obj - * @throws IOException - */ - public void save(URI uri, EObject obj) throws IOException { - if (null == uri) { - throw new IllegalArgumentException("Missing file URI."); - } - Resource resource = resourceSet.createResource(uri); - resource.getContents().add(obj); - Map<String, Boolean> options = new HashMap<String, Boolean>(); - options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); - options.put(XMIResource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER, Boolean.TRUE); - resource.save(options); - } - - /** Convenience method to create an URI. - * - * @param projectname - * @param filename - * @param filename_extension - * @return - */ - public static URI createFileURI(String projectname, String filename, String filename_extension) { - if (null == projectname) { - throw new IllegalArgumentException("Missing project name."); - } - if (null == filename) { - throw new IllegalArgumentException("Missing file name."); - } - if (null == filename_extension) { - throw new IllegalArgumentException("Missing file name extension."); - } - /* TODO check for null pointer exceptions */ - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IProject project = root.getProject(projectname); - String projectPath = project.getLocationURI().getPath(); - URI fileURI = URI.createFileURI(projectPath); - return fileURI.appendSegment(filename).appendFileExtension(filename_extension); - } - - /** - * Convenience method to determine the current model location. - * @return - */ - public URI getCurrentModelUri() { - return currentUri; - } -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/AdaptationProcessModelLoader.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/AdaptationProcessModelLoader.java deleted file mode 100644 index 63b83c06d379231455525135ff93400c86edf071..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/AdaptationProcessModelLoader.java +++ /dev/null @@ -1,111 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.model.dmm; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.change.ChangeDescription; -import org.eclipse.emf.ecore.change.util.ChangeRecorder; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.eclipse.emf.ecore.xmi.DanglingHREFException; -import org.eclipse.emf.ecore.xmi.XMIResource; -import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; - -import edu.kit.ipd.descartes.adaptation.model.AbstractEcoreModelLoader; -import edu.kit.ipd.descartes.mm.adaptation.AdaptationPackage; -import edu.kit.ipd.descartes.mm.adaptation.AdaptationProcess; -import edu.kit.ipd.descartes.mm.adaptationpoints.AdaptationpointsPackage; -import edu.kit.ipd.descartes.mm.containerrepository.ContainerrepositoryPackage; -import edu.kit.ipd.descartes.mm.resourcelandscape.DistributedDataCenter; -import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapePackage; - -public class AdaptationProcessModelLoader extends AbstractEcoreModelLoader { - - public static final EPackage[] DMM_EPACKAGES = new EPackage[] { - ResourcelandscapePackage.eINSTANCE, - AdaptationpointsPackage.eINSTANCE, - ContainerrepositoryPackage.eINSTANCE, - AdaptationPackage.eINSTANCE }; - - private static AdaptationProcessModelLoader instance = null; - private static ChangeRecorder recorder = null; - - public static AdaptationProcessModelLoader getInstance() { - if (instance == null) { - instance = new AdaptationProcessModelLoader(); - } - return instance; - } - - private AdaptationProcessModelLoader() { - initializeResourceSet(new ResourceSetImpl()); - } - - public static void saveAll() throws IOException { - - EList<Resource> resources = getInstance().getResourceSet().getResources(); - Map<String, String> options = new HashMap<String, String>(); - options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE.toString()); - options.put(XMIResource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER, Boolean.TRUE.toString()); - options.put(XMIResource.OPTION_PROCESS_DANGLING_HREF, XMIResource.OPTION_PROCESS_DANGLING_HREF_THROW); - - for (Resource res : resources) { - try { - res.save(options); - } catch (IOException e) { - if (e.getCause() instanceof DanglingHREFException) { - String newMessage = "Error while persisting " + res.getURI() - + " because of dangling references. Probably not all changes have been saved.\n"; - throw new IOException(newMessage + e.getMessage(), e.getCause()); - } - } - } - } - - @Override - public void initializeResourceSet(ResourceSet resourceSet) { - setResourceSet(resourceSet); - - /* Register the default resource factory -- only needed for stand-alone! */ - getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap() - .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); - - /* Register also the packages needed for the DMM meta model */ - for (EPackage ePackage : DMM_EPACKAGES) { - getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap().put(ePackage.getNsURI(), ePackage); - } - } - - public static DistributedDataCenter getDistributedDataCenter() { - for (Iterator<Resource> iter = getInstance().getResourceSet().getResources().iterator(); iter.hasNext();) { - Resource resource = (Resource) iter.next(); - if (resource.getContents().get(0).eClass().getClassifierID() == ResourcelandscapePackage.DISTRIBUTED_DATA_CENTER) - return (DistributedDataCenter) resource.getContents().get(0); - } - return null; - } - - @Override - public AdaptationProcess load(URI uri) { - return (AdaptationProcess) super.load(uri); - } - - public static void startRecording() { - recorder = new ChangeRecorder(getInstance().getResourceSet()); - } - - public static ChangeDescription endRecording() { - return recorder.endRecording(); - } - - public static void endRecordingAndRollback() { - recorder.endRecording().apply(); - - } -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/DmmModelActionHandler.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/DmmModelActionHandler.java deleted file mode 100644 index 82cacc29763f61f36e9fbb3373d3b67607e153ce..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/DmmModelActionHandler.java +++ /dev/null @@ -1,319 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.model.dmm; - -import java.io.IOException; -import java.util.List; -import java.util.Random; - -import org.apache.log4j.Logger; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; - -import edu.kit.ipd.descartes.adaptation.IActionHandler; -import edu.kit.ipd.descartes.adaptation.exceptions.OperationNotPerformedException; -import edu.kit.ipd.descartes.adaptation.model.dmm.util.DmmModelActionHelper; -import edu.kit.ipd.descartes.adaptation.model.dmm.util.DmmModelChanger; -import edu.kit.ipd.descartes.adaptation.model.dmm.util.OclEvaluationHelper; -import edu.kit.ipd.descartes.core.AdaptableEntity; -import edu.kit.ipd.descartes.core.Entity; -import edu.kit.ipd.descartes.mm.adaptation.AdaptationActionOperation; -import edu.kit.ipd.descartes.mm.adaptation.AdaptationScope; -import edu.kit.ipd.descartes.mm.adaptationpoints.AdaptationPoint; -import edu.kit.ipd.descartes.mm.adaptationpoints.ModelEntityConfigurationRange; -import edu.kit.ipd.descartes.mm.adaptationpoints.ModelVariableConfigurationRange; -import edu.kit.ipd.descartes.mm.adaptationpoints.PropertyRange; -import edu.kit.ipd.descartes.mm.adaptationpoints.SetOfConfigurations; -import edu.kit.ipd.descartes.mm.adaptationpoints.VariationType; -import edu.kit.ipd.descartes.mm.containerrepository.ContainerTemplate; -import edu.kit.ipd.descartes.mm.containerrepository.ContainerrepositoryPackage; -import edu.kit.ipd.descartes.mm.resourcelandscape.Container; -import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapePackage; -import edu.kit.ipd.descartes.mm.resourcelandscape.RuntimeEnvironment; - -public class DmmModelActionHandler implements IActionHandler { - static Logger logger = Logger.getLogger(DmmModelActionHandler.class); - - public DmmModelActionHandler() { - logger.info("DMM models loaded."); - } - - private void saveModels() { - try { - AdaptationProcessModelLoader.saveAll(); - } catch (IOException e) { - logger.error("Error while saving models", e); - } - } - - @Override - public void execute(AdaptationPoint point, AdaptationActionOperation operation) - throws OperationNotPerformedException { - - logger.debug("Executing adaptation action <<" + operation.getAdaptationOperationDirection().getLiteral() + ", " - + operation.getAdaptationOperationScope().getLiteral() + ">> on adaptation point <<" + point.getName() - + ">>."); - - if (point instanceof ModelEntityConfigurationRange) { - logger.debug("Type of Adaptation: EntityConfigurationRange"); - execEntityConfigRangeAdaptation(point, operation); - } else if (point instanceof ModelVariableConfigurationRange) { - logger.debug("Type of Adaptation Point: VariableConfigurationRange"); - execVariableConfigRangeAdaptation(point, operation); - } else { - logger.error("No matching type found for given adaptation point " + point.toString()); - throw new OperationNotPerformedException( - "No maching adaptation point execution found for adaptation point " + point); - } - } - - public void execVariableConfigRangeAdaptation(AdaptationPoint point, AdaptationActionOperation operation) - throws OperationNotPerformedException { - ModelVariableConfigurationRange configRange = (ModelVariableConfigurationRange) point; - - AdaptableEntity adaptedEntity = configRange.getAdaptableEntity(); - EObject actuallyConfiguredInstance = DmmModelActionHelper.findParentConfiguredInstance(adaptedEntity); - switch (actuallyConfiguredInstance.eClass().getClassifierID()) { - case ResourcelandscapePackage.RUNTIME_ENVIRONMENT: - DmmModelChanger.scaleModelVariable(configRange, operation.getAdaptationOperationDirection()); - break; - case ContainerrepositoryPackage.CONTAINER_TEMPLATE: - DmmModelChanger.scaleContainerTemplate((ContainerTemplate) actuallyConfiguredInstance, configRange, - operation); - break; - case ResourcelandscapePackage.CONTAINER: - /* - * This code should not be reached because RUNTIME_ENVIRONMENTS are also containers. - * Only AbstractHardwareInfrastructures are Containers but not RuntimeEnvironments, but - * they cannot be changed because they're hardware - */ - logger.error("You cannot specify an adaptation point for " + actuallyConfiguredInstance.eClass()); - break; - default: - logger.error("No adaptation action implemented for type " + actuallyConfiguredInstance.eClass()); - break; - } - } - - public void execEntityConfigRangeAdaptation(AdaptationPoint point, AdaptationActionOperation operation) - throws OperationNotPerformedException { - - ModelEntityConfigurationRange configRange = (ModelEntityConfigurationRange) point; - Entity adaptableEntity = configRange.getAdaptableEntity(); - VariationType range = configRange.getVariationPossibility(); - - switch (operation.getAdaptationOperationDirection()) { - case INCREASE: - scaleOutModelEntity(adaptableEntity, range); - break; - case DECREASE: - scaleInModelEntity(adaptableEntity, range); - break; - case MIGRATE: - logger.debug("Executing MIGRATE operation"); - migrate(adaptableEntity, range, operation.getAdaptationOperationScope()); - break; - default: - throw new OperationNotPerformedException("Operation " + operation + " on adaptation point " - + point.getName() + " not supported"); - } - } - - private void scaleInModelEntity(Entity adaptableEntity, VariationType range) throws OperationNotPerformedException { - logger.debug("Executing DECREASE operation"); - Entity scaledEntity = scaleIn(adaptableEntity); - if (scaledEntity == null) - throw new OperationNotPerformedException("Could not scale " + adaptableEntity.getName() - + ". Minimum has been reached!"); - } - - private void scaleOutModelEntity(Entity adaptableEntity, VariationType range) throws OperationNotPerformedException { - logger.debug("Executing INCREASE operation"); - RuntimeEnvironment scaledRE = scaleOut(adaptableEntity); - if (!invariantsAreValid(adaptableEntity, (PropertyRange) range)) { // spawn new - // runtimeEnvironment on - // different machine - List<Container> possibleTargets = DmmModelActionHelper.queryContainersWithSimilarTemplate(scaledRE - .getContainedIn()); - for (Container nextContainer : possibleTargets) { - scaledRE.setContainedIn(nextContainer); - if (invariantsAreValid(scaledRE, (PropertyRange) range)) { - logger.debug("Scaling entity " + scaledRE.getName() + " on altenative container " - + nextContainer.getName() + " (ID: " + nextContainer.getId() + ")"); - return; - } - } - // in case a violation occured and no alternative container was found - EcoreUtil.delete(scaledRE, true); - throw new OperationNotPerformedException("Could not scale " + adaptableEntity.getName() - + ". Maxiumum has been reached!"); - } - } - - private boolean invariantsAreValid(Entity adaptableEntity, PropertyRange range) { - boolean invariant = OclEvaluationHelper.evaluateOclConstraint(adaptableEntity, range.getMinValueConstraint() - .getOclString(), adaptableEntity.eClass()); - - if (!invariant) - logger.debug("Invariant " + range.getMinValueConstraint().getOclString() + " violated"); - - invariant &= OclEvaluationHelper.evaluateOclConstraint(adaptableEntity, range.getMaxValueConstraint() - .getOclString(), adaptableEntity.eClass()); - - if (!invariant) - logger.debug("Invariant " + range.getMaxValueConstraint().getOclString() + " violated"); - - return invariant; - } - - private void migrate(Entity adaptableEntity, VariationType targets, AdaptationScope adaptationScope) throws OperationNotPerformedException { - switch (adaptableEntity.eClass().getClassifierID()) { - case ResourcelandscapePackage.RUNTIME_ENVIRONMENT: - logger.debug("Starting migration of a runtime environment referring to container template " - + adaptableEntity.getName() + " (ID: " + adaptableEntity.getId() + ")"); - /* - * 1. Copy RE 2. Attach copy to a target specified in the Adaptation Point 3. Delete - * origin - */ - - if (!(targets instanceof SetOfConfigurations)) - throw new IllegalArgumentException( - "Migration could not be performed because no target specification found!"); - EList<Entity> migrationTargets = ((SetOfConfigurations) targets).getVariants(); - - RuntimeEnvironment migratedEntity = (RuntimeEnvironment) adaptableEntity; - Container source = migratedEntity.getContainedIn(); - // TODO Here you could implement something more sophisticated - // e.g., choose the container with the lowest util. - Entity target = randomTarget(migrationTargets, source); - - if (!(target instanceof Container)) - throw new IllegalArgumentException( - "Migration could not be performed because target is not a container!"); - Container targetContainer = (Container) target; - - if (migrationTargets.size() == 1 && EcoreUtil.equals(source, target)) - throw new OperationNotPerformedException("Migration operation not executed because source and destination are identical."); - - targetContainer.getContains().add(migratedEntity); - source.getContains().remove(migratedEntity); - break; - case ContainerrepositoryPackage.CONTAINER_TEMPLATE: -// logger.debug("Starting migration of a container referring to container template " -// + adaptableEntity.getName() + " (ID: " + adaptableEntity.getId() + ")"); - ContainerTemplate containerTemplate = (ContainerTemplate) adaptableEntity; - Container migratedContainer = DmmModelActionHelper.findSuitableContainer(containerTemplate, adaptationScope, targets); - if (migratedContainer == null) - throw new OperationNotPerformedException("Could not execute migration operation because no suitable migration candidate found"); - migrate(migratedContainer, targets, adaptationScope); - break; - default: - throw new IllegalArgumentException("No implemented migrate operation for " + adaptableEntity); - } - - } - - private Entity randomTarget(EList<Entity> destinations, Entity source) { - if (destinations.size() == 1) - return destinations.get(0); - - Entity destination = destinations.get(0); - Random randomGenerator = new Random(); - while (EcoreUtil.equals(destination, source)) { - int destNumber = randomGenerator.nextInt(destinations.size()); - destination = destinations.get(destNumber); - } - - return destination; - } - - private Entity scaleIn(Entity adaptableEntity) { - Entity result = null; - switch (adaptableEntity.eClass().getClassifierID()) { - case ResourcelandscapePackage.RUNTIME_ENVIRONMENT: - result = DmmModelChanger.scaleInRuntimeEnvironmentInstance((RuntimeEnvironment) adaptableEntity); - break; - case ContainerrepositoryPackage.CONTAINER_TEMPLATE: - // TODO: move to DmmModelChanger - result = scaleInContainerTemplate((ContainerTemplate) adaptableEntity); - break; - default: - throw new IllegalArgumentException("No implemented scale in operation for " + adaptableEntity); - } - return result; - } - - private RuntimeEnvironment scaleOut(Entity adaptableEntity) { - RuntimeEnvironment re = null; - switch (adaptableEntity.eClass().getClassifierID()) { - case ResourcelandscapePackage.RUNTIME_ENVIRONMENT: - re = DmmModelChanger.createNewRuntimeEnvironmentInstance((RuntimeEnvironment) adaptableEntity); - break; - case ContainerrepositoryPackage.CONTAINER_TEMPLATE: - re = scaleOutContainerTemplate((ContainerTemplate) adaptableEntity); - break; - default: - throw new IllegalArgumentException("No implemented scale out operation for " + adaptableEntity); - } - return re; - } - - private Entity scaleInContainerTemplate(ContainerTemplate template) { - Container referringContainer = template.getReferringContainers().get(0); - RuntimeEnvironment removedRe = null; - if (referringContainer != null && referringContainer instanceof RuntimeEnvironment) { - removedRe = DmmModelChanger.scaleInRuntimeEnvironmentInstance((RuntimeEnvironment) referringContainer); - } else { - logger.error("Cannot scale " + referringContainer); - } - - if (removedRe != null) - template.getReferringContainers().remove(removedRe); - - return removedRe; - } - - /** - * Creates a new RuntimeEnvironment. If you want to scale an attribute of the ContainerTemplate, - * ModelVariableConfigurationRange must be used. However, here we are scaling a - * ModelEntityConfigurationRange. - */ - // this is just a helper function - private RuntimeEnvironment scaleOutContainerTemplate(ContainerTemplate template) { - if (template.getReferringContainers().size() == 0) { - logger.debug("No referring containers found for template " + template.getName() - + ", creating new instance from template."); - return DmmModelChanger.createNewRuntimeEnvironmentInstanceFromTemplate(template); - } else { - Container referringContainer = template.getReferringContainers().get(0); - - if (referringContainer != null && referringContainer instanceof RuntimeEnvironment) { - return DmmModelChanger.createNewRuntimeEnvironmentInstance((RuntimeEnvironment) referringContainer); - } else { - logger.error("Cannot scale " + referringContainer); - } - } - return null; - } - - @Override - public void persistActions() { - saveModels(); - } - - // private boolean checkInvariants(EObject adaptableEntity, PropertyRange range) { - // OclEvaluationHelper evalHelper = new OclEvaluationHelper(); - // boolean invariant = evalHelper.evaluate(adaptableEntity, - // range.getMinValueConstraint().getOclString()); - // - // if (!invariant) - // logger.error("Invariant " + range.getMinValueConstraint().getOclString() + " violated"); - // - // invariant &= evalHelper.evaluate(adaptableEntity, - // range.getMaxValueConstraint().getOclString()); - // - // if (!invariant) - // logger.error("Invariant " + range.getMaxValueConstraint().getOclString() + " violated"); - // - // return invariant; - // } -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/DmmModelActionHelper.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/DmmModelActionHelper.java deleted file mode 100644 index 8059813d51882cc58d774e911f206dc504bba4ab..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/DmmModelActionHelper.java +++ /dev/null @@ -1,282 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.model.dmm.util; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Random; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; - -import edu.kit.ipd.descartes.core.AdaptableEntity; -import edu.kit.ipd.descartes.core.Entity; -import edu.kit.ipd.descartes.core.NamedElement; -import edu.kit.ipd.descartes.mm.adaptation.AdaptationScope; -import edu.kit.ipd.descartes.mm.adaptationpoints.SetOfConfigurations; -import edu.kit.ipd.descartes.mm.adaptationpoints.VariationType; -import edu.kit.ipd.descartes.mm.containerrepository.ContainerTemplate; -import edu.kit.ipd.descartes.mm.resourceconfiguration.ConfigurationSpecification; -import edu.kit.ipd.descartes.mm.resourceconfiguration.ResourceconfigurationPackage; -import edu.kit.ipd.descartes.mm.resourcelandscape.Container; -import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapePackage; -import edu.kit.ipd.descartes.mm.resourcelandscape.RuntimeEnvironment; - -public class DmmModelActionHelper { - - /** - * - * @param aEntity - * @return the {@link EObject} of the model instance that contains {@code aEntity} - */ - public static EObject findParentConfiguredInstance(AdaptableEntity aEntity) { - - ConfigurationSpecification c = null; - - if (aEntity.eClass().getClassifierID() == ResourceconfigurationPackage.NUMBER_OF_PARALLEL_PROCESSING_UNITS) - c = (ConfigurationSpecification) aEntity.eContainer().eContainer(); - else if (aEntity.eClass().getClassifierID() == ResourceconfigurationPackage.PASSIVE_RESOURCE_CAPACITY) - c = (ConfigurationSpecification) aEntity.eContainer(); - else - return null; - - return c.eContainer(); - } - - /** - * Query for a {@link Container} with similar specs - * - * @param candidates - * @param comparatorContainer - * @return - */ - public static List<Container> filterContainersWithSimilarSpecs(List<Container> candidates, - Container comparatorContainer) { - - List<Container> resultList = new ArrayList<Container>(); - - for (Container c : candidates) { - - /* - * Make sure we find a RuntimeEnvironment with 1. a DIFFERENT ID 2. similar properties - * and 3. name must contain COPY_MARK to make sure we remove only a copy - */ - if (c.getId() != comparatorContainer.getId() && c.getName().contains(DmmModelChanger.COPY_MARK) - && EcoreUtil.equals(comparatorContainer.getConfigSpec(), c.getConfigSpec()) - && EcoreUtil.equals(comparatorContainer.getTemplate(), c.getTemplate())) { - resultList.add(c); - } - } - return resultList; - } - - /** - * Query for a {@link RuntimeEnvironment} that has been copied (contains - * {@link DmmModelChanger.COPY_MARK}) and refers to the same ContainerTemplate. - * - * @param candidates - * @param comparatorRE - * @return - */ - public static RuntimeEnvironment filterCopiedRuntimeEnvironment(List<RuntimeEnvironment> candidates, - RuntimeEnvironment comparatorRE) { - - for (RuntimeEnvironment re : candidates) { - - if (re.getId() != comparatorRE.getId() && re.getName().contains(DmmModelChanger.COPY_MARK) - // && EcoreUtil.equals(comparatorRE.getConfigSpec(), re.getConfigSpec()) - // && EcoreUtil.equals(comparatorRE.getContainedIn(), re.getContainedIn()) - && EcoreUtil.equals(comparatorRE.getTemplate(), re.getTemplate())) { - return re; - } - } - return null; - } - - public static RuntimeEnvironment filterRuntimeEnvironment(List<RuntimeEnvironment> candidates, - RuntimeEnvironment comparatorRE) { - - // Filter RE with copy mark first - RuntimeEnvironment reWithCopyMark = filterCopiedRuntimeEnvironment(candidates, comparatorRE); - if (reWithCopyMark != null) { - return reWithCopyMark; - } else { - // If there is no copy mark, filter an RE with different ID - for (RuntimeEnvironment re : candidates) { - - if (re.getId() != comparatorRE.getId() - // && EcoreUtil.equals(comparatorRE.getConfigSpec(), re.getConfigSpec()) - // && EcoreUtil.equals(comparatorRE.getContainedIn(), re.getContainedIn()) - && EcoreUtil.equals(comparatorRE.getTemplate(), re.getTemplate())) { - return re; - } - } - } - // If no matches have been found, return the comparator element - return comparatorRE; - } - - public static NamedElement findEntityWithName(NamedElement element, String name) { - - if (element.getName().equals(name)) - return element; - else { - NamedElement result = null; - for (Iterator<EObject> iterator = element.eContents().iterator(); iterator.hasNext();) { - NamedElement nextElement = (NamedElement) iterator.next(); - result = findEntityWithName(nextElement, name); - if (result != null) - return result; - } - return result; - } - } - - /** - * Queries for all Container instances that have a similar configuration specification as - * Container <code>c</code>. Similar configuration specification meas that ContainerTemplate and - * ConfigurationSpecification are equal. - * - * @param c - * @return A list of Container instances - */ - public static List<Container> queryContainersWithSimilarSpecs(Container c) { - List<Container> result = queryContainersWithSimilarTemplate(c); - return filterContainersWithSimilarSpecs(result, c); - } - - /** - * Queries for a RuntimeEnvironment whose ContainerTemplate is similar to the given - * RuntimeEnvironment <code>re</code> and whose capacity is below <code>maxValue</code>. - * - * @param re - * @param maxValue - * @return - */ - public static RuntimeEnvironment queryUnfilledRuntimeEnvironment(RuntimeEnvironment re, double maxValue) { - // TODO SEAMS specific helper function! Generalize! - String queryExpression = "RuntimeEnvironment.allInstances()->select( re | re.template = self.template )->select(re | re.configSpec.oclAsType(resourceconfiguration::ActiveResourceSpecification).processingResourceSpecifications->forAll(nrOfParProcUnits.number < " - + maxValue + "))"; - List<EObject> resultList = new ArrayList<EObject>(OclEvaluationHelper.query(re, queryExpression, re.eClass())); - - if (resultList.size() > 0) - return (RuntimeEnvironment) resultList.get(0); - else - return null; - } - - public static RuntimeEnvironment queryNotEmptyRuntimeEnvironment(RuntimeEnvironment re, double minValue) { - // TODO SEAMS specific helper function! Generalize! - String queryExpression = "RuntimeEnvironment.allInstances()->select( re | re.template = self.template and not re.configSpec->isEmpty() )->select(re | re.configSpec.oclAsType(resourceconfiguration::ActiveResourceSpecification).processingResourceSpecifications->forAll(nrOfParProcUnits.number > " - + minValue + "))"; - List<EObject> resultList = new ArrayList<EObject>(OclEvaluationHelper.query(re, queryExpression, re.eClass())); - - if (resultList.size() > 0) - return (RuntimeEnvironment) resultList.get(0); - else - return null; - } - - /** - * Queries for all Container instances referring to the same ContainerTemplate as the given - * container. - * - * @param container - * The container to look for - * @return All Container Instances referring to the same ContainerTemplate - */ - public static List<Container> queryContainersWithSimilarTemplate(Container container) { -// String queryExpression = "RuntimeEnvironment.allInstances()->select( re | re.template = self.template and re.id <> self.id)"; - String queryExpression = "RuntimeEnvironment.allInstances()->select( re | re.template = self.template)"; - List<EObject> tempList = new ArrayList<EObject>(OclEvaluationHelper.query(container, queryExpression, - container.eClass())); - List<Container> resultList = new ArrayList<Container>(tempList.size()); - for (Iterator<EObject> iterator = tempList.iterator(); iterator.hasNext();) { - Container temp = (Container) iterator.next(); - resultList.add(temp); - } - return resultList; - } - - /** - * Filter the given {@code containerList} for RuntimeEnvironments and cast them to - * {@link RuntimeEnvironment} - * - * @param containerList - * @return a list of RuntimeEnvironments - */ - public static List<RuntimeEnvironment> filterAndConvertRuntimeEnvironment(List<Container> containerList) { - List<RuntimeEnvironment> result = new ArrayList<RuntimeEnvironment>(); - - for (Container container : containerList) { - if (container.eClass().getClassifierID() == ResourcelandscapePackage.RUNTIME_ENVIRONMENT) - result.add((RuntimeEnvironment) container); - } - - return result; - } - - /** - * Find a container that refers to the given {@link ContainerTemplate} and that suits the given - * {@link AdaptationScope}. This is the new target. - * - * @param containerTemplate - * @param adaptationScope - * @param targets - * @return - */ - public static Container findSuitableContainer(ContainerTemplate containerTemplate, AdaptationScope adaptationScope, - VariationType targets) { - // Get all containers referring to the template - List<Container> containers = containerTemplate.getReferringContainers(); - List<Entity> variants = ((SetOfConfigurations) targets).getVariants(); - - // Prepare the list of migration targets - List<Container> migrationTargets = new ArrayList<Container>(); - for (Entity entity : variants) { - migrationTargets.add((Container) entity); - } - - for (Container container : containers) { - - // Remove container from migration targets - List<Container> migrationTargetCandidates = excludeSelfContainmentFromTargetList(container, - migrationTargets); - - // If there are migration targets left - if (migrationTargetCandidates.size() > 0) { - switch (adaptationScope) { - case RANDOM: - Random generator = new Random(); - int next = generator.nextInt(containers.size()); - return containers.get(next); - default: - return null; - } - } - } - return null; - } - - /** - * Returns a list of {@code targets} excluding the target the container {@code self} is already - * contained in. - * - * @param self - * @param targets - * @return - */ - public static List<Container> excludeSelfContainmentFromTargetList(Container self, List<Container> targets) { - if (self == null || targets == null) - return null; - - List<Container> resultList = new ArrayList<Container>(); - - for (Container target : targets) { - if (!EcoreUtil.equals(target, self.eContainer())) - resultList.add(target); - } - - return resultList; - } - -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/DmmModelChanger.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/DmmModelChanger.java deleted file mode 100644 index 899d06f659d43a44a12ec16139e3d0f154657b9f..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/DmmModelChanger.java +++ /dev/null @@ -1,304 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.model.dmm.util; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Random; - -import org.apache.log4j.Logger; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EcoreUtil; - -import edu.kit.ipd.descartes.adaptation.exceptions.OperationNotPerformedException; -import edu.kit.ipd.descartes.core.AdaptableEntity; -import edu.kit.ipd.descartes.core.Entity; -import edu.kit.ipd.descartes.core.NamedElement; -import edu.kit.ipd.descartes.mm.adaptation.AdaptationActionOperation; -import edu.kit.ipd.descartes.mm.adaptation.AdaptationDirection; -import edu.kit.ipd.descartes.mm.adaptation.AdaptationScope; -import edu.kit.ipd.descartes.mm.adaptationpoints.ModelVariableConfigurationRange; -import edu.kit.ipd.descartes.mm.containerrepository.ContainerTemplate; -import edu.kit.ipd.descartes.mm.resourceconfiguration.ConfigurationSpecification; -import edu.kit.ipd.descartes.mm.resourceconfiguration.NumberOfParallelProcessingUnits; -import edu.kit.ipd.descartes.mm.resourceconfiguration.ResourceconfigurationPackage; -import edu.kit.ipd.descartes.mm.resourcelandscape.Container; -import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapeFactory; -import edu.kit.ipd.descartes.mm.resourcelandscape.RuntimeEnvironment; -import edu.kit.ipd.descartes.mm.runtimeenvironmentclasses.RuntimeEnvironmentClasses; - -public class DmmModelChanger { - - private static final int FIRST = 0; - - /** - * Denotes a Container as a copy of another by - * adding this mark to its name. - */ - public static final String COPY_MARK = "-Copy"; - - static Logger logger = Logger.getLogger(DmmModelChanger.class); - - /** - * Scales the actual number of a given model variable - * - * @param adaptedEntity - * @param operation - */ - public static void scaleModelVariable(ModelVariableConfigurationRange range, AdaptationDirection direction) - throws OperationNotPerformedException { - - switch (range.getAdaptableEntity().eClass().getClassifierID()) { - case ResourceconfigurationPackage.NUMBER_OF_PARALLEL_PROCESSING_UNITS: - adaptNumberOfCores(range.getAdaptableEntity(), range, direction); - break; - default: - logger.error("SCALING THIS TYPE OF MODEL VARIABLE HAS NOT BEEN IMPLEMENTED YET!"); - break; - } - } - - private static void adaptNumberOfCores(AdaptableEntity adaptedEntity, ModelVariableConfigurationRange range, - AdaptationDirection direction) throws OperationNotPerformedException { - NumberOfParallelProcessingUnits adaptableModelEntity = (NumberOfParallelProcessingUnits) adaptedEntity; - Entity containingEntity = (Entity) adaptableModelEntity.getProcessingResourceSpec().getParentResourceSpecification().eContainer(); - - Integer currentValue = adaptableModelEntity.getNumber(); - Integer maxValue = (int) Math.floor(range.getMaxValue()); - Integer minValue = (int) Math.ceil(range.getMinValue()); - - if (direction == AdaptationDirection.INCREASE) { - // if current value less than max value - if (currentValue < maxValue) { - adaptableModelEntity.setNumber(currentValue + 1); - logger.info("Number of " + containingEntity.getName() + " (ID: " + containingEntity.getId() + ")" + " increased to " - + (currentValue + 1) + "."); - } else - throw new OperationNotPerformedException("Adaptation operation " + direction.getLiteral() - + " for adaptation point " + adaptedEntity.getName() - + " could not be executed because the maximum has been reached"); - } else if (direction == AdaptationDirection.DECREASE) { - // if current value greater than min value - if (currentValue > minValue) { - adaptableModelEntity.setNumber(currentValue - 1); - logger.info("Number of " + containingEntity.getName() + " (ID: " + containingEntity.getId() + ")" + " decreased to " - + (currentValue - 1) + "."); - } else - throw new OperationNotPerformedException("Adaptation operation " + direction.getLiteral() - + " for adaptation point " + adaptedEntity.getName() - + " could not be executed because the minimum has been reached"); - } else - logger.error("Adaptation direction " + direction.getLiteral() + " not defined for " - + adaptedEntity.eClass()); - } - - /** - * Removes the given {@link RuntimeEnvironment} instance - * - * @param runtimeEnvironment - * the {@link RuntimeEnvironment} to remove - * @return - */ - public static RuntimeEnvironment scaleInRuntimeEnvironmentInstance(RuntimeEnvironment runtimeEnvironment) { - List<Container> similarContainers = DmmModelActionHelper.queryContainersWithSimilarTemplate(runtimeEnvironment); - List<RuntimeEnvironment> containedEntities = DmmModelActionHelper.filterAndConvertRuntimeEnvironment(similarContainers); - RuntimeEnvironment similarEntity = DmmModelActionHelper.filterRuntimeEnvironment(containedEntities, runtimeEnvironment); - if (similarEntity != null) { - runtimeEnvironment.getTemplate().getReferringContainers().remove(similarEntity); - similarEntity.getContainedIn().getContains().remove(similarEntity); - logger.info("RuntimeEnvironment " + similarEntity.getName() + " (ID: " + similarEntity.getId() + ") removed."); - } else - logger.error("Could not remove a runtime environment instance because no similar entity has been found."); - - return (RuntimeEnvironment) similarEntity; - } - - /** - * Creates a new {@link RuntimeEnvironment} instance - * - * @param runtimeEnvironment - * the {@link RuntimeEnvironment} to copy - * @return - */ - public static RuntimeEnvironment createNewRuntimeEnvironmentInstance(RuntimeEnvironment runtimeEnvironment) { - RuntimeEnvironment newRuntimeEnvironment = EcoreUtil.copy(runtimeEnvironment); - newRuntimeEnvironment.setId(EcoreUtil.generateUUID()); - newRuntimeEnvironment.setName(newRuntimeEnvironment.getName() + COPY_MARK); - newRuntimeEnvironment.setTemplate(runtimeEnvironment.getTemplate()); - runtimeEnvironment.getTemplate().getReferringContainers().add(newRuntimeEnvironment); - - if (runtimeEnvironment.getConfigSpec().size() > 0) { - newRuntimeEnvironment.getConfigSpec().clear(); - newRuntimeEnvironment.getConfigSpec().addAll(EcoreUtil.copyAll(runtimeEnvironment.getTemplate().getTemplateConfig())); - } - - runtimeEnvironment.getContainedIn().getContains().add(newRuntimeEnvironment); - logger.debug("New RuntimeEnvironment " + newRuntimeEnvironment.getName() + " (ID: " + - newRuntimeEnvironment.getId() + ") to " + - newRuntimeEnvironment.getContainedIn().getName() + " (ID: " + newRuntimeEnvironment.getContainedIn().getId() + ") added." ); - return newRuntimeEnvironment; - } - - /** - * Scales either the model variable if AdaptationScope is set to ALL - * or scales a ModelEntity referring to <code>actuallyConfiguredInstance</code> - * according to the specified <code>operation</code>. - * - * @param actuallyConfiguredInstance - * @param range - * @param operation - * @throws OperationNotPerformedException - */ - public static void scaleContainerTemplate(ContainerTemplate actuallyConfiguredInstance, ModelVariableConfigurationRange range, AdaptationActionOperation operation) throws OperationNotPerformedException { - - Container container = null; - - AdaptationScope scope = operation.getAdaptationOperationScope(); - AdaptationDirection direction = operation.getAdaptationOperationDirection(); - - if (operation.getAdaptationOperationScope() == AdaptationScope.ALL) { - switch (direction) { - case INCREASE : // falls SCALE_UP/DOWN -> Šndere Template - scaleModelVariable(range, direction); - break; - case DECREASE : // falls SCALE_UP/DOWN -> Šndere Template - scaleModelVariable(range, direction); - break; - default : - logger.error(scope.getLiteral() + ", " + direction.getLiteral() + " not defined for " + range.getAdaptableEntity().eClass()); - break; - } - } - - else { - switch (scope) { - case RANDOM: - // pick a random instance referring to this template and - // change its configuration - container = pickRandomReferringContainer(actuallyConfiguredInstance); - break; - case LEAST_UTILIZED_FIRST: - logger.error("NOT IMPLEMENTED YET"); - break; - case MOST_UTILIZED_FIRST: - logger.error("NOT IMPLEMENTED YET"); - break; - default: - logger.error("No adaptation operation defined for " + scope.getLiteral() + ", " - + direction.getLiteral()); - break; - } - if (container != null) - try { - scaleResourceProvidedByContainer(container, range, direction); - } catch (OperationNotPerformedException e) { - logger.error(container.getName() + " could not be adapted. Trying alternative containers."); - scaleResourcesOfAlternativeContainer(range, container, direction); - } - - else - throw new OperationNotPerformedException("No adaptable container found."); - } - } - - private static void scaleResourcesOfAlternativeContainer(ModelVariableConfigurationRange range, Container container, - AdaptationDirection direction) throws OperationNotPerformedException { - Container targetContainer = null; - switch (direction) { - case INCREASE: - targetContainer = DmmModelActionHelper.queryUnfilledRuntimeEnvironment((RuntimeEnvironment) container, range.getMaxValue()); - break; - case DECREASE: - targetContainer = DmmModelActionHelper.queryNotEmptyRuntimeEnvironment((RuntimeEnvironment) container, range.getMinValue()); - break; - default: - logger.error("No corresponding AdaptationDirection found for :" + range + "."); - break; - } - if (targetContainer == null) { - logger.error("No alternative container for adaptation found!"); - throw new OperationNotPerformedException("No alternative container found. Scale operation not performed!"); - } else { - scaleResourceProvidedByContainer(targetContainer, range, direction); - } - } - - - /**Scales the resource (capacity) provided by the container, e.g., - * the number of virtual cores of a VM. - * - * @param container The container to be scaled - * @param range The min and max capacity - * @param direction Specifies if up- or down-scaling - * @throws OperationNotPerformedException - */ - public static void scaleResourceProvidedByContainer(Container container, ModelVariableConfigurationRange range, - AdaptationDirection direction) throws OperationNotPerformedException { - - boolean copyWasCreated = false; - - if (container.getConfigSpec().isEmpty()) // Better check if configSpecs are identical - { - copyTemplateSpecToConfigSpec(container); - copyWasCreated = true; - } - - NamedElement changedElement = getRespectiveAdaptableConfigSpecElement(container, range); - - if (changedElement != null && changedElement instanceof AdaptableEntity) { - AdaptableEntity adaptableEntity = (AdaptableEntity) changedElement; - try { - adaptNumberOfCores(adaptableEntity, range, direction); - // in case operation was not executed, e.g. because min was reached - } catch (OperationNotPerformedException e) { - //undo copy of config spec - if (copyWasCreated) - container.getConfigSpec().clear(); - throw e; - } - } - - // If template and configSpec are identical, remove config spec - if (EcoreUtil.equals(container.getConfigSpec(), container.getTemplate().getTemplateConfig())) - container.getConfigSpec().clear(); - - } - - private static NamedElement getRespectiveAdaptableConfigSpecElement(Container container, - ModelVariableConfigurationRange range) { - NamedElement changedElement = null; - - for (Iterator<ConfigurationSpecification> iterator = container.getConfigSpec().iterator(); iterator.hasNext();) { - ConfigurationSpecification configurationSpecification = (ConfigurationSpecification) iterator.next(); - changedElement = DmmModelActionHelper.findEntityWithName(configurationSpecification, range - .getAdaptableEntity().getName()); - if (!changedElement.equals(null)) - break; - } - return changedElement; - } - - private static void copyTemplateSpecToConfigSpec(Container container) { - Collection<ConfigurationSpecification> copiedList = EcoreUtil.copyAll(container.getTemplate() - .getTemplateConfig()); - container.getConfigSpec().addAll(copiedList); - } - - private static Container pickRandomReferringContainer(ContainerTemplate template) { - Random randomGenerator = new Random(); - EList<Container> containers = template.getReferringContainers(); - int index = randomGenerator.nextInt(containers.size()); - return containers.get(index); - } - - public static RuntimeEnvironment createNewRuntimeEnvironmentInstanceFromTemplate(ContainerTemplate template) { - RuntimeEnvironment newRe = ResourcelandscapeFactory.eINSTANCE.createRuntimeEnvironment(); - newRe.setId(EcoreUtil.generateUUID()); - newRe.setName("RuntimeEnvironmentInstanceOfTemplate_" + template.getName()); - newRe.setTemplate(template); - newRe.setOfClass(RuntimeEnvironmentClasses.MIDDLEWARE); - newRe.setContainedIn(template.getRunningOn().get(FIRST)); - - template.getReferringContainers().add(newRe); - return newRe; - } -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/ObjectivesHelper.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/ObjectivesHelper.java deleted file mode 100644 index 0b57c8a8e347f370f4b8d975922d2c898a3eb831..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/ObjectivesHelper.java +++ /dev/null @@ -1,47 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.model.dmm.util; - -import java.util.List; - -import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.WeightedSumWeightingFunctionHelper; -import edu.kit.ipd.descartes.mm.adaptation.Event; -import edu.kit.ipd.descartes.mm.adaptation.RelationalOperator; -import edu.kit.ipd.descartes.mm.adaptation.Specification; -import edu.kit.ipd.descartes.perfdatarepo.MetricType; -import edu.kit.ipd.descartes.perfdatarepo.Result; - -public class ObjectivesHelper { - - public static boolean compare(double left, double right, RelationalOperator operator) { - switch (operator) { - case EQUAL: - return left == right; - case NOT_EQUAL: - return left != right; - case LESS: - return left < right; - case LESS_EQUAL: - return left <= right; - case GREATER: - return left > right; - case GREATER_EQUAL: - return left >= right; - default: - return false; - } - } - - public static boolean isObjectiveFulfilled(Event event, Result result) { - List<Specification> specs = event.getTriggers().getObjective().getSpecifications(); - for (Specification specification : specs) { - MetricType m = specification.getMetricType(); -// TODO: Connect QueryEngine: Double actualValue = QueryEngineAdapter.getValueForMetricType(m); - Double actualValue = WeightedSumWeightingFunctionHelper.getValueForMetricType(m, result); - Double threshold = specification.getValue(); - if (!ObjectivesHelper.compare(actualValue, threshold, specification.getRelationalOperator())) - return false; - - } - return true; - } - -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/OclEvaluationHelper.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/OclEvaluationHelper.java deleted file mode 100644 index 2a12b5912d1b4beef934581ad3340de7a4784c4b..0000000000000000000000000000000000000000 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/dmm/util/OclEvaluationHelper.java +++ /dev/null @@ -1,89 +0,0 @@ -package edu.kit.ipd.descartes.adaptation.model.dmm.util; - -import java.util.Set; - -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EClassifier; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.ocl.OCL; -import org.eclipse.ocl.ParserException; -import org.eclipse.ocl.Query; -import org.eclipse.ocl.ecore.Constraint; -import org.eclipse.ocl.ecore.EcoreEnvironmentFactory; -import org.eclipse.ocl.expressions.OCLExpression; -import org.eclipse.ocl.helper.OCLHelper; - -/** - * @author nhuber - * - */ -public class OclEvaluationHelper { - - private static Logger logger = Logger.getLogger(OclEvaluationHelper.class); - - /** - * @param checkedObject the checked object - * @param constraint the constraint to evaluate on the object - * @param context the {@link EClass} of the given object - * @return - * {@code true} if check was successful - */ - public static boolean evaluateOclConstraint(EObject checkedObject, String constraint, EClass context) { - Constraint invariant = null; - OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject> ocl; - ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE); - OCLHelper<EClassifier, ?, ?, Constraint> helper = ocl.createOCLHelper(); - - helper.setContext(context); - - try { - invariant = helper.createInvariant(constraint); - } catch (ParserException e) { - logger.error("Error parsing OCL string '" + constraint + "'", e); - return false; - } - - Query<EClassifier, EClass, EObject> eval = ocl.createQuery(invariant); - return eval.check(checkedObject); - } - - - - /** - * Executes the query on a given object. - * - * @param obj the model instance the query is executed on - * @param queryExpression the OCL query - * @param context the eClass of the model instance - * @return - */ - public static Set<EObject> query(EObject obj, String queryExpression, EClassifier context) { - OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject> ocl; - ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE); - OCLHelper<EClassifier, ?, ?, Constraint> helper = ocl.createOCLHelper(); - - helper.setContext(context); - - OCLExpression<EClassifier> query; - try { - query = helper.createQuery(queryExpression); - } catch (ParserException e) { - logger.error("Error parsing OCL query '" + queryExpression + "'", e); - return null; - } - - // create a Query to evaluate our query expression - Query<EClassifier, EClass, EObject> queryEval = ocl.createQuery(query); - - Object result = queryEval.evaluate(obj); - - if (result.toString().contains("invalid")) - return null; - - @SuppressWarnings("unchecked") - Set<EObject> resultList = (Set<EObject>) result; - - return resultList; - } -} diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/ObservationRepositoryHandler.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/ObservationRepositoryHandler.java index 1164bc5606a731a0b39248f6d9d0cd0575d83f3c..02e85323bcf024eb6701e94269380af0937203dc 100644 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/ObservationRepositoryHandler.java +++ b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/ObservationRepositoryHandler.java @@ -6,8 +6,8 @@ import org.apache.log4j.Logger; import org.eclipse.emf.common.util.URI; import edu.kit.ipd.descartes.adaptation.TacticsHistory; -import edu.kit.ipd.descartes.adaptation.model.AbstractEcoreModelLoader; -import edu.kit.ipd.descartes.adaptation.model.dmm.AdaptationProcessModelLoader; +import edu.kit.ipd.descartes.adaptation.modelrepository.AbstractEcoreModelLoader; +import edu.kit.ipd.descartes.adaptation.modelrepository.AdaptationProcessModelLoader; import edu.kit.ipd.descartes.adaptation.util.BlueYonderExperimentTracker; import edu.kit.ipd.descartes.mm.adaptation.WeightedTactic; import edu.kit.ipd.descartes.perfdatarepo.Impact; diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/ObservationRepositoryModelLoader.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/ObservationRepositoryModelLoader.java index c0c567598f25c4dcecd09e9be78d1d0f984090f9..48986fc0cc3d1845c67587569a45e8a851dcc9fb 100644 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/ObservationRepositoryModelLoader.java +++ b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/ObservationRepositoryModelLoader.java @@ -6,7 +6,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; -import edu.kit.ipd.descartes.adaptation.model.AbstractEcoreModelLoader; +import edu.kit.ipd.descartes.adaptation.modelrepository.AbstractEcoreModelLoader; import edu.kit.ipd.descartes.ql.models.repository.RepositoryPackage; public class ObservationRepositoryModelLoader extends AbstractEcoreModelLoader { diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/PerformanceDataRepositoryModelLoader.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/PerformanceDataRepositoryModelLoader.java index ca25ae9f9273f377871fc68555a890375acbd729..0a14f7050054dd7c315c23737c0b75b2c7ac89b2 100644 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/PerformanceDataRepositoryModelLoader.java +++ b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/model/perfdatarepo/PerformanceDataRepositoryModelLoader.java @@ -7,7 +7,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; -import edu.kit.ipd.descartes.adaptation.model.AbstractEcoreModelLoader; +import edu.kit.ipd.descartes.adaptation.modelrepository.AbstractEcoreModelLoader; import edu.kit.ipd.descartes.perfdatarepo.PerfdatarepoPackage; import edu.kit.ipd.descartes.perfdatarepo.PerformanceDataRepository; diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/util/BlueYonderExperimentTracker.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/util/BlueYonderExperimentTracker.java index 14dc5362f900c52f69131798c84ca17bf4e967ab..8b0bc49ad1cf17b931d2a3968304d454cbcd9029 100644 --- a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/util/BlueYonderExperimentTracker.java +++ b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/util/BlueYonderExperimentTracker.java @@ -7,8 +7,8 @@ import edu.kit.ipd.descartes.mm.resourcelandscape.DistributedDataCenter; public class BlueYonderExperimentTracker implements IObserver { - private static final String RESULT_NAME_TEMPLATE = "Xreq-par-$1Yps-desc4-gw-desc3-db-desc2-predict-Z ps=$2-req=5-size=50000"; -// private static final String RESULT_NAME_TEMPLATE = "Xreq-par-$1$3Yps-desc4-gw-desc3-db-desc2-predict-Z ps=$2-req=40-size=500000"; +// private static final String RESULT_NAME_TEMPLATE = "Xreq-par-$1Yps-desc4-gw-desc3-db-desc2-predict-Z ps=$2-req=5-size=50000"; + private static final String RESULT_NAME_TEMPLATE = "Xreq-par-$1$3Yps-desc4-gw-desc3-db-desc2-predict-Z ps=$2-req=40-size=500000"; // private static final String RESULT_NAME_TEMPLATE = "Xreq-par-$1$3Yps-desc4-gw-desc3-db-desc2-predict-Z ps=$2-req=30-size=500000"; private static BlueYonderExperimentTracker instance = null; private int psOnDescOne = 0;