use of org.btrplace.json.JSONConverterException 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 org.btrplace.json.JSONConverterException 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 org.btrplace.json.JSONConverterException in project scheduler by btrplace.
the class AttributesConverter method fromJSON.
/**
* Decode attributes
*
* @param mo the model to rely on
* @param o the encoded attributes
* @return the resulting attributes
* @throws JSONConverterException if the conversion failed
*/
public static Attributes fromJSON(Model mo, JSONObject o) throws JSONConverterException {
Attributes attrs = new DefaultAttributes();
try {
JSONObject vms = (JSONObject) o.get("vms");
if (vms != null) {
for (Map.Entry<String, Object> e : vms.entrySet()) {
String el = e.getKey();
VM vm = getVM(mo, Integer.parseInt(el));
JSONObject entries = (JSONObject) e.getValue();
putAttributes(attrs, vm, entries);
}
}
JSONObject nodes = (JSONObject) o.get("nodes");
if (nodes != null) {
for (Map.Entry<String, Object> e : nodes.entrySet()) {
String el = e.getKey();
Node n = getNode(mo, Integer.parseInt(el));
JSONObject entries = (JSONObject) e.getValue();
putAttributes(attrs, n, entries);
}
}
} catch (ClassCastException ex) {
throw new JSONConverterException(ex);
}
return attrs;
}
use of org.btrplace.json.JSONConverterException in project scheduler by btrplace.
the class ConstraintsConverter method fromJSON.
/**
* Convert a json-encoded constraint.
*
* @param mo the model to rely on
* @param in the constraint to decode
* @return the resulting constraint
* @throws JSONConverterException if the conversion failed
*/
public Constraint fromJSON(Model mo, JSONObject in) throws JSONConverterException {
checkKeys(in, "id");
Object id = in.get("id");
ConstraintConverter<? extends Constraint> c = json2java.get(id.toString());
if (c == null) {
throw new JSONConverterException("No converter available for a constraint having id '" + id + "'");
}
return c.fromJSON(mo, in);
}
use of org.btrplace.json.JSONConverterException in project scheduler by btrplace.
the class NetworkConverter method routingFromJSON.
/**
* Convert a JSON routing object into the corresponding java Routing implementation.
*
* @param mo the model we focus on
* @param o the JSON object to convert
* @return the resulting {@link Routing} object
* @throws JSONConverterException if the Routing implementation is not known
*/
public Routing routingFromJSON(Model mo, JSONObject o) throws JSONConverterException {
String type = requiredString(o, "type");
RoutingConverter<? extends Routing> c = json2java.get(type);
if (c == null) {
throw new JSONConverterException("No converter available for a routing of type '" + type + "'");
}
return c.fromJSON(mo, o);
}
Aggregations