Search in sources :

Example 11 with StreamNotFoundException

use of co.cask.cdap.common.StreamNotFoundException in project cdap by caskdata.

the class StreamClient method setDescription.

/**
   * Sets the description of a stream.
   *
   * @param stream ID of the stream
   * @param description description of the stream
   * @throws IOException if a network error occurred
   * @throws StreamNotFoundException if the stream with the specified ID was not found
   */
public void setDescription(StreamId stream, String description) 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("description", description))).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 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)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 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