Search in sources :

Example 61 with ShareableResource

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));
        }
                                 */
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 62 with ShareableResource

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));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 63 with ShareableResource

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);
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) Switch(org.btrplace.model.view.network.Switch) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) MigrateVM(org.btrplace.plan.event.MigrateVM) Network(org.btrplace.model.view.network.Network) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Fence(org.btrplace.model.constraint.Fence) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 64 with ShareableResource

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);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 65 with ShareableResource

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));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Fence(org.btrplace.model.constraint.Fence) Test(org.testng.annotations.Test)

Aggregations

ShareableResource (org.btrplace.model.view.ShareableResource)86 Test (org.testng.annotations.Test)61 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)47 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)41 SatConstraint (org.btrplace.model.constraint.SatConstraint)32 ArrayList (java.util.ArrayList)31 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)29 VM (org.btrplace.model.VM)27 Model (org.btrplace.model.Model)25 Node (org.btrplace.model.Node)25 DefaultModel (org.btrplace.model.DefaultModel)22 MigrateVM (org.btrplace.plan.event.MigrateVM)16 Mapping (org.btrplace.model.Mapping)13 Network (org.btrplace.model.view.network.Network)12 Switch (org.btrplace.model.view.network.Switch)12 Offline (org.btrplace.model.constraint.Offline)11 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)10 SchedulerException (org.btrplace.scheduler.SchedulerException)10 Fence (org.btrplace.model.constraint.Fence)7 Preserve (org.btrplace.model.constraint.Preserve)7