Search in sources :

Example 1 with OptConstraint

use of org.btrplace.model.constraint.OptConstraint 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 OptConstraint

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

the class CMinMigrationsTest method main.

public static void main(String[] args) {
    String root = "/Users/fabien.hermenier/Documents/BtrPlace/nutanix/instances";
    List<OptConstraint> objs = Arrays.asList(/*new MinMTTR(),*/
    new MinMigrations());
    boolean verbose = true;
    for (OptConstraint o : objs) {
        System.out.print(" " + o);
    }
    System.out.println();
    for (int idx = 1; idx <= 256; idx += 5) {
        String path = root + "/lazan/lazan-" + idx + ".json.gz";
        if (verbose) {
            System.out.println("--- " + idx + " --- ");
        } else {
            System.out.print(idx);
        }
        List<Long> res = new ArrayList<>();
        for (OptConstraint o : objs) {
            if (verbose) {
                System.out.println("\t" + o);
            }
            Instance i = JSON.readInstance(new File(path));
            if (Network.get(i.getModel()) != null) {
                i.getModel().detach(Network.get(i.getModel()));
            }
            i = new Instance(i.getModel(), i.getSatConstraints(), o);
            ChocoScheduler s = new DefaultChocoScheduler();
            s.doOptimize(false);
            s.setTimeLimit(30);
            s.doRepair(false);
            ReconfigurationPlan p = s.solve(i);
            Assert.assertNotNull(p);
            res.add(p.getActions().stream().filter(x -> x instanceof MigrateVM).mapToLong(x -> x.getEnd() - x.getStart()).sum());
            // res.add((long)s.getStatistics().lastSolution().getDuration());
            if (verbose) {
                System.out.println(s.getStatistics());
            // System.out.println(p);
            }
        }
        if (!verbose) {
            for (Long l : res) {
                System.out.print("\t" + l);
            }
            System.out.println();
        }
    }
}
Also used : Model(org.btrplace.model.Model) Arrays(java.util.Arrays) Node(org.btrplace.model.Node) OptConstraint(org.btrplace.model.constraint.OptConstraint) Spread(org.btrplace.model.constraint.Spread) Preserve(org.btrplace.model.constraint.Preserve) MigrateVM(org.btrplace.plan.event.MigrateVM) Test(org.testng.annotations.Test) DefaultModel(org.btrplace.model.DefaultModel) JSON(org.btrplace.json.JSON) File(java.io.File) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) VM(org.btrplace.model.VM) List(java.util.List) Assert(org.testng.Assert) ShareableResource(org.btrplace.model.view.ShareableResource) Instance(org.btrplace.model.Instance) MinMigrations(org.btrplace.model.constraint.MinMigrations) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Network(org.btrplace.model.view.network.Network) SatConstraint(org.btrplace.model.constraint.SatConstraint) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) Instance(org.btrplace.model.Instance) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) MigrateVM(org.btrplace.plan.event.MigrateVM) OptConstraint(org.btrplace.model.constraint.OptConstraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) OptConstraint(org.btrplace.model.constraint.OptConstraint) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) MinMigrations(org.btrplace.model.constraint.MinMigrations) File(java.io.File)

Aggregations

ArrayList (java.util.ArrayList)2 DefaultModel (org.btrplace.model.DefaultModel)2 Model (org.btrplace.model.Model)2 Node (org.btrplace.model.Node)2 OptConstraint (org.btrplace.model.constraint.OptConstraint)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 ShareableResource (org.btrplace.model.view.ShareableResource)2 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)2 Test (org.testng.annotations.Test)2 File (java.io.File)1 Arrays (java.util.Arrays)1 List (java.util.List)1 JSON (org.btrplace.json.JSON)1 Instance (org.btrplace.model.Instance)1 Mapping (org.btrplace.model.Mapping)1 VM (org.btrplace.model.VM)1 Ban (org.btrplace.model.constraint.Ban)1 MinMTTR (org.btrplace.model.constraint.MinMTTR)1 MinMigrations (org.btrplace.model.constraint.MinMigrations)1 Offline (org.btrplace.model.constraint.Offline)1