Search in sources :

Example 1 with StreamNotFoundException

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;
        }
    });
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) StreamNotFoundException(co.cask.cdap.common.StreamNotFoundException) NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) NotFoundException(co.cask.cdap.common.NotFoundException) StreamNotFoundException(co.cask.cdap.common.StreamNotFoundException)

Example 2 with StreamNotFoundException

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);
    }
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) StreamNotFoundException(co.cask.cdap.common.StreamNotFoundException) URL(java.net.URL)

Example 3 with StreamNotFoundException

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);
    }
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) HttpResponse(co.cask.common.http.HttpResponse) BadRequestException(co.cask.cdap.common.BadRequestException) StreamNotFoundException(co.cask.cdap.common.StreamNotFoundException) URL(java.net.URL)

Example 4 with StreamNotFoundException

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);
    }
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) StreamNotFoundException(co.cask.cdap.common.StreamNotFoundException) URL(java.net.URL)

Example 5 with StreamNotFoundException

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

Aggregations

StreamNotFoundException (co.cask.cdap.common.StreamNotFoundException)11 HttpResponse (co.cask.common.http.HttpResponse)8 URL (java.net.URL)8 HttpRequest (co.cask.common.http.HttpRequest)5 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)2 BadRequestException (co.cask.cdap.common.BadRequestException)2 StreamId (co.cask.cdap.proto.id.StreamId)2 IOException (java.io.IOException)2 NotFoundException (co.cask.cdap.common.NotFoundException)1 UnauthenticatedException (co.cask.cdap.common.UnauthenticatedException)1 NotificationFeedException (co.cask.cdap.notifications.feeds.NotificationFeedException)1 AccessToken (co.cask.cdap.security.authentication.client.AccessToken)1 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)1 JsonReader (com.google.gson.stream.JsonReader)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HttpURLConnection (java.net.HttpURLConnection)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1 Test (org.junit.Test)1