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

git-svn-id: https://se1.informatik.uni-wuerzburg.de/usvn/svn/code/code/DMM/trunk@12063 9e42b895-fcda-4063-8a3b-11be15eb1bbd
parent d6464682
No related branches found
No related tags found
No related merge requests found
......@@ -118,8 +118,8 @@ public class AdaptationControl {
applyTactic(currentTactic);
analyzeModel();
processResults(currentTactic);
evaluate(currentTactic);
processResults();
evaluate();
// save results
try {
......@@ -174,14 +174,17 @@ public class AdaptationControl {
*
* @param tactic
*/
public void processResults(WeightedTactic tactic) {
public void processResults() {
// Impact latestImpact = perfDataRepoHandler.getImpactAt(iteration);
Impact latestImpact = perfDataRepoHandler.getLatestImpact(tactic);
WeightedTactic tactic = TacticsHistory.getInstance().getLatestAppliedTactic();
// Connect parsed results to the executed tactic
if (latestImpact != null)
tactic.setLastImpact(latestImpact);
if (TacticsHistory.getInstance().wasLatestTacticSuccessful()) {
Impact latestImpact = perfDataRepoHandler.getLatestImpact(tactic);
if (latestImpact != null)
tactic.setLastImpact(latestImpact);
} else {
// Do nothing, impact will be evaluated in the evaluation phase.
}
}
/**
......@@ -190,17 +193,26 @@ public class AdaptationControl {
*
* @param tactic
*/
public void evaluate(WeightedTactic tactic) {
// Check if tactic has made anything stupid, i.e., violates the objectives. If yes, undo
// and/or assign bad weight.
if (evaluator.degradationDetected(tactic)) {
logger.warn("Degradation detected for tactic " + tactic.getName());
// undo tactic
// assign negative weight
public void evaluate() {
WeightedTactic tactic = TacticsHistory.getInstance().getLatestAppliedTactic();
if (TacticsHistory.getInstance().wasLatestTacticSuccessful()) {
// Check if tactic has made anything stupid, i.e., violates the objectives. If yes, undo
// and/or assign bad weight.
if (evaluator.degradationDetected(tactic)) {
logger.warn("Degradation detected for tactic " + tactic.getName());
// undo tactic
// assign negative weight
}
// If everything is fine, assign new weight.
evaluator.evaluate(tactic);
} else {
evaluator.punishTactic(tactic);
}
// If everything is fine, assign new weight.
evaluator.evaluate(tactic);
}
/**
......
......@@ -54,7 +54,6 @@ public class TacticExecutor {
} catch (OperationNotPerformedException e) {
logger.error("Tactic " + weightedTactic.getUsedTactic().getName()
+ " could not be executed. Please check adaptation plan and/or log files for errors.", e);
weightedTactic.setCurrentWeight(0.0);
hist.add(weightedTactic, TacticsHistory.NO_RESULT, false);
/*
* TODO Something went wrong.
......
......@@ -26,4 +26,11 @@ public interface IEvaluator {
*/
public boolean degradationDetected(WeightedTactic tactic);
/**
* Reduces the weight of the given tactic.
*
* @param tactic
*/
public void punishTactic(WeightedTactic tactic);
}
......@@ -76,4 +76,10 @@ public class WeightingFunctionEvaluator implements IEvaluator {
return false;
}
@Override
public void punishTactic(WeightedTactic tactic) {
tactic.setCurrentWeight(0.0);
}
}
......@@ -11,6 +11,7 @@ import org.eclipse.emf.ecore.EPackage;
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;
......@@ -24,11 +25,8 @@ 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 };
public static final EPackage[] DMM_EPACKAGES = new EPackage[] { ResourcelandscapePackage.eINSTANCE,
AdaptationpointsPackage.eINSTANCE, ContainerrepositoryPackage.eINSTANCE, AdaptationPackage.eINSTANCE };
private static AdaptationProcessModelLoader instance = null;
......@@ -52,14 +50,21 @@ public class AdaptationProcessModelLoader extends AbstractEcoreModelLoader {
options.put(XMIResource.OPTION_PROCESS_DANGLING_HREF, XMIResource.OPTION_PROCESS_DANGLING_HREF_THROW);
for (Resource res : resources) {
res.save(options);
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());
......
......@@ -7,7 +7,6 @@ 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 org.eclipse.emf.ecore.xmi.DanglingHREFException;
import edu.kit.ipd.descartes.adaptation.IActionHandler;
import edu.kit.ipd.descartes.adaptation.exceptions.OperationNotPerformedException;
......@@ -45,20 +44,17 @@ public class DmmModelActionHandler implements IActionHandler {
try {
adaptProcessModelMgr.saveAll();
} catch (IOException e) {
if (e.getCause() instanceof DanglingHREFException)
logger.error("Error while persisting results because of dangling references. Probably not all changes have been saved");
else
logger.error("Error while saving models", e);
logger.error("Error while saving models", e);
}
}
@Override
public void execute(AdaptationPoint point, AdaptationActionOperation operation) throws OperationNotPerformedException {
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() + ">>.");
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");
......@@ -84,7 +80,8 @@ public class DmmModelActionHandler implements IActionHandler {
DmmModelChanger.scaleModelVariable(configRange, operation.getAdaptationOperationDirection());
break;
case ContainerrepositoryPackage.CONTAINER_TEMPLATE:
DmmModelChanger.scaleContainerTemplate((ContainerTemplate) actuallyConfiguredInstance, configRange, operation);
DmmModelChanger.scaleContainerTemplate((ContainerTemplate) actuallyConfiguredInstance, configRange,
operation);
break;
case ResourcelandscapePackage.CONTAINER:
/*
......@@ -128,51 +125,54 @@ public class DmmModelActionHandler implements IActionHandler {
logger.debug("Executing DECREASE operation");
Entity scaledEntity = scaleIn(adaptableEntity);
if (scaledEntity == null)
throw new OperationNotPerformedException("Could not scale " + adaptableEntity.getName() + ". Minimum has been reached!");
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());
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() + ")");
logger.debug("Scaling entity " + scaledRE.getName() + " on altenative container "
+ nextContainer.getName() + " (ID: " + nextContainer.getId() + ")");
return;
}
}
// in case a violation occured but no alternative
// container was found, print
scaledRE.getContainedIn().getContains().remove(scaledRE);
throw new OperationNotPerformedException("Could not scale " + adaptableEntity.getName() + ". Maxiumum has been reached!");
}
// 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");
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) {
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() + ")");
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
......@@ -182,7 +182,7 @@ public class DmmModelActionHandler implements IActionHandler {
throw new IllegalArgumentException(
"Migration could not be performed because no target specification found!");
EList<Entity> migrationTargets = ((SetOfConfigurations) targets).getVariants();
RuntimeEnvironment migratedEntity = (RuntimeEnvironment) adaptableEntity;
Container parent = migratedEntity.getContainedIn();
// TODO Here you could implement something more sophisticated
......@@ -198,7 +198,8 @@ public class DmmModelActionHandler implements IActionHandler {
parent.getContains().remove(migratedEntity);
break;
case ContainerrepositoryPackage.CONTAINER_TEMPLATE:
logger.debug("Starting migration of a container referring to container template " + adaptableEntity.getName() + " (ID: " + adaptableEntity.getId() + ")");
logger.debug("Starting migration of a container referring to container template "
+ adaptableEntity.getName() + " (ID: " + adaptableEntity.getId() + ")");
ContainerTemplate ct = (ContainerTemplate) adaptableEntity;
Container c = DmmModelActionHelper.findSuitableContainer(ct, adaptationScope);
migrate(c, targets, adaptationScope);
......@@ -264,18 +265,20 @@ public class DmmModelActionHandler implements IActionHandler {
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.
/**
* 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.");
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);
......
......@@ -107,7 +107,7 @@ public class DmmModelChanger {
similarEntity.getContainedIn().getContains().remove(similarEntity);
logger.info("RuntimeEnvironment " + similarEntity.getName() + " (ID: " + similarEntity.getId() + ") removed.");
} else
logger.error("Could not remove a runtime environment instance since no similar entity has been found.");
logger.error("Could not remove a runtime environment instance because no similar entity has been found.");
return (RuntimeEnvironment) similarEntity;
}
......
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