Search in sources :

Example 46 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class RelocatableVMTest method testNotWorthyReInstantiation.

/**
 * The re-instantiation is possible but will lead in a waste of time.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testNotWorthyReInstantiation() throws SchedulerException {
    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.addRunningVM(vm1, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(MigrateVM.class, new ConstantActionDuration<>(2));
    mo.getAttributes().put(vm1, "template", "small");
    mo.getAttributes().put(vm1, "clone", true);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
    RelocatableVM am = (RelocatableVM) rp.getVMAction(vm1);
    Assert.assertFalse(am.getRelocationMethod().isInstantiated());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) Test(org.testng.annotations.Test)

Example 47 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class RelocatableVMTest method testWorthyReInstantiation.

/**
 * The re-instantiation is possible and worthy.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 * @throws ContradictionException
 */
@Test
public void testWorthyReInstantiation() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    VM vm10 = mo.newVM();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    // Not using vm1 because intPool starts at 0 so their will be multiple (0,1) VMs.
    map.addRunningVM(vm10, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.MigrateVM.class, new ConstantActionDuration<>(20));
    dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(3));
    dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(2));
    dev.register(org.btrplace.plan.event.ShutdownVM.class, new ConstantActionDuration<>(1));
    mo.getAttributes().put(vm10, "template", "small");
    mo.getAttributes().put(vm10, "clone", true);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).setManageableVMs(map.getAllVMs()).build();
    RelocatableVM am = (RelocatableVM) rp.getVMAction(vm10);
    am.getDSlice().getHoster().instantiateTo(rp.getNode(n2), Cause.Null);
    Solution sol = new Solution(rp.getModel());
    sol.record();
    rp.getSolver().plugMonitor((IMonitorSolution) () -> {
        sol.record();
    });
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(10, true);
    Assert.assertNotNull(p);
    Assert.assertEquals(sol.getIntVal(am.getRelocationMethod()), 1);
    Assert.assertEquals(p.getSize(), 3);
    Model res = p.getResult();
    // Check the VM has been relocated
    Assert.assertEquals(res.getMapping().getRunningVMs(n1).size(), 0);
    Assert.assertEquals(res.getMapping().getRunningVMs(n2).size(), 1);
    Assert.assertNotNull(p);
    for (Action a : p) {
        Assert.assertTrue(a.getStart() >= 0, a.toString());
        Assert.assertTrue(a.getEnd() >= a.getStart(), a.toString());
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Action(org.btrplace.plan.event.Action) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Parameters(org.btrplace.scheduler.choco.Parameters) 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) MigrateVM(org.btrplace.plan.event.MigrateVM) 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) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) Solution(org.chocosolver.solver.Solution) Test(org.testng.annotations.Test)

Example 48 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class RelocatableVMTest method testReinstantiationWithPreserve.

@Test
public void testReinstantiationWithPreserve() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    VM vm5 = mo.newVM();
    VM vm6 = mo.newVM();
    VM vm7 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addRunningVM(vm5, n1);
    map.addRunningVM(vm6, n1);
    map.addRunningVM(vm7, n2);
    ShareableResource rc = new ShareableResource("cpu", 10, 10);
    rc.setCapacity(n1, 7);
    rc.setConsumption(vm5, 3);
    rc.setConsumption(vm6, 3);
    rc.setConsumption(vm7, 5);
    for (VM vm : map.getAllVMs()) {
        mo.getAttributes().put(vm, "template", "small");
        mo.getAttributes().put(vm, "clone", true);
    }
    Preserve pr = new Preserve(vm5, "cpu", 5);
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.getDurationEvaluators().register(MigrateVM.class, new ConstantActionDuration<>(20));
    mo.attach(rc);
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Online.newOnline(map.getAllNodes()));
    cstrs.add(pr);
    cra.doOptimize(true);
    try {
        ReconfigurationPlan p = cra.solve(mo, cstrs);
        Assert.assertNotNull(p);
    } catch (SchedulerException e) {
        Assert.fail(e.getMessage(), e);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SchedulerException(org.btrplace.scheduler.SchedulerException) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) Preserve(org.btrplace.model.constraint.Preserve) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 49 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class CShareableResourceTest method testDefaultOverbookRatio.

/**
 * The default overbooking ratio of 1 will make this problem having no solution.
 */
@Test
public void testDefaultOverbookRatio() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    mo.getMapping().on(n1).run(n1, vm1, vm2);
    ShareableResource rc = new ShareableResource("foo", 0, 0);
    rc.setConsumption(vm1, 2);
    rc.setConsumption(vm2, 3);
    rc.setCapacity(n1, 5);
    mo.attach(rc);
    ChocoScheduler s = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.add(new Fence(vm1, n1));
    cstrs.add(new Preserve(vm2, "foo", 4));
    // rp.solve(0, false);
    ReconfigurationPlan p = s.solve(mo, cstrs);
    Assert.assertNull(p);
}
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) ShareableResource(org.btrplace.model.view.ShareableResource) Preserve(org.btrplace.model.constraint.Preserve) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Fence(org.btrplace.model.constraint.Fence) Test(org.testng.annotations.Test)

Example 50 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class CShareableResourceTest method testInsertAction.

/**
 * Reproduce issue#145.
 */
/*@Test*/
public void testInsertAction() {
    Model mo = new DefaultModel();
    ShareableResource cpu = new ShareableResource("cpu");
    ShareableResource mem = new ShareableResource("mem");
    mo.attach(cpu);
    mo.attach(mem);
    Node node = mo.newNode();
    Node node2 = mo.newNode();
    mo.getMapping().on(node, node2);
    cpu.setCapacity(node, 100000);
    mem.setCapacity(node, 100000);
    cpu.setCapacity(node2, 100000);
    mem.setCapacity(node2, 100000);
    for (int i = 0; i < 10000; i++) {
        VM vm = mo.newVM();
        mo.getMapping().run(node, vm);
        cpu.setConsumption(vm, 1);
        mem.setConsumption(vm, 1);
    }
    ChocoScheduler sched = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Running.newRunning(mo.getMapping().getAllVMs()));
    cstrs.addAll(NoDelay.newNoDelay(mo.getMapping().getAllVMs()));
    cstrs.addAll(Fence.newFence(mo.getMapping().getAllVMs(), Arrays.asList(node2)));
    cstrs.addAll(Preserve.newPreserve(mo.getMapping().getAllVMs(), "cpu", 2));
    cstrs.addAll(Preserve.newPreserve(mo.getMapping().getAllVMs(), "mem", 2));
    ReconfigurationPlan plan = sched.solve(mo, cstrs);
    System.out.println(plan);
    System.out.println(sched.getStatistics());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Aggregations

DefaultModel (org.btrplace.model.DefaultModel)201 Test (org.testng.annotations.Test)177 Model (org.btrplace.model.Model)157 Node (org.btrplace.model.Node)91 VM (org.btrplace.model.VM)91 HashSet (java.util.HashSet)48 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)40 Mapping (org.btrplace.model.Mapping)39 ArrayList (java.util.ArrayList)26 ShareableResource (org.btrplace.model.view.ShareableResource)24 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)22 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)18 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)17 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)17 MigrateVM (org.btrplace.plan.event.MigrateVM)16 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)16 KillVM (org.btrplace.scheduler.choco.transition.KillVM)16