Search in sources :

Example 46 with VM

use of org.btrplace.model.VM 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(-1, rcm.getVMsAllocation(rp.getVM(vm1)).getLB());
    Assert.assertEquals(-1, rcm.getVMAllocation(rp.getVM(vm1)));
    // Assert.assertEquals(-1, rcm.getVMsAllocation(rp.getVM(vm2)).getLB());
    Assert.assertEquals(-1, rcm.getVMAllocation(rp.getVM(vm2)));
    // Assert.assertEquals(0, rcm.getVMsAllocation(rp.getVM(vm3)).getUB()); //Will not be running so 0
    // Will not be running so 0
    Assert.assertEquals(0, rcm.getVMAllocation(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);
    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 47 with VM

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

the class Decommissionning method run.

@Override
public void run() {
    int ratio = 1;
    int nbPCPUs = 4;
    int nbNodes = 2;
    // The current DC
    Model mo = new DefaultModel();
    for (int i = 0; i < nbNodes; i++) {
        Node n = mo.newNode();
        mo.getMapping().addOnlineNode(n);
        // 4 VMs per node
        for (int j = 0; j < ratio * nbPCPUs; j++) {
            VM v = mo.newVM();
            mo.getMapping().addRunningVM(v, n);
        }
    }
    // Resource allocation
    ShareableResource rc = new ShareableResource("cpu", 8, 1);
    mo.attach(rc);
    // The new DC
    for (int i = 0; i < nbNodes; i++) {
        Node n = mo.newNode();
        mo.getMapping().addOfflineNode(n);
        rc.setCapacity(n, 10);
    }
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Offline.newOffline(mo.getMapping().getOnlineNodes()));
    MaxOnline m = new MaxOnline(mo.getMapping().getAllNodes(), nbNodes + 1, true);
    cstrs.add(m);
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.setMaxEnd(3);
    cra.setVerbosity(1);
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    System.out.println(p);
    System.out.println(cra.getStatistics());
}
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) SatConstraint(org.btrplace.model.constraint.SatConstraint) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) MaxOnline(org.btrplace.model.constraint.MaxOnline) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel)

Example 48 with VM

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

the class Instances method makeVMIndex.

/**
 * Make an index revealing the position of each VM in a collection
 * of disjoint instances
 *
 * @param instances the collection to browse. Instances are supposed to be disjoint
 * @return the index of every VM. Format {@code VM#id() -> position}
 */
public static TIntIntHashMap makeVMIndex(Collection<Instance> instances) {
    TIntIntHashMap index = new TIntIntHashMap();
    int p = 0;
    for (Instance i : instances) {
        Mapping m = i.getModel().getMapping();
        for (Node n : m.getOnlineNodes()) {
            for (VM v : m.getRunningVMs(n)) {
                index.put(v.id(), p);
            }
            for (VM v : m.getSleepingVMs(n)) {
                index.put(v.id(), p);
            }
        }
        for (VM v : m.getReadyVMs()) {
            index.put(v.id(), p);
        }
        p++;
    }
    return index;
}
Also used : Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Mapping(org.btrplace.model.Mapping) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap)

Example 49 with VM

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

the class PreserveSplitter method split.

@Override
public boolean split(Preserve cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    VM v = cstr.getInvolvedVMs().iterator().next();
    int p = vmsPosition.get(v.id());
    return partitions.get(p).getSatConstraints().add(cstr);
}
Also used : VM(org.btrplace.model.VM)

Example 50 with VM

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

the class SleepingSplitter method split.

@Override
public boolean split(Sleeping cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    VM v = cstr.getInvolvedVMs().iterator().next();
    int i = vmsPosition.get(v.id());
    return partitions.get(i).getSatConstraints().add(cstr);
}
Also used : VM(org.btrplace.model.VM)

Aggregations

VM (org.btrplace.model.VM)192 Node (org.btrplace.model.Node)110 Model (org.btrplace.model.Model)92 DefaultModel (org.btrplace.model.DefaultModel)91 Test (org.testng.annotations.Test)91 Mapping (org.btrplace.model.Mapping)64 HashSet (java.util.HashSet)58 ArrayList (java.util.ArrayList)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)40 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)39 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)35 IntVar (org.chocosolver.solver.variables.IntVar)35 ShareableResource (org.btrplace.model.view.ShareableResource)32 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)27 MigrateVM (org.btrplace.plan.event.MigrateVM)25 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)17 StayAwayVM (org.btrplace.scheduler.choco.transition.StayAwayVM)17 Slice (org.btrplace.scheduler.choco.Slice)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)16