Search in sources :

Example 1 with Seq

use of org.btrplace.model.constraint.Seq 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 2 with Seq

use of org.btrplace.model.constraint.Seq in project scheduler by btrplace.

the class SeqConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    Model mo = new DefaultModel();
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new SeqConverter());
    Seq d = new Seq(Arrays.asList(mo.newVM(), mo.newVM(), mo.newVM()));
    Seq c = new Seq(Arrays.asList(mo.newVM(), mo.newVM(), mo.newVM()));
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(c)), c);
    System.out.println(conv.toJSON(d));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Seq(org.btrplace.model.constraint.Seq) Test(org.testng.annotations.Test)

Example 3 with Seq

use of org.btrplace.model.constraint.Seq in project scheduler by btrplace.

the class SeqBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodseqs")
public void testGoodSignatures(String str, int nbVMs) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Seq x = (Seq) b.build("namespace test; VM[1..10] : tiny;\n" + str).getConstraints().iterator().next();
    Assert.assertEquals(x.getInvolvedVMs().size(), nbVMs);
    Assert.assertEquals(x.isContinuous(), true);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Seq(org.btrplace.model.constraint.Seq) Test(org.testng.annotations.Test)

Aggregations

Seq (org.btrplace.model.constraint.Seq)3 DefaultModel (org.btrplace.model.DefaultModel)2 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 JSONArray (net.minidev.json.JSONArray)1 JSONObject (net.minidev.json.JSONObject)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 JSONs.getVM (org.btrplace.json.JSONs.getVM)1 Model (org.btrplace.model.Model)1 VM (org.btrplace.model.VM)1