Search in sources :

Example 11 with MigrateVM

use of org.btrplace.plan.event.MigrateVM 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)

Example 12 with MigrateVM

use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.

the class DefaultChocoScheduler method solve.

@Override
public ReconfigurationPlan solve(Instance i) throws SchedulerException {
    Model mo = i.getModel();
    Collection<SatConstraint> cstrs = i.getSatConstraints();
    // If a network view is attached, ensure that all the migrations' destination node are defined
    Network net = Network.get(mo);
    stages = null;
    if (net != null) {
        // The network view is useless to take placement decisions
        mo.detach(net);
        // Solve a first time using placement oriented MinMTTR optimisation constraint
        ReconfigurationPlan p = runner.solve(params, i);
        stages = new StagedSolvingStatistics(runner.getStatistics());
        if (p == null) {
            return null;
        }
        // Add Fence constraints for each destination node chosen
        List<SatConstraint> newCstrs = p.getActions().stream().filter(a -> a instanceof MigrateVM).map(a -> new Fence(((MigrateVM) a).getVM(), Collections.singleton(((MigrateVM) a).getDestinationNode()))).collect(Collectors.toList());
        Model result = p.getResult();
        if (result == null) {
            throw new InconsistentSolutionException(mo, p, "The plan cannot be applied");
        }
        // Add Root constraints to all staying VMs
        newCstrs.addAll(mo.getMapping().getRunningVMs().stream().filter(v -> p.getOrigin().getMapping().getVMLocation(v).id() == result.getMapping().getVMLocation(v).id()).map(Root::new).collect(Collectors.toList()));
        // Add the old constraints
        newCstrs.addAll(cstrs);
        // Re-attach the network view
        mo.attach(net);
        // New timeout value = elapsed time - initial timeout value
        Parameters ps = new DefaultParameters(params);
        if (ps.getTimeLimit() > 0) {
            // in seconds
            double timeout = params.getTimeLimit() - runner.getStatistics().getMetrics().timeCount() / 1000;
            ps.setTimeLimit((int) timeout);
        }
        return runner.solve(ps, new Instance(mo, newCstrs, i.getOptConstraint()));
    }
    // Solve and return the computed plan
    return runner.solve(params, new Instance(mo, cstrs, i.getOptConstraint()));
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Root(org.btrplace.model.constraint.Root) SchedulerException(org.btrplace.scheduler.SchedulerException) MigrateVM(org.btrplace.plan.event.MigrateVM) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) Fence(org.btrplace.model.constraint.Fence) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SingleRunner(org.btrplace.scheduler.choco.runner.single.SingleRunner) BiConsumer(java.util.function.BiConsumer) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) StagedSolvingStatistics(org.btrplace.scheduler.choco.runner.StagedSolvingStatistics) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) Collection(java.util.Collection) TransitionFactory(org.btrplace.scheduler.choco.transition.TransitionFactory) Collectors(java.util.stream.Collectors) MinMTTR(org.btrplace.model.constraint.MinMTTR) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) List(java.util.List) Instance(org.btrplace.model.Instance) InstanceSolver(org.btrplace.scheduler.choco.runner.InstanceSolver) Collections(java.util.Collections) Network(org.btrplace.model.view.network.Network) Settings(org.chocosolver.solver.Settings) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) Root(org.btrplace.model.constraint.Root) Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) StagedSolvingStatistics(org.btrplace.scheduler.choco.runner.StagedSolvingStatistics) Network(org.btrplace.model.view.network.Network) Model(org.btrplace.model.Model) Fence(org.btrplace.model.constraint.Fence)

Example 13 with MigrateVM

use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.

the class GatherTest method testContinuousIsSatisfied.

@Test(dependsOnMethods = { "testDiscreteIsSatisfied" })
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Set<VM> s = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1)));
    Gather g = new Gather(s);
    g.setContinuous(true);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addReadyVM(vms.get(1));
    map.addRunningVM(vms.get(1), ns.get(1));
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(g.isSatisfied(plan), false);
    map.addReadyVM(vms.get(1));
    Assert.assertEquals(g.isSatisfied(plan), true);
    plan.add(new BootVM(vms.get(1), ns.get(0), 0, 1));
    Assert.assertEquals(g.isSatisfied(plan), true);
    map.addRunningVM(vms.get(1), ns.get(0));
    plan = new DefaultReconfigurationPlan(mo);
    plan.add(new MigrateVM(vms.get(1), ns.get(0), ns.get(1), 0, 1));
    plan.add(new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 1));
    Assert.assertEquals(g.isSatisfied(plan), false);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) BootVM(org.btrplace.plan.event.BootVM) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 14 with MigrateVM

use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.

the class NoDelayTest method testIsSatisfied.

