use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class AmongConverter method toJSON.
@Override
public JSONObject toJSON(Among o) {
JSONObject c = new JSONObject();
c.put("id", getJSONId());
c.put("vms", vmsToJSON(o.getInvolvedVMs()));
JSONArray a = new JSONArray();
for (Collection<Node> grp : o.getGroupsOfNodes()) {
a.add(nodesToJSON(grp));
}
c.put("parts", a);
c.put("continuous", o.isContinuous());
return c;
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class TestCase method fromJSON.
public static TestCase fromJSON(List<Constraint> cstrs, String c) throws ParseException, JSONConverterException {
JSONParser p = new JSONParser(JSONParser.MODE_RFC4627);
JSONObject o = (JSONObject) p.parse(new StringReader(c));
String cId = o.getAsString("constraint");
Optional<Constraint> opt = cstrs.stream().filter(x -> x.id().equals(cId)).findFirst();
if (!opt.isPresent()) {
throw new IllegalArgumentException("Unknown constraint '" + cId + "'");
}
Constraint cstr = opt.get();
InstanceConverter ic = new InstanceConverter();
ic.getConstraintsConverter().register(new ScheduleConverter());
ReconfigurationPlanConverter rc = new ReconfigurationPlanConverter();
Instance i = ic.fromJSON(o.getAsString("instance"));
ReconfigurationPlan plan = rc.fromJSON(o.getAsString("plan"));
TestCase tc = new TestCase(i, plan, cstr);
List<Constant> l = new ArrayList<>();
for (Object x : (JSONArray) o.get("args")) {
l.add(Constant.fromJSON((JSONObject) x));
}
tc.args(l);
if (cstr.isSatConstraint()) {
tc.impl(cstr.instantiate(l.stream().map(x -> x.eval(null)).collect(Collectors.toList())));
}
if (tc.impl() != null) {
tc.impl().setContinuous((Boolean) o.get("continuous"));
}
return tc;
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class StaticRoutingConverter method fromJSON.
@Override
public StaticRouting fromJSON(Model mo, JSONObject o) throws JSONConverterException {
Network v = Network.get(mo);
TIntObjectMap<Link> idToLink = new TIntObjectHashMap<>();
for (Link l : v.getLinks()) {
idToLink.put(l.id(), l);
}
StaticRouting r = new StaticRouting();
checkKeys(o, ROUTES_LABEL);
JSONArray a = (JSONArray) o.get(ROUTES_LABEL);
for (Object ao : a) {
StaticRouting.NodesMap nm = nodesMapFromJSON(mo, (JSONObject) ((JSONObject) ao).get("nodes_map"));
Map<Link, Boolean> links = new LinkedHashMap<>();
JSONArray aoa = (JSONArray) ((JSONObject) ao).get("links");
for (Object aoao : aoa) {
links.put(idToLink.get(requiredInt((JSONObject) aoao, "link")), Boolean.valueOf(requiredString((JSONObject) aoao, "direction")));
}
r.setStaticRoute(nm, links);
}
return r;
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class StaticRoutingConverter method toJSON.
/**
* Convert a Routing implementation into a JSON object
*
* @param routing the routing implementation to convert
* @return the JSON formatted routing object
*/
@Override
public JSONObject toJSON(StaticRouting routing) {
JSONObject o = new JSONObject();
o.put("type", getJSONId());
JSONArray a = new JSONArray();
Map<StaticRouting.NodesMap, Map<Link, Boolean>> routes = routing.getStaticRoutes();
for (Map.Entry<StaticRouting.NodesMap, Map<Link, Boolean>> e : routes.entrySet()) {
StaticRouting.NodesMap nm = e.getKey();
JSONObject ao = new JSONObject();
ao.put("nodes_map", nodesMapToJSON(nm));
JSONArray links = new JSONArray();
Map<Link, Boolean> v = e.getValue();
for (Link l : v.keySet()) {
JSONObject lo = new JSONObject();
lo.put("link", l.id());
lo.put("direction", routes.get(nm).get(l).toString());
links.add(lo);
}
ao.put("links", links);
a.add(ao);
}
o.put(ROUTES_LABEL, a);
return o;
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class SplitConverter method toJSON.
@Override
public JSONObject toJSON(Split o) {
JSONObject c = new JSONObject();
c.put("id", getJSONId());
JSONArray a = new JSONArray();
for (Collection<VM> grp : o.getSets()) {
a.add(vmsToJSON(grp));
}
c.put("parts", a);
c.put("continuous", o.isContinuous());
return c;
}
Aggregations