Search in sources :

Example 6 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class LonelyTest method testContinuousIsSatisfied.

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

Example 7 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class OverbookTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    Node n0 = mo.newNode();
    Node n1 = mo.newNode();
    Model i = new DefaultModel();
    Mapping cfg = i.getMapping();
    cfg.addOnlineNode(n0);
    cfg.addOnlineNode(n1);
    ShareableResource rc = new ShareableResource("cpu");
    rc.setCapacity(n0, 1);
    rc.setCapacity(n1, 4);
    rc.setConsumption(vms.get(0), 2);
    rc.setConsumption(vms.get(1), 2);
    rc.setConsumption(vms.get(2), 4);
    cfg.addRunningVM(vms.get(0), n0);
    cfg.addRunningVM(vms.get(1), n1);
    cfg.addRunningVM(vms.get(2), n1);
    cfg.addRunningVM(vms.get(3), n1);
    i.attach(rc);
    Overbook o = new Overbook(n1, "cpu", 2);
    o.setContinuous(true);
    ReconfigurationPlan p = new DefaultReconfigurationPlan(i);
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(0), n0, "cpu", 1, 2, 5));
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(1), n1, "cpu", 5, 2, 5));
    Assert.assertEquals(o.isSatisfied(p), false);
    p.add(new Allocate(vms.get(2), n1, "cpu", 2, 0, 1));
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(3), n1, "cpu", 3, 4, 6));
    Assert.assertEquals(o.isSatisfied(p), false);
    p.add(new ShutdownVM(vms.get(2), n1, 2, 3));
    Assert.assertEquals(o.isSatisfied(p), true);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ShutdownVM(org.btrplace.plan.event.ShutdownVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShareableResource(org.btrplace.model.view.ShareableResource) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Allocate(org.btrplace.plan.event.Allocate) Test(org.testng.annotations.Test)

Example 8 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class ResourceCapacityTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addRunningVM(vms.get(1), ns.get(0));
    map.addRunningVM(vms.get(2), ns.get(1));
    map.addRunningVM(vms.get(3), ns.get(2));
    map.addReadyVM(vms.get(4));
    ShareableResource rc = new ShareableResource("foo", 1, 1);
    mo.attach(rc);
    Set<Node> nodes = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
    ResourceCapacity cc = new ResourceCapacity(nodes, "foo", 4, true);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(cc.isSatisfied(plan), true);
    // 3/4
    MigrateVM m = new MigrateVM(vms.get(3), ns.get(2), ns.get(1), 0, 1);
    m.addEvent(Action.Hook.POST, new AllocateEvent(vms.get(3), "foo", 2));
    plan.add(m);
    // 5/4
    plan.add(new ShutdownVM(vms.get(2), ns.get(1), 1, 2));
    // 4/4
    plan.add(new BootVM(vms.get(4), ns.get(2), 2, 3));
    // 4/4
    plan.add(new Allocate(vms.get(1), ns.get(0), "foo", 2, 2, 3));
    // 5/4
    plan.add(new MigrateVM(vms.get(0), ns.get(0), ns.get(2), 3, 4));
    System.out.println(plan);
    Assert.assertEquals(cc.isSatisfied(plan), true);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 9 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class InstanceSolverRunner method call.

@Override
// for the LifeCycleViolationException
@SuppressWarnings("squid:S1166")
public SolvingStatistics call() throws SchedulerException {
    stats = new SingleRunnerStatistics(params, instance, System.currentTimeMillis());
    rp = null;
    // Build the core problem
    long d = -System.currentTimeMillis();
    try {
        rp = buildRP();
    } catch (@SuppressWarnings("unused") LifeCycleViolationException ex) {
        // If there is a violation of the cycle it is not a bug that should be propagated
        // it it just indicating there is no solution
        stats.setCompleted(true);
        stats.setMetrics(new Metrics());
        return stats;
    } finally {
        d += System.currentTimeMillis();
        stats.setCoreBuildDuration(d);
    }
    stats.setNbManagedVMs(rp.getManageableVMs().size());
    // Customize the core problem
    d = -System.currentTimeMillis();
    if (!specialise()) {
        d += System.currentTimeMillis();
        stats.setSpecialisationDuration(d);
        stats.setCompleted(true);
        return getStatistics();
    }
    d += System.currentTimeMillis();
    stats.setSpecialisationDuration(d);
    // statistics
    stats.setMetrics(new Metrics(rp.getSolver().getMeasures()));
    rp.getLogger().debug(stats.toString());
    // The solution monitor to store the measures at each solution
    rp.getSolver().plugMonitor((IMonitorSolution) () -> {
        Solution solution = new Solution(rp.getModel());
        solution.record();
        ReconfigurationPlan plan = rp.buildReconfigurationPlan(solution, origin);
        views.forEach(v -> v.insertActions(rp, solution, plan));
        MeasuresRecorder m = rp.getSolver().getMeasures();
        SolutionStatistics st = new SolutionStatistics(new Metrics(m), plan);
        IntVar o = rp.getObjective();
        if (o != null) {
            st.setObjective(solution.getIntVal(o));
        }
        stats.addSolution(st);
        params.solutionListeners().forEach(c -> c.accept(rp, plan));
    });
    setVerbosity();
    // The actual solving process
    rp.solve(params.getTimeLimit(), params.doOptimize());
    return getStatistics();
}
Also used : LifeCycleViolationException(org.btrplace.scheduler.choco.LifeCycleViolationException) ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Ready(org.btrplace.model.constraint.Ready) MeasuresRecorder(org.chocosolver.solver.search.measure.MeasuresRecorder) SchedulerException(org.btrplace.scheduler.SchedulerException) Node(org.btrplace.model.Node) OptConstraint(org.btrplace.model.constraint.OptConstraint) ContradictionException(org.chocosolver.solver.exception.ContradictionException) Callable(java.util.concurrent.Callable) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) CObjective(org.btrplace.scheduler.choco.constraint.CObjective) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) Running(org.btrplace.model.constraint.Running) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException) Measures(org.chocosolver.solver.search.measure.Measures) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) SearchState(org.chocosolver.solver.search.SearchState) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) Sleeping(org.btrplace.model.constraint.Sleeping) Constraint(org.btrplace.model.constraint.Constraint) Collection(java.util.Collection) SolutionStatistics(org.btrplace.scheduler.choco.runner.SolutionStatistics) Set(java.util.Set) ChocoConstraint(org.btrplace.scheduler.choco.constraint.ChocoConstraint) Cause(org.chocosolver.solver.Cause) Parameters(org.btrplace.scheduler.choco.Parameters) IntVar(org.chocosolver.solver.variables.IntVar) List(java.util.List) Killed(org.btrplace.model.constraint.Killed) Metrics(org.btrplace.scheduler.choco.runner.Metrics) ChocoViews(org.btrplace.scheduler.choco.view.ChocoViews) Solution(org.chocosolver.solver.Solution) Optional(java.util.Optional) Instance(org.btrplace.model.Instance) Metrics(org.btrplace.scheduler.choco.runner.Metrics) LifeCycleViolationException(org.btrplace.scheduler.choco.LifeCycleViolationException) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SolutionStatistics(org.btrplace.scheduler.choco.runner.SolutionStatistics) IntVar(org.chocosolver.solver.variables.IntVar) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) Solution(org.chocosolver.solver.Solution) MeasuresRecorder(org.chocosolver.solver.search.measure.MeasuresRecorder)

