Search in sources :

Example 51 with Mapping

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

the class DefaultChocoSchedulerTest method testGetStatisticsWithNoSolution.

@Test
public void testGetStatisticsWithNoSolution() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    VM v = mo.newVM();
    Node n = mo.newNode();
    map.addReadyVM(v);
    map.addOfflineNode(n);
    ChocoScheduler cra = new DefaultChocoScheduler();
    ReconfigurationPlan p = cra.solve(mo, Arrays.asList(new Running(v), new Offline(n)));
    Assert.assertNull(p);
    SolvingStatistics stats = cra.getStatistics();
    Assert.assertNotNull(stats);
    Assert.assertTrue(stats.getSolutions().isEmpty());
// Assert.assertFalse(stats.hitTimeout());
}
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) Running(org.btrplace.model.constraint.Running) Offline(org.btrplace.model.constraint.Offline) Mapping(org.btrplace.model.Mapping) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) Test(org.testng.annotations.Test)

Example 52 with Mapping

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

the class DefaultReconfigurationProblemTest method testMinimize.

/**
 * Test a minimization problem: use the minimum number of nodes.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testMinimize() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    for (int i = 0; i < 10; i++) {
        Node n = mo.newNode();
        VM vm = mo.newVM();
        map.addOnlineNode(n);
        map.addRunningVM(vm, n);
    }
    Parameters ps = new DefaultParameters();
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    Solver s = rp.getSolver();
    IntVar nbNodes = rp.getModel().intVar("nbNodes", 1, map.getAllNodes().size(), true);
    Stream<Slice> dSlices = rp.getVMActions().stream().filter(t -> t.getDSlice() != null).map(VMTransition::getDSlice);
    IntVar[] hosters = dSlices.map(Slice::getHoster).toArray(IntVar[]::new);
    rp.getModel().post(rp.getModel().atMostNValues(hosters, nbNodes, true));
    rp.setObjective(true, nbNodes);
    ReconfigurationPlan plan = rp.solve(-1, true);
    Assert.assertNotNull(plan);
    Assert.assertEquals(s.getMeasures().getSolutionCount(), 1);
    Mapping dst = plan.getResult().getMapping();
    Assert.assertEquals(usedNodes(dst), 1);
}
Also used : ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Arrays(java.util.Arrays) SchedulerException(org.btrplace.scheduler.SchedulerException) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) Node(org.btrplace.model.Node) ModelView(org.btrplace.model.view.ModelView) UnstatableProblemException(org.btrplace.scheduler.UnstatableProblemException) NodeTransition(org.btrplace.scheduler.choco.transition.NodeTransition) ContradictionException(org.chocosolver.solver.exception.ContradictionException) Test(org.testng.annotations.Test) Solver(org.chocosolver.solver.Solver) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) Assert(org.testng.Assert) Mapping(org.btrplace.model.Mapping) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) Model(org.btrplace.model.Model) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) Set(java.util.Set) DefaultModel(org.btrplace.model.DefaultModel) Cause(org.chocosolver.solver.Cause) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) Stream(java.util.stream.Stream) KillVM(org.btrplace.scheduler.choco.transition.KillVM) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) ShareableResource(org.btrplace.model.view.ShareableResource) Solution(org.chocosolver.solver.Solution) Collections(java.util.Collections) DefaultModel(org.btrplace.model.DefaultModel) Solver(org.chocosolver.solver.Solver) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) 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) Test(org.testng.annotations.Test)

Example 53 with Mapping

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

the class DefaultReconfigurationProblemTest method testMaintainState.

@Test
public void testMaintainState() 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();
    Node n1 = mo.newNode();
    Mapping map = mo.getMapping();
    map.addOnlineNode(n1);
    map.addRunningVM(vm1, n1);
    map.addReadyVM(vm2);
    map.addSleepingVM(vm3, n1);
    map.addReadyVM(vm5);
    ShareableResource rc = new ShareableResource("foo");
    rc.setConsumption(vm1, 5);
    rc.setConsumption(vm2, 7);
    mo.getAttributes().put(vm4, "template", "small");
    mo.attach(rc);
    ReconfigurationProblem rp = new DefaultReconfigurationProblem(mo, new DefaultParameters(), Collections.singleton(vm4), Collections.singleton(vm5), Collections.singleton(vm1), Collections.emptySet(), map.getAllVMs());
    Assert.assertTrue(rp.getFutureSleepingVMs().contains(vm1));
    Assert.assertTrue(rp.getFutureReadyVMs().contains(vm2));
    Assert.assertTrue(rp.getFutureSleepingVMs().contains(vm3));
    Assert.assertTrue(rp.getFutureReadyVMs().contains(vm4));
    Assert.assertTrue(rp.getFutureRunningVMs().contains(vm5));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) 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) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 54 with Mapping

use of org.btrplace.model.Mapping 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 55 with Mapping

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

the class DefaultReconfigurationProblemTest method testVMStayRunning.

@Test
public void testVMStayRunning() 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);
    Mapping m = mo.getMapping();
    m.addOnlineNode(n1);
    m.addRunningVM(vm1, n1);
    DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), Collections.singleton(vm1), new HashSet<>(), new HashSet<>()).build();
    VMTransition a = rp.getVMActions().get(0);
    Assert.assertEquals(a, rp.getVMAction(vm1));
    Assert.assertEquals(RelocatableVM.class, a.getClass());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) 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) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Mapping (org.btrplace.model.Mapping)83 Node (org.btrplace.model.Node)68 VM (org.btrplace.model.VM)62 Model (org.btrplace.model.Model)42 DefaultModel (org.btrplace.model.DefaultModel)39 Test (org.testng.annotations.Test)39 HashSet (java.util.HashSet)29 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)23 ShareableResource (org.btrplace.model.view.ShareableResource)16 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)16 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)15 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)15 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)15 IntVar (org.chocosolver.solver.variables.IntVar)15 SatConstraint (org.btrplace.model.constraint.SatConstraint)14 BootVM (org.btrplace.scheduler.choco.transition.BootVM)14 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)14 KillVM (org.btrplace.scheduler.choco.transition.KillVM)14 ResumeVM (org.btrplace.scheduler.choco.transition.ResumeVM)14 ShutdownVM (org.btrplace.scheduler.choco.transition.ShutdownVM)14