Package co.cask.cdap.common.http

Examples of co.cask.cdap.common.http.HttpRequest$Builder


  }

  public void setAclForUser(EntityId entityId, String userId, List<PermissionType> permissions) throws IOException {
    URL url = resolveURL(String.format("/v2/admin/acls/%s/%s/user/%s", entityId.getType().getPluralForm(),
                                       entityId.getId(), userId));
    HttpRequest request = HttpRequest.builder(HttpMethod.PUT, url).withBody(GSON.toJson(permissions)).build();
    HttpRequests.execute(request);
  }
View Full Code Here


  }

  public void setAclForGroup(EntityId entityId, String groupId, List<PermissionType> permissions) throws IOException {
    URL url = resolveURL(String.format("/v2/admin/acls/%s/%s/group/%s", entityId.getType().getPluralForm(),
                                       entityId.getId(), groupId));
    HttpRequest request = HttpRequest.builder(HttpMethod.PUT, url).withBody(GSON.toJson(permissions)).build();
    HttpRequests.execute(request);
  }
View Full Code Here

    throws Exception {


    Map<String, String> headers = ImmutableMap.of("instance-props", GSON.toJson(props),
                                                  "type-meta", GSON.toJson(typeMeta));
    HttpRequest request = HttpRequest.post(resolve(instanceName, "create")).addHeaders(headers).build();
    HttpResponse response = HttpRequests.execute(request);
    verifyResponse(response);

    return ObjectResponse.fromJsonBody(response, DatasetSpecification.class).getResponseObject();
  }
View Full Code Here

  @Override
  public void drop(DatasetSpecification spec, DatasetTypeMeta typeMeta) throws Exception {
    Map<String, String> headers = ImmutableMap.of("instance-spec", GSON.toJson(spec),
                                                  "type-meta", GSON.toJson(typeMeta));
    HttpRequest request = HttpRequest.post(resolve(spec.getName(), "drop")).addHeaders(headers).build();
    HttpResponse response = HttpRequests.execute(request);
    verifyResponse(response);
  }
View Full Code Here

   */
  public void deploy(File jarFile) throws IOException {
    URL url = config.resolveURL("apps");
    Map<String, String> headers = ImmutableMap.of("X-Archive-Name", jarFile.getName());

    HttpRequest request = HttpRequest.post(url).addHeaders(headers).withBody(jarFile).build();
    restClient.upload(request, config.getAccessToken());
  }
View Full Code Here

    UnAuthorizedAccessTokenException {

    Preconditions.checkArgument(programType.isListable());

    URL url = config.resolveURL(programType.getCategoryName());
    HttpRequest request = HttpRequest.get(url).build();

    ObjectResponse<List<ProgramRecord>> response = ObjectResponse.fromJsonBody(
      restClient.execute(request, config.getAccessToken()), new TypeToken<List<ProgramRecord>>() { });

    return response.getResponseObject();
View Full Code Here

  public List<ProgramRecord> listPrograms(String appId, ProgramType programType)
    throws ApplicationNotFoundException, IOException, UnAuthorizedAccessTokenException {
    Preconditions.checkArgument(programType.isListable());

    URL url = config.resolveURL(String.format("apps/%s/%s", appId, programType.getCategoryName()));
    HttpRequest request = HttpRequest.get(url).build();

    ObjectResponse<List<ProgramRecord>> response = ObjectResponse.fromJsonBody(
      restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND),
      new TypeToken<List<ProgramRecord>>() { });
View Full Code Here

   */
  public void create(String datasetName, DatasetInstanceConfiguration properties)
    throws DatasetTypeNotFoundException, DatasetAlreadyExistsException, IOException, UnAuthorizedAccessTokenException {

    URL url = config.resolveURL(String.format("data/datasets/%s", datasetName));
    HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(properties)).build();

    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND,
                                               HttpURLConnection.HTTP_CONFLICT);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new DatasetTypeNotFoundException(properties.getTypeName());
View Full Code Here

   * @throws StreamNotFoundException if the stream with the specified name was not found
   */
  public void setTTL(String streamId, long ttlInSeconds) throws IOException, StreamNotFoundException,
    UnAuthorizedAccessTokenException {
    URL url = config.resolveURL(String.format("streams/%s/config", streamId));
    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(streamId);
    }
View Full Code Here

   * Writes stream event using the given URL. The write maybe sync or async, depending on the URL.
   */
  private void writeEvent(URL url, String streamId, String event) throws IOException,
                                                                         StreamNotFoundException,
                                                                         UnAuthorizedAccessTokenException {
    HttpRequest request = HttpRequest.post(url).withBody(event).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new StreamNotFoundException(streamId);
    }
  }
View Full Code Here

TOP

Related Classes of co.cask.cdap.common.http.HttpRequest$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.