Search in sources :

Example 31 with DefaultReconfigurationProblemBuilder

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

the class ShutdownableNodeTest method testNodeHostingEnd.

/**
 * Issue #2 about NodeTransition.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 * @throws ContradictionException
 */
@Test
public void testNodeHostingEnd() throws SchedulerException, ContradictionException {
    Model model = new DefaultModel();
    Mapping map = model.getMapping();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addOfflineNode(n3);
    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(model).setParams(ps).build();
    ShutdownableNode shd = (ShutdownableNode) rp.getNodeAction(n1);
    // Stay online
    shd.getState().instantiateTo(1, Cause.Null);
    ShutdownableNode shd2 = (ShutdownableNode) rp.getNodeAction(n2);
    // Go offline
    shd2.getState().instantiateTo(0, Cause.Null);
    // Start going offline at 1
    shd2.getStart().instantiateTo(1, Cause.Null);
    BootableNode bn = (BootableNode) rp.getNodeAction(n3);
    // Go online
    bn.getState().instantiateTo(1, Cause.Null);
    // Start going online at 6
    bn.getStart().instantiateTo(6, Cause.Null);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    System.out.println(p);
    Assert.assertEquals(shd.getDuration().getValue(), 0);
    Assert.assertEquals(shd.getStart().getValue(), 0);
    Assert.assertEquals(shd.getEnd().getValue(), 0);
    Assert.assertEquals(shd.getHostingStart().getValue(), 0);
    Assert.assertEquals(shd.getHostingEnd().getValue(), 16);
    Assert.assertEquals(shd2.getDuration().getValue(), 5);
    Assert.assertEquals(shd2.getStart().getValue(), 1);
    Assert.assertEquals(shd2.getEnd().getValue(), 6);
    Assert.assertEquals(shd2.getHostingStart().getValue(), 0);
    Assert.assertEquals(shd2.getHostingEnd().getValue(), 1);
    Assert.assertEquals(bn.getStart().getValue(), 6);
    Assert.assertEquals(bn.getDuration().getValue(), 10);
    Assert.assertEquals(bn.getEnd().getValue(), 16);
    Assert.assertEquals(bn.getHostingStart().getValue(), 16);
    Assert.assertEquals(bn.getHostingEnd().getValue(), 16);
    Assert.assertEquals(p.getSize(), 2);
    Model res = p.getResult();
    Assert.assertTrue(res.getMapping().isOnline(n1));
    Assert.assertTrue(res.getMapping().isOnline(n3));
    Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n2));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Test(org.testng.annotations.Test)

Example 32 with DefaultReconfigurationProblemBuilder

use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder 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 : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Test(org.testng.annotations.Test)

Example 33 with DefaultReconfigurationProblemBuilder

use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder 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 : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) 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 34 with DefaultReconfigurationProblemBuilder

use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder 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 : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Test(org.testng.annotations.Test)

Example 35 with DefaultReconfigurationProblemBuilder

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

the class BootVMTest method testBasics.

/**
 * Just boot a VM on a  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.addReadyVM(vm1);
    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();
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
    BootVM m = (BootVM) rp.getVMActions().get(0);
    Assert.assertEquals(vm1, m.getVM());
    Assert.assertNull(m.getCSlice());
    Assert.assertTrue(m.getDuration().isInstantiatedTo(5));
    Assert.assertTrue(m.getState().isInstantiatedTo(1));
    Assert.assertFalse(m.getDSlice().getHoster().isInstantiated());
    Assert.assertFalse(m.getDSlice().getStart().isInstantiated());
    Assert.assertFalse(m.getDSlice().getEnd().isInstantiated());
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    org.btrplace.plan.event.BootVM a = (org.btrplace.plan.event.BootVM) p.getActions().iterator().next();
    Node dest = rp.getNode(m.getDSlice().getHoster().getValue());
    Assert.assertEquals(vm1, a.getVM());
    Assert.assertEquals(dest, a.getDestinationNode());
    Assert.assertEquals(5, a.getEnd() - a.getStart());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) 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) 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) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)39 DefaultModel (org.btrplace.model.DefaultModel)38 Model (org.btrplace.model.Model)38 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)38 Test (org.testng.annotations.Test)38 Mapping (org.btrplace.model.Mapping)36 Node (org.btrplace.model.Node)36 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)35 Parameters (org.btrplace.scheduler.choco.Parameters)33 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)33 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)31 VM (org.btrplace.model.VM)25 ShutdownNode (org.btrplace.plan.event.ShutdownNode)17 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)17 BootNode (org.btrplace.plan.event.BootNode)16 HashSet (java.util.HashSet)9 Action (org.btrplace.plan.event.Action)8 MigrateVM (org.btrplace.plan.event.MigrateVM)8 ShutdownVM (org.btrplace.plan.event.ShutdownVM)2 ShareableResource (org.btrplace.model.view.ShareableResource)1