private List<InstanceRest> loadInstances() throws RestException { List<InstanceRest> instances = new ArrayList<>(); for(DBInstance instance : instanceFactory.listInstances()) { instances.add(new InstanceRest(instance.getPath(), "OK", engineManager.getEngineVersion(), instance.getInstanceId())); } return instances; }
@RequestMapping(value = "/Instances", method = POST, consumes = "application/json", produces = "application/json") public RestEntity writeEntry(@RequestBody InstanceRest dbInstance) throws RestException { try { instanceFactory.addInstance(dbInstance.getInstanceId()); return getInstance(dbInstance.getInstanceId()); } catch(JasDBStorageException e) { throw new RestException("Unable to create new instance: " + e.getMessage()); } }
private InstanceRest loadInstance(String instanceId) throws RestException { try { DBInstance dbInstance = instanceFactory.getInstance(instanceId); return new InstanceRest(dbInstance.getPath(), "OK", engineManager.getEngineVersion(), dbInstance.getInstanceId()); } catch(ConfigurationException e) { throw new RestException("Unable to retrieve the instance", e); } }
@Override public Instance addInstance(RemotingContext context, String instanceId) throws RemoteException { String connectionString = new RestConnectionBuilder().instance().getConnectionString(); try { InstanceRest instance = new InstanceRest(null, "OK", null, instanceId); ByteArrayOutputStream bos = new ByteArrayOutputStream(); new JsonRestResponseHandler().serialize(instance, bos); ClientResponse clientResponse = doRequest(context, connectionString, new HashMap<>(), bos.toString(CHARACTER_ENCODING), REQUEST_MODE.POST); try { instance = new JsonRestResponseHandler().deserialize(InstanceRest.class, clientResponse.getEntityInputStream()); } finally { clientResponse.close(); } return instance; } catch(RestException e) { throw new RemoteException("Unable to parse remote bag definition", e); } catch(UnsupportedEncodingException e) { throw new RemoteException("Unable to serialize bag", e); } }