Search in sources :

Example 1 with JSONArray

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;
}
Also used : JSONArray(net.minidev.json.JSONArray) JSONObject(net.minidev.json.JSONObject)

Example 2 with JSONArray

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);
}
Also used : JSONArray(net.minidev.json.JSONArray) JSONObject(net.minidev.json.JSONObject)

Example 3 with JSONArray

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;
}
Also used : JSONArray(net.minidev.json.JSONArray) JSONObject(net.minidev.json.JSONObject)

Example 4 with JSONArray

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)));
}
Also used : Instance(org.btrplace.model.Instance) Model(org.btrplace.model.Model) JSONArray(net.minidev.json.JSONArray)

Example 5 with JSONArray

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();
}
Also used : ScheduleConverter(org.btrplace.safeplace.testing.verification.btrplace.ScheduleConverter) JSONObject(net.minidev.json.JSONObject) Constant(org.btrplace.safeplace.spec.term.Constant) InstanceConverter(org.btrplace.json.model.InstanceConverter) ReconfigurationPlanConverter(org.btrplace.json.plan.ReconfigurationPlanConverter) JSONArray(net.minidev.json.JSONArray)

Aggregations

JSONArray (net.minidev.json.JSONArray)55 JSONObject (net.minidev.json.JSONObject)41 Test (org.junit.Test)9 HashMap (java.util.HashMap)8 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 JSONParser (net.minidev.json.parser.JSONParser)5 Test (org.testng.annotations.Test)5 DocumentContext (com.jayway.jsonpath.DocumentContext)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 JSONConverterException (org.btrplace.json.JSONConverterException)3 VM (org.btrplace.model.VM)3 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)2 ContentType (ddf.catalog.data.ContentType)2 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)2 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)2 SourceInfoRequestEnterprise (ddf.catalog.operation.impl.SourceInfoRequestEnterprise)2 SourceDescriptor (ddf.catalog.source.SourceDescriptor)2 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)2