Package co.cask.cdap.common.http

Examples of co.cask.cdap.common.http.HttpResponse


   * @throws UnAuthorizedAccessTokenException if the request is not authorized successfully in the gateway server
   */
  public void cancel(QueryHandle queryHandle) throws IOException, QueryNotFoundException, BadRequestException,
    UnAuthorizedAccessTokenException {
    URL url = config.resolveURL(String.format("data/explore/queries/%s/cancel", queryHandle.getHandle()));
    HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND,
                                               HttpURLConnection.HTTP_BAD_REQUEST);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new QueryNotFoundException(queryHandle.getHandle());
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
      throw new BadRequestException("The query '" + queryHandle + "' was not in a state that can be canceled");
    }
  }
View Full Code Here


    throws BadRequestException, NotFoundException, IOException, UnAuthorizedAccessTokenException {

    URL url = config.resolveURL(String.format("apps/%s/procedures/%s/methods/%s", appId, procedureId, methodId));
    HttpRequest request = HttpRequest.post(url).withBody(GSON.toJson(parameters)).build();

    HttpResponse response = restClient.execute(request, config.getAccessToken(),
                                               HttpURLConnection.HTTP_BAD_REQUEST,
                                               HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
      throw new BadRequestException("The Application, Procedure and method exist, " +
                                      "but the arguments are not as expected: " + GSON.toJson(parameters));
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new NotFoundException("application or procedure or method", appId + "/" + procedureId + "/" + methodId);
    }
    return new String(response.getResponseBody(), Charsets.UTF_8);
  }
View Full Code Here

   * @throws IOException if a network error occurred
   * @throws UnAuthorizedAccessTokenException if the request is not authorized successfully in the gateway server
   */
  public List<ProgramRecord> list() throws IOException, UnAuthorizedAccessTokenException {
    URL url = config.resolveURL("procedures");
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
    return ObjectResponse.fromJsonBody(response, new TypeToken<List<ProgramRecord>>() { }).getResponseObject();
  }
View Full Code Here

    URL url = config.resolveURL(String.format("data/modules/%s", moduleName));
    Map<String, String> headers = ImmutableMap.of("X-Class-Name", className);
    HttpRequest request = HttpRequest.put(url).addHeaders(headers).withBody(moduleJarFile).build();

    HttpResponse response = restClient.upload(request, config.getAccessToken(),
                                              HttpURLConnection.HTTP_BAD_REQUEST,
                                              HttpURLConnection.HTTP_CONFLICT);
    if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
      throw new BadRequestException(String.format("Module jar file does not exist: %s", moduleJarFile));
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
      throw new DatasetModuleAlreadyExistsException(moduleName);
    }
  }
View Full Code Here

  public void delete(String moduleName)
    throws DatasetModuleCannotBeDeletedException, DatasetModuleNotFoundException, IOException,
    UnAuthorizedAccessTokenException {

    URL url = config.resolveURL(String.format("data/modules/%s", moduleName));
    HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_CONFLICT,
                                               HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
      throw new DatasetModuleCannotBeDeletedException(moduleName);
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new DatasetModuleNotFoundException(moduleName);
    }
  }
View Full Code Here

   * @throws IOException if a network error occurred
   * @throws UnAuthorizedAccessTokenException if the request is not authorized successfully in the gateway server
   */
  public void deleteAll() throws DatasetModuleCannotBeDeletedException, IOException, UnAuthorizedAccessTokenException {
    URL url = config.resolveURL("data/modules");
    HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_CONFLICT);
    if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
      // TODO: exception for all modules
      throw new DatasetModuleCannotBeDeletedException(null);
    }
  }
View Full Code Here

   * @throws UnAuthorizedAccessTokenException if the request is not authorized successfully in the gateway server
   */
  public DatasetModuleMeta get(String moduleName) throws DatasetModuleNotFoundException, IOException,
    UnAuthorizedAccessTokenException {
    URL url = config.resolveURL(String.format("data/modules/%s", moduleName));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new DatasetModuleNotFoundException(moduleName);
    }

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

   * @throws IOException if a network error occurred
   * @throws UnAuthorizedAccessTokenException if the request is not authorized successfully in the gateway server
   */
  public ServiceMeta get(String appId, String serviceId) throws IOException, UnAuthorizedAccessTokenException {
    URL url = config.resolveURL(String.format("apps/%s/services/%s", appId, serviceId));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
    return ObjectResponse.fromJsonBody(response, ServiceMeta.class).getResponseObject();
  }
View Full Code Here

  public void start(String appId, ProgramType programType, String programName)
    throws IOException, ProgramNotFoundException, UnAuthorizedAccessTokenException {

    URL url = config.resolveURL(String.format("apps/%s/%s/%s/start",
                                              appId, programType.getCategoryName(), programName));
    HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new ProgramNotFoundException(programType, appId, programName);
    }
  }
View Full Code Here

  public void stop(String appId, ProgramType programType, String programName)
    throws IOException, ProgramNotFoundException, UnAuthorizedAccessTokenException {

    URL url = config.resolveURL(String.format("apps/%s/%s/%s/stop",
                                              appId, programType.getCategoryName(), programName));
    HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new ProgramNotFoundException(programType, appId, programName);
    }
  }
View Full Code Here

TOP

Related Classes of co.cask.cdap.common.http.HttpResponse

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.