Skip to content
Snippets Groups Projects
Commit 0b3aa2db authored by Nikolaus Huber's avatar Nikolaus Huber
Browse files

refactorings

git-svn-id: https://se1.informatik.uni-wuerzburg.de/usvn/svn/code/code/DMM/trunk@11548 9e42b895-fcda-4063-8a3b-11be15eb1bbd
parent 2d92fd36
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,6 @@ import org.apache.log4j.Level; ...@@ -9,7 +9,6 @@ import org.apache.log4j.Level;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.URI; 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.evaluation.WeightingFunctionEvaluator;
import edu.kit.ipd.descartes.adaptation.model.analysis.IModelAnalyzer; 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.analysis.pcm.PcmModelAnalyzer;
...@@ -22,7 +21,6 @@ import edu.kit.ipd.descartes.mm.adaptation.AdaptationProcess; ...@@ -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.Event;
import edu.kit.ipd.descartes.mm.adaptation.Strategy; import edu.kit.ipd.descartes.mm.adaptation.Strategy;
import edu.kit.ipd.descartes.mm.adaptation.WeightedTactic; 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.Impact;
import edu.kit.ipd.descartes.perfdatarepo.PerformanceDataRepository; import edu.kit.ipd.descartes.perfdatarepo.PerformanceDataRepository;
...@@ -94,33 +92,88 @@ public class AdaptationControl { ...@@ -94,33 +92,88 @@ public class AdaptationControl {
adaptationController.doAdaptation(triggeringEvent); adaptationController.doAdaptation(triggeringEvent);
} }
private void loadProperties(String propertiesFilePath) throws IOException { public void doAdaptation(Event triggeringEvent) {
Properties properties = new Properties();
FileInputStream propFile = new FileInputStream(propertiesFilePath); // Determine the suitable strategy via the objective
properties.load(propFile); // which is currently implemented as the first element
logger.debug("Loaded properties of " + properties.getProperty(PROP_ADAPTATION_PROCESS_NAME)); Strategy currentStrategy = AdaptationControl.findTriggeredStrategy(adaptationProcess, triggeringEvent);
adaptationProcessXmiFilePath = properties.getProperty(PROP_ADAPTATION_PROCESS_XMI_FILE_PATH_NAME); if (currentStrategy == null) {
performanceDataRepoXmiFilePath = properties.getProperty(PROP_PERF_DATA_REPO_XMI_FILE_PATH_NAME); logger.error("No strategy found to handle this event!");
maxIterations = Integer.parseInt(properties.getProperty(PROP_MAX_ITERATIONS)); abort();
eventType = properties.getProperty(PROP_TRIGGERING_EVENT_TYPE).trim(); return;
logger.debug("Maximum iterations till abort: " + maxIterations); }
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() { public void init() {
try { try {
// load properties file
loadProperties(DEFAULT_PROP_FILE_PATH); loadProperties(DEFAULT_PROP_FILE_PATH);
// load required models
adaptationProcess = adaptationProcessModelManager.load(URI.createFileURI(adaptationProcessXmiFilePath)); adaptationProcess = adaptationProcessModelManager.load(URI.createFileURI(adaptationProcessXmiFilePath));
perfDataRepo = perfDataModelManager.load(URI.createFileURI(performanceDataRepoXmiFilePath)); perfDataRepo = perfDataModelManager.load(URI.createFileURI(performanceDataRepoXmiFilePath));
// set handlers
executor = new TacticExecutor(new DmmModelActionHandler()); executor = new TacticExecutor(new DmmModelActionHandler());
modelAnalyzer = new PcmModelAnalyzer(); modelAnalyzer = new PcmModelAnalyzer();
evaluator = new WeightingFunctionEvaluator(); evaluator = new WeightingFunctionEvaluator();
} catch (IOException e) { } catch (IOException e) {
logger.error("Error while loading configuration files", e); logger.error("Error while initializinig controller.", e);
abort(); 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 // Creates an "artifical event". Will be replaced later when integrated in the system
private Event createTriggeringEvent() { private Event createTriggeringEvent() {
EventType type = EventType.getEventType(eventType); EventType type = EventType.getEventType(eventType);
...@@ -137,46 +190,6 @@ public class AdaptationControl { ...@@ -137,46 +190,6 @@ public class AdaptationControl {
return triggeringEvent; 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) { private void processResults(WeightedTactic tactic) {
Impact latestImpact = PerfDataRepoHelper.getImpactAt(perfDataRepo, iteration); Impact latestImpact = PerfDataRepoHelper.getImpactAt(perfDataRepo, iteration);
// Connect parsed results to the executed tactic // Connect parsed results to the executed tactic
...@@ -221,20 +234,4 @@ public class AdaptationControl { ...@@ -221,20 +234,4 @@ public class AdaptationControl {
return null; 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();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment