use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class IssuesTest method testIssue86.
@Test
public void testIssue86() throws Exception {
Model mo = new DefaultModel();
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addOnlineNode(mo.newNode());
mo.getMapping().addOnlineNode(mo.newNode());
mo.getMapping().addOnlineNode(mo.newNode());
List<SatConstraint> cstrs = mo.getMapping().getAllVMs().stream().map(Running::new).collect(Collectors.toList());
cstrs.add(new Spread(mo.getMapping().getAllVMs(), false));
cstrs.addAll(mo.getMapping().getOnlineNodes().stream().map(n -> new RunningCapacity(n, 1)).collect(Collectors.toList()));
Instance i = new Instance(mo, cstrs, new MinMTTR());
ChocoScheduler s = new DefaultChocoScheduler();
s.doOptimize(false);
s.doRepair(false);
ReconfigurationPlan p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
Assert.assertNotNull(p);
Assert.assertEquals(3, p.getActions().size());
s.doRepair(true);
p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
Assert.assertNotNull(p);
Assert.assertEquals(3, p.getActions().size());
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class IssuesTest method test16b.
/**
* Unit test derived from Issue 16.
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void test16b() throws SchedulerException {
Model model = new DefaultModel();
Node n1 = model.newNode();
Node n2 = model.newNode();
Node n3 = model.newNode();
Node n4 = model.newNode();
VM vm1 = model.newVM();
VM vm2 = model.newVM();
VM vm3 = model.newVM();
VM vm4 = model.newVM();
VM vm5 = model.newVM();
VM vm6 = model.newVM();
model.getMapping().on(n1, n2, n3, n4).run(n1, vm1, vm2).run(n2, vm3, vm4).run(n3, vm5, vm6);
Set<SatConstraint> ctrsC = new HashSet<>();
Set<VM> vms1 = new HashSet<>(Arrays.asList(vm1, vm3, vm5));
Set<VM> vms2 = new HashSet<>(Arrays.asList(vm2, vm4, vm6));
ctrsC.add(new Spread(vms1));
ctrsC.add(new Spread(vms2));
ctrsC.add(new Fence(vm3, Collections.singleton(n1)));
Offline off = new Offline(n2);
ctrsC.add(off);
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan dp = cra.solve(model, ctrsC);
Assert.assertNotNull(dp);
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class RelocatableVMTest method testWorthlessReInstantiation.
/**
* The re-instantiation is possible and worthy.
*
* @throws org.btrplace.scheduler.SchedulerException
* @throws ContradictionException
*/
@Test
public void testWorthlessReInstantiation() 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<>(2));
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);
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(10, true);
Assert.assertNotNull(p);
Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(0));
Assert.assertEquals(p.getSize(), 1);
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);
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class RelocatableVMTest method testForcedMigration.
@Test
public void testForcedMigration() 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(0, 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(0));
Assert.assertEquals(p.getSize(), 1);
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);
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class RelocatableVMTest method testRelocateDueToPreserve.
@Test
public void testRelocateDueToPreserve() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
final VM vm2 = mo.newVM();
final VM vm3 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
org.btrplace.model.view.ShareableResource rc = new ShareableResource("cpu", 10, 10);
rc.setCapacity(n1, 7);
rc.setConsumption(vm1, 3);
rc.setConsumption(vm2, 3);
rc.setConsumption(vm3, 5);
Preserve pr = new Preserve(vm1, "cpu", 5);
ChocoScheduler cra = new DefaultChocoScheduler();
mo.attach(rc);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Online.newOnline(map.getAllNodes()));
cstrs.addAll(Overbook.newOverbooks(map.getAllNodes(), "cpu", 1));
cstrs.add(pr);
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
}
Aggregations