use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ClientMessagingService method listTopics.
@Override
public List<TopicId> listTopics(NamespaceId namespaceId) throws IOException {
HttpRequest request = remoteClient.requestBuilder(HttpMethod.GET, namespaceId.getNamespace() + "/topics").build();
HttpResponse response = remoteClient.execute(request);
handleError(response, "Failed to list topics in namespace " + namespaceId);
List<String> topics = GSON.fromJson(response.getResponseBodyAsString(), TOPIC_LIST_TYPE);
List<TopicId> result = new ArrayList<>(topics.size());
for (String topic : topics) {
result.add(namespaceId.topic(topic));
}
return Collections.unmodifiableList(result);
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class HDFSNodes method getNumDataNodes.
private int getNumDataNodes() throws IOException, JSONException {
int dataNodes = 0;
URL url = new URL(getWebURL() + "/jmx");
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = HttpRequests.execute(request);
JSONObject responseJSON = new JSONObject(response.getResponseBodyAsString());
JSONArray array = responseJSON.getJSONArray("beans");
for (int idx = 0; idx < array.length(); ++idx) {
if (array.getJSONObject(idx).get("name").equals("Hadoop:service=NameNode,name=FSNamesystemState")) {
dataNodes = array.getJSONObject(idx).getInt("NumLiveDataNodes");
break;
}
}
return dataNodes;
}
Aggregations