use of co.cask.cdap.common.StreamNotFoundException in project cdap by caskdata.
the class FileStreamAdmin method deleteView.
@Override
public void deleteView(final StreamViewId viewId) throws Exception {
final StreamId stream = viewId.getParent();
streamCoordinatorClient.exclusiveAction(stream, new Callable<Void>() {
@Override
public Void call() throws Exception {
if (!exists(stream)) {
throw new StreamNotFoundException(stream);
}
viewAdmin.delete(viewId);
return null;
}
});
}
use of co.cask.cdap.common.StreamNotFoundException 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.cdap.common.StreamNotFoundException in project cdap by caskdata.
the class StreamClient method setStreamProperties.
/**
* Sets properties of a stream.
*
* @param stream ID of the stream
* @param properties properties to set
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the client is unauthorized
* @throws BadRequestException if the request is bad
* @throws StreamNotFoundException if the stream was not found
*/
public void setStreamProperties(StreamId stream, StreamProperties properties) throws IOException, UnauthenticatedException, BadRequestException, StreamNotFoundException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(stream.getParent(), String.format("streams/%s/properties", stream.getStream()));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(properties)).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST);
if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException("Bad request: " + response.getResponseBodyAsString());
}
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new StreamNotFoundException(stream);
}
}
use of co.cask.cdap.common.StreamNotFoundException in project cdap by caskdata.
the class StreamClient method truncate.
/**
* Truncates a stream, deleting all stream events belonging to the 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 truncate(StreamId stream) throws IOException, StreamNotFoundException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(stream.getParent(), String.format("streams/%s/truncate", stream.getStream()));
HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new StreamNotFoundException(stream);
}
}
use of co.cask.cdap.common.StreamNotFoundException in project cdap by caskdata.
the class StreamClient method setTTL.
/**
* Sets the Time-to-Live (TTL) of a stream. TTL governs how long stream events are readable.
*
* @param stream ID of the stream
* @param ttlInSeconds desired TTL, in seconds
* @throws IOException if a network error occurred
* @throws StreamNotFoundException if the stream with the specified name was not found
*/
public void setTTL(StreamId stream, long ttlInSeconds) throws IOException, StreamNotFoundException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(stream.getParent(), String.format("streams/%s/properties", stream.getStream()));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(ImmutableMap.of("ttl", ttlInSeconds))).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new StreamNotFoundException(stream);
}
}
Aggregations