Search in sources :

Example 16 with DefaultParameters

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

the class SuspendVMTest method testSuspendSequences.

/**
 * Test that check that the action duration is lesser than
 * the cSlice duration. This allows actions scheduling
 * In practice, for this test, 2 suspend actions have to be executed sequentially
 */
@Test
public void testSuspendSequences() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Mapping map = mo.getMapping();
    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.SuspendVM.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), new HashSet<>(), map.getAllVMs(), new HashSet<>()).build();
    SuspendVM m1 = (SuspendVM) rp.getVMActions().get(rp.getVM(vm1));
    SuspendVM m2 = (SuspendVM) rp.getVMActions().get(rp.getVM(vm2));
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    org.chocosolver.solver.Model csp = rp.getModel();
    csp.post(csp.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.SuspendVM b1 = (org.btrplace.plan.event.SuspendVM) ite.next();
    org.btrplace.plan.event.SuspendVM b2 = (org.btrplace.plan.event.SuspendVM) 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 17 with DefaultParameters

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

the class SuspendVMTest method testBasic.

@Test
public void testBasic() throws ContradictionException, SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    Mapping map = mo.getMapping();
    map.addOnlineNode(n1);
    map.addRunningVM(vm1, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.SuspendVM.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), new HashSet<>(), map.getAllVMs(), new HashSet<>()).build();
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    SuspendVM m = (SuspendVM) rp.getVMActions().get(0);
    Assert.assertEquals(vm1, m.getVM());
    Assert.assertNull(m.getDSlice());
    Assert.assertTrue(m.getDuration().isInstantiatedTo(5));
    Assert.assertTrue(m.getState().isInstantiatedTo(0));
    Assert.assertTrue(m.getCSlice().getHoster().isInstantiatedTo(0));
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(0, false);
    org.btrplace.plan.event.SuspendVM a = (org.btrplace.plan.event.SuspendVM) p.getActions().iterator().next();
    Assert.assertEquals(n1, a.getSourceNode());
    Assert.assertEquals(vm1, a.getVM());
    Assert.assertEquals(5, 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) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 18 with DefaultParameters

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

the class CShareableResourceTest method testSimple.

/**
 * Test the instantiation and the creation of the variables.
 *
 * @throws org.btrplace.scheduler.SchedulerException should not occur
 */
@Test
public void testSimple() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping ma = mo.getMapping();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    ma.addOnlineNode(n1);
    ma.addOfflineNode(n2);
    ma.addRunningVM(vm1, n1);
    ma.addRunningVM(vm2, n1);
    ma.addReadyVM(vm3);
    ShareableResource rc = new ShareableResource("foo", 0, 0);
    rc.setConsumption(vm2, 3);
    rc.setCapacity(n1, 4);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).build();
    CShareableResource rcm = new CShareableResource(rc);
    rcm.inject(new DefaultParameters(), rp);
    Assert.assertEquals(rc.getIdentifier(), rcm.getIdentifier());
    // Assert.assertEquals(-1, rcm.getVMsAllocation(rp.getVM(vm1)).getLB());
    Assert.assertEquals(-1, rcm.getVMAllocation(rp.getVM(vm1)));
    // Assert.assertEquals(-1, rcm.getVMsAllocation(rp.getVM(vm2)).getLB());
    Assert.assertEquals(-1, rcm.getVMAllocation(rp.getVM(vm2)));
    // Assert.assertEquals(0, rcm.getVMsAllocation(rp.getVM(vm3)).getUB()); //Will not be running so 0
    // Will not be running so 0
    Assert.assertEquals(0, rcm.getVMAllocation(rp.getVM(vm3)));
    IntVar pn1 = rcm.getPhysicalUsage().get(rp.getNode(n1));
    IntVar pn2 = rcm.getPhysicalUsage().get(rp.getNode(n2));
    Assert.assertTrue(pn1.getLB() == 0 && pn1.getUB() == 4);
    Assert.assertTrue(pn2.getLB() == 0 && pn2.getUB() == 0);
    pn1 = rcm.getPhysicalUsage(rp.getNode(n1));
    Assert.assertTrue(pn1.getLB() == 0 && pn1.getUB() == 4);
    IntVar vn1 = rcm.getVirtualUsage().get(rp.getNode(n1));
    IntVar vn2 = rcm.getVirtualUsage().get(rp.getNode(n2));
    Assert.assertEquals(vn1.getLB(), 0);
    Assert.assertEquals(vn2.getLB(), 0);
    Assert.assertEquals(rc, rcm.getSourceResource());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) ShareableResource(org.btrplace.model.view.ShareableResource) IntVar(org.chocosolver.solver.variables.IntVar) Test(org.testng.annotations.Test)

