Search in sources :

Example 11 with NotFoundException

use of io.cdap.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(io.cdap.common.http.HttpResponse) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) URL(java.net.URL)

Example 12 with NotFoundException

use of io.cdap.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(io.cdap.common.http.HttpResponse) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) URL(java.net.URL)

Example 13 with NotFoundException

use of io.cdap.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(io.cdap.common.http.HttpResponse) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) URL(java.net.URL)

Example 14 with NotFoundException

use of io.cdap.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(io.cdap.common.http.HttpResponse) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) URL(java.net.URL)

Example 15 with NotFoundException

use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.

the class ServiceClient method checkAvailability.

/**
 * Checks whether the {@link Service} is active.
 *
 * @param service ID of the service
 * @throws IOException if a network error occurred
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 * @throws NotFoundException if the app or service could not be found
 * @throws ServiceUnavailableException if the service is not available
 */
public void checkAvailability(ServiceId service) throws IOException, UnauthenticatedException, NotFoundException, ServiceUnavailableException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/versions/%s/services/%s/available", service.getApplication(), service.getVersion(), service.getProgram()));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_UNAVAILABLE);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(service);
    }
    if (response.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE) {
        throw new ServiceUnavailableException(service.getProgram());
    }
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) NotFoundException(io.cdap.cdap.common.NotFoundException) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) URL(java.net.URL)

Aggregations

NotFoundException (io.cdap.cdap.common.NotFoundException)266 HttpResponse (io.cdap.common.http.HttpResponse)86 URL (java.net.URL)76 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)54 ProgramId (io.cdap.cdap.proto.id.ProgramId)52 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)50 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)50 Path (javax.ws.rs.Path)50 BadRequestException (io.cdap.cdap.common.BadRequestException)42 ProgramNotFoundException (io.cdap.cdap.common.ProgramNotFoundException)42 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)36 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)36 IOException (java.io.IOException)36 GET (javax.ws.rs.GET)36 Test (org.junit.Test)30 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)28 HashMap (java.util.HashMap)28 ProgramSpecification (io.cdap.cdap.api.ProgramSpecification)26 ConflictException (io.cdap.cdap.common.ConflictException)26 ArrayList (java.util.ArrayList)26