Search in sources :

Example 1 with MinMTTR

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

the class BenchTest method instance.

public static Instance instance() {
    Model mo = new DefaultModel();
    VM v1 = mo.newVM();
    VM v2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    mo.getMapping().on(n1, n2, n3).run(n1, v1).run(n2, v2).off(n3);
    Set<VM> s = new HashSet<>();
    s.add(v1);
    s.add(v2);
    List<SatConstraint> cstrs = Arrays.asList(new Spread(s, true), new Fence(v1, n2), new Offline(n1));
    return new Instance(mo, cstrs, new MinMTTR());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) MinMTTR(org.btrplace.model.constraint.MinMTTR) Offline(org.btrplace.model.constraint.Offline) Spread(org.btrplace.model.constraint.Spread) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Fence(org.btrplace.model.constraint.Fence) HashSet(java.util.HashSet)

Example 2 with MinMTTR

use of org.btrplace.model.constraint.MinMTTR 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 : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Killed(org.btrplace.model.constraint.Killed) MinMTTR(org.btrplace.model.constraint.MinMTTR) Test(org.testng.annotations.Test)

Example 3 with MinMTTR

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

the class InstanceConverterTest method testConversion.

@Test
public void testConversion() throws JSONConverterException {
    Model mo = new DefaultModel();
    Mapping ma = mo.getMapping();
    Node n1 = mo.newNode();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    ma.addOnlineNode(n1);
    ma.addOfflineNode(n1);
    ma.addReadyVM(vm1);
    ma.addReadyVM(vm2);
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Online.newOnline(ma.getAllNodes()));
    cstrs.add(new Running(vm2));
    Instance i = new Instance(mo, cstrs, new MinMTTR());
    InstanceConverter conv = new InstanceConverter();
    String o = conv.toJSONString(i);
    System.out.println(o);
    Instance res = conv.fromJSON(o);
    Assert.assertEquals(i, res);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) Mapping(org.btrplace.model.Mapping) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) Test(org.testng.annotations.Test)

Example 4 with MinMTTR

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

the class MinMttrConverterTest method test.

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

Example 5 with MinMTTR

use of org.btrplace.model.constraint.MinMTTR 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 : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) Sleeping(org.btrplace.model.constraint.Sleeping) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

MinMTTR (org.btrplace.model.constraint.MinMTTR)47 Model (org.btrplace.model.Model)42 Instance (org.btrplace.model.Instance)41 Test (org.testng.annotations.Test)41 DefaultModel (org.btrplace.model.DefaultModel)40 Node (org.btrplace.model.Node)33 VM (org.btrplace.model.VM)33 ArrayList (java.util.ArrayList)22 HashSet (java.util.HashSet)22 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)15 SatConstraint (org.btrplace.model.constraint.SatConstraint)10 Mapping (org.btrplace.model.Mapping)9 Running (org.btrplace.model.constraint.Running)8 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)8 Collection (java.util.Collection)6 Offline (org.btrplace.model.constraint.Offline)5 ShareableResource (org.btrplace.model.view.ShareableResource)5 Spread (org.btrplace.model.constraint.Spread)4 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)4 Ban (org.btrplace.model.constraint.Ban)3