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();
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ProgramClient method setFlowletInstances.
/**
* Sets the number of instances that a flowlet will run on.
*
* @param flowlet the flowlet
* @param instances number of instances for the flowlet to run on
* @throws IOException if a network error occurred
* @throws NotFoundException if the application, flow, or flowlet could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void setFlowletInstances(FlowletId flowlet, int instances) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(flowlet.getParent().getNamespaceId(), String.format("apps/%s/flows/%s/flowlets/%s/instances", flowlet.getApplication(), flowlet.getFlow(), flowlet.getFlowlet()));
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(flowlet);
}
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ScheduleClient method delete.
/**
* Delete an existing schedule.
*
* @param scheduleId the ID of the schedule to be deleted
*/
public void delete(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s/schedules/%s", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
URL url = config.resolveNamespacedURLV3(scheduleId.toId().getNamespace(), path);
HttpResponse response = restClient.execute(HttpMethod.DELETE, 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 ScheduleClient method doUpdate.
private void doUpdate(ScheduleId scheduleId, String json) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException, AlreadyExistsException {
String path = String.format("apps/%s/versions/%s/schedules/%s/update", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path);
HttpRequest request = HttpRequest.post(url).withBody(json).build();
HttpResponse response = restClient.execute(request, 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 ScheduleClient method doList.
private List<ScheduleDetail> doList(WorkflowId workflow) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
String path = String.format("apps/%s/workflows/%s/schedules", workflow.getApplication(), workflow.getProgram());
URL url = config.resolveNamespacedURLV3(workflow.getNamespaceId(), path);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
throw new NotFoundException(workflow);
}
ObjectResponse<List<ScheduleDetail>> objectResponse = ObjectResponse.fromJsonBody(response, LIST_SCHEDULE_DETAIL_TYPE, GSON);
return objectResponse.getResponseObject();
}
Aggregations