use of net.minidev.json.JSONObject in project scheduler by btrplace.
the class ConstraintConverterTest method testBadCheckIdBadId.
@Test(expectedExceptions = { JSONConverterException.class })
public void testBadCheckIdBadId() throws JSONConverterException {
ConstraintConverter<?> c = new Mock<>("foo");
JSONObject o = new JSONObject();
o.put("id", "bar");
c.checkId(o);
}
use of net.minidev.json.JSONObject in project scheduler by btrplace.
the class ReconfigurationPlanConverter method fromJSON.
@Override
public ReconfigurationPlan fromJSON(JSONObject ob) throws JSONConverterException {
JSONs.checkKeys(ob, ORIGIN_LABEL, ACTIONS_LABEL);
final Model m = mc.fromJSON((JSONObject) ob.get(ORIGIN_LABEL));
final ReconfigurationPlan plan = new DefaultReconfigurationPlan(m);
for (final JSONObject json : (List<JSONObject>) ob.get(ACTIONS_LABEL)) {
final String id = json.getAsString(ActionConverter.ID_LABEL);
ActionConverter<? extends Action> ac = json3java.get(id);
if (ac == null) {
throw new JSONConverterException("No converter for action '" + id + "'");
}
final Action action = ac.fromJSON(m, json);
eventsFromJSON(json, m, action);
plan.add(action);
}
return plan;
}
use of net.minidev.json.JSONObject in project scheduler by btrplace.
the class ReconfigurationPlanConverter method eventFromJSON.
private Event eventFromJSON(final Model mo, final Object o) throws JSONConverterException {
final JSONObject json = (JSONObject) o;
JSONs.checkKeys(json, ActionConverter.ID_LABEL);
final String id = json.get(ActionConverter.ID_LABEL).toString();
final EventConverter<? extends Event> ec = json2java.get(id);
if (ec == null) {
throw new JSONConverterException("No converter available for a event having id '" + id + "'");
}
return ec.fromJSON(mo, json);
}
use of net.minidev.json.JSONObject 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);
}
}
}
use of net.minidev.json.JSONObject in project scheduler by btrplace.
the class NetworkConverter method physicalElementToJSON.
/**
* Convert a PhysicalElement to a JSON object.
*
* @param pe the physical element to convert
* @return the JSON object
* @throws IllegalArgumentException if the physical element is not supported
*/
public JSONObject physicalElementToJSON(PhysicalElement pe) {
JSONObject o = new JSONObject();
if (pe instanceof Node) {
o.put("type", NODE_LABEL);
o.put("id", ((Node) pe).id());
} else if (pe instanceof Switch) {
o.put("type", SWITCH_LABEL);
o.put("id", ((Switch) pe).id());
} else {
throw new IllegalArgumentException("Unsupported physical element '" + pe.getClass().toString() + "'");
}
return o;
}
Aggregations