Search in sources :

Example 16 with ApplicationNotFoundException

use of co.cask.cdap.common.ApplicationNotFoundException in project cdap by caskdata.

the class PreferencesClient method getApplicationPreferences.

/**
   * Returns the Preferences stored at the Application Level.
   *
   * @param application Application Id
   * @param resolved Set to True if collapsed/resolved properties are desired
   * @return map of key-value pairs
   * @throws IOException if a network error occurred
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   * @throws ApplicationNotFoundException if the requested application is not found
   */
public Map<String, String> getApplicationPreferences(ApplicationId application, boolean resolved) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    String res = Boolean.toString(resolved);
    URL url = config.resolveNamespacedURLV3(application.getParent(), String.format("/apps/%s/preferences?resolved=%s", application.getApplication(), res));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(application);
    }
    return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, String>>() {
    }).getResponseObject();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) HttpResponse(co.cask.common.http.HttpResponse) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) URL(java.net.URL)

Example 17 with ApplicationNotFoundException

use of co.cask.cdap.common.ApplicationNotFoundException in project cdap by caskdata.

the class ApplicationClient method get.

/**
   * Get details about the specified application.
   *
   * @param appId the id of the application to get
   * @return details about the specified application
   * @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 ApplicationDetail get(ApplicationId appId) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
    String path = String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion());
    HttpResponse response = restClient.execute(HttpMethod.GET, config.resolveNamespacedURLV3(appId.getParent(), path), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ApplicationNotFoundException(appId);
    }
    return ObjectResponse.fromJsonBody(response, ApplicationDetail.class).getResponseObject();
}
Also used : ApplicationDetail(co.cask.cdap.proto.ApplicationDetail) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) HttpResponse(co.cask.common.http.HttpResponse)

Aggregations

ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)17 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)8 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)7 ApplicationId (co.cask.cdap.proto.id.ApplicationId)6 HttpResponse (co.cask.common.http.HttpResponse)5 NotFoundException (co.cask.cdap.common.NotFoundException)4 ProgramId (co.cask.cdap.proto.id.ProgramId)3 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)3 URL (java.net.URL)3 InstanceNotFoundException (co.cask.cdap.api.dataset.InstanceNotFoundException)2 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)2 ProgramRuntimeService (co.cask.cdap.app.runtime.ProgramRuntimeService)2 NamespaceId (co.cask.cdap.proto.id.NamespaceId)2 HttpRequest (co.cask.common.http.HttpRequest)2 TypeToken (com.google.common.reflect.TypeToken)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 ArtifactId (co.cask.cdap.api.artifact.ArtifactId)1