Search in sources :

Example 1 with Killed

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

the class KilledSplitterTest method simpleTest.

@Test
public void simpleTest() {
    KilledSplitter splitter = new KilledSplitter();
    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    VM v = m0.newVM(1);
    m0.getMapping().addReadyVM(v);
    m0.getMapping().addRunningVM(m0.newVM(2), m0.newNode(1));
    Model m1 = new DefaultModel();
    m1.getMapping().addReadyVM(m1.newVM(3));
    m1.getMapping().addSleepingVM(m1.newVM(4), m1.newNode(2));
    m1.getMapping().addRunningVM(m1.newVM(5), m1.newNode(3));
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    TIntIntHashMap index = Instances.makeVMIndex(instances);
    Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
    all.addAll(m1.getMapping().getAllVMs());
    // Only VMs in m0
    Killed single = new Killed(v);
    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 : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) VM(org.btrplace.model.VM) ArrayList(java.util.ArrayList) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) Killed(org.btrplace.model.constraint.Killed) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with Killed

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

the class CKilledTest method testGetMisplaced.

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

Example 3 with Killed

use of org.btrplace.model.constraint.Killed 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)

Example 4 with Killed

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

the class KilledConverterTest method testViables.

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

Example 5 with Killed

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

the class KilledBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodKilleds")
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 Killed);
        Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
        Assert.assertEquals(x.isContinuous(), c);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SatConstraint(org.btrplace.model.constraint.SatConstraint) VM(org.btrplace.model.VM) Killed(org.btrplace.model.constraint.Killed) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Killed (org.btrplace.model.constraint.Killed)5 Test (org.testng.annotations.Test)4 HashSet (java.util.HashSet)3 DefaultModel (org.btrplace.model.DefaultModel)3 VM (org.btrplace.model.VM)3 Model (org.btrplace.model.Model)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 Instance (org.btrplace.model.Instance)1 Ready (org.btrplace.model.constraint.Ready)1 Running (org.btrplace.model.constraint.Running)1 Sleeping (org.btrplace.model.constraint.Sleeping)1 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)1 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)1 ContradictionException (org.chocosolver.solver.exception.ContradictionException)1