Search in sources :

Example 46 with ShareableResource

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;
}
Also used : BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) MigrateVM(org.btrplace.plan.event.MigrateVM) ShareableResource(org.btrplace.model.view.ShareableResource) Allocate(org.btrplace.plan.event.Allocate)

Example 47 with ShareableResource

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));
}
Also used : MigrateVM(org.btrplace.plan.event.MigrateVM) ShutdownNode(org.btrplace.plan.event.ShutdownNode) BootNode(org.btrplace.plan.event.BootNode) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 48 with ShareableResource

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

Example 49 with ShareableResource

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;
}
Also used : Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource)

Example 50 with ShareableResource

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);
}
Also used : ShareableResource(org.btrplace.model.view.ShareableResource)

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