Search in sources :

Example 1 with DefaultReconfigurationProblemBuilder

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

the class CShareableResourceTest method testSimple.

/**
 * Test the instantiation and the creation of the variables.
 *
 * @throws org.btrplace.scheduler.SchedulerException should not occur
 */
@Test
public void testSimple() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping ma = mo.getMapping();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    ma.addOnlineNode(n1);
    ma.addOfflineNode(n2);
    ma.addRunningVM(vm1, n1);
    ma.addRunningVM(vm2, n1);
    ma.addReadyVM(vm3);
    ShareableResource rc = new ShareableResource("foo", 0, 0);
    rc.setConsumption(vm2, 3);
    rc.setCapacity(n1, 4);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).build();
    CShareableResource rcm = new CShareableResource(rc);
    rcm.inject(new DefaultParameters(), rp);
    Assert.assertEquals(rc.getIdentifier(), rcm.getIdentifier());
    Assert.assertEquals(0, rcm.getFutureVMAllocation(rp.getVM(vm1)));
    Assert.assertEquals(3, rcm.getFutureVMAllocation(rp.getVM(vm2)));
    // Will not be running so 0
    Assert.assertEquals(0, rcm.getFutureVMAllocation(rp.getVM(vm3)));
    IntVar pn1 = rcm.getPhysicalUsage().get(rp.getNode(n1));
    IntVar pn2 = rcm.getPhysicalUsage().get(rp.getNode(n2));
    Assert.assertTrue(pn1.getLB() == 0 && pn1.getUB() == 4);
    Assert.assertTrue(pn2.getLB() == 0 && pn2.getUB() == 0);
    Assert.assertEquals(rc.getCapacity(n1), rcm.getFutureNodeCapacity(rp.getNode(n1)));
    Assert.assertEquals(rc.getCapacity(n2), rcm.getFutureNodeCapacity(rp.getNode(n2)));
    pn1 = rcm.getPhysicalUsage(rp.getNode(n1));
    Assert.assertTrue(pn1.getLB() == 0 && pn1.getUB() == 4);
    IntVar vn1 = rcm.getVirtualUsage().get(rp.getNode(n1));
    IntVar vn2 = rcm.getVirtualUsage().get(rp.getNode(n2));
    Assert.assertEquals(vn1.getLB(), 0);
    Assert.assertEquals(vn2.getLB(), 0);
    Assert.assertEquals(rc, rcm.getSourceResource());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) 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) ShareableResource(org.btrplace.model.view.ShareableResource) IntVar(org.chocosolver.solver.variables.IntVar) Test(org.testng.annotations.Test)

Example 2 with DefaultReconfigurationProblemBuilder

use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder 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(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 3 with DefaultReconfigurationProblemBuilder

use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder 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 4 with DefaultReconfigurationProblemBuilder

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

the class RelocatableVMTest method testForcedMigration.

@Test
public void testForcedMigration() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm10 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    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(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.getRelocationMethod().instantiateTo(0, Cause.Null);
    am.getDSlice().getHoster().instantiateTo(rp.getNode(n2), Cause.Null);
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(10, true);
    Assert.assertNotNull(p);
    Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(0));
    Assert.assertEquals(p.getSize(), 1);
    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);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) 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) Test(org.testng.annotations.Test)

Example 5 with DefaultReconfigurationProblemBuilder

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

the class RelocatableVMTest method testWorthlessReInstantiation.

/**
 * The re-instantiation is possible and worthy.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 * @throws ContradictionException
 */
@Test
public void testWorthlessReInstantiation() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm10 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    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(MigrateVM.class, new ConstantActionDuration<>(2));
    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);
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(10, true);
    Assert.assertNotNull(p);
    Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(0));
    Assert.assertEquals(p.getSize(), 1);
    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);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) 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) Test(org.testng.annotations.Test)

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