Search in sources :

Example 51 with VM

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

the class SeqConverter method fromJSON.

@Override
public Seq fromJSON(Model mo, JSONObject o) throws JSONConverterException {
    checkId(o);
    List<VM> s = new ArrayList<>();
    for (Object ob : (JSONArray) o.get("vms")) {
        s.add(getVM(mo, (Integer) ob));
    }
    return new Seq(s);
}
Also used : VM(org.btrplace.model.VM) JSONs.getVM(org.btrplace.json.JSONs.getVM) ArrayList(java.util.ArrayList) JSONArray(net.minidev.json.JSONArray) JSONObject(net.minidev.json.JSONObject) Seq(org.btrplace.model.constraint.Seq)

Example 52 with VM

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

the class PrecedenceConverter method toJSON.

@Override
public JSONObject toJSON(Precedence precedence) {
    JSONObject c = new JSONObject();
    Iterator<VM> it = precedence.getInvolvedVMs().iterator();
    c.put("id", getJSONId());
    c.put("vm1", JSONs.elementToJSON(it.next()));
    c.put("vm2", JSONs.elementToJSON(it.next()));
    c.put("continuous", precedence.isContinuous());
    return c;
}
Also used : JSONObject(net.minidev.json.JSONObject) JSONs.requiredVM(org.btrplace.json.JSONs.requiredVM) VM(org.btrplace.model.VM)

Example 53 with VM

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

the class ShareableResourceConverter method parseVMs.

private static void parseVMs(Model mo, ShareableResource rc, Object o) throws JSONConverterException {
    if (o != null) {
        try {
            JSONObject values = (JSONObject) o;
            for (Map.Entry<String, Object> e : values.entrySet()) {
                String k = e.getKey();
                VM u = getVM(mo, Integer.parseInt(k));
                int v = Integer.parseInt(e.getValue().toString());
                rc.setConsumption(u, v);
            }
        } catch (ClassCastException cc) {
            throw new JSONConverterException("Unable to read the VMs at key 'vms'. Expect a JSONObject but got a '" + o.getClass().getName() + "'", cc);
        }
    }
}
Also used : JSONObject(net.minidev.json.JSONObject) JSONs.getVM(org.btrplace.json.JSONs.getVM) VM(org.btrplace.model.VM) JSONObject(net.minidev.json.JSONObject) JSONs.requiredString(org.btrplace.json.JSONs.requiredString) Map(java.util.Map) JSONConverterException(org.btrplace.json.JSONConverterException)

Example 54 with VM

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

the class NamingServiceConverterTest method test.

@Test
public void test() throws JSONConverterException {
    NamingService<VM> ns = NamingService.newVMNS();
    Model mo = new DefaultModel();
    for (int i = 0; i < 10; i++) {
        VM v = mo.newVM();
        ns.register(v, "VM " + i);
    }
    NamingServiceConverter nsc = new NamingServiceConverter();
    JSONObject o = nsc.toJSON(ns);
    System.out.println(o);
    @SuppressWarnings("unchecked") NamingService<VM> ns2 = (NamingService<VM>) nsc.fromJSON(mo, o);
    Assert.assertEquals(ns, ns2);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) JSONObject(net.minidev.json.JSONObject) NamingService(org.btrplace.model.view.NamingService) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 55 with VM

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

the class SliceRcComparatorTest method testDescending.

@Test
public void testDescending() {
    List<Slice> l = makeSlices();
    ShareableResource rc = new ShareableResource("cpu");
    for (Slice s : l) {
        rc.setConsumption(s.getSubject(), rnd.nextInt(10));
    }
    SliceRcComparator cmp = new SliceRcComparator(rc, false);
    Collections.sort(l, cmp);
    for (int i = 0; i < l.size() - 1; i++) {
        VM u1 = l.get(i).getSubject();
        VM u2 = l.get(i + 1).getSubject();
        Assert.assertTrue(rc.getConsumption(u1) >= rc.getConsumption(u2));
    }
}
Also used : VM(org.btrplace.model.VM) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

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