Search in sources :

Example 11 with Action

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

the class BootVMTest method testBootSequence.

/**
 * Test that check when the action is shorter than the end of
 * the reconfiguration process.
 * In practice, 2 boot actions have to be executed sequentially
 */
@Test
public void testBootSequence() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm1 = mo.newVM();
    final VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addReadyVM(vm1);
    map.addReadyVM(vm2);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
    BootVM m1 = (BootVM) rp.getVMActions().get(rp.getVM(vm1));
    BootVM m2 = (BootVM) rp.getVMActions().get(rp.getVM(vm2));
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
    rp.getModel().post(rp.getModel().arithm(m2.getStart(), ">=", m1.getEnd()));
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Iterator<Action> ite = p.iterator();
    org.btrplace.plan.event.BootVM b1 = (org.btrplace.plan.event.BootVM) ite.next();
    org.btrplace.plan.event.BootVM b2 = (org.btrplace.plan.event.BootVM) ite.next();
    Assert.assertEquals(vm1, b1.getVM());
    Assert.assertEquals(vm2, b2.getVM());
    Assert.assertTrue(b1.getEnd() <= b2.getStart());
    Assert.assertEquals(5, b1.getEnd() - b1.getStart());
    Assert.assertEquals(5, b2.getEnd() - b2.getStart());
}
Also used : Action(org.btrplace.plan.event.Action) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 12 with Action

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

the class BootableNodeTest method testRequiredOnline.

@Test
public void testRequiredOnline() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    map.addOfflineNode(n1);
    map.addReadyVM(vm1);
    ChocoScheduler s = new DefaultChocoScheduler();
    Parameters ps = s.getParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(BootNode.class, new ConstantActionDuration<>(5));
    dev.register(BootVM.class, new ConstantActionDuration<>(2));
    ReconfigurationPlan plan = s.solve(mo, Collections.singleton(new Running(vm1)));
    Assert.assertNotNull(plan);
    Assert.assertEquals(plan.getSize(), 2);
    for (Action a : plan.getActions()) {
        if (a instanceof BootNode) {
            Assert.assertEquals(a.getStart(), 0);
            Assert.assertEquals(a.getEnd(), 5);
        } else {
            Assert.assertEquals(a.getStart(), 5);
            Assert.assertEquals(a.getEnd(), 7);
        }
    }
}
Also used : Action(org.btrplace.plan.event.Action) BootNode(org.btrplace.plan.event.BootNode) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) BootVM(org.btrplace.plan.event.BootVM) Running(org.btrplace.model.constraint.Running) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) Test(org.testng.annotations.Test)

Example 13 with Action

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

the class ForgeVMTest method testResolution.

@Test
public void testResolution() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping m = mo.getMapping();
    final VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    m.addOnlineNode(n1);
    mo.getAttributes().put(vm1, "template", "small");
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(7));
    dev.register(ShutdownNode.class, new ConstantActionDuration<>(20));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(Collections.singleton(vm1), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()).build();
    // Force the node to get offline
    ShutdownableNode n = (ShutdownableNode) rp.getNodeAction(n1);
    n.getState().instantiateTo(0, Cause.Null);
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Assert.assertEquals(p.getDuration(), 20);
    for (Action a : p) {
        if (a instanceof org.btrplace.plan.event.ForgeVM) {
            org.btrplace.plan.event.ForgeVM action = (org.btrplace.plan.event.ForgeVM) a;
            Assert.assertTrue(p.getResult().getMapping().isReady(vm1));
            Assert.assertEquals(action.getVM(), vm1);
            Assert.assertEquals(action.getEnd(), 7);
            Assert.assertEquals(action.getStart(), 0);
        }
    }
}
Also used : Action(org.btrplace.plan.event.Action) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) 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)

Example 14 with Action

use of org.btrplace.plan.event.Action 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(org.btrplace.plan.event.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 15 with Action

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

the class ShutdownVMTest method testShutdownSequence.

/**
 * Test that check that the action duration is lesser than
 * the cSlice duration. This allows actions scheduling
 * In practice, for this test, 2 shutdown actions have to be executed sequentially
 */
@Test
public void testShutdownSequence() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm1 = mo.newVM();
    final VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    map.addOnlineNode(n1);
    map.addRunningVM(vm1, n1);
    map.addRunningVM(vm2, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.ShutdownVM.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(map.getAllVMs(), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
    ShutdownVM m1 = (ShutdownVM) rp.getVMActions().get(rp.getVM(vm1));
    ShutdownVM m2 = (ShutdownVM) rp.getVMActions().get(rp.getVM(vm2));
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    rp.getModel().post(rp.getModel().arithm(m2.getStart(), ">=", m1.getEnd()));
    // System.out.println(s);
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    // System.out.println(p);
    Iterator<Action> ite = p.iterator();
    org.btrplace.plan.event.ShutdownVM b1 = (org.btrplace.plan.event.ShutdownVM) ite.next();
    org.btrplace.plan.event.ShutdownVM b2 = (org.btrplace.plan.event.ShutdownVM) ite.next();
    Assert.assertEquals(vm1, b1.getVM());
    Assert.assertEquals(vm2, b2.getVM());
    Assert.assertTrue(b1.getEnd() <= b2.getStart());
    Assert.assertEquals(5, b1.getEnd() - b1.getStart());
    Assert.assertEquals(5, b2.getEnd() - b2.getStart());
}
Also used : Action(org.btrplace.plan.event.Action) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Action (org.btrplace.plan.event.Action)40 Test (org.testng.annotations.Test)25 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)18 MigrateVM (org.btrplace.plan.event.MigrateVM)10 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)10 HashSet (java.util.HashSet)9 Parameters (org.btrplace.scheduler.choco.Parameters)9 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)9 VM (org.btrplace.model.VM)8 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)8 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)8 Model (org.btrplace.model.Model)7 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)7 ArrayList (java.util.ArrayList)6 SatConstraint (org.btrplace.model.constraint.SatConstraint)6 Node (org.btrplace.model.Node)5 ShareableResource (org.btrplace.model.view.ShareableResource)5 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)5 BootVM (org.btrplace.plan.event.BootVM)4 ShutdownNode (org.btrplace.plan.event.ShutdownNode)4