use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ProgramClient method getWorkflowCurrent.
/**
* Get the current run information for the Workflow based on the runid
*
* @param workflowId ID of the workflow
* @param runId ID of the run for which the details are to be returned
* @return list of {@link WorkflowActionNode} currently running for the given runid
* @throws IOException if a network error occurred
* @throws NotFoundException if the application, workflow, or runid could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<WorkflowActionNode> getWorkflowCurrent(WorkflowId workflowId, String runId) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
String path = String.format("/apps/%s/workflows/%s/runs/%s/current", workflowId.getApplication(), workflowId.getProgram(), runId);
URL url = config.resolveNamespacedURLV3(workflowId.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(workflowId.run(runId));
}
ObjectResponse<List<WorkflowActionNode>> objectResponse = ObjectResponse.fromJsonBody(response, new TypeToken<List<WorkflowActionNode>>() {
}.getType(), GSON);
return objectResponse.getResponseObject();
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class MonitorClient method getSystemServiceInstances.
/**
* Gets the number of instances the system service is running on.
*
* @param serviceName name of the system service
* @return number of instances the system service is running on
* @throws IOException if a network error occurred
* @throws NotFoundException if the system service with the specified name was not found
* @throws ServiceNotEnabledException if the system service is not currently enabled
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public int getSystemServiceInstances(String serviceName) throws IOException, NotFoundException, ServiceNotEnabledException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveURL(String.format("system/services/%s/instances", serviceName));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_FORBIDDEN);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(new SystemServiceId(serviceName));
} else if (response.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) {
throw new ServiceNotEnabledException(serviceName);
}
return ObjectResponse.fromJsonBody(response, Instances.class).getResponseObject().getInstances();
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ScheduleClient method getStatus.
public String getStatus(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s/schedules/%s/status", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
URL url = config.resolveNamespacedURLV3(scheduleId.getParent().getParent(), path);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
throw new NotFoundException(scheduleId);
}
Map<String, String> responseObject = ObjectResponse.<Map<String, String>>fromJsonBody(response, MAP_STRING_STRING_TYPE, GSON).getResponseObject();
return responseObject.get("status");
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ScheduleClient method resume.
public void resume(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s/schedules/%s/resume", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
URL url = config.resolveNamespacedURLV3(scheduleId.toId().getNamespace(), path);
HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
throw new NotFoundException(scheduleId);
}
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class AbstractMetadataClient method makeRequest.
// makes a request and throws BadRequestException or NotFoundException, as appropriate
private HttpResponse makeRequest(Id.NamespacedId namespacedId, String path, HttpMethod httpMethod, @Nullable String body) throws IOException, UnauthenticatedException, NotFoundException, BadRequestException, UnauthorizedException {
URL url = resolve(namespacedId.getNamespace(), path);
HttpRequest.Builder builder = HttpRequest.builder(httpMethod, url);
if (body != null) {
builder.withBody(body);
}
HttpResponse response = execute(builder.build(), 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(namespacedId.toEntityId());
}
return response;
}
Aggregations