Search in sources :

Example 31 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class ResumeVMTest method testBasics.

/**
 * Just resume a VM on its current node.
 */
@Test
public void testBasics() throws SchedulerException, ContradictionException {
    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.addSleepingVM(vm1, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.ResumeVM.class, new ConstantActionDuration<>(10));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
    ResumeVM m = (ResumeVM) rp.getVMActions().get(0);
    Assert.assertEquals(vm1, m.getVM());
    Assert.assertNull(m.getCSlice());
    Assert.assertTrue(m.getDuration().isInstantiatedTo(10));
    Assert.assertTrue(m.getState().isInstantiatedTo(1));
    Assert.assertFalse(m.getDSlice().getHoster().isInstantiated());
    Assert.assertFalse(m.getDSlice().getStart().isInstantiated());
    Assert.assertFalse(m.getDSlice().getEnd().isInstantiated());
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    org.btrplace.plan.event.ResumeVM a = (org.btrplace.plan.event.ResumeVM) p.getActions().iterator().next();
    Node dest = rp.getNode(m.getDSlice().getHoster().getValue());
    Assert.assertEquals(vm1, a.getVM());
    Assert.assertEquals(dest, a.getDestinationNode());
    Assert.assertEquals(n1, a.getSourceNode());
    Assert.assertEquals(10, a.getEnd() - a.getStart());
}
Also used : 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) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 32 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan 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)

Example 33 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class ShutdownableNodeTest method testCascadedShutdown.

/**
 * The 2 nodes are set offline but n2 will consume being offline after n1
 *
 * @throws org.btrplace.scheduler.SchedulerException
 * @throws ContradictionException
 */
@Test
public void testCascadedShutdown() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(ShutdownVM.class, new ConstantActionDuration<>(2));
    dev.register(ShutdownNode.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    ShutdownableNode ma1 = (ShutdownableNode) rp.getNodeAction(n1);
    ShutdownableNode ma2 = (ShutdownableNode) rp.getNodeAction(n2);
    ma1.getState().instantiateTo(0, Cause.Null);
    ma2.getState().instantiateTo(0, Cause.Null);
    rp.getModel().post(rp.getModel().arithm(ma2.getStart(), "=", ma1.getEnd()));
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    System.out.println(p);
    Assert.assertEquals(ma1.getStart().getValue(), 0);
    Assert.assertEquals(ma2.getStart().getValue(), ma1.getEnd().getValue());
    Model res = p.getResult();
    Assert.assertEquals(res.getMapping().getOfflineNodes().size(), 2);
}
Also used : Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) Test(org.testng.annotations.Test)

Example 34 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class ShutdownableNodeTest method testSwitchState.

@Test
public void testSwitchState() throws ContradictionException, SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOnlineNode(n1);
    map.addOfflineNode(n2);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(BootNode.class, new ConstantActionDuration<>(2));
    dev.register(ShutdownNode.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    ShutdownableNode ma1 = (ShutdownableNode) rp.getNodeAction(n1);
    BootableNode ma2 = (BootableNode) rp.getNodeAction(n2);
    ma1.getState().instantiateTo(0, Cause.Null);
    ma2.getState().instantiateTo(1, Cause.Null);
    rp.getModel().post(rp.getModel().arithm(ma1.getEnd(), "=", ma2.getStart()));
    ReconfigurationPlan p = rp.solve(0, false);
    // ChocoLogging.flushLogs();
    Assert.assertNotNull(p);
    System.out.println(p);
    System.out.flush();
}
Also used : Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) BootNode(org.btrplace.plan.event.BootNode) 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) Test(org.testng.annotations.Test)

Example 35 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class ShutdownableNodeTest method testActionDurationSimple.

@Test
public void testActionDurationSimple() throws SchedulerException, ContradictionException {
    Model model = new DefaultModel();
    Mapping map = model.getMapping();
    Node n1 = model.newNode();
    Node n4 = model.newNode();
    map.addOnlineNode(n1);
    map.addOfflineNode(n4);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(ShutdownNode.class, new ConstantActionDuration<>(5));
    dev.register(BootNode.class, new ConstantActionDuration<>(3));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(model).setParams(ps).build();
    ShutdownableNode sn1 = (ShutdownableNode) rp.getNodeAction(n1);
    sn1.getState().instantiateTo(0, Cause.Null);
    BootableNode bn4 = (BootableNode) rp.getNodeAction(n4);
    bn4.getState().instantiateTo(0, Cause.Null);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    System.out.println(p);
    Assert.assertEquals(rp.getStart().getValue(), 0);
    Assert.assertEquals(bn4.getStart().getValue(), 0);
    Assert.assertEquals(bn4.getDuration().getValue(), 0);
    Assert.assertEquals(bn4.getEnd().getValue(), 0);
    Assert.assertEquals(bn4.getHostingStart().getValue(), 0);
    Assert.assertEquals(bn4.getHostingEnd().getValue(), 0);
    Assert.assertEquals(p.getSize(), 1);
    Model res = p.getResult();
    Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n1));
    Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n4));
}
Also used : Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) BootNode(org.btrplace.plan.event.BootNode) 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) Test(org.testng.annotations.Test)

Aggregations

ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)185 Test (org.testng.annotations.Test)160 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)94 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)74 SatConstraint (org.btrplace.model.constraint.SatConstraint)53 ShareableResource (org.btrplace.model.view.ShareableResource)52 Model (org.btrplace.model.Model)49 ArrayList (java.util.ArrayList)46 Node (org.btrplace.model.Node)45 DefaultModel (org.btrplace.model.DefaultModel)44 VM (org.btrplace.model.VM)41 MigrateVM (org.btrplace.plan.event.MigrateVM)37 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)34 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)32 Parameters (org.btrplace.scheduler.choco.Parameters)29 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)29 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)28 DefaultReconfigurationPlan (org.btrplace.plan.DefaultReconfigurationPlan)24 Mapping (org.btrplace.model.Mapping)23 HashSet (java.util.HashSet)22