From 0b3aa2dbd2b36b4159bfcc24adaf8af6addc2d63 Mon Sep 17 00:00:00 2001 From: Nikolaus Huber <nikolaus.huber@uni-wuerzburg.de> Date: Tue, 14 May 2013 13:05:25 +0000 Subject: [PATCH] refactorings git-svn-id: https://se1.informatik.uni-wuerzburg.de/usvn/svn/code/code/DMM/trunk@11548 9e42b895-fcda-4063-8a3b-11be15eb1bbd --- .../adaptation/AdaptationControl.java | 137 +++++++++--------- 1 file changed, 67 insertions(+), 70 deletions(-) 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 3f4f3995..87ac5dc7 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 @@ -9,7 +9,6 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.eclipse.emf.common.util.URI; -import edu.kit.ipd.descartes.adaptation.evaluation.IEvaluator; import edu.kit.ipd.descartes.adaptation.evaluation.WeightingFunctionEvaluator; import edu.kit.ipd.descartes.adaptation.model.analysis.IModelAnalyzer; import edu.kit.ipd.descartes.adaptation.model.analysis.pcm.PcmModelAnalyzer; @@ -22,7 +21,6 @@ import edu.kit.ipd.descartes.mm.adaptation.AdaptationProcess; import edu.kit.ipd.descartes.mm.adaptation.Event; import edu.kit.ipd.descartes.mm.adaptation.Strategy; 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.PerformanceDataRepository; @@ -94,33 +92,88 @@ public class AdaptationControl { adaptationController.doAdaptation(triggeringEvent); } - private void loadProperties(String propertiesFilePath) throws IOException { - Properties properties = new Properties(); - FileInputStream propFile = new FileInputStream(propertiesFilePath); - properties.load(propFile); - logger.debug("Loaded properties of " + properties.getProperty(PROP_ADAPTATION_PROCESS_NAME)); - adaptationProcessXmiFilePath = properties.getProperty(PROP_ADAPTATION_PROCESS_XMI_FILE_PATH_NAME); - performanceDataRepoXmiFilePath = properties.getProperty(PROP_PERF_DATA_REPO_XMI_FILE_PATH_NAME); - maxIterations = Integer.parseInt(properties.getProperty(PROP_MAX_ITERATIONS)); - eventType = properties.getProperty(PROP_TRIGGERING_EVENT_TYPE).trim(); - logger.debug("Maximum iterations till abort: " + maxIterations); + public void doAdaptation(Event triggeringEvent) { + + // Determine the suitable strategy via the objective + // which is currently implemented as the first element + Strategy currentStrategy = AdaptationControl.findTriggeredStrategy(adaptationProcess, triggeringEvent); + if (currentStrategy == null) { + logger.error("No strategy found to handle this event!"); + abort(); + return; + } + + while (!isProblemSolved() && iteration < maxIterations) { + // Execute the strategie's tactic with the currently highest weight + WeightedTactic currentTactic = currentStrategy.getTacticWithHighestWeight(); + + applyTactic(currentTactic); + analyzeModel(); + processResults(currentTactic); + evaluator.evaluate(currentTactic); + + // save results + try { + logger.debug("Saving tactics evaluation results..."); + adaptationProcessModelManager.saveAll(); + } catch (IOException e) { + logger.error("Error while persisting evaluation results.", e); + } + + iteration++; + } + + printLogInformation(); + } public void init() { try { + // load properties file loadProperties(DEFAULT_PROP_FILE_PATH); + + // load required models adaptationProcess = adaptationProcessModelManager.load(URI.createFileURI(adaptationProcessXmiFilePath)); perfDataRepo = perfDataModelManager.load(URI.createFileURI(performanceDataRepoXmiFilePath)); + + // set handlers executor = new TacticExecutor(new DmmModelActionHandler()); modelAnalyzer = new PcmModelAnalyzer(); evaluator = new WeightingFunctionEvaluator(); } catch (IOException e) { - logger.error("Error while loading configuration files", e); + logger.error("Error while initializinig controller.", e); abort(); - return; } } + /** + * Graceful stop the adaptation process. + */ + public void stop() { + logger.info("Stopping adaptation process"); + return; + } + + /** + * Aborts the adaptation process because of errors + */ + public void abort() { + logger.error("Stopping adaptation process due to errors."); + stop(); + } + + private void loadProperties(String propertiesFilePath) throws IOException { + Properties properties = new Properties(); + FileInputStream propFile = new FileInputStream(propertiesFilePath); + properties.load(propFile); + logger.debug("Loaded properties of " + properties.getProperty(PROP_ADAPTATION_PROCESS_NAME)); + adaptationProcessXmiFilePath = properties.getProperty(PROP_ADAPTATION_PROCESS_XMI_FILE_PATH_NAME); + performanceDataRepoXmiFilePath = properties.getProperty(PROP_PERF_DATA_REPO_XMI_FILE_PATH_NAME); + maxIterations = Integer.parseInt(properties.getProperty(PROP_MAX_ITERATIONS)); + eventType = properties.getProperty(PROP_TRIGGERING_EVENT_TYPE).trim(); + logger.debug("Maximum iterations till abort: " + maxIterations); + } + // Creates an "artifical event". Will be replaced later when integrated in the system private Event createTriggeringEvent() { EventType type = EventType.getEventType(eventType); @@ -137,46 +190,6 @@ public class AdaptationControl { return triggeringEvent; } - public void doAdaptation(Event triggeringEvent) { - - // Determine the suitable strategy via the objective - // which is currently implemented as the first element - Strategy currentStrategy = AdaptationControl.findTriggeredStrategy(adaptationProcess, triggeringEvent); - if (currentStrategy == null) { - logger.error("No strategy found to handle this event!"); - abort(); - return; - } - - while (!isProblemSolved() && iteration < maxIterations) { - // Execute the strategie's tactic with the currently highest weight - WeightedTactic currentTactic = currentStrategy.getTacticWithHighestWeight(); - - applyTactic(currentTactic); - analyzeModel(); - processResults(currentTactic); - evaluate(currentTactic); - - // save results - try { - logger.debug("Saving tactics evaluation results..."); - adaptationProcessModelManager.saveAll(); - } catch (IOException e) { - logger.error("Error while persisting evaluation results.", e); - } - - iteration++; - } - - printLogInformation(); - - } - - private void evaluate(WeightedTactic currentTactic) { - WeightingFunction f = currentTactic.getParentStrategy().getWeightingFunction(); - evaluator.evaluate(currentTactic); - } - private void processResults(WeightedTactic tactic) { Impact latestImpact = PerfDataRepoHelper.getImpactAt(perfDataRepo, iteration); // Connect parsed results to the executed tactic @@ -221,20 +234,4 @@ public class AdaptationControl { return null; } - - /** - * Graceful stop the adaptation process. - */ - public void stop() { - logger.info("Stopping adaptation process"); - return; - } - - /** - * Aborts the adaptation process because of errors - */ - public void abort() { - logger.error("Stopping adaptation process due to errors."); - stop(); - } } -- GitLab