use of org.btrplace.model.constraint.SatConstraint 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.constraint.SatConstraint 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);
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);
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class Decommissionning method run.
@Override
public void run() {
int ratio = 1;
int nbPCPUs = 4;
int nbNodes = 2;
// The current DC
Model mo = new DefaultModel();
for (int i = 0; i < nbNodes; i++) {
Node n = mo.newNode();
mo.getMapping().addOnlineNode(n);
// 4 VMs per node
for (int j = 0; j < ratio * nbPCPUs; j++) {
VM v = mo.newVM();
mo.getMapping().addRunningVM(v, n);
}
}
// Resource allocation
ShareableResource rc = new ShareableResource("cpu", 8, 1);
mo.attach(rc);
// The new DC
for (int i = 0; i < nbNodes; i++) {
Node n = mo.newNode();
mo.getMapping().addOfflineNode(n);
rc.setCapacity(n, 10);
}
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Offline.newOffline(mo.getMapping().getOnlineNodes()));
MaxOnline m = new MaxOnline(mo.getMapping().getAllNodes(), nbNodes + 1, true);
cstrs.add(m);
ChocoScheduler cra = new DefaultChocoScheduler();
cra.setMaxEnd(3);
cra.setVerbosity(1);
ReconfigurationPlan p = cra.solve(mo, cstrs);
System.out.println(p);
System.out.println(cra.getStatistics());
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class GettingStarted method makeConstraints.
/**
* Declare some constraints.
*/
public List<SatConstraint> makeConstraints() {
List<SatConstraint> cstrs = new ArrayList<>();
// VM1 and VM2 must be running on distinct nodes
cstrs.add(new Spread(new HashSet<>(Arrays.asList(vms.get(1), vms.get(2)))));
// VM0 must have at least 3 virtual CPU dedicated to it
cstrs.add(new Preserve(vms.get(0), "cpu", 3));
// N3 must be set offline
cstrs.add(new Offline(nodes.get(3)));
// VM4 must be running, It asks for 3 cpu and 2 mem resources
cstrs.add(new Running(vms.get(4)));
cstrs.add(new Preserve(vms.get(4), "cpu", 3));
cstrs.add(new Preserve(vms.get(4), "mem", 2));
// VM3 must be turned off, i.e. set back to the ready state
cstrs.add(new Ready(vms.get(3)));
return cstrs;
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class GettingStarted method run.
@Override
public void run() {
Model model = makeModel();
List<SatConstraint> cstrs = makeConstraints();
ChocoScheduler ra = new DefaultChocoScheduler();
ReconfigurationPlan plan = ra.solve(model, cstrs);
if (plan != null) {
System.out.println("Time-based plan:");
System.out.println(new TimeBasedPlanApplier().toString(plan));
System.out.println("\nDependency based plan:");
System.out.println(new DependencyBasedPlanApplier().toString(plan));
}
}
Aggregations