use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMRunningToSleeping.
@Test
public void testVMRunningToSleeping() 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.addOnlineNode(n1);
m.addRunningVM(vm1, n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), new HashSet<>(), Collections.singleton(vm1), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(0);
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(SuspendVM.class, a.getClass());
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMSleepToRun.
@Test
public void testVMSleepToRun() 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.addOnlineNode(n1);
m.addSleepingVM(vm1, n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), Collections.singleton(vm1), new HashSet<>(), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(0);
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(ResumeVM.class, a.getClass());
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class IssuesTest method issue33.
@Test
public void issue33() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Node n = mo.newNode();
VM v = mo.newVM();
mo.getMapping().addOnlineNode(n);
mo.getMapping().addRunningVM(v, n);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), Collections.emptySet(), Collections.singleton(v), Collections.emptySet()).build();
NodeTransition na = rp.getNodeAction(n);
na.getStart().instantiateTo(0, Cause.Null);
na.getEnd().instantiateTo(1, Cause.Null);
VMTransition vma = rp.getVMAction(v);
vma.getStart().instantiateTo(0, Cause.Null);
vma.getEnd().instantiateTo(1, Cause.Null);
ReconfigurationPlan plan = rp.solve(0, false);
Assert.assertEquals(plan, null);
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CNoDelay method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
VM v = noDelay.getInvolvedVMs().iterator().next();
// For each vm involved in the constraint
VMTransition vt = rp.getVMAction(v);
// Get the VMTransition start time
// Add the constraint "start = 0" to the solver
Slice d = vt.getDSlice();
if (d == null) {
return true;
}
if (!(vt instanceof RelocatableVM)) {
try {
d.getStart().instantiateTo(0, Cause.Null);
} catch (ContradictionException ex) {
rp.getLogger().error("Unable to prevent any delay on '" + v + "'", ex);
return false;
}
} else {
Constraint c = rp.getModel().arithm(d.getStart(), "=", 0);
BoolVar move = ((RelocatableVM) vt).isStaying().not();
ChocoUtils.postImplies(rp, move, c);
}
return true;
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CResourceCapacity method injectContinuous.
private boolean injectContinuous(ReconfigurationProblem rp, CShareableResource rcm) throws SchedulerException {
// The constraint must be already satisfied
if (!cstr.isSatisfied(rp.getSourceModel())) {
rp.getLogger().error("The constraint '{}' must be already satisfied to provide a continuous restriction", cstr);
return false;
}
int[] alias = new int[cstr.getInvolvedNodes().size()];
int i = 0;
for (Node n : cstr.getInvolvedNodes()) {
alias[i++] = rp.getNode(n);
}
TIntArrayList cUse = new TIntArrayList();
List<IntVar> dUse = new ArrayList<>();
for (VM vmId : rp.getVMs()) {
VMTransition a = rp.getVMAction(vmId);
Slice c = a.getCSlice();
Slice d = a.getDSlice();
if (c != null) {
cUse.add(rcm.getSourceResource().getConsumption(vmId));
}
if (d != null) {
int m = rcm.getVMAllocation(rp.getVM(vmId));
dUse.add(rp.fixed(m, "vmAllocation('", rcm.getResourceIdentifier(), "', '", vmId, "'"));
}
}
ChocoView v = rp.getView(AliasedCumulatives.VIEW_ID);
if (v == null) {
throw SchedulerModelingException.missingView(rp.getSourceModel(), AliasedCumulatives.VIEW_ID);
}
((AliasedCumulatives) v).addDim(cstr.getAmount(), cUse.toArray(), dUse.toArray(new IntVar[dUse.size()]), alias);
return true;
}
Aggregations