Example 10 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class DefaultReconfigurationProblemTest method testVMCounting.

/**
 * Check the consistency between the variables counting the number of VMs on
 * each node, and the placement variable.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 * @throws ContradictionException
 */
@Test
public void testVMCounting() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Node n3 = mo.newNode();
    Node n2 = mo.newNode();
    Mapping map = mo.getMapping();
    for (int i = 0; i < 7; i++) {
        VM v = mo.newVM();
        map.addReadyVM(v);
    }
    map.addOnlineNode(n3);
    map.addOnlineNode(n2);
    Parameters ps = new DefaultParameters();
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
    // Restrict the capacity to 5 at most
    for (IntVar capa : rp.getNbRunningVMs()) {
        capa.updateUpperBound(5, Cause.Null);
    }
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(-1, false);
    Assert.assertNotNull(p);
    // Check consistency between the counting and the hoster variables
    int[] counts = new int[map.getAllNodes().size()];
    for (Node n : map.getOnlineNodes()) {
        int nIdx = rp.getNode(n);
        counts[nIdx] = rp.getNbRunningVMs().get(nIdx).getValue();
    }
    for (VM vm : rp.getFutureRunningVMs()) {
        VMTransition vmo = rp.getVMActions().get(rp.getVM(vm));
        int on = vmo.getDSlice().getHoster().getValue();
        counts[on]--;
    }
    for (int count : counts) {
        Assert.assertEquals(count, 0);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) KillVM(org.btrplace.scheduler.choco.transition.KillVM) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)185 Test (org.testng.annotations.Test)160 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)94 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)74 SatConstraint (org.btrplace.model.constraint.SatConstraint)53 ShareableResource (org.btrplace.model.view.ShareableResource)52 Model (org.btrplace.model.Model)49 ArrayList (java.util.ArrayList)46 Node (org.btrplace.model.Node)45 DefaultModel (org.btrplace.model.DefaultModel)44 VM (org.btrplace.model.VM)41 MigrateVM (org.btrplace.plan.event.MigrateVM)37 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)34 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)32 Parameters (org.btrplace.scheduler.choco.Parameters)29 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)29 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)28 DefaultReconfigurationPlan (org.btrplace.plan.DefaultReconfigurationPlan)24 Mapping (org.btrplace.model.Mapping)23 HashSet (java.util.HashSet)22