Search in sources :

Example 26 with HttpRequest

use of co.cask.common.http.HttpRequest in project cdap by caskdata.

the class ApplicationClient method listPrograms.

/**
   * Lists all programs belonging to an application.
   *
   * @param app the application
   * @return List of all {@link ProgramRecord}s
   * @throws ApplicationNotFoundException if the application with the given ID was not found
   * @throws IOException if a network error occurred
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public List<ProgramRecord> listPrograms(ApplicationId app) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
    String path = String.format("apps/%s/versions/%s", app.getApplication(), app.getVersion());
    URL url = config.resolveNamespacedURLV3(app.getParent(), path);
    HttpRequest request = HttpRequest.get(url).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ApplicationNotFoundException(app);
    }
    return ObjectResponse.fromJsonBody(response, ApplicationDetail.class).getResponseObject().getPrograms();
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL)

Example 27 with HttpRequest

use of co.cask.common.http.HttpRequest in project cdap by caskdata.

the class ApplicationClient method listAllPrograms.

/**
   * Lists all programs of a type.
   *
   * @param programType type of the programs to list
   * @return list of {@link ProgramRecord}s
   * @throws IOException if a network error occurred
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public List<ProgramRecord> listAllPrograms(NamespaceId namespace, ProgramType programType) throws IOException, UnauthenticatedException, UnauthorizedException {
    Preconditions.checkArgument(programType.isListable());
    String path = programType.getCategoryName();
    URL url = config.resolveNamespacedURLV3(namespace, path);
    HttpRequest request = HttpRequest.get(url).build();
    ObjectResponse<List<ProgramRecord>> response = ObjectResponse.fromJsonBody(restClient.execute(request, config.getAccessToken()), new TypeToken<List<ProgramRecord>>() {
    });
    return response.getResponseObject();
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) List(java.util.List) URL(java.net.URL)

Example 28 with HttpRequest

use of co.cask.common.http.HttpRequest in project cdap by caskdata.

the class ApplicationClient method listAppVersions.

/**
   * Lists all applications currently deployed, optionally filtering to only include applications that use one of
   * the specified artifact names and the specified artifact version.
   *
   * @param namespace the namespace to list application versions from
   * @param appName the application name to list versions for
   * @return list of {@link String} application versions.
   * @throws IOException if a network error occurred
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public List<String> listAppVersions(NamespaceId namespace, String appName) throws IOException, UnauthenticatedException, UnauthorizedException, ApplicationNotFoundException {
    String path = String.format("apps/%s/versions", appName);
    URL url = config.resolveNamespacedURLV3(namespace, path);
    HttpRequest request = HttpRequest.get(url).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ApplicationNotFoundException(namespace.app(appName));
    }
    return ObjectResponse.fromJsonBody(response, new TypeToken<List<String>>() {
    }).getResponseObject();
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) TypeToken(com.google.common.reflect.TypeToken) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL)

Example 29 with HttpRequest

use of co.cask.common.http.HttpRequest in project cdap by caskdata.

the class ApplicationClient method deployApp.

private void deployApp(NamespaceId namespace, File jarFile, Map<String, String> headers) throws IOException, UnauthenticatedException {
    URL url = config.resolveNamespacedURLV3(namespace, "apps");
    HttpRequest request = HttpRequest.post(url).addHeaders(headers).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM).withBody(jarFile).build();
    restClient.upload(request, config.getAccessToken());
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) URL(java.net.URL)

Example 30 with HttpRequest

use of co.cask.common.http.HttpRequest in project cdap by caskdata.

the class AuthorizationClient method addRoleToPrincipal.

@Override
public void addRoleToPrincipal(Role role, Principal principal) throws IOException, FeatureDisabledException, UnauthenticatedException, UnauthorizedException, RoleNotFoundException, NotFoundException {
    URL url = config.resolveURLV3(String.format(AUTHORIZATION_BASE + "%s/%s/roles/%s", principal.getType(), principal.getName(), role.getName()));
    HttpRequest request = HttpRequest.put(url).build();
    executeExistingRolesRequest(role, request);
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) URL(java.net.URL)

Aggregations

HttpRequest (co.cask.common.http.HttpRequest)97 URL (java.net.URL)75 HttpResponse (co.cask.common.http.HttpResponse)71 Test (org.junit.Test)22 AccessToken (co.cask.cdap.security.authentication.client.AccessToken)13 BadRequestException (co.cask.cdap.common.BadRequestException)10 NotFoundException (co.cask.cdap.common.NotFoundException)9 ApplicationManager (co.cask.cdap.test.ApplicationManager)9 ServiceManager (co.cask.cdap.test.ServiceManager)9 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)6 IOException (java.io.IOException)6 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)5 StreamNotFoundException (co.cask.cdap.common.StreamNotFoundException)5 TypeToken (com.google.common.reflect.TypeToken)5 TypeToken (com.google.gson.reflect.TypeToken)5 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)4 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)4 Instances (co.cask.cdap.proto.Instances)4 SparkManager (co.cask.cdap.test.SparkManager)4 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)3