Search in sources :

Example 6 with MigrateVM

use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.

the class DependencyBasedPlanApplierTest method testApply.

@Test
public void testApply() {
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    List<Node> ns = Util.newNodes(mo, 10);
    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);
    Model res = new DependencyBasedPlanApplier().apply(plan);
    Assert.assertNotNull(res);
    Mapping resMapping = res.getMapping();
    Assert.assertTrue(resMapping.isOffline(ns.get(0)));
    Assert.assertTrue(resMapping.isOnline(ns.get(3)));
    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 : BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) BootNode(org.btrplace.plan.event.BootNode) MigrateVM(org.btrplace.plan.event.MigrateVM) ShareableResource(org.btrplace.model.view.ShareableResource) MigrateVM(org.btrplace.plan.event.MigrateVM) ShutdownNode(org.btrplace.plan.event.ShutdownNode) Allocate(org.btrplace.plan.event.Allocate) Test(org.testng.annotations.Test)

Example 7 with MigrateVM

use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.

the class RelocatableVM method insertActions.

@Override
public boolean insertActions(Solution s, ReconfigurationPlan plan) {
    DurationEvaluators dev = rp.getDurationEvaluators();
    // Only if the VM doesn't stay
    if (s.getIntVal(cSlice.getHoster()) != (s.getIntVal(dSlice.getHoster()))) {
        Action a;
        Node dst = rp.getNode(s.getIntVal(dSlice.getHoster()));
        // Migration
        if (s.getIntVal(doReinstantiation) == 0) {
            int st = s.getIntVal(getStart());
            int ed = s.getIntVal(getEnd());
            if (getBandwidth() != null) {
                a = new MigrateVM(vm, src, dst, st, ed, s.getIntVal(getBandwidth()));
            } else {
                a = new MigrateVM(vm, src, dst, st, ed);
            }
            plan.add(a);
        // Re-instantiation
        } else {
            VM newVM = rp.cloneVM(vm);
            if (newVM == null) {
                rp.getLogger().error("Unable to get a new int to plan the re-instantiate of VM {}", vm);
                return false;
            }
            org.btrplace.plan.event.ForgeVM fvm = new org.btrplace.plan.event.ForgeVM(newVM, s.getIntVal(dSlice.getStart()) - dev.evaluate(rp.getSourceModel(), org.btrplace.plan.event.ForgeVM.class, vm), s.getIntVal(dSlice.getStart()));
            // forge the new VM from a template
            plan.add(fvm);
            // Boot the new VM
            int endForging = fvm.getEnd();
            org.btrplace.plan.event.BootVM boot = new org.btrplace.plan.event.BootVM(newVM, dst, endForging, endForging + dev.evaluate(rp.getSourceModel(), org.btrplace.plan.event.BootVM.class, newVM));
            boot.addEvent(Action.Hook.PRE, new SubstitutedVMEvent(vm, newVM));
            return plan.add(boot) && plan.add(new org.btrplace.plan.event.ShutdownVM(vm, src, boot.getEnd(), s.getIntVal(cSlice.getEnd())));
        }
    }
    return true;
}
Also used : Action(org.btrplace.plan.event.Action) Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) SubstitutedVMEvent(org.btrplace.plan.event.SubstitutedVMEvent) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators)

Example 8 with MigrateVM

use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.

the class ModelCustomization method run.

@Override
public void run() {
    Model model = makeModel();
    List<SatConstraint> cstrs = makeConstraints(model);
    // Set attributes for the VMs
    Attributes attrs = model.getAttributes();
    for (VM vm : model.getMapping().getAllVMs()) {
        attrs.put(vm, "template", vm.id() % 2 == 0 ? "small" : "large");
        attrs.put(vm, "clone", true);
        attrs.put(vm, "forge", vm.id() % 2 == 0 ? 2 : 10);
    // forge == 2 && template == small  for vm0, vm2, vm4, vm6, vm8
    // forge == 10 && template == large for vm1, vm3, vm5, vm7, vm9
    }
    // Change the duration evaluator for MigrateVM action
    ChocoScheduler cra = new DefaultChocoScheduler();
    DurationEvaluators dev = cra.getDurationEvaluators();
    dev.register(MigrateVM.class, new LinearToAResourceActionDuration<VM>("mem", 2, 3));
    dev.register(BootVM.class, new ConstantActionDuration<>(1));
    dev.register(ShutdownVM.class, new ConstantActionDuration<>(1));
    // Relocate VM4:
    // using a migration: (2 * mem + 3) = (2 * 2 + 3) = 7 sec.
    // using a re-instantiation: forge + boot + shutdown = 2 + 1 + 1 = 4 sec.
    // Relocate VM5:
    // using a migration: (2 * mem + 3) = (2 * 3 + 3) = 9 sec.
    // using a re-instantiation: forge + boot + shutdown = 10 + 1 + 1 = 12 sec.
    cra.doOptimize(true);
    ReconfigurationPlan plan = cra.solve(model, cstrs);
    System.out.println(plan);
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators)

