use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class ShareableResourceConverterTest method testSimple.
@Test
public void testSimple() throws JSONConverterException {
Model mo = new DefaultModel();
ShareableResource rc = new ShareableResource("foo", 3, 8);
rc.setConsumption(mo.newVM(), 3);
rc.setConsumption(mo.newVM(), 4);
rc.setCapacity(mo.newNode(), 5);
rc.setCapacity(mo.newNode(), 6);
ShareableResourceConverter s = new ShareableResourceConverter();
ShareableResource rc2 = s.fromJSON(mo, s.toJSON(rc));
Assert.assertEquals(rc, rc2);
/* Assert.assertEquals(rc.getIdentifier(), rc2.getIdentifier());
Assert.assertEquals(rc.getResourceIdentifier(), rc2.getResourceIdentifier());
Assert.assertEquals(rc.getDefinedVMs(), rc2.getDefinedVMs());
Assert.assertEquals(rc.getDefinedNodes(), rc2.getDefinedNodes());
for (VM u : rc.getDefinedVMs()) {
Assert.assertEquals(rc.getConsumption(u), rc2.getConsumption(u));
}
for (Node u : rc.getDefinedNodes()) {
Assert.assertEquals(rc.getCapacity(u), rc2.getCapacity(u));
}
*/
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class ShareableResourceConverterTest method testWithDifferentRcId.
@Test(dependsOnMethods = { "testSimple" })
public void testWithDifferentRcId() throws JSONConverterException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
ShareableResourceConverter s = new ShareableResourceConverter();
ShareableResource rc = new ShareableResource("foo");
rc.setConsumption(vm1, 3).setConsumption(vm2, 4).setCapacity(n1, 5);
ShareableResource rcBis = s.fromJSON(mo, s.toJSON(rc));
ShareableResource rc2 = new ShareableResource("bar");
rc2.setConsumption(vm1, 3).setConsumption(vm2, 4).setCapacity(n1, 5);
ShareableResource rc2Bis = s.fromJSON(mo, s.toJSON(rc2));
Assert.assertFalse(rcBis.equals(rc2Bis));
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class CNetworkTest method testWithSwitchCapacity.
@Test
public void testWithSwitchCapacity() {
Model mo = new DefaultModel();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
VM v = mo.newVM();
mo.getMapping().on(n1, n2).run(n1, v);
ShareableResource mem = new ShareableResource("mem", 10000, 5000);
Network net = new Network();
mo.attach(net);
mo.attach(mem);
mo.getAttributes().put(v, "memUsed", 10000);
Switch sw = net.newSwitch(1000);
net.connect(2000, sw, n1, n2);
ChocoScheduler s = new DefaultChocoScheduler();
ReconfigurationPlan p = s.solve(mo, Collections.singletonList(new Fence(v, n2)));
Assert.assertNotNull(p);
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class CShareableResourceTest method testMaintainResourceUsage.
@Test
public void testMaintainResourceUsage() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
mo.getMapping().on(n1).run(n1, vm1, vm2);
ShareableResource rc = new ShareableResource("foo");
rc.setConsumption(vm1, 5);
rc.setConsumption(vm2, 7);
rc.setCapacity(n1, 25);
mo.attach(rc);
ChocoScheduler s = new DefaultChocoScheduler();
ReconfigurationPlan p = s.solve(mo, new ArrayList<>());
Assert.assertNotNull(p);
// And on the resulting plan.
Model res = p.getResult();
ShareableResource resRc = ShareableResource.get(res, rc.getResourceIdentifier());
Assert.assertEquals(resRc.getConsumption(vm1), 5);
Assert.assertEquals(resRc.getConsumption(vm2), 7);
}
use of org.btrplace.model.view.ShareableResource 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));
}
Aggregations