Search in sources :

Example 1 with Online

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

the class OnlineSplitterTest method simpleTest.

@Test
public void simpleTest() {
    OnlineSplitter splitter = new OnlineSplitter();
    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    Node n = m0.newNode();
    m0.getMapping().addOnlineNode(n);
    m0.getMapping().addOnlineNode(m0.newNode(1));
    Model m1 = new DefaultModel();
    m1.getMapping().addOnlineNode(m1.newNode(2));
    m1.getMapping().addOnlineNode(m1.newNode(3));
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    Set<Node> all = new HashSet<>(m0.getMapping().getAllNodes());
    all.addAll(m1.getMapping().getAllNodes());
    TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
    // Only nodes in m0
    Online oSimple = new Online(n);
    Assert.assertTrue(splitter.split(oSimple, null, instances, new TIntIntHashMap(), nodeIndex));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(oSimple));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(oSimple));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) ArrayList(java.util.ArrayList) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Online(org.btrplace.model.constraint.Online) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with Online

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

the class OnlineConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    Model mo = new DefaultModel();
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new OnlineConverter());
    Online d = new Online(mo.newNode());
    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) Online(org.btrplace.model.constraint.Online) Test(org.testng.annotations.Test)

Example 3 with Online

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

the class CMaxOnlineTest method testSimpleContinuousCase.

@Test
public void testSimpleContinuousCase() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    model.getMapping().addOnlineNode(n1);
    model.getMapping().addOfflineNode(n2);
    MaxOnline maxOnline = new MaxOnline(model.getMapping().getAllNodes(), 1, true);
    List<SatConstraint> constraints = new ArrayList<>();
    constraints.add(maxOnline);
    constraints.add(new Online(n2));
    ChocoScheduler cra = new DefaultChocoScheduler();
    // cra.setTimeLimit(5);
    cra.setMaxEnd(4);
    cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
    ReconfigurationPlan plan = cra.solve(model, constraints);
    Assert.assertNotNull(plan);
    Assert.assertTrue(maxOnline.isSatisfied(plan));
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) MaxOnline(org.btrplace.model.constraint.MaxOnline) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Online(org.btrplace.model.constraint.Online) MaxOnline(org.btrplace.model.constraint.MaxOnline) Test(org.testng.annotations.Test)

Example 4 with Online

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

the class CMaxOnlineTest method testContinuousRestrictionSimpleCase.

@Test
public void testContinuousRestrictionSimpleCase() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    VM vm1 = model.newVM();
    VM vm3 = model.newVM();
    VM vm4 = model.newVM();
    ShareableResource resources = new ShareableResource("cpu", 4, 1);
    resources.setCapacity(n1, 8);
    resources.setConsumption(vm4, 2);
    Mapping map = model.getMapping().on(n1, n3).off(n2).run(n1, vm1, vm4).run(n3, vm3);
    MappingUtils.fill(map, model.getMapping());
    model.attach(resources);
    MaxOnline maxon = new MaxOnline(map.getAllNodes(), 2, true);
    List<SatConstraint> constraints = new ArrayList<>();
    constraints.add(maxon);
    constraints.add(new Online(n2));
    ChocoScheduler cra = new DefaultChocoScheduler();
    // cra.setTimeLimit(3);
    cra.setMaxEnd(3);
    cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
    ReconfigurationPlan plan = cra.solve(model, constraints);
    Assert.assertNotNull(plan);
    Assert.assertTrue(maxon.isSatisfied(plan));
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) MaxOnline(org.btrplace.model.constraint.MaxOnline) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Online(org.btrplace.model.constraint.Online) MaxOnline(org.btrplace.model.constraint.MaxOnline) Test(org.testng.annotations.Test)

Example 5 with Online

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

the class DefaultChocoSchedulerTest method testNonHomogeneousIncrease.

/**
 * Issue #14
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testNonHomogeneousIncrease() throws SchedulerException {
    ShareableResource cpu = new ShareableResource("cpu");
    ShareableResource mem = new ShareableResource("mem");
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    cpu.setCapacity(n1, 10);
    mem.setCapacity(n1, 10);
    cpu.setCapacity(n2, 10);
    mem.setCapacity(n2, 10);
    cpu.setConsumption(vm1, 5);
    mem.setConsumption(vm1, 4);
    cpu.setConsumption(vm2, 3);
    mem.setConsumption(vm2, 8);
    cpu.setConsumption(vm3, 5);
    cpu.setConsumption(vm3, 4);
    cpu.setConsumption(vm4, 4);
    cpu.setConsumption(vm4, 5);
    // vm1 requires more cpu resources, but fewer mem resources
    Preserve pCPU = new Preserve(vm1, "cpu", 7);
    Preserve pMem = new Preserve(vm1, "mem", 2);
    mo.getMapping().on(n1, n2).run(n1, vm1).run(n2, vm3, vm4).ready(vm2);
    mo.attach(cpu);
    mo.attach(mem);
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.setMaxEnd(5);
    ReconfigurationPlan p = cra.solve(mo, Arrays.asList(pCPU, pMem, new Online(n1), new Running(vm2), new Ready(vm3)));
    Assert.assertNotNull(p);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Ready(org.btrplace.model.constraint.Ready) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) ShareableResource(org.btrplace.model.view.ShareableResource) Online(org.btrplace.model.constraint.Online) Preserve(org.btrplace.model.constraint.Preserve) Test(org.testng.annotations.Test)

Aggregations

Online (org.btrplace.model.constraint.Online)7 Test (org.testng.annotations.Test)7 DefaultModel (org.btrplace.model.DefaultModel)5 Model (org.btrplace.model.Model)5 Node (org.btrplace.model.Node)4 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)4 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)3 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)3 MaxOnline (org.btrplace.model.constraint.MaxOnline)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 ShareableResource (org.btrplace.model.view.ShareableResource)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Instance (org.btrplace.model.Instance)1 VM (org.btrplace.model.VM)1 MinMTTR (org.btrplace.model.constraint.MinMTTR)1 Preserve (org.btrplace.model.constraint.Preserve)1 Ready (org.btrplace.model.constraint.Ready)1 Running (org.btrplace.model.constraint.Running)1