Search in sources :

Example 1 with Ban

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

the class IssuesTest method testIssue89.

@Test
public static void testIssue89() throws Exception {
    final Model model = new DefaultModel();
    final Mapping mapping = model.getMapping();
    final Node node0 = model.newNode(0);
    final int[] ids0 = { 1, 45, 43, 40, 39, 38, 82, 80, 79, 78, 30, 75, 18, 16, 15, 14, 60, 9, 55, 54, 50, 48 };
    final Node node1 = model.newNode(1);
    final int[] ids1 = { 84, 83, 81, 77, 73, 71, 64, 63, 62, 57, 53, 52, 47, 46, 44, 41, 34, 31, 28, 25, 13, 8, 6, 4, 3, 0 };
    final Node node2 = model.newNode(2);
    final int[] ids2 = { 21, 67, 42, 36, 35, 33, 76, 74, 23, 69, 68, 20, 61, 12, 11, 10, 5, 51 };
    final Node node3 = model.newNode(3);
    final int[] ids3 = { 2, 66, 86, 85, 37, 32, 29, 27, 26, 72, 24, 70, 22, 19, 65, 17, 59, 58, 56, 7, 49 };
    final ShareableResource cpu = new ShareableResource("cpu", 45, 1);
    final ShareableResource mem = new ShareableResource("mem", 90, 2);
    populateNodeVm(model, mapping, node0, ids0);
    populateNodeVm(model, mapping, node1, ids1);
    populateNodeVm(model, mapping, node2, ids2);
    populateNodeVm(model, mapping, node3, ids3);
    model.attach(cpu);
    model.attach(mem);
    final Collection<SatConstraint> satConstraints = new ArrayList<>();
    // We want to cause Node 3 to go offline to see how the VMs hosted on that
    // node will get rebalanced.
    satConstraints.add(new Offline(node3));
    final OptConstraint optConstraint = new MinMTTR();
    DefaultChocoScheduler scheduler = new DefaultChocoScheduler();
    scheduler.doOptimize(false);
    scheduler.doRepair(true);
    scheduler.setTimeLimit(60000);
    ReconfigurationPlan plan = scheduler.solve(model, satConstraints, optConstraint);
    System.out.println(scheduler.getStatistics());
    Assert.assertTrue(plan.isApplyable());
    satConstraints.clear();
    // This is somewhat similar to making Node 3 going offline by ensuring that
    // all VMs can no longer get hosted on that node.
    satConstraints.addAll(mapping.getAllVMs().stream().map(vm -> new Ban(vm, Collections.singletonList(node3))).collect(Collectors.toList()));
    scheduler = new DefaultChocoScheduler();
    scheduler.doOptimize(false);
    scheduler.doRepair(true);
    plan = scheduler.solve(model, satConstraints, optConstraint);
    Assert.assertTrue(plan.isApplyable());
}
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) MinMTTR(org.btrplace.model.constraint.MinMTTR) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Offline(org.btrplace.model.constraint.Offline) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) Ban(org.btrplace.model.constraint.Ban) OptConstraint(org.btrplace.model.constraint.OptConstraint) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 2 with Ban

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

the class BanConverterTest method testViables.

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

Example 3 with Ban

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

the class CNoDelayTest method testOk2.

@Test
public void testOk2() 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(vm4);
    // 1 solution (priority to vm4): vm4 to n2 ; vm3 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 4 with Ban

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

the class BanBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodBans")
public void testGoodSignatures(String str, int nbVMs, int nbNodes, boolean c) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..10] : defaultNode;\n" + str).getConstraints();
    Assert.assertEquals(cstrs.size(), nbVMs);
    Set<VM> vms = new HashSet<>();
    for (SatConstraint s : cstrs) {
        Assert.assertTrue(s instanceof Ban);
        Assert.assertEquals(s.getInvolvedVMs().size(), 1);
        Assert.assertTrue(vms.addAll(s.getInvolvedVMs()));
        Assert.assertEquals(s.getInvolvedNodes().size(), nbNodes);
        Assert.assertEquals(s.isContinuous(), c);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SatConstraint(org.btrplace.model.constraint.SatConstraint) VM(org.btrplace.model.VM) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Ban(org.btrplace.model.constraint.Ban) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with Ban

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

the class BanSplitter method split.

@Override
public boolean split(Ban cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    final SplittableElementSet<Node> nodeIndex = SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition);
    VM v = cstr.getInvolvedVMs().iterator().next();
    int p = vmsPosition.get(v.id());
    return partitions.get(p).getSatConstraints().add(new Ban(v, nodeIndex.getSubSet(p)));
}
Also used : Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Ban(org.btrplace.model.constraint.Ban)

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