Search in sources :

Example 26 with DefaultReconfigurationProblemBuilder

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

the class RelocatableVMTest method testForcedToMove.

@Test
public void testForcedToMove() 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.addRunningVM(vm1, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(MigrateVM.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
    RelocatableVM am = (RelocatableVM) rp.getVMAction(vm1);
    Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(0));
    Assert.assertEquals(vm1, am.getVM());
    Assert.assertEquals(2, am.getDuration().getDomainSize());
    Assert.assertEquals(0, am.getDuration().getLB());
    Assert.assertEquals(5, am.getDuration().getUB());
    Assert.assertFalse(am.getStart().isInstantiated());
    Assert.assertFalse(am.getEnd().isInstantiated());
    Assert.assertNotNull(am.getCSlice());
    Assert.assertTrue(am.getCSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
    Assert.assertTrue(am.getState().isInstantiatedTo(1));
    Assert.assertNotNull(am.getDSlice());
    Assert.assertFalse(am.getDSlice().getHoster().isInstantiated());
    // No VMs on n1, discrete mode
    rp.getModel().post(rp.getModel().arithm(rp.getNbRunningVMs().get(rp.getNode(n1)), "=", 0));
    new CMinMTTR().inject(new DefaultParameters(), rp);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Model m = p.getResult();
    Assert.assertEquals(n2, m.getMapping().getVMLocation(vm1));
    MigrateVM a = (MigrateVM) p.getActions().iterator().next();
    Assert.assertEquals(0, a.getStart());
    Assert.assertEquals(5, a.getEnd());
    Assert.assertEquals(n1, a.getSourceNode());
    Assert.assertEquals(n2, a.getDestinationNode());
    Assert.assertEquals(vm1, a.getVM());
}
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) MigrateVM(org.btrplace.plan.event.MigrateVM) 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 27 with DefaultReconfigurationProblemBuilder

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

the class RelocatableVMTest method testStayRunning.

@Test
public void testStayRunning() throws 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);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(new DefaultParameters()).setManageableVMs(Collections.emptySet()).build();
    Assert.assertEquals(rp.getVMAction(vm1).getClass(), RelocatableVM.class);
    RelocatableVM m1 = (RelocatableVM) rp.getVMAction(vm1);
    Assert.assertNotNull(m1.getCSlice());
    Assert.assertNotNull(m1.getDSlice());
    Assert.assertTrue(m1.getCSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
    Assert.assertTrue(m1.getDSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
    Assert.assertTrue(m1.getDuration().isInstantiatedTo(0));
    Assert.assertTrue(m1.getStart().isInstantiatedTo(0));
    Assert.assertTrue(m1.getEnd().isInstantiatedTo(0));
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Assert.assertEquals(p.getSize(), 0);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MigrateVM(org.btrplace.plan.event.MigrateVM) 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 28 with DefaultReconfigurationProblemBuilder

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

the class RelocatableVMTest method testForcedToStay.

@Test
public void testForcedToStay() 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.addRunningVM(vm1, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(MigrateVM.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
    RelocatableVM am = (RelocatableVM) rp.getVMAction(vm1);
    // No VMs on n2
    rp.getNbRunningVMs().get(rp.getNode(n2)).instantiateTo(0, Cause.Null);
    new CMinMTTR().inject(new DefaultParameters(), rp);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Assert.assertEquals(0, p.getSize());
    Assert.assertTrue(am.getDuration().isInstantiatedTo(0));
    Assert.assertTrue(am.getDSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
    Assert.assertTrue(am.getStart().isInstantiatedTo(0));
    Assert.assertTrue(am.getEnd().isInstantiatedTo(0));
    Model m = p.getResult();
    Assert.assertEquals(n1, m.getMapping().getVMLocation(vm1));
}
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 29 with DefaultReconfigurationProblemBuilder

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

the class ResumeVMTest method testResumeSequence.

/**
 * Test that check when the action is shorter than the end of
 * the reconfiguration process.
 * In practice, 2 resume actions have to be executed sequentially
 */
@Test
public void testResumeSequence() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addSleepingVM(vm1, n1);
    map.addSleepingVM(vm2, n2);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.ResumeVM.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
    ResumeVM m1 = (ResumeVM) rp.getVMActions().get(rp.getVM(vm1));
    ResumeVM m2 = (ResumeVM) rp.getVMActions().get(rp.getVM(vm2));
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
    rp.getModel().post(rp.getModel().arithm(m2.getStart(), ">=", m1.getEnd()));
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Iterator<Action> ite = p.iterator();
    org.btrplace.plan.event.ResumeVM b1 = (org.btrplace.plan.event.ResumeVM) ite.next();
    org.btrplace.plan.event.ResumeVM b2 = (org.btrplace.plan.event.ResumeVM) ite.next();
    Assert.assertEquals(vm1, b1.getVM());
    Assert.assertEquals(vm2, b2.getVM());
    Assert.assertTrue(b1.getEnd() <= b2.getStart());
    Assert.assertEquals(5, b1.getEnd() - b1.getStart());
    Assert.assertEquals(5, b2.getEnd() - b2.getStart());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Action(org.btrplace.plan.event.Action) 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) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 30 with DefaultReconfigurationProblemBuilder

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

the class ShutdownableNodeTest method testScheduledShutdown.

@Test
public void testScheduledShutdown() throws SchedulerException, ContradictionException {
    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(ShutdownVM.class, new ConstantActionDuration<>(2));
    dev.register(ShutdownNode.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(Collections.singleton(vm1), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()).build();
    ShutdownableNode ma = (ShutdownableNode) rp.getNodeAction(n1);
    ma.getState().instantiateTo(0, Cause.Null);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Assert.assertEquals(ma.getState().getValue(), 0);
    Assert.assertEquals(ma.getDuration().getValue(), 5);
    Assert.assertEquals(ma.getStart().getValue(), 2);
    Assert.assertEquals(ma.getEnd().getValue(), 7);
    Assert.assertEquals(ma.getHostingStart().getValue(), 0);
    Assert.assertEquals(ma.getHostingEnd().getValue(), 2);
    Model res = p.getResult();
    Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n1));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) 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) ShutdownVM(org.btrplace.plan.event.ShutdownVM) 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)

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