Example 9 with MigrateVM

use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.

the class ReconfigurationPlanConverterTest method testConversion.

@Test
public void testConversion() throws JSONConverterException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Mapping map = mo.getMapping();
    map.addOnlineNode(n1);
    map.addOfflineNode(n2);
    map.addOnlineNode(n3);
    map.addReadyVM(vm1);
    map.addRunningVM(vm2, n1);
    map.addRunningVM(vm3, n1);
    map.addSleepingVM(vm4, n3);
    map.addRunningVM(vm5, n3);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    plan.add(new MigrateVM(vm2, n1, n3, 0, 1));
    plan.add(new BootVM(vm1, n3, 1, 2));
    plan.add(new BootNode(n2, 2, 5));
    plan.add(new Allocate(vm1, n3, "foo", 5, 3, 5));
    ReconfigurationPlanConverter rcp = new ReconfigurationPlanConverter();
    String j = rcp.toJSONString(plan);
    ReconfigurationPlan p2 = rcp.fromJSON(j);
    Assert.assertEquals(p2, plan);
}
Also used : BootNode(org.btrplace.plan.event.BootNode) BootNode(org.btrplace.plan.event.BootNode) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) BootVM(org.btrplace.plan.event.BootVM) Allocate(org.btrplace.plan.event.Allocate) Test(org.testng.annotations.Test)

Example 10 with MigrateVM

use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.

the class CFenceTest method testBasic.

@Test
public void testBasic() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3);
    Set<Node> on = new HashSet<>(Arrays.asList(n1, n3));
    Fence f = new Fence(vm2, on);
    ChocoScheduler cra = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.add(f);
    cstrs.addAll(Online.newOnline(map.getAllNodes()));
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNotNull(p);
    Assert.assertTrue(p.getSize() > 0);
    Assert.assertTrue(p.iterator().next() instanceof MigrateVM);
    // Assert.assertEquals(SatConstraint.Sat.SATISFIED, f.isSatisfied(p.getResult()));
    cstrs.add(new Ready(vm2));
    p = cra.solve(mo, cstrs);
    Assert.assertNotNull(p);
    // Just the suspend of vm2
    Assert.assertEquals(1, p.getSize());
// Assert.assertEquals(SatConstraint.Sat.SATISFIED, f.isSatisfied(p.getResult()));
}
Also used : ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) MigrateVM(org.btrplace.plan.event.MigrateVM) Test(org.testng.annotations.Test)

Aggregations

MigrateVM (org.btrplace.plan.event.MigrateVM)31 Test (org.testng.annotations.Test)25 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)24 DefaultReconfigurationPlan (org.btrplace.plan.DefaultReconfigurationPlan)12 ShareableResource (org.btrplace.model.view.ShareableResource)10 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)9 SatConstraint (org.btrplace.model.constraint.SatConstraint)8 ArrayList (java.util.ArrayList)7 Network (org.btrplace.model.view.network.Network)7 BootVM (org.btrplace.plan.event.BootVM)7 Node (org.btrplace.model.Node)6 Allocate (org.btrplace.plan.event.Allocate)6 BootNode (org.btrplace.plan.event.BootNode)6 ShutdownVM (org.btrplace.plan.event.ShutdownVM)6 List (java.util.List)5 Model (org.btrplace.model.Model)5 VM (org.btrplace.model.VM)5 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)5 Switch (org.btrplace.model.view.network.Switch)5 Action (org.btrplace.plan.event.Action)5