Search in sources :

Example 6 with Ban

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

the class BanSplitterTest method simpleTest.

@Test
public void simpleTest() {
    BanSplitter splitter = new BanSplitter();
    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 vmIndex = Instances.makeVMIndex(instances);
    TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
    // Only VMs & nodes in m0
    Ban single = new Ban(vm1, m0.getMapping().getAllNodes());
    Assert.assertTrue(splitter.split(single, null, instances, vmIndex, nodeIndex));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
    // All the VMs, nodes in m1.
    Ban among = new Ban(vm3, m1.getMapping().getAllNodes());
    Assert.assertTrue(splitter.split(among, null, instances, vmIndex, nodeIndex));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(new Ban(vm1, m0.getMapping().getAllNodes())));
    Assert.assertTrue(instances.get(1).getSatConstraints().contains(new Ban(vm3, m1.getMapping().getAllNodes())));
}
Also used : ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) Ban(org.btrplace.model.constraint.Ban) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 7 with Ban

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

the class CNoDelayTest method testOk1.

@Test
public void testOk1() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    VM vm3 = model.newVM();
    VM vm4 = model.newVM();
    ShareableResource resources = new ShareableResource("cpu", 4, 1);
    resources.setCapacity(n2, 3);
    resources.setConsumption(vm1, 4);
    Mapping map = model.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2).run(n3, vm3).run(n3, vm4);
    MappingUtils.fill(map, model.getMapping());
    model.attach(resources);
    Ban b = new Ban(vm1, Collections.singleton(n1));
    NoDelay nd = new NoDelay(vm3);
    // 1 solution (priority to vm3): vm3 to n2 ; vm4 to n2 ; vm1 to n3
    List<SatConstraint> constraints = new ArrayList<>();
    constraints.add(nd);
    constraints.add(b);
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
    ReconfigurationPlan plan = cra.solve(model, constraints);
    Assert.assertNotNull(plan);
    Assert.assertTrue(nd.isSatisfied(plan));
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) Ban(org.btrplace.model.constraint.Ban) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) NoDelay(org.btrplace.model.constraint.NoDelay) Test(org.testng.annotations.Test)

Example 8 with Ban

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

the class CNoDelayTest method testKo.

@Test
public void testKo() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    VM vm3 = model.newVM();
    VM vm4 = model.newVM();
    ShareableResource resources = new ShareableResource("cpu", 4, 1);
    resources.setCapacity(n2, 3);
    resources.setConsumption(vm1, 4);
    Mapping map = model.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2).run(n3, vm3).run(n3, vm4);
    MappingUtils.fill(map, model.getMapping());
    model.attach(resources);
    Ban b = new Ban(vm1, Collections.singleton(n1));
    NoDelay nd = new NoDelay(vm1);
    // No solution: unable to migrate vm1 at t=0
    List<SatConstraint> constraints = new ArrayList<>();
    constraints.add(nd);
    constraints.add(b);
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
    ReconfigurationPlan plan = cra.solve(model, constraints);
    Assert.assertNull(plan);
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) Ban(org.btrplace.model.constraint.Ban) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) NoDelay(org.btrplace.model.constraint.NoDelay) Test(org.testng.annotations.Test)

Aggregations

Ban (org.btrplace.model.constraint.Ban)8 Test (org.testng.annotations.Test)7 ArrayList (java.util.ArrayList)5 SatConstraint (org.btrplace.model.constraint.SatConstraint)5 ShareableResource (org.btrplace.model.view.ShareableResource)4 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)4 DefaultModel (org.btrplace.model.DefaultModel)3 NoDelay (org.btrplace.model.constraint.NoDelay)3 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)3 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)3 HashSet (java.util.HashSet)2 Model (org.btrplace.model.Model)2 Node (org.btrplace.model.Node)2 VM (org.btrplace.model.VM)2 MinMTTR (org.btrplace.model.constraint.MinMTTR)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 Mapping (org.btrplace.model.Mapping)1 Offline (org.btrplace.model.constraint.Offline)1 OptConstraint (org.btrplace.model.constraint.OptConstraint)1