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();
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ScheduleClient method doAdd.
/*------------ private helpers ---------------------*/
private void doAdd(ScheduleId scheduleId, String json) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException, AlreadyExistsException {
String path = String.format("apps/%s/versions/%s/schedules/%s", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path);
HttpRequest request = HttpRequest.put(url).withBody(json).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_CONFLICT);
if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
throw new NotFoundException(scheduleId);
} else if (HttpURLConnection.HTTP_CONFLICT == response.getResponseCode()) {
throw new AlreadyExistsException(scheduleId);
}
}
Aggregations