use of org.btrplace.scheduler.choco.transition.NodeTransition in project scheduler by btrplace.
the class CPowerView method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
powerStarts = new TIntObjectHashMap<>(rp.getNodes().size());
powerEnds = new TIntObjectHashMap<>(rp.getNodes().size());
for (Node n : rp.getNodes()) {
NodeTransition na = rp.getNodeAction(n);
if (na instanceof ShutdownableNode) {
powerStarts.put(rp.getNode(n), rp.getStart());
IntVar powerEnd = rp.makeUnboundedDuration("NodeActionType(", n, ").Pe");
TaskMonitor.build(na.getHostingEnd(), na.getDuration(), powerEnd);
powerEnds.put(rp.getNode(n), powerEnd);
rp.getModel().post(rp.getModel().arithm(powerEnd, "<=", rp.getEnd()));
} else if (na instanceof BootableNode) {
powerStarts.put(rp.getNode(n), na.getStart());
powerEnds.put(rp.getNode(n), rp.getEnd());
}
}
return true;
}
use of org.btrplace.scheduler.choco.transition.NodeTransition in project scheduler by btrplace.
the class COffline method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
if (cstr.isContinuous() && !cstr.getChecker().startsWith(rp.getSourceModel())) {
rp.getLogger().debug("Constraint {} is not satisfied initially", cstr);
return false;
}
Node nId = cstr.getInvolvedNodes().iterator().next();
int id = rp.getNode(nId);
NodeTransition m = rp.getNodeAction(nId);
try {
m.getState().instantiateTo(0, Cause.Null);
if (rp.getSourceModel().getMapping().isOffline(nId)) {
m.getStart().instantiateTo(0, Cause.Null);
}
} catch (ContradictionException ex) {
rp.getLogger().debug("Unable to force node '" + nId + "' at being offline", ex);
return false;
}
for (VMTransition am : rp.getVMActions()) {
Slice s = am.getDSlice();
if (s != null) {
try {
s.getHoster().removeValue(id, Cause.Null);
} catch (ContradictionException e) {
rp.getLogger().debug("Unable to remove " + am.getVM() + " of node " + nId, e);
}
}
}
return true;
}
use of org.btrplace.scheduler.choco.transition.NodeTransition in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testNodeOn.
@Test
public void testNodeOn() throws SchedulerException {
Model mo = new DefaultModel();
Mapping m = mo.getMapping();
Node n1 = mo.newNode();
m.addOnlineNode(n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
NodeTransition a = rp.getNodeActions().get(0);
Assert.assertEquals(a, rp.getNodeAction(n1));
Assert.assertEquals(ShutdownableNode.class, a.getClass());
}
use of org.btrplace.scheduler.choco.transition.NodeTransition in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testNodeOff.
@Test
public void testNodeOff() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
map.addSleepingVM(vm4, n2);
map.addReadyVM(vm5);
map.addReadyVM(vm6);
Mapping m = mo.getMapping();
m.addOfflineNode(n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
NodeTransition a = rp.getNodeActions().get(rp.getNode(n3));
Assert.assertEquals(a, rp.getNodeAction(n3));
Assert.assertEquals(BootableNode.class, a.getClass());
}
use of org.btrplace.scheduler.choco.transition.NodeTransition in project scheduler by btrplace.
the class CMinMTTRMig method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
this.rp = rp;
List<IntVar> endVars = new ArrayList<>();
// Define the cost constraint: sum of all actions' end time
for (VMTransition m : rp.getVMActions()) {
endVars.add(m.getEnd());
}
for (NodeTransition m : rp.getNodeActions()) {
endVars.add(m.getEnd());
}
IntVar[] costs = endVars.toArray(new IntVar[endVars.size()]);
IntVar cost = rp.getModel().intVar(rp.makeVarLabel("costEndVars"), 0, Integer.MAX_VALUE / 100, true);
costConstraints.add(rp.getModel().sum(costs, "=", cost));
// Set the objective, minimize the cost
rp.setObjective(true, cost);
// Inject the scheduling heuristic
injectSchedulingHeuristic(cost);
// Post the cost constraint
postCostConstraints();
return true;
}
Aggregations