Search in sources :

Example 76 with NotFoundException

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

the class LineageClient method getLineage.

private LineageRecord getLineage(NamespacedEntityId namespacedId, String path) throws IOException, UnauthenticatedException, NotFoundException, BadRequestException, UnauthorizedException {
    URL lineageURL = config.resolveNamespacedURLV3(new NamespaceId(namespacedId.getNamespace()), path);
    HttpResponse response = restClient.execute(HttpRequest.get(lineageURL).build(), config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
        throw new BadRequestException(response.getResponseBodyAsString());
    }
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(response.getResponseBodyAsString());
    }
    return GSON.fromJson(response.getResponseBodyAsString(), LineageRecord.class);
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) BadRequestException(co.cask.cdap.common.BadRequestException) NotFoundException(co.cask.cdap.common.NotFoundException) NamespaceId(co.cask.cdap.proto.id.NamespaceId) URL(java.net.URL)

Example 77 with NotFoundException

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

the class PreferencesClient method deleteApplicationPreferences.

/**
   * Deletes Preferences at the Application Level.
   *
   * @param application Application Id
   * @throws IOException if a network error occurred
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   * @throws NotFoundException if the request application or namespace is not found
   */
public void deleteApplicationPreferences(ApplicationId application) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(application.getParent(), String.format("/apps/%s/preferences", application.getApplication()));
    HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(application);
    }
}
Also used : 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 78 with NotFoundException

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

the class PreferencesClient method getNamespacePreferences.

/**
   * Returns the Preferences stored at the Namespace Level.
   *
   * @param namespace Namespace 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 NotFoundException if the requested namespace is not found
   */
public Map<String, String> getNamespacePreferences(NamespaceId namespace, boolean resolved) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    String res = Boolean.toString(resolved);
    URL url = config.resolveURLV3(String.format("namespaces/%s/preferences?resolved=%s", namespace.getNamespace(), res));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(namespace);
    }
    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 79 with NotFoundException

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

the class ProgramClient method getServiceInstances.

/**
   * Gets the number of instances of a service.
   *
   * @param service the service
   * @return number of instances of the service handler
   * @throws IOException if a network error occurred
   * @throws NotFoundException if the application or service could not found
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public int getServiceInstances(ServiceId service) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/services/%s/instances", service.getApplication(), service.getProgram()));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(service);
    }
    return ObjectResponse.fromJsonBody(response, Instances.class).getResponseObject().getInstances();
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) URL(java.net.URL)

Example 80 with NotFoundException

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

the class ProgramClient method getProgramRuns.

/**
   * Gets the run records of a program.
   *
   * @param program the program
   * @param state - filter by status of the program
   * @return the run records of the program
   * @throws IOException if a network error occurred
   * @throws NotFoundException if the application or program could not be found
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public List<RunRecord> getProgramRuns(ProgramId program, String state, long startTime, long endTime, int limit) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
    String queryParams = String.format("%s=%s&%s=%d&%s=%d&%s=%d", Constants.AppFabric.QUERY_PARAM_STATUS, state, Constants.AppFabric.QUERY_PARAM_START_TIME, startTime, Constants.AppFabric.QUERY_PARAM_END_TIME, endTime, Constants.AppFabric.QUERY_PARAM_LIMIT, limit);
    String path = String.format("apps/%s/versions/%s/%s/%s/runs?%s", program.getApplication(), program.getVersion(), program.getType().getCategoryName(), program.getProgram(), queryParams);
    URL url = config.resolveNamespacedURLV3(program.getNamespaceId(), path);
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(program);
    }
    return ObjectResponse.fromJsonBody(response, new TypeToken<List<RunRecord>>() {
    }).getResponseObject();
}
Also used : RunRecord(co.cask.cdap.proto.RunRecord) TypeToken(com.google.common.reflect.TypeToken) HttpResponse(co.cask.common.http.HttpResponse) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) URL(java.net.URL)

Aggregations

NotFoundException (co.cask.cdap.common.NotFoundException)122 URL (java.net.URL)42 HttpResponse (co.cask.common.http.HttpResponse)41 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)28 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)26 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)25 Path (javax.ws.rs.Path)25 BadRequestException (co.cask.cdap.common.BadRequestException)22 ProgramId (co.cask.cdap.proto.id.ProgramId)19 ApplicationId (co.cask.cdap.proto.id.ApplicationId)17 NamespaceId (co.cask.cdap.proto.id.NamespaceId)14 Test (org.junit.Test)14 POST (javax.ws.rs.POST)12 HttpRequest (co.cask.common.http.HttpRequest)10 IOException (java.io.IOException)10 GET (javax.ws.rs.GET)10 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)9 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)8 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)8 TypeToken (com.google.common.reflect.TypeToken)8