Search in sources :

Example 91 with NotFoundException

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

the class PreferencesClient method setNamespacePreferences.

/**
   * Sets Preferences at the Namespace Level.
   *
   * @param namespace Namespace Id
   * @param preferences 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 void setNamespacePreferences(NamespaceId namespace, Map<String, String> preferences) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    URL url = config.resolveURLV3(String.format("namespaces/%s/preferences", namespace.getNamespace()));
    HttpResponse response = restClient.execute(HttpMethod.PUT, url, GSON.toJson(preferences), null, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(namespace);
    }
}
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 92 with NotFoundException

use of co.cask.cdap.common.NotFoundException 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 93 with NotFoundException

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

the class PreferencesClient method deleteNamespacePreferences.

/**
   * Deletes Preferences at the Namespace Level.
   *
   * @param namespace Namespace 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 requested namespace is not found
   */
public void deleteNamespacePreferences(NamespaceId namespace) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    URL url = config.resolveURLV3(String.format("namespaces/%s/preferences", namespace.getNamespace()));
    HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(namespace);
    }
}
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 94 with NotFoundException

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

the class PreferencesClient method setApplicationPreferences.

/**
   * Sets Preferences at the Application Level.
   *
   * @param application Application Id
   * @param preferences 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 application or namespace is not found
   */
public void setApplicationPreferences(ApplicationId application, Map<String, String> preferences) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(application.getParent(), String.format("/apps/%s/preferences", application.getApplication()));
    HttpResponse response = restClient.execute(HttpMethod.PUT, url, GSON.toJson(preferences), null, 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 95 with NotFoundException

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

the class ProgramClient method setWorkerInstances.

/**
   * Sets the number of instances that a worker will run on.
   *
   * @param instances number of instances for the worker to run on
   * @throws IOException if a network error occurred
   * @throws NotFoundException if the application or worker could not be found
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public void setWorkerInstances(ProgramId worker, int instances) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(worker.getNamespaceId(), String.format("apps/%s/workers/%s/instances", worker.getApplication(), worker.getProgram()));
    HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(new Instances(instances))).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(worker);
    }
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) Instances(co.cask.cdap.proto.Instances) 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