use of org.btrplace.json.JSONConverterException in project scheduler by btrplace.
the class ModelConverter method newVMs.
/**
* Build VMs from a key.
*
* @param mo the model to build
* @param o the object that contains the vm
* @param key the key associated to the VMs
* @return the resulting set of VMs
* @throws JSONConverterException if at least one of the parsed VM already exists
*/
private static Set<VM> newVMs(Model mo, JSONObject o, String key) throws JSONConverterException {
checkKeys(o, key);
Object x = o.get(key);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("array expected at key '" + key + "'");
}
Set<VM> s = new HashSet<>(((JSONArray) x).size());
for (Object i : (JSONArray) x) {
int id = (Integer) i;
VM vm = mo.newVM(id);
if (vm == null) {
throw JSONConverterException.vmAlreadyDeclared(id);
}
s.add(vm);
}
return s;
}
Aggregations