Search in sources :

Example 31 with ReconfigurationProblem

use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.

the class ShutdownableNodeTest method testShutdownable.

@Test
public void testShutdownable() throws SchedulerException, ContradictionException {
    Model model = new DefaultModel();
    Mapping map = model.getMapping();
    Node n1 = model.newNode();
    Node n4 = model.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(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);
    sn1.getStart().instantiateTo(2, Cause.Null);
    ShutdownableNode sn4 = (ShutdownableNode) rp.getNodeAction(n4);
    sn4.getState().instantiateTo(1, Cause.Null);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    System.out.println(p);
    Assert.assertEquals(rp.getStart().getValue(), 0);
    Assert.assertEquals(rp.getEnd().getValue(), 7);
    Assert.assertEquals(sn1.getStart().getValue(), 2);
    Assert.assertEquals(sn1.getDuration().getValue(), 5);
    Assert.assertEquals(sn1.getEnd().getValue(), 7);
    Assert.assertEquals(sn1.getHostingStart().getValue(), 0);
    Assert.assertEquals(sn1.getHostingEnd().getValue(), 2);
    Assert.assertEquals(rp.getStart().getValue(), 0);
    Assert.assertEquals(sn4.getStart().getValue(), 0);
    Assert.assertEquals(sn4.getDuration().getValue(), 0);
    Assert.assertEquals(sn4.getEnd().getValue(), 0);
    Assert.assertEquals(sn4.getHostingStart().getValue(), 0);
    Assert.assertEquals(sn4.getHostingEnd().getValue(), 7);
    Assert.assertEquals(p.getSize(), 1);
    Model res = p.getResult();
    Assert.assertTrue(res.getMapping().isOnline(n4));
    Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n1));
}
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 32 with ReconfigurationProblem

use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.

the class ShutdownableNodeTest method testForcedOnline.

@Test
public void testForcedOnline() throws SchedulerException, ContradictionException {
    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(ShutdownNode.class, new ConstantActionDuration<>(5));
    dev.register(BootNode.class, new ConstantActionDuration<>(10));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    ShutdownableNode ma = (ShutdownableNode) rp.getNodeAction(n1);
    // stay online
    ma.getState().instantiateTo(1, Cause.Null);
    // To make the result plan 10 seconds long
    BootableNode ma2 = (BootableNode) rp.getNodeAction(n2);
    // go online
    ma2.getState().instantiateTo(1, Cause.Null);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    System.out.println(p);
    Assert.assertEquals(ma.getDuration().getValue(), 0);
    Assert.assertEquals(ma.getStart().getValue(), 0);
    Assert.assertEquals(ma.getEnd().getValue(), 0);
    Assert.assertEquals(ma.getHostingStart().getValue(), 0);
    Assert.assertEquals(ma.getHostingEnd().getValue(), 10);
    Assert.assertEquals(p.getSize(), 1);
    Model res = p.getResult();
    Assert.assertTrue(res.getMapping().isOnline(n1));
}
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 33 with ReconfigurationProblem

use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.

the class ShutdownableNodeTest method testShutdownBeforeVMsLeave.

@Test
public void testShutdownBeforeVMsLeave() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    map.addOnlineNode(n1);
    map.addRunningVM(vm1, n1);
    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).setNextVMsStates(Collections.singleton(vm1), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
    ShutdownableNode ma1 = (ShutdownableNode) rp.getNodeAction(n1);
    ma1.getState().instantiateTo(0, Cause.Null);
    ma1.getHostingEnd().instantiateTo(0, Cause.Null);
    rp.getEnd().updateUpperBound(10, Cause.Null);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNull(p);
}
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) ShutdownVM(org.btrplace.plan.event.ShutdownVM) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Test(org.testng.annotations.Test)

Example 34 with ReconfigurationProblem

use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.

the class ShutdownableNodeTest method testScheduledShutdown.

@Test
public void testScheduledShutdown() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    map.addOnlineNode(n1);
    map.addRunningVM(vm1, n1);
    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).setNextVMsStates(Collections.singleton(vm1), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()).build();
    ShutdownableNode ma = (ShutdownableNode) rp.getNodeAction(n1);
    ma.getState().instantiateTo(0, Cause.Null);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Assert.assertEquals(ma.getState().getValue(), 0);
    Assert.assertEquals(ma.getDuration().getValue(), 5);
    Assert.assertEquals(ma.getStart().getValue(), 2);
    Assert.assertEquals(ma.getEnd().getValue(), 7);
    Assert.assertEquals(ma.getHostingStart().getValue(), 0);
    Assert.assertEquals(ma.getHostingEnd().getValue(), 2);
    Model res = p.getResult();
    Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n1));
}
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) ShutdownVM(org.btrplace.plan.event.ShutdownVM) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Test(org.testng.annotations.Test)

Example 35 with ReconfigurationProblem

use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.

the class StayAwayVMTest method testBasic.

@Test
public void testBasic() 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.addSleepingVM(vm1, n1);
    map.addReadyVM(vm2);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).build();
    rp.getNodeAction(n1).getState().instantiateTo(1, Cause.Null);
    StayAwayVM ma1 = (StayAwayVM) rp.getVMAction(vm1);
    StayAwayVM ma2 = (StayAwayVM) rp.getVMAction(vm2);
    Assert.assertEquals(vm1, ma1.getVM());
    Assert.assertEquals(vm2, ma2.getVM());
    for (VMTransition am : rp.getVMActions()) {
        Assert.assertTrue(am.getState().isInstantiatedTo(0));
        Assert.assertNull(am.getCSlice());
        Assert.assertNull(am.getDSlice());
        Assert.assertTrue(am.getStart().isInstantiatedTo(0));
        Assert.assertTrue(am.getEnd().isInstantiatedTo(0));
        Assert.assertTrue(am.getDuration().isInstantiatedTo(0));
    }
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Assert.assertEquals(0, p.getSize());
}
Also used : ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) Test(org.testng.annotations.Test)

Aggregations

ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)35 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)32 Test (org.testng.annotations.Test)31 Parameters (org.btrplace.scheduler.choco.Parameters)30 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)29 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)28 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)27 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)14 HashSet (java.util.HashSet)13 VM (org.btrplace.model.VM)13 Mapping (org.btrplace.model.Mapping)12 Model (org.btrplace.model.Model)12 ShutdownNode (org.btrplace.plan.event.ShutdownNode)11 Node (org.btrplace.model.Node)10 BootNode (org.btrplace.plan.event.BootNode)10 DefaultModel (org.btrplace.model.DefaultModel)9 Action (org.btrplace.plan.event.Action)9 MigrateVM (org.btrplace.plan.event.MigrateVM)9 ShareableResource (org.btrplace.model.view.ShareableResource)4 IntVar (org.chocosolver.solver.variables.IntVar)4