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