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);
}
}
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();
}
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);
}
}
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);
}
}
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);
}
}
Aggregations