Search in sources :

Example 96 with HttpRequest

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);
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) ArrayList(java.util.ArrayList) HttpResponse(co.cask.common.http.HttpResponse) TopicId(co.cask.cdap.proto.id.TopicId)

Example 97 with HttpRequest

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;
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL)

Aggregations

HttpRequest (co.cask.common.http.HttpRequest)97 URL (java.net.URL)75 HttpResponse (co.cask.common.http.HttpResponse)71 Test (org.junit.Test)22 AccessToken (co.cask.cdap.security.authentication.client.AccessToken)13 BadRequestException (co.cask.cdap.common.BadRequestException)10 NotFoundException (co.cask.cdap.common.NotFoundException)9 ApplicationManager (co.cask.cdap.test.ApplicationManager)9 ServiceManager (co.cask.cdap.test.ServiceManager)9 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)6 IOException (java.io.IOException)6 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)5 StreamNotFoundException (co.cask.cdap.common.StreamNotFoundException)5 TypeToken (com.google.common.reflect.TypeToken)5 TypeToken (com.google.gson.reflect.TypeToken)5 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)4 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)4 Instances (co.cask.cdap.proto.Instances)4 SparkManager (co.cask.cdap.test.SparkManager)4 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)3