use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class StreamClient method delete.
/**
* Deletes a stream.
*
* @param stream ID of the stream to truncate
* @throws IOException if a network error occurred
* @throws StreamNotFoundException if the stream with the specified name was not found
*/
public void delete(StreamId stream) throws IOException, StreamNotFoundException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(stream.getParent(), String.format("streams/%s", stream.getStream()));
HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new StreamNotFoundException(stream);
}
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class StreamClient method getConfig.
/**
* Gets the configuration of a stream.
*
* @param stream ID of the stream
* @throws IOException if a network error occurred
* @throws StreamNotFoundException if the stream was not found
*/
public StreamProperties getConfig(StreamId stream) throws IOException, StreamNotFoundException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(stream.getParent(), String.format("streams/%s", stream.getStream()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new StreamNotFoundException(stream);
}
return GSON.fromJson(response.getResponseBodyAsString(Charsets.UTF_8), StreamProperties.class);
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class StreamViewClient method list.
/**
* Lists all views associated with a stream.
*
* @return the list of views associated with a stream
*/
public List<String> list(StreamId stream) throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(stream.getParent(), String.format("streams/%s/views", stream.getStream()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
return ObjectResponse.fromJsonBody(response, LIST_TYPE).getResponseObject();
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class RemoteDatasetOpExecutor method create.
@Override
public DatasetSpecification create(DatasetId datasetInstanceId, DatasetTypeMeta typeMeta, DatasetProperties props) throws Exception {
InternalDatasetCreationParams creationParams = new InternalDatasetCreationParams(typeMeta, props);
HttpResponse response = doRequest(datasetInstanceId, "create", GSON.toJson(creationParams));
return ObjectResponse.fromJsonBody(response, DatasetSpecification.class).getResponseObject();
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class RemoteDatasetOpExecutor method doRequest.
private HttpResponse doRequest(DatasetId datasetInstanceId, String opName, @Nullable String body) throws IOException, ConflictException {
String path = String.format("namespaces/%s/data/datasets/%s/admin/%s", datasetInstanceId.getNamespace(), datasetInstanceId.getEntityName(), opName);
HttpRequest.Builder builder = remoteClient.requestBuilder(HttpMethod.POST, path);
if (body != null) {
builder.withBody(body);
}
String userId = authenticationContext.getPrincipal().getName();
if (userId != null) {
builder.addHeader(Constants.Security.Headers.USER_ID, userId);
}
HttpResponse httpResponse = remoteClient.execute(builder.build());
verifyResponse(httpResponse);
return httpResponse;
}
Aggregations