use of org.btrplace.model.view.ShareableResource 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.view.ShareableResource 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.view.ShareableResource 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.view.ShareableResource in project scheduler by btrplace.
the class ModelCustomization method makeModel.
private Model makeModel() {
Model mo = new DefaultModel();
vms = new ArrayList<>();
List<Node> ns = new ArrayList<>();
for (int i = 0; i < 10; i++) {
vms.add(mo.newVM());
}
ns.add(mo.newNode());
ns.add(mo.newNode());
Mapping map = mo.getMapping();
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
// 32GB by default for the nodes, 1 for the VMs
ShareableResource rcMem = new ShareableResource("mem", 32, 1);
for (int i = 0; i < 10; i++) {
rcMem.setConsumption(vms.get(i), i % 3 + 1);
// vm0: 1, vm1:2, vm2:3, vm3:1, vm4:2, vm5:3, vm6:1, ...
}
map.addRunningVM(vms.get(0), ns.get(0));
map.addRunningVM(vms.get(1), ns.get(0));
map.addRunningVM(vms.get(2), ns.get(0));
map.addRunningVM(vms.get(3), ns.get(0));
map.addRunningVM(vms.get(4), ns.get(0));
map.addRunningVM(vms.get(5), ns.get(0));
map.addRunningVM(vms.get(6), ns.get(1));
map.addRunningVM(vms.get(7), ns.get(1));
map.addRunningVM(vms.get(8), ns.get(1));
map.addReadyVM(vms.get(9));
mo.attach(rcMem);
return mo;
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class AdvancedMigScheduling method run.
@Override
public void run() {
Model mo = makeModel();
// Create, define, and attach CPU and Mem resource decorators for nodes and VMs
int memSrc = 8;
int cpuSrc = 4;
int memDst = 16;
int cpuDst = 8;
ShareableResource rcMem = new ShareableResource("mem", 0, 8);
ShareableResource rcCPU = new ShareableResource("cpu", 0, 4);
// VMs resources consumption
// Nodes resources capacity
rcMem.setCapacity(srcNode1, memSrc).setCapacity(srcNode2, memSrc).setCapacity(srcNode3, memSrc).setCapacity(srcNode4, memSrc).setCapacity(dstNode1, memDst).setCapacity(dstNode2, memDst);
rcCPU.setCapacity(srcNode1, cpuSrc).setCapacity(srcNode2, cpuSrc).setCapacity(srcNode3, cpuSrc).setCapacity(srcNode4, cpuSrc).setCapacity(dstNode1, cpuDst).setCapacity(dstNode2, cpuDst);
mo.attach(rcMem);
mo.attach(rcCPU);
// Set VM attributes 'hot dirty page size', 'hot dirty page duration', and 'cold dirty pages rate'
// to simulate a memory intensive workload equivalent to "stress --vm 1000 --bytes 50K"
int vmHds = 56;
int vmHdd = 2;
double vmCdr = 22.6;
// vm0 is an 'idle' VM (with no special memory activity) but still consumes 2 GiB of memory
mo.getAttributes().put(vm0, "memUsed", 2000);
// vm1 is an 'idle' VM (with no special memory activity) but still consumes 4 GiB of memory
mo.getAttributes().put(vm1, "memUsed", 3000);
// vm2 consumes 4 GiB memory and has a memory intensive workload
mo.getAttributes().put(vm2, "memUsed", 4000);
mo.getAttributes().put(vm2, "hotDirtySize", vmHds);
mo.getAttributes().put(vm2, "hotDirtyDuration", vmHdd);
mo.getAttributes().put(vm2, "coldDirtyRate", vmCdr);
// vm3 consumes 6 GiB memory and has a memory intensive workload
mo.getAttributes().put(vm3, "memUsed", 5000);
mo.getAttributes().put(vm3, "hotDirtySize", vmHds);
mo.getAttributes().put(vm3, "hotDirtyDuration", vmHdd);
mo.getAttributes().put(vm3, "coldDirtyRate", vmCdr);
// Attach a network view
Network net = new Network();
mo.attach(net);
Switch swMain = net.newSwitch(30000);
net.connect(10000, swMain, srcNode1, srcNode2, srcNode3, srcNode4);
// The destination nodes have twice the bandwidth of source nodes
net.connect(20000, swMain, dstNode1, dstNode2);
// Create constraints
List<SatConstraint> cstrs = new ArrayList<>();
// We want to boot the destination nodes
cstrs.addAll(Online.newOnline(Arrays.asList(dstNode1, dstNode2)));
// We want to shutdown the source nodes
cstrs.addAll(Offline.newOffline(Arrays.asList(srcNode1, srcNode2, srcNode3, srcNode4)));
// Try to solve as is, and show the computed plan
solve(mo, cstrs);
/**
******* Add some migrations scheduling constraints ********
*/
// We want vm0 and vm1 migrations to terminate at the same time
cstrs.add(new Sync(vm0, vm1));
// We want to serialize the migrations of vm1, vm2, and vm3
cstrs.add(new Serialize(new HashSet<>(Arrays.asList(vm1, vm2, vm3))));
// We want vm0 migration terminate before vm2 start to migrate
cstrs.add(new Precedence(vm1, vm2));
// We want vm3 migration terminate before 10s
cstrs.add(new Deadline(vm3, "+0:0:10"));
// Try to solve, and show the computed plan
solve(mo, cstrs);
}
Aggregations