use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class RelocatableVMTest method testWorthyReInstantiation.
/**
* The re-instantiation is possible and worthy.
*
* @throws org.btrplace.scheduler.SchedulerException
* @throws ContradictionException
*/
@Test
public void testWorthyReInstantiation() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
VM vm10 = mo.newVM();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
// Not using vm1 because intPool starts at 0 so their will be multiple (0,1) VMs.
map.addRunningVM(vm10, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.MigrateVM.class, new ConstantActionDuration<>(20));
dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(3));
dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(2));
dev.register(org.btrplace.plan.event.ShutdownVM.class, new ConstantActionDuration<>(1));
mo.getAttributes().put(vm10, "template", "small");
mo.getAttributes().put(vm10, "clone", true);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).setManageableVMs(map.getAllVMs()).build();
RelocatableVM am = (RelocatableVM) rp.getVMAction(vm10);
am.getDSlice().getHoster().instantiateTo(rp.getNode(n2), Cause.Null);
Solution sol = new Solution(rp.getModel());
sol.record();
rp.getSolver().plugMonitor((IMonitorSolution) () -> {
sol.record();
});
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(10, true);
Assert.assertNotNull(p);
Assert.assertEquals(sol.getIntVal(am.getRelocationMethod()), 1);
Assert.assertEquals(p.getSize(), 3);
Model res = p.getResult();
// Check the VM has been relocated
Assert.assertEquals(res.getMapping().getRunningVMs(n1).size(), 0);
Assert.assertEquals(res.getMapping().getRunningVMs(n2).size(), 1);
Assert.assertNotNull(p);
for (Action a : p) {
Assert.assertTrue(a.getStart() >= 0, a.toString());
Assert.assertTrue(a.getEnd() >= a.getStart(), a.toString());
}
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class RelocatableVMTest method testReinstantiationWithPreserve.
@Test
public void testReinstantiationWithPreserve() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
VM vm7 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addRunningVM(vm5, n1);
map.addRunningVM(vm6, n1);
map.addRunningVM(vm7, n2);
ShareableResource rc = new ShareableResource("cpu", 10, 10);
rc.setCapacity(n1, 7);
rc.setConsumption(vm5, 3);
rc.setConsumption(vm6, 3);
rc.setConsumption(vm7, 5);
for (VM vm : map.getAllVMs()) {
mo.getAttributes().put(vm, "template", "small");
mo.getAttributes().put(vm, "clone", true);
}
Preserve pr = new Preserve(vm5, "cpu", 5);
ChocoScheduler cra = new DefaultChocoScheduler();
cra.getDurationEvaluators().register(MigrateVM.class, new ConstantActionDuration<>(20));
mo.attach(rc);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Online.newOnline(map.getAllNodes()));
cstrs.add(pr);
cra.doOptimize(true);
try {
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
} catch (SchedulerException e) {
Assert.fail(e.getMessage(), e);
}
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class CShareableResourceTest method testWithFloat.
@Test
public void testWithFloat() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2);
org.btrplace.model.view.ShareableResource rc = new ShareableResource("foo");
rc.setCapacity(n1, 32);
rc.setConsumption(vm1, 3);
rc.setConsumption(vm2, 2);
mo.attach(rc);
ChocoScheduler cra = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Online.newOnline(map.getAllNodes()));
Overbook o = new Overbook(n1, "foo", 1.5, false);
cstrs.add(o);
Overbook o2 = new Overbook(n2, "foo", 1.5, false);
cstrs.add(o2);
cstrs.add(new Preserve(vm1, "foo", 5));
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class CShareableResourceTest method testSimple.
/**
* Test the instantiation and the creation of the variables.
*
* @throws org.btrplace.scheduler.SchedulerException should not occur
*/
@Test
public void testSimple() throws SchedulerException {
Model mo = new DefaultModel();
Mapping ma = mo.getMapping();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
ma.addOnlineNode(n1);
ma.addOfflineNode(n2);
ma.addRunningVM(vm1, n1);
ma.addRunningVM(vm2, n1);
ma.addReadyVM(vm3);
ShareableResource rc = new ShareableResource("foo", 0, 0);
rc.setConsumption(vm2, 3);
rc.setCapacity(n1, 4);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).build();
CShareableResource rcm = new CShareableResource(rc);
rcm.inject(new DefaultParameters(), rp);
Assert.assertEquals(rc.getIdentifier(), rcm.getIdentifier());
// Assert.assertEquals(-1, rcm.getVMsAllocation(rp.getVM(vm1)).getLB());
Assert.assertEquals(-1, rcm.getVMAllocation(rp.getVM(vm1)));
// Assert.assertEquals(-1, rcm.getVMsAllocation(rp.getVM(vm2)).getLB());
Assert.assertEquals(-1, rcm.getVMAllocation(rp.getVM(vm2)));
// Assert.assertEquals(0, rcm.getVMsAllocation(rp.getVM(vm3)).getUB()); //Will not be running so 0
// Will not be running so 0
Assert.assertEquals(0, rcm.getVMAllocation(rp.getVM(vm3)));
IntVar pn1 = rcm.getPhysicalUsage().get(rp.getNode(n1));
IntVar pn2 = rcm.getPhysicalUsage().get(rp.getNode(n2));
Assert.assertTrue(pn1.getLB() == 0 && pn1.getUB() == 4);
Assert.assertTrue(pn2.getLB() == 0 && pn2.getUB() == 0);
pn1 = rcm.getPhysicalUsage(rp.getNode(n1));
Assert.assertTrue(pn1.getLB() == 0 && pn1.getUB() == 4);
IntVar vn1 = rcm.getVirtualUsage().get(rp.getNode(n1));
IntVar vn2 = rcm.getVirtualUsage().get(rp.getNode(n2));
Assert.assertEquals(vn1.getLB(), 0);
Assert.assertEquals(vn2.getLB(), 0);
Assert.assertEquals(rc, rcm.getSourceResource());
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class ReconfigurationPlanFuzzer method setInitialState.
private void setInitialState(ReconfigurationPlan p, VM v) {
Mapping map = p.getOrigin().getMapping();
Set<Node> onlines = map.getOnlineNodes();
if (onlines.isEmpty()) {
map.addReadyVM(v);
return;
}
// CDF to consider the distribution
int n = rnd.nextInt(srcReadyVMs + srcRunningVMs + srcSleepingVMs);
if (n < srcReadyVMs) {
map.addReadyVM(v);
} else if (n < srcReadyVMs + srcRunningVMs) {
map.addRunningVM(v, pick(onlines));
} else {
map.addSleepingVM(v, pick(onlines));
}
}
Aggregations