Search in sources :

Example 1 with DurationEvaluators

use of org.btrplace.scheduler.choco.duration.DurationEvaluators 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().debug("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 2 with DurationEvaluators

use of org.btrplace.scheduler.choco.duration.DurationEvaluators 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) SatConstraint(org.btrplace.model.constraint.SatConstraint) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Attributes(org.btrplace.model.Attributes) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators)

Example 3 with DurationEvaluators

use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.

the class RelocatableVMTest method testWorthyReInstantiation.

/**
 * The re-instantiation is possible and worthy.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 * @throws ContradictionException
 */
@Test
public void testWorthyReInstantiation() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    VM vm10 = mo.newVM();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    // Not using vm1 because intPool starts at 0 so their will be multiple (0,1) VMs.
    map.addRunningVM(vm10, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(MigrateVM.class, new ConstantActionDuration<>(20));
    dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(3));
    dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(2));
    dev.register(org.btrplace.plan.event.ShutdownVM.class, new ConstantActionDuration<>(1));
    mo.getAttributes().put(vm10, "template", "small");
    mo.getAttributes().put(vm10, "clone", true);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).setManageableVMs(map.getAllVMs()).build();
    RelocatableVM am = (RelocatableVM) rp.getVMAction(vm10);
    am.getDSlice().getHoster().instantiateTo(rp.getNode(n2), Cause.Null);
    Solution sol = new Solution(rp.getModel());
    sol.record();
    rp.getSolver().plugMonitor((IMonitorSolution) () -> {
        sol.record();
    });
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(10, true);
    Assert.assertNotNull(p);
    Assert.assertEquals(sol.getIntVal(am.getRelocationMethod()), 1);
    Assert.assertEquals(p.getSize(), 3);
    Model res = p.getResult();
    // Check the VM has been relocated
    Assert.assertEquals(res.getMapping().getRunningVMs(n1).size(), 0);
    Assert.assertEquals(res.getMapping().getRunningVMs(n2).size(), 1);
    Assert.assertNotNull(p);
    for (Action a : p) {
        Assert.assertTrue(a.getStart() >= 0, a.toString());
        Assert.assertTrue(a.getEnd() >= a.getStart(), a.toString());
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Action(org.btrplace.plan.event.Action) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Parameters(org.btrplace.scheduler.choco.Parameters) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) Solution(org.chocosolver.solver.Solution) Test(org.testng.annotations.Test)

Example 4 with DurationEvaluators

use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.

the class RelocatableVMTest method testNotWorthyReInstantiation.

/**
 * The re-instantiation is possible but will lead in a waste of time.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testNotWorthyReInstantiation() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addRunningVM(vm1, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(MigrateVM.class, new ConstantActionDuration<>(2));
    mo.getAttributes().put(vm1, "template", "small");
    mo.getAttributes().put(vm1, "clone", true);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
    RelocatableVM am = (RelocatableVM) rp.getVMAction(vm1);
    Assert.assertFalse(am.getRelocationMethod().isInstantiated());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) Test(org.testng.annotations.Test)

Example 5 with DurationEvaluators

use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.

the class RelocatableVMTest method testForcedMigration.

@Test
public void testForcedMigration() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm10 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    // Not using vm1 because intPool starts at 0 so their will be multiple (0,1) VMs.
    map.addRunningVM(vm10, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(MigrateVM.class, new ConstantActionDuration<>(20));
    dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(3));
    dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(2));
    dev.register(org.btrplace.plan.event.ShutdownVM.class, new ConstantActionDuration<>(1));
    mo.getAttributes().put(vm10, "template", "small");
    mo.getAttributes().put(vm10, "clone", true);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).setManageableVMs(map.getAllVMs()).build();
    RelocatableVM am = (RelocatableVM) rp.getVMAction(vm10);
    am.getRelocationMethod().instantiateTo(0, Cause.Null);
    am.getDSlice().getHoster().instantiateTo(rp.getNode(n2), Cause.Null);
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(10, true);
    Assert.assertNotNull(p);
    Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(0));
    Assert.assertEquals(p.getSize(), 1);
    Model res = p.getResult();
    // Check the VM has been relocated
    Assert.assertEquals(res.getMapping().getRunningVMs(n1).size(), 0);
    Assert.assertEquals(res.getMapping().getRunningVMs(n2).size(), 1);
    Assert.assertNotNull(p);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Parameters(org.btrplace.scheduler.choco.Parameters) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Aggregations

DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)37 DefaultModel (org.btrplace.model.DefaultModel)35 Model (org.btrplace.model.Model)35 Test (org.testng.annotations.Test)35 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)34 Parameters (org.btrplace.scheduler.choco.Parameters)34 Node (org.btrplace.model.Node)33 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)33 Mapping (org.btrplace.model.Mapping)32 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)32 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)31 VM (org.btrplace.model.VM)24 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)17 ShutdownNode (org.btrplace.plan.event.ShutdownNode)16 BootNode (org.btrplace.plan.event.BootNode)15 HashSet (java.util.HashSet)10 Action (org.btrplace.plan.event.Action)10 MigrateVM (org.btrplace.plan.event.MigrateVM)9 ShutdownVM (org.btrplace.plan.event.ShutdownVM)3 BootVM (org.btrplace.plan.event.BootVM)2