@Test
public void testIsSatisfied() {
    // Create a new default model
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    // Create 4 nodes
    List<Node> ns = Util.newNodes(mo, 4);
    // Create 2 vms
    List<VM> vms = Util.newVMs(mo, 2);
    // Set the nodes online
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    map.addOnlineNode(ns.get(3));
    // Run the 2 vms on the two first nodes
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addRunningVM(vms.get(1), ns.get(1));
    // Set as initial plan
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    // Create a NoDelay constraint by constraining the first VM
    NoDelay nd = new NoDelay(vms.get(0));
    // The constraint should be satisfied by default
    Assert.assertEquals(nd.isSatisfied(plan), true);
    // Migrate the first VM (constrained) at t=0 to the third node
    plan.add(new MigrateVM(vms.get(0), ns.get(0), ns.get(2), 0, 1));
    Assert.assertEquals(nd.isSatisfied(plan), true);
    // Migrate the second VM at t=0 to the last node
    plan.add(new MigrateVM(vms.get(1), ns.get(1), ns.get(3), 0, 1));
    Assert.assertEquals(nd.isSatisfied(plan), true);
    // Re-Migrate the second VM at t=1 to the second node
    plan.add(new MigrateVM(vms.get(1), ns.get(3), ns.get(1), 1, 2));
    Assert.assertEquals(nd.isSatisfied(plan), true);
    // Re-Migrate the first VM (constrained) at t=1 to the first node
    plan.add(new MigrateVM(vms.get(0), ns.get(2), ns.get(0), 1, 2));
    Assert.assertEquals(nd.isSatisfied(plan), false);
// Shutdown node
// plan.add(new ShutdownNode(ns.get(2), 0, 1));
// Assert.assertEquals(nd.isSatisfied(plan), true);
// Boot node
// plan.add(new BootNode(ns.get(2), 1, 3));
// Assert.assertEquals(nd.isSatisfied(plan), false);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) Test(org.testng.annotations.Test)

Example 15 with MigrateVM

use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.

the class PreserveTest method testIsSatisfied.

@Test(dependsOnMethods = { "testInstantiation" })
public void testIsSatisfied() {
    Model m = new DefaultModel();
    List<VM> vms = Util.newVMs(m, 5);
    List<Node> ns = Util.newNodes(m, 5);
    ShareableResource rc = new ShareableResource("cpu", 3, 3);
    Mapping map = m.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addSleepingVM(vms.get(1), ns.get(0));
    map.addRunningVM(vms.get(2), ns.get(0));
    m.attach(rc);
    Preserve p = new Preserve(vms.get(0), "cpu", 3);
    rc.setConsumption(vms.get(0), 3);
    // Not running so we don't care
    rc.setConsumption(vms.get(1), 1);
    rc.setConsumption(vms.get(2), 3);
    Assert.assertEquals(true, p.isSatisfied(m));
    // Set to 3 by default
    rc.unset(vms.get(2));
    Assert.assertEquals(true, p.isSatisfied(m));
    Assert.assertEquals(false, new Preserve(vms.get(2), "mem", 3).isSatisfied(m));
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(m);
    rc.setConsumption(vms.get(1), 1);
    Assert.assertFalse(new Preserve(vms.get(2), "cpu", 4).isSatisfied(plan));
    plan.add(new Allocate(vms.get(2), ns.get(0), "cpu", 7, 5, 7));
    Assert.assertTrue(p.isSatisfied(plan));
    rc.setConsumption(vms.get(0), 1);
    AllocateEvent e = new AllocateEvent(vms.get(0), "cpu", 4);
    Assert.assertFalse(p.isSatisfied(plan));
    MigrateVM mig = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
    mig.addEvent(Action.Hook.POST, e);
    plan.add(mig);
    Assert.assertTrue(p.isSatisfied(plan));
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) Allocate(org.btrplace.plan.event.Allocate) AllocateEvent(org.btrplace.plan.event.AllocateEvent) Test(org.testng.annotations.Test)

Aggregations

MigrateVM (org.btrplace.plan.event.MigrateVM)31 Test (org.testng.annotations.Test)25 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)24 DefaultReconfigurationPlan (org.btrplace.plan.DefaultReconfigurationPlan)12 ShareableResource (org.btrplace.model.view.ShareableResource)10 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)9 SatConstraint (org.btrplace.model.constraint.SatConstraint)8 ArrayList (java.util.ArrayList)7 Network (org.btrplace.model.view.network.Network)7 BootVM (org.btrplace.plan.event.BootVM)7 Node (org.btrplace.model.Node)6 Allocate (org.btrplace.plan.event.Allocate)6 BootNode (org.btrplace.plan.event.BootNode)6 ShutdownVM (org.btrplace.plan.event.ShutdownVM)6 List (java.util.List)5 Model (org.btrplace.model.Model)5 VM (org.btrplace.model.VM)5 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)5 Switch (org.btrplace.model.view.network.Switch)5 Action (org.btrplace.plan.event.Action)5