use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class RelocatableVMTest method testStayRunning.
@Test
public void testStayRunning() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
Node n1 = mo.newNode();
map.addOnlineNode(n1);
map.addRunningVM(vm1, n1);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(new DefaultParameters()).setManageableVMs(Collections.emptySet()).build();
Assert.assertEquals(rp.getVMAction(vm1).getClass(), RelocatableVM.class);
RelocatableVM m1 = (RelocatableVM) rp.getVMAction(vm1);
Assert.assertNotNull(m1.getCSlice());
Assert.assertNotNull(m1.getDSlice());
Assert.assertTrue(m1.getCSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
Assert.assertTrue(m1.getDSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
Assert.assertTrue(m1.getDuration().isInstantiatedTo(0));
Assert.assertTrue(m1.getStart().isInstantiatedTo(0));
Assert.assertTrue(m1.getEnd().isInstantiatedTo(0));
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Assert.assertEquals(p.getSize(), 0);
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class RelocatableVMTest method testForcedReInstantiation.
@Test
public void testForcedReInstantiation() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm10 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
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(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.getRelocationMethod().instantiateTo(1, Cause.Null);
am.getDSlice().getHoster().instantiateTo(rp.getNode(n2), Cause.Null);
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(10, true);
Assert.assertNotNull(p);
Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(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);
// Check for the actions duration
for (Action a : p) {
if (a instanceof org.btrplace.plan.event.ForgeVM) {
Assert.assertEquals(a.getEnd() - a.getStart(), 3);
} else if (a instanceof org.btrplace.plan.event.ShutdownVM) {
Assert.assertEquals(a.getEnd() - a.getStart(), 1);
} else if (a instanceof org.btrplace.plan.event.BootVM) {
Assert.assertEquals(a.getEnd() - a.getStart(), 2);
} else {
Assert.fail();
}
}
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class CShareableResourceTest method testRealNodeUsage.
/**
* Place some VMs and check realNodeUsage is updated accordingly
*/
@Test
public void testRealNodeUsage() throws SchedulerException {
Model mo = new DefaultModel();
Mapping ma = mo.getMapping();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
ma.addOnlineNode(n1);
ma.addOnlineNode(n2);
ma.addRunningVM(vm1, n1);
ma.addRunningVM(vm2, n1);
ShareableResource rc = new ShareableResource("foo", 0, 0);
rc.setConsumption(vm1, 2);
rc.setConsumption(vm2, 3);
rc.setCapacity(n1, 5);
rc.setCapacity(n2, 3);
mo.attach(rc);
ChocoScheduler s = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(new Fence(vm1, n1));
cstrs.add(new Fence(vm2, n2));
ReconfigurationPlan p = s.solve(mo, cstrs);
Assert.assertNotNull(p);
Model res = p.getResult();
rc = (ShareableResource.get(res, "foo"));
// rcm.getVirtualUsage(0).isInstantiatedTo(2));
Assert.assertEquals(2, rc.getConsumption(vm1));
// rcm.getVirtualUsage(1).isInstantiatedTo(3));
Assert.assertEquals(3, rc.getConsumption(vm2));
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultReconfigurationProblemBuilder method build.
/**
* Build the problem
*
* @return the builder problem
* @throws org.btrplace.scheduler.SchedulerException if an error occurred
*/
public DefaultReconfigurationProblem build() throws SchedulerException {
if (runs == null) {
// The others are supposed to be null too as they are set using the same method
Mapping map = model.getMapping();
runs = new HashSet<>();
sleep = new HashSet<>();
for (Node n : map.getOnlineNodes()) {
runs.addAll(map.getRunningVMs(n));
sleep.addAll(map.getSleepingVMs(n));
}
waits = map.getReadyVMs();
over = Collections.emptySet();
}
if (manageable == null) {
manageable = new HashSet<>();
manageable.addAll(model.getMapping().getSleepingVMs());
manageable.addAll(model.getMapping().getRunningVMs());
manageable.addAll(model.getMapping().getReadyVMs());
}
if (ps == null) {
ps = new DefaultParameters();
}
return new DefaultReconfigurationProblem(model, ps, waits, runs, sleep, over, manageable);
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class CBan method getMisPlacedVMs.
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
Mapping map = i.getModel().getMapping();
VM vm = ban.getInvolvedVMs().iterator().next();
if (map.isRunning(vm) && ban.getInvolvedNodes().contains(map.getVMLocation(vm))) {
return Collections.singleton(vm);
}
return Collections.emptySet();
}
Aggregations