Search in sources :

Example 21 with DurationEvaluators

use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.

the class ModelCustomization method run.

@Override
public void run() {
    Model model = makeModel();
    List<SatConstraint> cstrs = makeConstraints(model);
    // Set attributes for the VMs
    Attributes attrs = model.getAttributes();
    for (VM vm : model.getMapping().getAllVMs()) {
        attrs.put(vm, "template", vm.id() % 2 == 0 ? "small" : "large");
        attrs.put(vm, "clone", true);
        attrs.put(vm, "forge", vm.id() % 2 == 0 ? 2 : 10);
    // forge == 2 && template == small  for vm0, vm2, vm4, vm6, vm8
    // forge == 10 && template == large for vm1, vm3, vm5, vm7, vm9
    }
    // Change the duration evaluator for MigrateVM action
    ChocoScheduler cra = new DefaultChocoScheduler();
    DurationEvaluators dev = cra.getDurationEvaluators();
    dev.register(MigrateVM.class, new LinearToAResourceActionDuration<VM>("mem", 2, 3));
    dev.register(BootVM.class, new ConstantActionDuration<>(1));
    dev.register(ShutdownVM.class, new ConstantActionDuration<>(1));
    // Relocate VM4:
    // using a migration: (2 * mem + 3) = (2 * 2 + 3) = 7 sec.
    // using a re-instantiation: forge + boot + shutdown = 2 + 1 + 1 = 4 sec.
    // Relocate VM5:
    // using a migration: (2 * mem + 3) = (2 * 3 + 3) = 9 sec.
    // using a re-instantiation: forge + boot + shutdown = 10 + 1 + 1 = 12 sec.
    cra.doOptimize(true);
    ReconfigurationPlan plan = cra.solve(model, cstrs);
    System.out.println(plan);
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators)

Example 22 with DurationEvaluators

use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.

the class DefaultReconfigurationProblemTest method testSimplestInstantiation.

/*private static Model defaultModel() {
        Model mo = new DefaultModel();
        VM vm1 = mo.newVM();
        VM vm2 = mo.newVM();
        VM vm3 = mo.newVM();
        VM vm4 = mo.newVM();
        VM vm5 = mo.newVM();
        VM vm6 = mo.newVM();
        Node n1 = mo.newNode();
        Node n2 = mo.newNode();
        Node n3 = mo.newNode();

        Mapping map = mo.getMapping();
        map.addOnlineNode(n1);
        map.addOnlineNode(n2);
        map.addOfflineNode(n3);

        map.addRunningVM(vm1, n1);
        map.addRunningVM(vm2, n1);
        map.addRunningVM(vm3, n2);
        map.addSleepingVM(vm4, n2);
        map.addReadyVM(vm5);
        map.addReadyVM(vm6);
        return mo;
    }                 */
/**
 * Just test the state definition of the actions.
 *
 * @throws org.btrplace.scheduler.SchedulerException should not occur
 */
@Test
public void testSimplestInstantiation() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    VM vm6 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Mapping map = mo.getMapping();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addOfflineNode(n3);
    map.addRunningVM(vm1, n1);
    map.addRunningVM(vm2, n1);
    map.addRunningVM(vm3, n2);
    map.addSleepingVM(vm4, n2);
    map.addReadyVM(vm5);
    map.addReadyVM(vm6);
    VM vm7 = mo.newVM();
    Set<VM> toRun = new HashSet<>();
    Set<VM> toWait = new HashSet<>();
    toWait.add(vm6);
    toWait.add(vm7);
    toRun.add(vm5);
    toRun.add(vm4);
    toRun.add(vm1);
    mo.getAttributes().put(vm7, "template", "small");
    Parameters ps = new DefaultParameters();
    DurationEvaluators dEval = ps.getDurationEvaluators();
    DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(toWait, toRun, Collections.singleton(vm3), Collections.singleton(vm2)).setParams(ps).build();
    Assert.assertEquals(dEval, rp.getDurationEvaluators());
    Assert.assertEquals(rp.getFutureReadyVMs(), toWait);
    Assert.assertEquals(rp.getFutureRunningVMs(), toRun);
    Assert.assertEquals(rp.getFutureSleepingVMs(), Collections.singleton(vm3));
    Assert.assertEquals(rp.getFutureKilledVMs(), Collections.singleton(vm2));
    Assert.assertEquals(rp.getVMs().size(), 7);
    Assert.assertEquals(rp.getNodes().size(), 3);
    Assert.assertEquals(rp.getManageableVMs().size(), rp.getVMs().size(), rp.getManageableVMs().toString());
    Assert.assertTrue(rp.getStart().isInstantiated() && rp.getStart().getValue() == 0);
    // Test the index values of the nodes and the VMs.
    for (int i = 0; i < rp.getVMs().size(); i++) {
        VM vm = rp.getVM(i);
        Assert.assertEquals(i, rp.getVM(vm));
    }
    Assert.assertEquals(rp.getVM(mo.newVM()), -1);
    for (int i = 0; i < rp.getNodes().size(); i++) {
        Node n = rp.getNode(i);
        Assert.assertEquals(i, rp.getNode(n));
    }
    Assert.assertEquals(rp.getNode(mo.newNode()), -1);
}
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) Mapping(org.btrplace.model.Mapping) 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) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 23 with DurationEvaluators

