Search in sources :

Example 51 with HttpResponse

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

Example 52 with HttpResponse

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

Example 53 with HttpResponse

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

Example 54 with HttpResponse

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();
}
Also used : DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) HttpResponse(co.cask.common.http.HttpResponse)

Example 55 with HttpResponse

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

Aggregations

HttpResponse (co.cask.common.http.HttpResponse)204 URL (java.net.URL)145 HttpRequest (co.cask.common.http.HttpRequest)77 NotFoundException (co.cask.cdap.common.NotFoundException)41 TypeToken (com.google.common.reflect.TypeToken)26 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)24 Test (org.junit.Test)24 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)19 BadRequestException (co.cask.cdap.common.BadRequestException)17 IOException (java.io.IOException)14 ExploreException (co.cask.cdap.explore.service.ExploreException)12 ServiceManager (co.cask.cdap.test.ServiceManager)12 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)10 ApplicationManager (co.cask.cdap.test.ApplicationManager)10 StreamNotFoundException (co.cask.cdap.common.StreamNotFoundException)8 AccessToken (co.cask.cdap.security.authentication.client.AccessToken)6 TypeToken (com.google.gson.reflect.TypeToken)6 List (java.util.List)6 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)5 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)5