Search in sources :

Example 71 with Mapping

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

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

the class RelocatableVMTest method testForcedReInstantiation.

@Test
public void testForcedReInstantiation() 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(1, 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(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);
    // Check for the actions duration
    for (Action a : p) {
        if (a instanceof org.btrplace.plan.event.ForgeVM) {
            Assert.assertEquals(a.getEnd() - a.getStart(), 3);
        } else if (a instanceof org.btrplace.plan.event.ShutdownVM) {
            Assert.assertEquals(a.getEnd() - a.getStart(), 1);
        } else if (a instanceof org.btrplace.plan.event.BootVM) {
            Assert.assertEquals(a.getEnd() - a.getStart(), 2);
        } else {
            Assert.fail();
        }
    }
}
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) Test(org.testng.annotations.Test)

Example 73 with Mapping

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

the class CShareableResourceTest method testRealNodeUsage.

/**
 * Place some VMs and check realNodeUsage is updated accordingly
 */
@Test
public void testRealNodeUsage() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping ma = mo.getMapping();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    ma.addOnlineNode(n1);
    ma.addOnlineNode(n2);
    ma.addRunningVM(vm1, n1);
    ma.addRunningVM(vm2, n1);
    ShareableResource rc = new ShareableResource("foo", 0, 0);
    rc.setConsumption(vm1, 2);
    rc.setConsumption(vm2, 3);
    rc.setCapacity(n1, 5);
    rc.setCapacity(n2, 3);
    mo.attach(rc);
    ChocoScheduler s = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.add(new Fence(vm1, n1));
    cstrs.add(new Fence(vm2, n2));
    ReconfigurationPlan p = s.solve(mo, cstrs);
    Assert.assertNotNull(p);
    Model res = p.getResult();
    rc = (ShareableResource.get(res, "foo"));
    // rcm.getVirtualUsage(0).isInstantiatedTo(2));
    Assert.assertEquals(2, rc.getConsumption(vm1));
    // rcm.getVirtualUsage(1).isInstantiatedTo(3));
    Assert.assertEquals(3, rc.getConsumption(vm2));
}
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) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) 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 74 with Mapping

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

the class DefaultReconfigurationProblemBuilder method build.

/**
 * Build the problem
 *
 * @return the builder problem
 * @throws org.btrplace.scheduler.SchedulerException if an error occurred
 */
public DefaultReconfigurationProblem build() throws SchedulerException {
    if (runs == null) {
        // The others are supposed to be null too as they are set using the same method
        Mapping map = model.getMapping();
        runs = new HashSet<>();
        sleep = new HashSet<>();
        for (Node n : map.getOnlineNodes()) {
            runs.addAll(map.getRunningVMs(n));
            sleep.addAll(map.getSleepingVMs(n));
        }
        waits = map.getReadyVMs();
        over = Collections.emptySet();
    }
    if (manageable == null) {
        manageable = new HashSet<>();
        manageable.addAll(model.getMapping().getSleepingVMs());
        manageable.addAll(model.getMapping().getRunningVMs());
        manageable.addAll(model.getMapping().getReadyVMs());
    }
    if (ps == null) {
        ps = new DefaultParameters();
    }
    return new DefaultReconfigurationProblem(model, ps, waits, runs, sleep, over, manageable);
}
Also used : Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping)

Example 75 with Mapping

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

the class CBan method getMisPlacedVMs.

@Override
public Set<VM> getMisPlacedVMs(Instance i) {
    Mapping map = i.getModel().getMapping();
    VM vm = ban.getInvolvedVMs().iterator().next();
    if (map.isRunning(vm) && ban.getInvolvedNodes().contains(map.getVMLocation(vm))) {
        return Collections.singleton(vm);
    }
    return Collections.emptySet();
}
Also used : VM(org.btrplace.model.VM) Mapping(org.btrplace.model.Mapping)

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