use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class DefaultMetadataServiceClient method drop.
@Override
public void drop(MetadataMutation.Drop dropMutation) {
HttpRequest request = remoteClient.requestBuilder(HttpMethod.DELETE, "metadata-internals/drop").withBody(GSON.toJson(dropMutation)).build();
HttpResponse response = execute(request);
if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
LOG.trace("Failed to drop metadata for entity %s: %s", dropMutation.getEntity(), response);
}
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class DefaultMetadataServiceClient method remove.
@Override
public void remove(MetadataMutation.Remove removeMutation) {
HttpRequest request = remoteClient.requestBuilder(HttpMethod.DELETE, "metadata-internals/remove").withBody(GSON.toJson(removeMutation)).build();
HttpResponse response = execute(request);
if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
LOG.trace("Failed to remove metadata for entity %s: %s", removeMutation.getEntity(), response);
}
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class ArtifactLocalizerClient method sendRequest.
private File sendRequest(ArtifactId artifactId, boolean unpack) throws IOException, ArtifactNotFoundException {
String urlPath = String.format("/artifact/namespaces/%s/artifacts/%s/versions/%s?unpack=%b", artifactId.getNamespace(), artifactId.getArtifact(), artifactId.getVersion(), unpack);
URL url;
try {
url = new URI(sidecarBaseURL + urlPath).toURL();
} catch (URISyntaxException e) {
throw new IOException(e);
}
LOG.debug("Sending request to {}", url);
HttpRequest httpRequest = HttpRequest.builder(HttpMethod.GET, url).build();
Multimap<String, String> headers = httpRequest.getHeaders();
internalAuthenticator.applyInternalAuthenticationHeaders(headers::put);
HttpResponse httpResponse = HttpRequests.execute(httpRequest);
if (httpResponse.getResponseCode() != HttpURLConnection.HTTP_OK) {
if (httpResponse.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ArtifactNotFoundException(artifactId);
}
BasicThrowable basicThrowable = GSON.fromJson(httpResponse.getResponseBodyAsString(), BasicThrowable.class);
throw new IOException(RemoteExecutionException.fromBasicThrowable(basicThrowable));
}
String path = httpResponse.getResponseBodyAsString();
LOG.debug("ArtifactLocalizer request returned path {}", path);
return new File(path);
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class TaskWorkerHttpHandlerInternal method token.
@GET
@Path("/token")
public void token(io.netty.handler.codec.http.HttpRequest request, HttpResponder responder) {
if (metadataServiceEndpoint == null) {
responder.sendString(HttpResponseStatus.NOT_IMPLEMENTED, String.format("%s has not been set", Constants.TaskWorker.METADATA_SERVICE_END_POINT));
return;
}
try {
URL url = new URL(metadataServiceEndpoint);
HttpRequest tokenRequest = HttpRequest.get(url).addHeader("Metadata-Flavor", "Google").build();
HttpResponse tokenResponse = HttpRequests.execute(tokenRequest);
responder.sendByteArray(HttpResponseStatus.OK, tokenResponse.getResponseBody(), EmptyHttpHeaders.INSTANCE);
} catch (Exception ex) {
LOG.warn("Failed to fetch token from metadata service", ex);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, exceptionToJson(ex), EmptyHttpHeaders.INSTANCE);
}
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class OAuthServiceTest method makePutCall.
private <T> HttpResponse makePutCall(String endpoint, T body) throws IOException {
URL url = serviceURI.resolve(String.format("v1/oauth/%s", endpoint)).toURL();
HttpRequest request = HttpRequest.builder(HttpMethod.PUT, url).withBody(GSON.toJson(body)).build();
return HttpRequests.execute(request, new DefaultHttpRequestConfig(false));
}
Aggregations