Search in sources :

Example 1 with CMinMTTR

use of org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR in project scheduler by btrplace.

the class DefaultReconfigurationProblemTest method testVMCounting.

/**
 * Check the consistency between the variables counting the number of VMs on
 * each node, and the placement variable.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 * @throws ContradictionException
 */
@Test
public void testVMCounting() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Node n3 = mo.newNode();
    Node n2 = mo.newNode();
    Mapping map = mo.getMapping();
    for (int i = 0; i < 7; i++) {
        VM v = mo.newVM();
        map.addReadyVM(v);
    }
    map.addOnlineNode(n3);
    map.addOnlineNode(n2);
    Parameters ps = new DefaultParameters();
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
    // Restrict the capacity to 5 at most
    for (IntVar capa : rp.getNbRunningVMs()) {
        capa.updateUpperBound(5, Cause.Null);
    }
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(-1, false);
    Assert.assertNotNull(p);
    // Check consistency between the counting and the hoster variables
    int[] counts = new int[map.getAllNodes().size()];
    for (Node n : map.getOnlineNodes()) {
        int nIdx = rp.getNode(n);
        counts[nIdx] = rp.getNbRunningVMs().get(nIdx).getValue();
    }
    for (VM vm : rp.getFutureRunningVMs()) {
        VMTransition vmo = rp.getVMActions().get(rp.getVM(vm));
        int on = vmo.getDSlice().getHoster().getValue();
        counts[on]--;
    }
    for (int count : counts) {
        Assert.assertEquals(count, 0);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) KillVM(org.btrplace.scheduler.choco.transition.KillVM) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with CMinMTTR

use of org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR in project scheduler by btrplace.

the class IssuesTest method testIssue10.

@Test
public void testIssue10() throws SchedulerException, ContradictionException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    Mapping map = model.getMapping().on(n1, n2).off(n3).run(n1, vm1, vm2);
    // model.attach(resources);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(model).build();
    // n3 goes online
    rp.getNodeAction(n3).getState().instantiateTo(1, Cause.Null);
    rp.getModel().post(rp.getModel().arithm(rp.getEnd(), "<=", 10));
    int NUMBER_OF_NODE = map.getAllNodes().size();
    // Extract all the state of the involved nodes (all nodes in this case)
    List<IntVar> VMsOnAllNodes = rp.getNbRunningVMs();
    // Each element is the number of VMs on each node
    IntVar[] vmsOnInvolvedNodes = new IntVar[NUMBER_OF_NODE];
    BoolVar[] idles = new BoolVar[NUMBER_OF_NODE];
    int i = 0;
    int maxVMs = rp.getSourceModel().getMapping().getAllVMs().size();
    for (Node n : map.getAllNodes()) {
        vmsOnInvolvedNodes[i] = rp.getModel().intVar("nVMs" + n, -1, maxVMs, true);
        IntVar state = rp.getNodeAction(n).getState();
        // If the node is offline -> the temporary variable is 1, otherwise, it equals the number of VMs on that node
        Constraint elem = rp.getModel().element(vmsOnInvolvedNodes[i], new IntVar[] { rp.getModel().intVar(-1), VMsOnAllNodes.get(rp.getNode(n)) }, state, 0);
        rp.getModel().post(elem);
        // IF number of VMs on a node is 0 -> Idle
        idles[i] = rp.getModel().boolVar("idle" + n);
        ChocoUtils.postIfOnlyIf(rp, idles[i], rp.getModel().arithm(vmsOnInvolvedNodes[i], "=", 0));
        i++;
    }
    IntVar sum = rp.getModel().intVar("sum", 0, 1000, true);
    rp.getModel().post(rp.getModel().sum(idles, "=", sum));
    // idle should be less than Amount for MaxSN (0, in this case)
    rp.getModel().post(rp.getModel().arithm(sum, "=", 0));
    System.err.flush();
    CMinMTTR obj = new CMinMTTR();
    obj.inject(new DefaultParameters(), rp);
    ReconfigurationPlan plan = rp.solve(0, false);
    Assert.assertNotNull(plan);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) OptConstraint(org.btrplace.model.constraint.OptConstraint) Constraint(org.chocosolver.solver.constraints.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) OptConstraint(org.btrplace.model.constraint.OptConstraint) Constraint(org.chocosolver.solver.constraints.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) BoolVar(org.chocosolver.solver.variables.BoolVar) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Example 3 with CMinMTTR

use of org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR 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 4 with CMinMTTR

use of org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR 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 : BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Example 5 with CMinMTTR

use of org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR 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 : BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Aggregations

CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)19 Test (org.testng.annotations.Test)19 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)18 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)17 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)14 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)14 Parameters (org.btrplace.scheduler.choco.Parameters)14 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)14 HashSet (java.util.HashSet)8 DefaultModel (org.btrplace.model.DefaultModel)8 Mapping (org.btrplace.model.Mapping)8 Model (org.btrplace.model.Model)8 Node (org.btrplace.model.Node)8 VM (org.btrplace.model.VM)8 Action (org.btrplace.plan.event.Action)7 MigrateVM (org.btrplace.plan.event.MigrateVM)6 ShutdownNode (org.btrplace.plan.event.ShutdownNode)4 BootNode (org.btrplace.plan.event.BootNode)3 IntVar (org.chocosolver.solver.variables.IntVar)2 OptConstraint (org.btrplace.model.constraint.OptConstraint)1