use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class JSONs method requiredVMPart.
/**
* Read partitions of VMs.
*
* @param mo the associated model to browse
* @param o the object to parse
* @param id the key in the map that points to the partitions
* @return the parsed partition
* @throws JSONConverterException if the key does not point to partitions of VMs
*/
public static Set<Collection<VM>> requiredVMPart(Model mo, JSONObject o, String id) throws JSONConverterException {
Set<Collection<VM>> vms = new HashSet<>();
Object x = o.get(id);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("Set of identifiers sets expected at key '" + id + "'");
}
for (Object obj : (JSONArray) x) {
vms.add(vmsFromJSON(mo, (JSONArray) obj));
}
return vms;
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class JSONs method requiredVMs.
/**
* Read an expected list of VMs.
*
* @param mo the associated model to browse
* @param o the object to parse
* @param id the key in the map that points to the list
* @return the parsed list
* @throws JSONConverterException if the key does not point to a list of VM identifiers
*/
public static List<VM> requiredVMs(Model mo, JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
Object x = o.get(id);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("integers expected at key '" + id + "'");
}
return vmsFromJSON(mo, (JSONArray) x);
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class JSONs method requiredNodePart.
/**
* Read partitions of nodes.
*
* @param mo the associated model to browse
* @param o the object to parse
* @param id the key in the map that points to the partitions
* @return the parsed partition
* @throws JSONConverterException if the key does not point to partitions of nodes
*/
public static Set<Collection<Node>> requiredNodePart(Model mo, JSONObject o, String id) throws JSONConverterException {
Set<Collection<Node>> nodes = new HashSet<>();
Object x = o.get(id);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("Set of identifiers sets expected at key '" + id + "'");
}
for (Object obj : (JSONArray) x) {
nodes.add(nodesFromJSON(mo, (JSONArray) obj));
}
return nodes;
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class InstanceConverter method fromJSON.
@Override
public Instance fromJSON(JSONObject in) throws JSONConverterException {
checkKeys(in, MODEL_LABEL, CONSTRAINTS_LABEL, OBJ_LABEL);
Model mo = moc.fromJSON((JSONObject) in.get(MODEL_LABEL));
return new Instance(mo, cc.listFromJSON(mo, (JSONArray) in.get(CONSTRAINTS_LABEL)), (OptConstraint) cc.fromJSON(mo, (JSONObject) in.get(OBJ_LABEL)));
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class TestCase method toJSON.
public String toJSON() throws JSONConverterException {
InstanceConverter ic = new InstanceConverter();
ic.getConstraintsConverter().register(new ScheduleConverter());
ReconfigurationPlanConverter pc = new ReconfigurationPlanConverter();
JSONObject o = new JSONObject();
o.put("constraint", constraint().id());
JSONArray a = new JSONArray();
for (Constant c : args()) {
a.add(c.toJSON());
}
o.put("args", a);
o.put("continuous", continuous());
o.put("groups", groups());
o.put("plan", pc.toJSON(plan()));
o.put("instance", ic.toJSON(instance()));
return o.toJSONString();
}
Aggregations