use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class TimeBasedPlanApplierTest method makePlan.
private static ReconfigurationPlan makePlan(Model mo, List<Node> ns, List<VM> vms) {
Mapping map = mo.getMapping();
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addOnlineNode(ns.get(2));
map.addOfflineNode(ns.get(3));
map.addRunningVM(vms.get(0), ns.get(2));
map.addRunningVM(vms.get(1), ns.get(0));
map.addRunningVM(vms.get(2), ns.get(1));
map.addRunningVM(vms.get(3), ns.get(1));
BootNode bN4 = new BootNode(ns.get(3), 3, 5);
MigrateVM mVM1 = new MigrateVM(vms.get(0), ns.get(2), ns.get(3), 6, 7);
Allocate aVM3 = new Allocate(vms.get(2), ns.get(1), "cpu", 7, 8, 9);
MigrateVM mVM2 = new MigrateVM(vms.get(1), ns.get(0), ns.get(1), 1, 3);
MigrateVM mVM4 = new MigrateVM(vms.get(3), ns.get(1), ns.get(2), 1, 7);
ShutdownNode sN1 = new ShutdownNode(ns.get(0), 5, 7);
ShareableResource rc = new ShareableResource("cpu");
rc.setConsumption(vms.get(2), 3);
mo.attach(rc);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
plan.add(bN4);
plan.add(mVM1);
plan.add(aVM3);
plan.add(mVM2);
plan.add(mVM4);
plan.add(sN1);
return plan;
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class TimeBasedPlanApplierTest method testApply.
@Test
public void testApply() {
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
List<Node> ns = Util.newNodes(mo, 10);
ReconfigurationPlan plan = makePlan(mo, ns, vms);
Model res = new DependencyBasedPlanApplier().apply(plan);
Mapping resMapping = res.getMapping();
Assert.assertTrue(resMapping.isOffline(ns.get(0)));
Assert.assertTrue(resMapping.isOnline(ns.get(3)));
ShareableResource rc = ShareableResource.get(res, "cpu");
Assert.assertEquals(rc.getConsumption(vms.get(2)), 7);
Assert.assertEquals(resMapping.getVMLocation(vms.get(0)), ns.get(3));
Assert.assertEquals(resMapping.getVMLocation(vms.get(1)), ns.get(1));
Assert.assertEquals(resMapping.getVMLocation(vms.get(3)), ns.get(2));
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class AllocateTest method testApply.
@Test
public void testApply() {
Model mo = new DefaultModel();
Allocate na = new Allocate(vms.get(0), ns.get(1), "foo", 3, 3, 5);
Mapping map = mo.getMapping();
map.addOnlineNode(ns.get(0));
map.addRunningVM(vms.get(0), ns.get(0));
Assert.assertFalse(na.apply(mo));
ShareableResource rc = new ShareableResource("foo");
mo.attach(rc);
Assert.assertTrue(na.apply(mo));
Assert.assertEquals(3, rc.getConsumption(vms.get(0)));
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class OverbookChecker method endsWith.
@Override
public boolean endsWith(Model i) {
Mapping cfg = i.getMapping();
ShareableResource rc = ShareableResource.get(i, id);
if (rc == null) {
return false;
}
for (Node nId : getNodes()) {
if (cfg.isOnline(nId)) {
// Server capacity with the ratio
double c = rc.getCapacity(nId) * ratio;
// Minus the VMs usage
for (VM vmId : cfg.getRunningVMs(nId)) {
c -= rc.getConsumption(vmId);
if (c < 0) {
return false;
}
}
}
}
return true;
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class DependenciesExtractor method visit.
@Override
public Boolean visit(Allocate a) {
// If the resource allocation is increasing, it's
// a consuming action. Otherwise, it's a freeing action
String rcId = a.getResourceId();
int newAmount = a.getAmount();
ShareableResource rc = ShareableResource.get(origin, rcId);
if (rc == null) {
return false;
}
int oldAmount = rc.getConsumption(a.getVM());
if (newAmount > oldAmount) {
demandingNodes.put(a, a.getHost());
return getDemandings(a.getHost()).add(a);
}
return getFreeings(a.getHost()).add(a);
}
Aggregations