Search in sources :

Example 1 with Sleeping

use of org.btrplace.model.constraint.Sleeping in project scheduler by btrplace.

the class SleepingSplitterTest method simpleTest.

@Test
public void simpleTest() {
    SleepingSplitter splitter = new SleepingSplitter();
    List<Instance> instances = new ArrayList<>();
    Model origin = new DefaultModel();
    Node n1 = origin.newNode();
    Node n2 = origin.newNode();
    VM vm1 = origin.newVM();
    VM vm2 = origin.newVM();
    VM vm3 = origin.newVM();
    VM vm4 = origin.newVM();
    /**
     * READY: vm1
     * n1 vm2
     * n2 (vm3) vm4
     */
    origin.getMapping().addOnlineNode(n1);
    origin.getMapping().addReadyVM(vm1);
    origin.getMapping().addRunningVM(vm2, n1);
    origin.getMapping().addOnlineNode(n2);
    origin.getMapping().addSleepingVM(vm3, n2);
    origin.getMapping().addRunningVM(vm4, n2);
    Model m0 = new DefaultModel();
    m0.newNode(n1.id());
    m0.newVM(vm1.id());
    m0.newVM(vm2.id());
    m0.getMapping().addOnlineNode(n1);
    m0.getMapping().addReadyVM(vm1);
    m0.getMapping().addRunningVM(vm2, n1);
    Model m1 = new DefaultModel();
    m1.newNode(n2.id());
    m1.newVM(vm3.id());
    m1.newVM(vm4.id());
    m1.getMapping().addOnlineNode(n2);
    m1.getMapping().addSleepingVM(vm3, n2);
    m1.getMapping().addRunningVM(vm4, n2);
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
    all.addAll(m1.getMapping().getAllVMs());
    TIntIntHashMap index = Instances.makeVMIndex(instances);
    // Only VMs in m0
    Sleeping single = new Sleeping(vm2);
    Assert.assertTrue(splitter.split(single, null, instances, index, new TIntIntHashMap()));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
}
Also used : ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) Sleeping(org.btrplace.model.constraint.Sleeping) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with Sleeping

use of org.btrplace.model.constraint.Sleeping in project scheduler by btrplace.

the class SleepingConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    Model mo = new DefaultModel();
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new SleepingConverter());
    Sleeping d = new Sleeping(mo.newVM());
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
    System.out.println(conv.toJSON(d));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Sleeping(org.btrplace.model.constraint.Sleeping) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 3 with Sleeping

use of org.btrplace.model.constraint.Sleeping in project scheduler by btrplace.

the class CSleepingTest method testGetMisplaced.

@Test
public void testGetMisplaced() {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    Node n1 = mo.newNode();
    mo.getMapping().on(n1).ready(vm1).run(n1, vm2).sleep(n1, vm3);
    Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
    CSleeping k = new CSleeping(new Sleeping(vm3));
    Assert.assertEquals(0, k.getMisPlacedVMs(i).size());
    k = new CSleeping(new Sleeping(vm1));
    Assert.assertEquals(1, k.getMisPlacedVMs(i).size());
    Assert.assertTrue(k.getMisPlacedVMs(i).contains(vm1));
    k = new CSleeping(new Sleeping(vm3));
    Assert.assertEquals(0, k.getMisPlacedVMs(i).size());
}
Also used : Sleeping(org.btrplace.model.constraint.Sleeping) MinMTTR(org.btrplace.model.constraint.MinMTTR) Test(org.testng.annotations.Test)

Example 4 with Sleeping

use of org.btrplace.model.constraint.Sleeping in project scheduler by btrplace.

the class SleepingBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodsleepings")
public void testGoodSignatures(String str, int nbVMs, boolean c) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;" + str).getConstraints();
    Set<VM> vms = new HashSet<>();
    Assert.assertEquals(cstrs.size(), nbVMs);
    for (SatConstraint x : cstrs) {
        Assert.assertTrue(x instanceof Sleeping);
        Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
        Assert.assertEquals(x.isContinuous(), c);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Sleeping(org.btrplace.model.constraint.Sleeping) SatConstraint(org.btrplace.model.constraint.SatConstraint) VM(org.btrplace.model.VM) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with Sleeping

use of org.btrplace.model.constraint.Sleeping in project scheduler by btrplace.

the class InstanceSolverRunner method buildRP.

private ReconfigurationProblem buildRP() throws SchedulerException {
    // Build the RP. As VM state management is not possible
    // We extract VM-state related constraints first.
    // For other constraint, we just create the right choco constraint
    Set<VM> toRun = new HashSet<>();
    Set<VM> toForge = new HashSet<>();
    Set<VM> toKill = new HashSet<>();
    Set<VM> toSleep = new HashSet<>();
    cConstraints = new ArrayList<>();
    for (SatConstraint cstr : cstrs) {
        checkNodesExistence(origin, cstr.getInvolvedNodes());
        // (when they will be forged)
        if (!(cstrs instanceof Ready)) {
            checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
        }
        if (cstr instanceof Running) {
            toRun.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Sleeping) {
            toSleep.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Ready) {
            checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
            toForge.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Killed) {
            checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
            toKill.addAll(cstr.getInvolvedVMs());
        }
        cConstraints.add(build(cstr));
    }
    cConstraints.add(build(obj));
    views = makeViews();
    DefaultReconfigurationProblemBuilder rpb = new DefaultReconfigurationProblemBuilder(origin).setNextVMsStates(toForge, toRun, toSleep, toKill).setParams(params);
    if (params.doRepair()) {
        Set<VM> toManage = new HashSet<>();
        cConstraints.forEach(c -> toManage.addAll(c.getMisPlacedVMs(instance)));
        views.forEach(v -> toManage.addAll(v.getMisPlacedVMs(instance)));
        rpb.setManageableVMs(toManage);
    }
    // The core views have been instantiated and available through rp.getViews()
    // Set the maximum duration
    ReconfigurationProblem p = rpb.build();
    try {
        p.getEnd().updateUpperBound(params.getMaxEnd(), Cause.Null);
    } catch (ContradictionException e) {
        p.getLogger().error("Unable to restrict the maximum plan duration to " + params.getMaxEnd(), e);
        return null;
    }
    return p;
}
Also used : Ready(org.btrplace.model.constraint.Ready) Sleeping(org.btrplace.model.constraint.Sleeping) ContradictionException(org.chocosolver.solver.exception.ContradictionException) VM(org.btrplace.model.VM) SatConstraint(org.btrplace.model.constraint.SatConstraint) Running(org.btrplace.model.constraint.Running) Killed(org.btrplace.model.constraint.Killed) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) HashSet(java.util.HashSet)

Aggregations

Sleeping (org.btrplace.model.constraint.Sleeping)5 Test (org.testng.annotations.Test)4 HashSet (java.util.HashSet)3 DefaultModel (org.btrplace.model.DefaultModel)2 VM (org.btrplace.model.VM)2 MinMTTR (org.btrplace.model.constraint.MinMTTR)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 ArrayList (java.util.ArrayList)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 Model (org.btrplace.model.Model)1 Killed (org.btrplace.model.constraint.Killed)1 Ready (org.btrplace.model.constraint.Ready)1 Running (org.btrplace.model.constraint.Running)1 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)1 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)1 ContradictionException (org.chocosolver.solver.exception.ContradictionException)1