Search in sources :

Example 6 with MaxOnline

use of org.btrplace.model.constraint.MaxOnline 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 : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) 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) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Online(org.btrplace.model.constraint.Online) MaxOnline(org.btrplace.model.constraint.MaxOnline) Test(org.testng.annotations.Test)

Example 7 with MaxOnline

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

the class CMaxOnlineTest method discreteMaxOnlineTest2.

@Test
public void discreteMaxOnlineTest2() 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("vcpu", 1, 1);
    resources.setCapacity(n1, 4);
    resources.setCapacity(n2, 8);
    resources.setCapacity(n3, 2);
    resources.setConsumption(vm4, 2);
    Mapping map = model.getMapping().on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3);
    model.attach(resources);
    MappingUtils.fill(map, model.getMapping());
    Set<Node> nodes = map.getAllNodes();
    MaxOnline maxon = new MaxOnline(nodes, 2);
    Set<Node> nodes2 = new HashSet<>(Arrays.asList(n1, n2));
    MaxOnline maxon2 = new MaxOnline(nodes2, 1);
    List<SatConstraint> constraints = new ArrayList<>();
    constraints.add(maxon);
    constraints.add(maxon2);
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.setMaxEnd(4);
    cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
    ReconfigurationPlan plan = cra.solve(model, constraints);
    Assert.assertNotNull(plan);
    Assert.assertTrue(maxon.isSatisfied(plan.getResult()));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) 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) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 8 with MaxOnline

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

the class MaxOnlineBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodMaxOnline")
public void testGoodSignatures(String str, int nbNodes) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    MaxOnline x = (MaxOnline) b.build("namespace test; VM[1..10] : tiny;\n@N[1..10] : mock;" + str).getConstraints().iterator().next();
    Assert.assertEquals(x.getInvolvedNodes().size(), nbNodes);
    Assert.assertEquals(x.isContinuous(), !str.startsWith(">>"));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) MaxOnline(org.btrplace.model.constraint.MaxOnline) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Test(org.testng.annotations.Test)

Example 9 with MaxOnline

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

the class MaxOnlineConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    Model model = new DefaultModel();
    Set<Node> s = new HashSet<>(Arrays.asList(model.newNode(), model.newNode(), model.newNode()));
    MaxOnline mo = new MaxOnline(s, 2);
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new MaxOnlineConverter());
    Constraint new_max = conv.fromJSON(model, conv.toJSON(mo));
    Assert.assertEquals(mo, new_max);
    System.out.println(conv.toJSON(mo));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) MaxOnline(org.btrplace.model.constraint.MaxOnline) Constraint(org.btrplace.model.constraint.Constraint) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with MaxOnline

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

the class CMaxOnlineTest method complexContinuousTest2.

@Test
public void complexContinuousTest2() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode(1);
    Node n2 = model.newNode(2);
    Node n3 = model.newNode(3);
    Node n4 = model.newNode(4);
    Node n5 = model.newNode(5);
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    VM vm3 = model.newVM();
    VM vm4 = model.newVM();
    ShareableResource resources = new ShareableResource("cpu", 2, 1);
    resources.setCapacity(n1, 4);
    resources.setCapacity(n2, 8);
    resources.setConsumption(vm4, 2);
    Mapping map = model.getMapping().on(n1, n2, n3).off(n4, n5).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3);
    MappingUtils.fill(map, model.getMapping());
    model.attach(resources);
    MaxOnline maxOn = new MaxOnline(map.getAllNodes(), 4, true);
    MaxOnline maxOn2 = new MaxOnline(new HashSet<>(Arrays.asList(n2, n3, n4)), 2, true);
    List<SatConstraint> constraints = new ArrayList<>();
    constraints.add(maxOn);
    constraints.add(maxOn2);
    constraints.addAll(Online.newOnline(n4, n5));
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.setTimeLimit(3);
    cra.setMaxEnd(10);
    cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
    ReconfigurationPlan plan = cra.solve(model, constraints);
    Assert.assertNotNull(plan);
    Assert.assertTrue(maxOn.isSatisfied(plan));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) 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) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Aggregations

MaxOnline (org.btrplace.model.constraint.MaxOnline)11 DefaultModel (org.btrplace.model.DefaultModel)9 Node (org.btrplace.model.Node)9 Test (org.testng.annotations.Test)9 Model (org.btrplace.model.Model)8 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)6 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)6 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)6 ArrayList (java.util.ArrayList)5 VM (org.btrplace.model.VM)5 SatConstraint (org.btrplace.model.constraint.SatConstraint)5 Mapping (org.btrplace.model.Mapping)4 ShareableResource (org.btrplace.model.view.ShareableResource)4 HashSet (java.util.HashSet)3 Instance (org.btrplace.model.Instance)2 Online (org.btrplace.model.constraint.Online)2 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 Collection (java.util.Collection)1 List (java.util.List)1