Search in sources :

Example 16 with DefaultReconfigurationProblemBuilder

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

Example 17 with DefaultReconfigurationProblemBuilder

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

the class ForgeVMTest method testBasics.

@Test
public void testBasics() throws SchedulerException {
    Model mo = new DefaultModel();
    final VM vm1 = mo.newVM();
    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));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(Collections.singleton(vm1), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()).build();
    ForgeVM ma = (ForgeVM) rp.getVMAction(vm1);
    Assert.assertEquals(vm1, ma.getVM());
    Assert.assertEquals(ma.getTemplate(), "small");
    Assert.assertTrue(ma.getDuration().isInstantiatedTo(7));
    Assert.assertFalse(ma.getStart().isInstantiated());
    Assert.assertFalse(ma.getEnd().isInstantiated());
    Assert.assertTrue(ma.getState().isInstantiatedTo(0));
    Assert.assertNull(ma.getCSlice());
    Assert.assertNull(ma.getDSlice());
}
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) 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) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) Test(org.testng.annotations.Test)

Example 18 with DefaultReconfigurationProblemBuilder

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

the class BootableNodeTest method testForcingOffline.

@Test
public void testForcingOffline() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    Node n1 = mo.newNode();
    map.addOfflineNode(n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(BootNode.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    BootableNode na = (BootableNode) rp.getNodeAction(n1);
    na.getState().instantiateTo(0, Cause.Null);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Assert.assertEquals(na.getDuration().getValue(), 0);
    Assert.assertEquals(na.getStart().getValue(), 0);
    Assert.assertEquals(na.getEnd().getValue(), 0);
    Assert.assertEquals(na.getHostingStart().getValue(), rp.getEnd().getValue());
    Assert.assertEquals(na.getHostingEnd().getValue(), rp.getEnd().getValue());
    Assert.assertNotNull(p);
    Assert.assertEquals(p.getSize(), 0);
    Model res = p.getResult();
    Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n1));
}
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) 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 19 with DefaultReconfigurationProblemBuilder

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

the class BootableNodeTest method testDelayedBooting.

@Test
public void testDelayedBooting() throws ContradictionException, SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    Node n2 = mo.newNode();
    map.addOfflineNode(n2);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(BootNode.class, new ConstantActionDuration<>(2));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    BootableNode ma2 = (BootableNode) rp.getNodeAction(n2);
    ma2.getState().instantiateTo(1, Cause.Null);
    ma2.getStart().updateLowerBound(5, Cause.Null);
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(0, false);
    // ChocoLogging.flushLogs();
    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) 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) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Example 20 with DefaultReconfigurationProblemBuilder

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

the class BootableNodeTest method testActionDurationSimple.

/**
 * Unit test for issue #3
 */
@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);
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    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 : DefaultModel(org.btrplace.model.DefaultModel) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Parameters(org.btrplace.scheduler.choco.Parameters) 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) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) 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