use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.

the class BootVMTest method testBasics.

/**
 * Just boot a VM on a  node.
 */
@Test
public void testBasics() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addReadyVM(vm1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
    BootVM m = (BootVM) rp.getVMActions().get(0);
    Assert.assertEquals(vm1, m.getVM());
    Assert.assertNull(m.getCSlice());
    Assert.assertTrue(m.getDuration().isInstantiatedTo(5));
    Assert.assertTrue(m.getState().isInstantiatedTo(1));
    Assert.assertFalse(m.getDSlice().getHoster().isInstantiated());
    Assert.assertFalse(m.getDSlice().getStart().isInstantiated());
    Assert.assertFalse(m.getDSlice().getEnd().isInstantiated());
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    org.btrplace.plan.event.BootVM a = (org.btrplace.plan.event.BootVM) p.getActions().iterator().next();
    Node dest = rp.getNode(m.getDSlice().getHoster().getValue());
    Assert.assertEquals(vm1, a.getVM());
    Assert.assertEquals(dest, a.getDestinationNode());
    Assert.assertEquals(5, a.getEnd() - a.getStart());
}
Also used : Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) 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 24 with DurationEvaluators

use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.

the class BootableNodeTest method testBootCascade.

@Test
public void testBootCascade() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOfflineNode(n1);
    map.addOfflineNode(n2);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(BootNode.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    BootableNode na1 = (BootableNode) rp.getNodeAction(n1);
    BootableNode na2 = (BootableNode) rp.getNodeAction(n2);
    na1.getState().instantiateTo(1, Cause.Null);
    na2.getState().instantiateTo(1, Cause.Null);
    rp.getModel().post(rp.getModel().arithm(na1.getEnd(), "=", na2.getEnd()));
    new CMinMTTR().inject(ps, rp);
    Assert.assertNotNull(rp.solve(0, false));
}
Also used : BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Example 25 with DurationEvaluators

use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.

the class BootableNodeTest method testForcingBoot.

@Test
public void testForcingBoot() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    Node n1 = mo.newNode();
    map.addOfflineNode(n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(BootNode.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    BootableNode na = (BootableNode) rp.getNodeAction(n1);
    na.getState().instantiateTo(1, Cause.Null);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Assert.assertEquals(na.getDuration().getValue(), 5);
    Assert.assertEquals(na.getStart().getValue(), 0);
    Assert.assertEquals(na.getEnd().getValue(), 5);
    Assert.assertEquals(na.getHostingStart().getValue(), 5);
    Assert.assertEquals(na.getHostingEnd().getValue(), 5);
    Model res = p.getResult();
    Assert.assertTrue(res.getMapping().isOnline(n1));
}
Also used : BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) Test(org.testng.annotations.Test)

Aggregations

DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)37 Test (org.testng.annotations.Test)35 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)31 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)28 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)28 Parameters (org.btrplace.scheduler.choco.Parameters)28 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)27 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)17 ShutdownNode (org.btrplace.plan.event.ShutdownNode)16 BootNode (org.btrplace.plan.event.BootNode)15 HashSet (java.util.HashSet)10 Action (org.btrplace.plan.event.Action)10 Node (org.btrplace.model.Node)9 VM (org.btrplace.model.VM)9 MigrateVM (org.btrplace.plan.event.MigrateVM)9 DefaultModel (org.btrplace.model.DefaultModel)8 Mapping (org.btrplace.model.Mapping)8 Model (org.btrplace.model.Model)8 ShutdownVM (org.btrplace.plan.event.ShutdownVM)3 BootVM (org.btrplace.plan.event.BootVM)2