Search in sources :

Example 21 with MinMTTR

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

the class CSplitTest method testGetMisplaced.

@Test
public void testGetMisplaced() {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    VM vm6 = mo.newVM();
    VM vm7 = mo.newVM();
    VM vm8 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Node n4 = mo.newNode();
    Node n5 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2, n3, n4, n5).run(n1, vm1, vm2).run(n2, vm3).run(n3, vm4, vm5).run(n4, vm6).run(n5, vm7, vm8);
    Collection<VM> g1 = Arrays.asList(vm1, vm2);
    Collection<VM> g2 = new HashSet<>(Arrays.asList(vm3, vm4, vm5));
    Collection<VM> g3 = new HashSet<>(Arrays.asList(vm6, vm7));
    Collection<Collection<VM>> grps = Arrays.asList(g1, g2, g3);
    Split s = new Split(grps);
    CSplit cs = new CSplit(s);
    Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
    Assert.assertTrue(cs.getMisPlacedVMs(i).isEmpty());
    map.addRunningVM(vm5, n1);
    Set<VM> bad = cs.getMisPlacedVMs(i);
    Assert.assertEquals(bad.size(), 3);
    Assert.assertTrue(bad.contains(vm1) && bad.contains(vm2) && bad.contains(vm5));
    map.addRunningVM(vm6, n3);
    bad = cs.getMisPlacedVMs(i);
    Assert.assertTrue(bad.contains(vm4) && bad.contains(vm5) && bad.contains(vm6));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) 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) Collection(java.util.Collection) Split(org.btrplace.model.constraint.Split) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 22 with MinMTTR

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

the class IssuesTest method testIssue86.

@Test
public void testIssue86() throws Exception {
    Model mo = new DefaultModel();
    mo.getMapping().addReadyVM(mo.newVM());
    mo.getMapping().addReadyVM(mo.newVM());
    mo.getMapping().addReadyVM(mo.newVM());
    mo.getMapping().addOnlineNode(mo.newNode());
    mo.getMapping().addOnlineNode(mo.newNode());
    mo.getMapping().addOnlineNode(mo.newNode());
    List<SatConstraint> cstrs = mo.getMapping().getAllVMs().stream().map(Running::new).collect(Collectors.toList());
    cstrs.add(new Spread(mo.getMapping().getAllVMs(), false));
    cstrs.addAll(mo.getMapping().getOnlineNodes().stream().map(n -> new RunningCapacity(n, 1)).collect(Collectors.toList()));
    Instance i = new Instance(mo, cstrs, new MinMTTR());
    ChocoScheduler s = new DefaultChocoScheduler();
    s.doOptimize(false);
    s.doRepair(false);
    ReconfigurationPlan p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
    Assert.assertNotNull(p);
    Assert.assertEquals(3, p.getActions().size());
    s.doRepair(true);
    p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
    Assert.assertNotNull(p);
    Assert.assertEquals(3, p.getActions().size());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Spread(org.btrplace.model.constraint.Spread) RunningCapacity(org.btrplace.model.constraint.RunningCapacity) Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Example 23 with MinMTTR

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

the class CResourceCapacityTest method testGetMisplaced.

@Test
public void testGetMisplaced() {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Mapping m = mo.getMapping().on(n1, n2, n3).run(n1, vm1, vm2, vm3).run(n2, vm4).ready(vm5);
    ShareableResource rc = new ShareableResource("cpu", 5, 5);
    rc.setConsumption(vm1, 2);
    rc.setConsumption(vm2, 3);
    rc.setConsumption(vm3, 3);
    rc.setConsumption(vm4, 1);
    rc.setConsumption(vm5, 5);
    mo.attach(rc);
    ResourceCapacity c = new ResourceCapacity(m.getAllNodes(), "cpu", 10);
    CResourceCapacity cc = new CResourceCapacity(c);
    Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
    Assert.assertTrue(cc.getMisPlacedVMs(i).isEmpty());
    m.addRunningVM(vm5, n3);
    Assert.assertEquals(cc.getMisPlacedVMs(i), m.getAllVMs());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) 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) MinMTTR(org.btrplace.model.constraint.MinMTTR) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 24 with MinMTTR

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

the class CResourceCapacityTest method testCapacityEstimation.

/**
 * Test how CResourceCapacity notifies the view about the future capacity.
 */
@Test
public void testCapacityEstimation() {
    final Model mo = new DefaultModel();
    final Node n0 = mo.newNode();
    final Node n1 = mo.newNode();
    final VM vm = mo.newVM();
    final ShareableResource cpu = new ShareableResource("cpu");
    mo.attach(cpu);
    cpu.setCapacity(n0, 5).setCapacity(n1, 7);
    cpu.setConsumption(vm, 3);
    mo.getMapping().on(n0, n1).ready(vm);
    final List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.add(new Running(vm));
    final Instance i = new Instance(mo, cstrs, new MinMTTR());
    // Because of the worst-fit approach, the VM will go on n1 which has the
    // highest capacity.
    final ChocoScheduler sched = new DefaultChocoScheduler();
    ReconfigurationPlan res = sched.solve(i);
    Assert.assertEquals(n1, res.getResult().getMapping().getVMLocation(vm));
    // With a ResourceCapacity, we restrict n1 so that now n0 is the node
    // that will have the highest capacity. So the wort-fit approach inside
    // MinMTTR() should pick n0.
    i.getSatConstraints().add(new ResourceCapacity(n1, "cpu", 4));
    res = sched.solve(i);
    Assert.assertEquals(n0, res.getResult().getMapping().getVMLocation(vm));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) 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 25 with MinMTTR

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

the class InstanceTest method testEqualsAndHashcode.

@Test
public void testEqualsAndHashcode() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Mapping ma = mo.getMapping();
    ma.addOnlineNode(ns.get(0));
    ma.addOfflineNode(ns.get(0));
    ma.addReadyVM(vms.get(0));
    List<SatConstraint> cstrs = new ArrayList<>(Online.newOnline(ma.getAllNodes()));
    cstrs.add(new Running(vms.get(0)));
    Instance i = new Instance(mo, cstrs, new MinMTTR());
    Instance i2 = new Instance(mo.copy(), new ArrayList<>(cstrs), new MinMTTR());
    Assert.assertEquals(i, i2);
    Assert.assertEquals(i, i);
    Assert.assertNotEquals(i, null);
    Assert.assertNotEquals(ma, i);
    Assert.assertEquals(i.hashCode(), i2.hashCode());
    i2.getModel().getMapping().addReadyVM(vms.get(2));
    Assert.assertNotEquals(i, i2);
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) Running(org.btrplace.model.constraint.Running) 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