use of com.sun.jersey.api.client.WebResource in project zookeeper by apache.
the class SessionTest method testSendHeartbeat.
@Test
public void testSendHeartbeat() throws InterruptedException {
ZSession session = createSession("2");
Thread.sleep(1000);
WebResource wr = sessionsr.path(session.id);
Builder b = wr.accept(MediaType.APPLICATION_JSON);
ClientResponse cr = b.put(ClientResponse.class, null);
Assert.assertEquals(ClientResponse.Status.OK, cr.getClientResponseStatus());
Thread.sleep(1500);
Assert.assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
Thread.sleep(1000);
Assert.assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
}
use of com.sun.jersey.api.client.WebResource in project zookeeper by apache.
the class SessionTest method createSession.
private ZSession createSession(String expire) {
WebResource wr = sessionsr.queryParam("op", "create").queryParam("expire", expire);
Builder b = wr.accept(MediaType.APPLICATION_JSON);
ClientResponse cr = b.post(ClientResponse.class, null);
Assert.assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus());
return cr.getEntity(ZSession.class);
}
use of com.sun.jersey.api.client.WebResource in project zookeeper by apache.
the class SessionTest method testDeleteSession.
@Test
public void testDeleteSession() {
ZSession session = createSession("30");
WebResource wr = sessionsr.path(session.id);
Builder b = wr.accept(MediaType.APPLICATION_JSON);
Assert.assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
ClientResponse cr = b.delete(ClientResponse.class, null);
Assert.assertEquals(ClientResponse.Status.NO_CONTENT, cr.getClientResponseStatus());
Assert.assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
}
use of com.sun.jersey.api.client.WebResource in project hadoop by apache.
the class LogsCLI method getAMContainerInfoForRMWebService.
protected List<JSONObject> getAMContainerInfoForRMWebService(Configuration conf, String appId) throws ClientHandlerException, UniformInterfaceException, JSONException {
Client webServiceClient = Client.create();
String webAppAddress = WebAppUtils.getRMWebAppURLWithScheme(conf);
WebResource webResource = webServiceClient.resource(webAppAddress);
ClientResponse response = webResource.path("ws").path("v1").path("cluster").path("apps").path(appId).path("appattempts").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
JSONObject json = response.getEntity(JSONObject.class).getJSONObject("appAttempts");
JSONArray requests = json.getJSONArray("appAttempt");
List<JSONObject> amContainersList = new ArrayList<JSONObject>();
for (int i = 0; i < requests.length(); i++) {
amContainersList.add(requests.getJSONObject(i));
}
return amContainersList;
}
use of com.sun.jersey.api.client.WebResource in project hadoop by apache.
the class LogsCLI method getContainerLogFiles.
private List<Pair<PerContainerLogFileInfo, String>> getContainerLogFiles(Configuration conf, String containerIdStr, String nodeHttpAddress) throws IOException {
List<Pair<PerContainerLogFileInfo, String>> logFileInfos = new ArrayList<>();
Client webServiceClient = Client.create();
try {
WebResource webResource = webServiceClient.resource(WebAppUtils.getHttpSchemePrefix(conf) + nodeHttpAddress);
ClientResponse response = webResource.path("ws").path("v1").path("node").path("containers").path(containerIdStr).path("logs").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
if (response.getStatusInfo().getStatusCode() == ClientResponse.Status.OK.getStatusCode()) {
try {
JSONArray array = new JSONArray();
JSONObject json = response.getEntity(JSONObject.class);
Object logsInfoObj = json.get("containerLogsInfo");
if (logsInfoObj instanceof JSONObject) {
array.put((JSONObject) logsInfoObj);
} else if (logsInfoObj instanceof JSONArray) {
JSONArray logsArray = (JSONArray) logsInfoObj;
for (int i = 0; i < logsArray.length(); i++) {
array.put(logsArray.getJSONObject(i));
}
}
for (int i = 0; i < array.length(); i++) {
JSONObject log = array.getJSONObject(i);
String aggregateType = log.has("logAggregationType") ? log.getString("logAggregationType") : "N/A";
Object ob = log.get("containerLogInfo");
if (ob instanceof JSONArray) {
JSONArray obArray = (JSONArray) ob;
for (int j = 0; j < obArray.length(); j++) {
logFileInfos.add(new Pair<PerContainerLogFileInfo, String>(generatePerContainerLogFileInfoFromJSON(obArray.getJSONObject(j)), aggregateType));
}
} else if (ob instanceof JSONObject) {
logFileInfos.add(new Pair<PerContainerLogFileInfo, String>(generatePerContainerLogFileInfoFromJSON((JSONObject) ob), aggregateType));
}
}
} catch (Exception e) {
System.err.println("Unable to parse json from webservice. Error:");
System.err.println(e.getMessage());
throw new IOException(e);
}
}
} catch (ClientHandlerException | UniformInterfaceException ex) {
System.err.println("Unable to fetch log files list");
throw new IOException(ex);
}
return logFileInfos;
}
Aggregations