Example 19 with DefaultParameters

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

the class Bench method benchHA.

public static void benchHA(int nbSamples, Integer partSize, Integer ratio, Integer nbParts) {
    Model mo = new DefaultModel();
    Instance inst = new Instance(mo, new MinMTTR());
    int nbNodes = partSize * nbParts;
    int nbVMs = ratio * nbNodes;
    // Make the infrastructure
    List<Node> l = makeNodeList(mo, nbNodes);
    ShareableResource rcCpu = new ShareableResource("cpu", 20, 0);
    ShareableResource rcMem = new ShareableResource("mem", 16, /*GB*/
    0);
    List<Collection<Node>> edges = makeEdges(l, 250);
    mo.attach(rcCpu);
    mo.attach(rcMem);
    while (nbVMs != 0) {
        nbVMs -= makeApp(inst, nbVMs, edges);
    }
    FixedSizePartitioning partitioner = new FixedSizePartitioning(partSize);
    try {
        for (int x = 0; x < nbSamples; x++) {
            long start = System.currentTimeMillis();
            List<Instance> instances = partitioner.split(new DefaultParameters(), inst);
            long end = System.currentTimeMillis();
            System.err.println(instances.size() + " " + nbNodes + " " + nbNodes * ratio + " " + inst.getSatConstraints().size() + " " + (end - start));
        }
    } catch (SchedulerException ex) {
        Assert.fail(ex.getMessage(), ex);
    }
}
Also used : SchedulerException(org.btrplace.scheduler.SchedulerException) MinMTTR(org.btrplace.model.constraint.MinMTTR) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters)

Example 20 with DefaultParameters

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

the class FixedNodeSetsPartitioningTest method testSplit.

@Test
public void testSplit() throws SchedulerException {
    Instance origin = makeInstance();
    List<Collection<Node>> parts = splitIn(origin.getModel().getMapping().getAllNodes(), 3);
    FixedNodeSetsPartitioning f = new FixedNodeSetsPartitioning(parts);
    f.setWorkersCount(3);
    List<Instance> subs = f.split(new DefaultParameters(), origin);
    // Check disjoint set of ready VMs
    Set<VM> allReady = new HashSet<>();
    for (Instance i : subs) {
        allReady.addAll(i.getModel().getMapping().getReadyVMs());
    }
    Assert.assertEquals(allReady.size(), 30);
    // Quick solve
    DefaultChocoScheduler cra = new DefaultChocoScheduler();
    cra.setInstanceSolver(f);
    ReconfigurationPlan plan = cra.solve(origin);
    // all the VMs to launch have been booted
    Assert.assertEquals(plan.getSize(), 30);
    System.out.println(cra.getStatistics());
    System.out.flush();
}
Also used : DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Test(org.testng.annotations.Test)

Aggregations

DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)40 Test (org.testng.annotations.Test)35 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)32 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)30 Parameters (org.btrplace.scheduler.choco.Parameters)29 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)29 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)28 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)14 DefaultModel (org.btrplace.model.DefaultModel)11 Model (org.btrplace.model.Model)11 Node (org.btrplace.model.Node)10 ShutdownNode (org.btrplace.plan.event.ShutdownNode)10 HashSet (java.util.HashSet)9 Mapping (org.btrplace.model.Mapping)9 VM (org.btrplace.model.VM)9 BootNode (org.btrplace.plan.event.BootNode)9 Action (org.btrplace.plan.event.Action)8 MigrateVM (org.btrplace.plan.event.MigrateVM)8 ShareableResource (org.btrplace.model.view.ShareableResource)6 ArrayList (java.util.ArrayList)5