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

added log messages for tactic execution

removed log messages for adaptationPlan

git-svn-id: https://se1.informatik.uni-wuerzburg.de/usvn/svn/code/code/DMM/trunk@12188 9e42b895-fcda-4063-8a3b-11be15eb1bbd
parent baf8443a
No related branches found
No related tags found
No related merge requests found
...@@ -31,20 +31,21 @@ import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapePackage; ...@@ -31,20 +31,21 @@ import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapePackage;
public class TacticExecutor { public class TacticExecutor {
private static Logger logger = Logger.getLogger(TacticExecutor.class); private static Logger logger = Logger.getLogger(TacticExecutor.class);
private List<IObserver> observers = new ArrayList<IObserver>(); private List<IObserver> observers = new ArrayList<IObserver>();
private IActionHandler dmmModelActionHandler; private IActionHandler dmmModelActionHandler;
private TacticsHistory hist; private TacticsHistory hist;
private ChangeDescription changeDescription = null; private ChangeDescription changeDescription = null;
public TacticExecutor(IActionHandler actionExecutor) { public TacticExecutor(IActionHandler actionExecutor) {
dmmModelActionHandler = actionExecutor; dmmModelActionHandler = actionExecutor;
hist = TacticsHistory.getInstance(); hist = TacticsHistory.getInstance();
register(BlueYonderExperimentTracker.getInstance()); // TODO implement clean observer pattern register(BlueYonderExperimentTracker.getInstance()); // TODO implement clean observer
} // pattern
}
/**
/**
* Applies the the given tactic. * Applies the the given tactic.
* *
* @param currentTactic * @param currentTactic
...@@ -52,38 +53,37 @@ public class TacticExecutor { ...@@ -52,38 +53,37 @@ public class TacticExecutor {
* @return * @return
*/ */
public void applyTactic(WeightedTactic weightedTactic) { public void applyTactic(WeightedTactic weightedTactic) {
try { try {
AdaptationProcessModelLoader.startRecording(); logger.info("Applying tactic " + weightedTactic.getUsedTactic().getName() + ", ID: "
+ weightedTactic.getUsedTactic().getId() + ".");
AdaptationProcessModelLoader.startRecording();
executeAdaptationPlan(weightedTactic.getUsedTactic().getImplementedPlan()); executeAdaptationPlan(weightedTactic.getUsedTactic().getImplementedPlan());
logger.info("Tactic " + weightedTactic.getUsedTactic().getName() logger.info("Tactic " + weightedTactic.getUsedTactic().getName() + " successfully applied.");
+ " successfully applied.");
hist.add(weightedTactic, TacticsHistory.NO_RESULT, true); hist.add(weightedTactic, TacticsHistory.NO_RESULT, true);
// if this point is reached everything was fine, so persist them (save the models) // if this point is reached everything was fine, so persist them (save the models)
dmmModelActionHandler.persistActions(); dmmModelActionHandler.persistActions();
changeDescription = AdaptationProcessModelLoader.endRecording(); changeDescription = AdaptationProcessModelLoader.endRecording();
return; return;
} catch (OperationNotPerformedException e) { } catch (OperationNotPerformedException e) {
logger.error("Tactic " + weightedTactic.getUsedTactic().getName() logger.error("Tactic " + weightedTactic.getUsedTactic().getName()
+ " could not be executed. Please check adaptation plan and/or log files for errors.", e); + " could not be executed. Please check adaptation plan and/or log files for errors.", e);
hist.add(weightedTactic, TacticsHistory.NO_RESULT, false); hist.add(weightedTactic, TacticsHistory.NO_RESULT, false);
/* /*
* TODO Something went wrong. * TODO Something went wrong. 1) Detect error 2) reevaluate tactics 3) apply different
* 1) Detect error * tactic.
* 2) reevaluate tactics
* 3) apply different tactic.
*/ */
} }
} }
private StartAction findStartAction(AdaptationPlan plan) { private StartAction findStartAction(AdaptationPlan plan) {
for (AbstractControlFlowElement abstractControlFlowElement : plan.getSteps()) { for (AbstractControlFlowElement abstractControlFlowElement : plan.getSteps()) {
// Find start of adaptation plan // Find start of adaptation plan
if (abstractControlFlowElement instanceof StartAction) { if (abstractControlFlowElement instanceof StartAction) {
return (StartAction) abstractControlFlowElement; return (StartAction) abstractControlFlowElement;
} }
} }
return null; return null;
} }
/** /**
...@@ -97,50 +97,49 @@ public class TacticExecutor { ...@@ -97,50 +97,49 @@ public class TacticExecutor {
private void executeAdaptationPlan(AdaptationPlan plan) throws OperationNotPerformedException { private void executeAdaptationPlan(AdaptationPlan plan) throws OperationNotPerformedException {
StartAction start = findStartAction(plan); StartAction start = findStartAction(plan);
if (start == null) if (start == null)
throw new OperationNotPerformedException("No start action for adaptation plan " + plan.getName() + " found."); throw new OperationNotPerformedException("No start action for adaptation plan " + plan.getName()
+ " found.");
logger.info("Executing the adaptation plan <<" + plan.getName() + ">>.");
try { try {
executeNextStep(start.getSuccessor()); executeNextStep(start.getSuccessor());
} catch (InvalidAdaptationPlan e) { } catch (InvalidAdaptationPlan e) {
logger.error("Invalid adaptation plan <<" + plan.getName() + ">> when executing action with ID <<" + start.getId() + ">>.", e); logger.error(
"Invalid adaptation plan <<" + plan.getName() + ">> when executing action with ID <<"
+ start.getId() + ">>.", e);
} }
logger.info("Adaptation plan of adaptation plan <<" + plan.getName() + ">> terminated.");
} }
private void executeNextStep(AbstractControlFlowElement step) private void executeNextStep(AbstractControlFlowElement step) throws OperationNotPerformedException,
throws OperationNotPerformedException, InvalidAdaptationPlan { InvalidAdaptationPlan {
if (step == null) if (step == null)
throw new InvalidAdaptationPlan("Current AbstractControlFlowElement is null!"); throw new InvalidAdaptationPlan("Current AbstractControlFlowElement is null!");
if (step instanceof StopAction) { if (step instanceof StopAction) {
return; return;
} else if (step instanceof BranchAction) { } else if (step instanceof BranchAction) {
executeBranchAction(step); executeBranchAction(step);
} else if (step instanceof LoopAction) { } else if (step instanceof LoopAction) {
execLoopAction(step); execLoopAction(step);
} else if (step instanceof ActionReference) { } else if (step instanceof ActionReference) {
executeReferredAction(step); executeReferredAction(step);
} else // Handle invalid actions and control flow elements } else
throw new OperationNotPerformedException( // Handle invalid actions and control flow elements
"No valid control flow element " + step.toString()); throw new OperationNotPerformedException("No valid control flow element " + step.toString());
// in any case (except stop action) // in any case (except stop action)
// continue with the next step // continue with the next step
executeNextStep(step.getSuccessor()); executeNextStep(step.getSuccessor());
} }
private void executeReferredAction(AbstractControlFlowElement step) throws OperationNotPerformedException { private void executeReferredAction(AbstractControlFlowElement step) throws OperationNotPerformedException {
ActionReference ref = (ActionReference) step; ActionReference ref = (ActionReference) step;
Action action = ref.getRefersTo(); Action action = ref.getRefersTo();
logger.info("Executing action <<" + action.getName() + ">>."); logger.info("Executing action <<" + action.getName() + ">>.");
AdaptationPoint currentAdaptationPoint = action AdaptationPoint currentAdaptationPoint = action.getReferredAdaptationPoint();
.getReferredAdaptationPoint();
dmmModelActionHandler.execute(currentAdaptationPoint, action.getAdaptationActionOperation());
dmmModelActionHandler.execute(currentAdaptationPoint,
action.getAdaptationActionOperation());
} }
private void executeBranchAction(AbstractControlFlowElement branchAction) throws OperationNotPerformedException { private void executeBranchAction(AbstractControlFlowElement branchAction) throws OperationNotPerformedException {
...@@ -155,9 +154,9 @@ public class TacticExecutor { ...@@ -155,9 +154,9 @@ public class TacticExecutor {
LoopAction loop = (LoopAction) loopAction; LoopAction loop = (LoopAction) loopAction;
Parameter counter = loop.getCounter(); Parameter counter = loop.getCounter();
int counterValue = Integer.parseInt(counter.getValue()); int counterValue = Integer.parseInt(counter.getValue());
int i = 1; int i = 1;
while (i <= counterValue) { while (i <= counterValue) {
logger.debug("Executing iteration " + i + " of loop action " + loop.getBody().getName()); logger.debug("Executing iteration " + i + " of loop action " + loop.getBody().getName());
executeAdaptationPlan(loop.getBody()); executeAdaptationPlan(loop.getBody());
...@@ -176,7 +175,7 @@ public class TacticExecutor { ...@@ -176,7 +175,7 @@ public class TacticExecutor {
case ContainerrepositoryPackage.CONTAINER_TEMPLATE: case ContainerrepositoryPackage.CONTAINER_TEMPLATE:
context = ContainerrepositoryPackage.Literals.CONTAINER_TEMPLATE; context = ContainerrepositoryPackage.Literals.CONTAINER_TEMPLATE;
break; break;
// TODO add further contexts if necessary // TODO add further contexts if necessary
default: default:
logger.error("Could not set context for eClass " + obj.getClass()); logger.error("Could not set context for eClass " + obj.getClass());
return false; return false;
...@@ -188,16 +187,16 @@ public class TacticExecutor { ...@@ -188,16 +187,16 @@ public class TacticExecutor {
public void undoPreviousTactic() { public void undoPreviousTactic() {
logger.info("Reverting model to previous state"); logger.info("Reverting model to previous state");
for(IObserver o : observers) for (IObserver o : observers)
o.undo(); o.undo();
if (changeDescription != null) if (changeDescription != null)
changeDescription.apply(); changeDescription.apply();
} }
public void register(IObserver observer) { public void register(IObserver observer) {
observers.add(observer); observers.add(observer);
} }
public void remove(IObserver observer) { public void remove(IObserver observer) {
observers.remove(observer); observers.remove(observer);
} }
......
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