Package co.cask.cdap.common.http

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


  public String getProgramLogs(String appId, ProgramType programType, String programId, long start, long stop)
    throws IOException, NotFoundException, UnAuthorizedAccessTokenException {

    URL url = config.resolveURL(String.format("apps/%s/%s/%s/logs?start=%d&stop=%d",
                                              appId, programType.getCategoryName(), programId, start, stop));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new ProgramNotFoundException(programType, appId, programId);
    }

    return new String(response.getResponseBody(), Charsets.UTF_8);
  }
View Full Code Here


  public String getServiceRunnableLogs(String appId, String serviceId, String runnableId, long start, long stop)
    throws IOException, NotFoundException, UnAuthorizedAccessTokenException {

    URL url = config.resolveURL(String.format("apps/%s/services/%s/runnables/%s/logs?start=%d&stop=%d",
                                              appId, serviceId, runnableId, start, stop));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new NotFoundException("application or service or runnable", appId + "/" + serviceId + "/" + runnableId);
    }

    return new String(response.getResponseBody(), Charsets.UTF_8);
  }
View Full Code Here

   * @throws UnAuthorizedAccessTokenException if the request is not authorized successfully in the gateway server
   */
  public Map<String, String> getRuntimeArgs(String appId, ProgramType programType, String programId)
    throws IOException, UnAuthorizedAccessTokenException, ProgramNotFoundException {
    String path = String.format("apps/%s/%s/%s/runtimeargs", appId, programType.getCategoryName(), programId);
    HttpResponse response = restClient.execute(HttpMethod.GET, config.resolveURL(path), config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new ProgramNotFoundException(programType, appId, programId);
    }
    return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, String>>() { }).getResponseObject();
  }
View Full Code Here

   */
  public void setRuntimeArgs(String appId, ProgramType programType, String programId, Map<String, String> runtimeArgs)
    throws IOException, UnAuthorizedAccessTokenException, ProgramNotFoundException {
    String path = String.format("apps/%s/%s/%s/runtimeargs", appId, programType.getCategoryName(), programId);
    HttpRequest request = HttpRequest.put(config.resolveURL(path)).withBody(GSON.toJson(runtimeArgs)).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new ProgramNotFoundException(programType, appId, programId);
    }
  }
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<SystemServiceMeta> listSystemServices() throws IOException, UnAuthorizedAccessTokenException {
    URL url = config.resolveURL("system/services");
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
    return ObjectResponse.fromJsonBody(response, new TypeToken<List<SystemServiceMeta>>() { }).getResponseObject();
  }
View Full Code Here

   * @throws UnAuthorizedAccessTokenException if the request is not authorized successfully in the gateway server
   */
  public String getSystemServiceStatus(String serviceName) throws IOException, NotFoundException, BadRequestException,
    UnAuthorizedAccessTokenException {
    URL url = config.resolveURL(String.format("system/services/%s/status", serviceName));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND,
                                               HttpURLConnection.HTTP_BAD_REQUEST);
    String responseBody = new String(response.getResponseBody());
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new NotFoundException("system service", serviceName);
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
      throw new BadRequestException(responseBody);
    }
    Map<String, String> status = GSON.fromJson(responseBody, new TypeToken<Map<String, String>>() { }.getType());
    return status.get("status");
  }
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 Map<String, String> getAllSystemServiceStatus() throws IOException, UnAuthorizedAccessTokenException {
    URL url = config.resolveURL("system/services/status");
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
    return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, String>>() { }).getResponseObject();
  }
View Full Code Here

  public void setSystemServiceInstances(String serviceName, int instances)
    throws IOException, NotFoundException, BadRequestException, UnAuthorizedAccessTokenException {

    URL url = config.resolveURL(String.format("system/services/%s/instances", serviceName));
    HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(new Instances(instances))).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND,
                                               HttpURLConnection.HTTP_BAD_REQUEST);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new NotFoundException("system service", serviceName);
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
      throw new BadRequestException(new String(response.getResponseBody()));
    }
  }
View Full Code Here

   */
  public int getSystemServiceInstances(String serviceName)
    throws IOException, NotFoundException, ServiceNotEnabledException, UnAuthorizedAccessTokenException {

    URL url = config.resolveURL(String.format("system/services/%s/instances", serviceName));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND,
                                               HttpURLConnection.HTTP_FORBIDDEN);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new NotFoundException("system service", serviceName);
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) {
      throw new ServiceNotEnabledException(serviceName);
    }

    return ObjectResponse.fromJsonBody(response, Instances.class).getResponseObject().getInstances();
  }
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.