Search in sources :

Example 36 with DefaultReconfigurationProblemBuilder

use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.

the class ForgeVMTest method testWithoutTemplate.

@Test(expectedExceptions = { SchedulerException.class })
public void testWithoutTemplate() throws SchedulerException {
    Model mo = new DefaultModel();
    final VM vm1 = mo.newVM();
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(7));
    new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(Collections.singleton(vm1), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()).build();
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Test(org.testng.annotations.Test)

Example 37 with DefaultReconfigurationProblemBuilder

use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.

the class ShutdownVMTest method testBasic.

@Test
public void testBasic() throws ContradictionException, SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    map.addOnlineNode(n1);
    map.addRunningVM(vm1, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.ShutdownVM.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(map.getAllVMs(), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    ShutdownVM m = (ShutdownVM) rp.getVMActions().get(0);
    Assert.assertEquals(vm1, m.getVM());
    Assert.assertNull(m.getDSlice());
    Assert.assertTrue(m.getDuration().isInstantiatedTo(5));
    Assert.assertTrue(m.getState().isInstantiatedTo(0));
    Assert.assertTrue(m.getCSlice().getHoster().isInstantiatedTo(0));
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(0, false);
    org.btrplace.plan.event.ShutdownVM a = (org.btrplace.plan.event.ShutdownVM) p.getActions().iterator().next();
    Assert.assertEquals(vm1, a.getVM());
    Assert.assertEquals(5, a.getEnd() - a.getStart());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 38 with DefaultReconfigurationProblemBuilder

use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.

the class StayAwayVMTest method testBasic.

@Test
public void testBasic() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm1 = mo.newVM();
    final VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    map.addOnlineNode(n1);
    map.addSleepingVM(vm1, n1);
    map.addReadyVM(vm2);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).build();
    rp.getNodeAction(n1).getState().instantiateTo(1, Cause.Null);
    StayAwayVM ma1 = (StayAwayVM) rp.getVMAction(vm1);
    StayAwayVM ma2 = (StayAwayVM) rp.getVMAction(vm2);
    Assert.assertEquals(vm1, ma1.getVM());
    Assert.assertEquals(vm2, ma2.getVM());
    for (VMTransition am : rp.getVMActions()) {
        Assert.assertTrue(am.getState().isInstantiatedTo(0));
        Assert.assertNull(am.getCSlice());
        Assert.assertNull(am.getDSlice());
        Assert.assertTrue(am.getStart().isInstantiatedTo(0));
        Assert.assertTrue(am.getEnd().isInstantiatedTo(0));
        Assert.assertTrue(am.getDuration().isInstantiatedTo(0));
    }
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Assert.assertEquals(0, p.getSize());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) Test(org.testng.annotations.Test)

Example 39 with DefaultReconfigurationProblemBuilder

use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.

the class InstanceSolverRunner method buildRP.

private ReconfigurationProblem buildRP() throws SchedulerException {
    // Build the RP. As VM state management is not possible
    // We extract VM-state related constraints first.
    // For other constraint, we just create the right choco constraint
    Set<VM> toRun = new HashSet<>();
    Set<VM> toForge = new HashSet<>();
    Set<VM> toKill = new HashSet<>();
    Set<VM> toSleep = new HashSet<>();
    cConstraints = new ArrayList<>();
    for (SatConstraint cstr : cstrs) {
        if (params.getVerbosity() >= 1) {
            checkNodesExistence(origin, cstr.getInvolvedNodes());
        }
        // (when they will be forged)
        if (!(cstrs instanceof Ready)) {
            if (params.getVerbosity() >= 1) {
                checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
            }
        }
        if (cstr instanceof Running) {
            toRun.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Sleeping) {
            toSleep.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Ready) {
            if (params.getVerbosity() >= 1) {
                checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
            }
            toForge.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Killed) {
            if (params.getVerbosity() >= 1) {
                checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
            }
            toKill.addAll(cstr.getInvolvedVMs());
        }
        cConstraints.add(build(cstr));
    }
    cConstraints.add(build(obj));
    views = makeViews();
    DefaultReconfigurationProblemBuilder rpb = new DefaultReconfigurationProblemBuilder(origin).setNextVMsStates(toForge, toRun, toSleep, toKill).setParams(params);
    if (params.doRepair()) {
        Set<VM> toManage = new HashSet<>();
        cConstraints.forEach(c -> toManage.addAll(c.getMisPlacedVMs(instance)));
        views.forEach(v -> toManage.addAll(v.getMisPlacedVMs(instance)));
        rpb.setManageableVMs(toManage);
    }
    // The core views have been instantiated and available through rp.getViews()
    // Set the maximum duration
    ReconfigurationProblem p = rpb.build();
    try {
        p.getEnd().updateUpperBound(params.getMaxEnd(), Cause.Null);
    } catch (ContradictionException e) {
        p.getLogger().debug("Unable to restrict the maximum plan duration to " + params.getMaxEnd(), e);
        return null;
    }
    return p;
}
Also used : ContradictionException(org.chocosolver.solver.exception.ContradictionException) VM(org.btrplace.model.VM) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem)

Aggregations

DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)39 DefaultModel (org.btrplace.model.DefaultModel)38 Model (org.btrplace.model.Model)38 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)38 Test (org.testng.annotations.Test)38 Mapping (org.btrplace.model.Mapping)36 Node (org.btrplace.model.Node)36 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)35 Parameters (org.btrplace.scheduler.choco.Parameters)33 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)33 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)31 VM (org.btrplace.model.VM)25 ShutdownNode (org.btrplace.plan.event.ShutdownNode)17 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)17 BootNode (org.btrplace.plan.event.BootNode)16 HashSet (java.util.HashSet)9 Action (org.btrplace.plan.event.Action)8 MigrateVM (org.btrplace.plan.event.MigrateVM)8 ShutdownVM (org.btrplace.plan.event.ShutdownVM)2 ShareableResource (org.btrplace.model.view.ShareableResource)1