use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class RemotePrivilegesManager method listPrivileges.
@Override
public Set<Privilege> listPrivileges(Principal principal) throws Exception {
LOG.trace("Listing privileges for {}", principal);
HttpResponse httpResponse = executeRequest("listPrivileges", principal);
String responseBody = httpResponse.getResponseBodyAsString();
LOG.debug("List privileges response for principal {}: {}", principal, responseBody);
return GSON.fromJson(responseBody, SET_PRIVILEGES_TYPE);
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class RemoteUGIProvider method executeRequest.
private HttpResponse executeRequest(ImpersonationRequest impersonationRequest) throws IOException {
HttpRequest request = remoteClient.requestBuilder(HttpMethod.POST, "impersonation/credentials").withBody(GSON.toJson(impersonationRequest)).build();
HttpResponse response = remoteClient.execute(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return response;
}
throw new IOException(String.format("%s Response: %s.", createErrorMessage(request.getURL()), response));
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class StreamHandlerTest method getNumProcessed.
private long getNumProcessed(StreamId streamId) throws Exception {
String path = String.format("/v3/metrics/query?metric=system.collect.events&tag=namespace:%s&tag=stream:%s&aggregate=true", streamId.getNamespace(), streamId.getEntityName());
HttpRequest request = HttpRequest.post(getEndPoint(path).toURL()).build();
HttpResponse response = HttpRequests.execute(request);
Assert.assertEquals(200, response.getResponseCode());
return getNumEventsFromResponse(response.getResponseBodyAsString());
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class StreamHandlerTest method sendEvent.
private void sendEvent(StreamId streamId, String body) throws Exception {
URL url = createURL(streamId.getNamespace(), "streams/" + streamId.getEntityName());
HttpRequest request = HttpRequest.post(url).withBody(body).build();
HttpResponse response = HttpRequests.execute(request);
Assert.assertEquals(200, response.getResponseCode());
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class StreamHandlerTest method testStreamCreateInNonexistentNamespace.
@Test
public void testStreamCreateInNonexistentNamespace() throws Exception {
NamespaceId originallyNonExistentNamespace = new NamespaceId("originallyNonExistentNamespace");
StreamId streamId = originallyNonExistentNamespace.stream("streamName");
HttpResponse response = createStream(streamId, 404);
Assert.assertEquals(HttpResponseStatus.NOT_FOUND.code(), response.getResponseCode());
// once the namespace exists, the same stream create works.
namespaceAdmin.create(new NamespaceMeta.Builder().setName(originallyNonExistentNamespace).build());
createStream(streamId);
}
Aggregations