@GET @Path("/{taskId}/await") @ApiOperation(value = "Await, then get a task execution details") @ApiResponses(value = { @ApiResponse(code = HttpStatus.OK_200, message = "A specific class execution details", response = ExecutionDetailsDto.class), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The taskId is invalid"), @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The taskId is not found") }) public Object await(Request req, Response response) { TaskId taskId = getTaskId(req); return respondStatus(taskId, () -> taskManager.await(getTaskId(req))); }
@DELETE @Path("/{taskId}") @ApiOperation(value = "Cancel a given task") @ApiResponses(value = { @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "Task is cancelled"), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The taskId is invalid") }) public Object cancel(Request req, Response response) { TaskId taskId = getTaskId(req); taskManager.cancel(taskId); response.status(HttpStatus.NO_CONTENT_204); return Constants.EMPTY_BODY; }
@GET @Path("/{taskId}") @ApiOperation(value = "Getting a task execution details") @ApiResponses(value = { @ApiResponse(code = HttpStatus.OK_200, message = "A specific class execution details", response = ExecutionDetailsDto.class), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The taskId is invalid"), @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The taskId is not found") }) public Object getStatus(Request req, Response response) { TaskId taskId = getTaskId(req); return respondStatus(taskId, () -> taskManager.getExecutionDetails(getTaskId(req))); }
@POST @Path("upgrade/latest") @ApiOperation("Triggers a migration of Cassandra schema to the latest available") @ApiResponses({ @ApiResponse(code = HttpStatus.CREATED_201, message = "The taskId of the given scheduled task", response = TaskIdDto.class, responseHeaders = { @ResponseHeader(name = "Location", description = "URL of the resource associated with the scheduled task") }), @ApiResponse(code = HttpStatus.CONFLICT_409, message = "Migration can not be done") }) public Object upgradeToLatest(Response response) { try { Migration migration = cassandraMigrationService.upgradeToLastVersion(); TaskId taskId = taskManager.submit(migration); return TaskIdDto.respond(response, taskId); } catch (IllegalStateException e) { LOGGER.info(MIGRATION_REQUEST_CAN_NOT_BE_DONE, e); throw ErrorResponder.builder() .statusCode(HttpStatus.CONFLICT_409) .type(ErrorType.WRONG_STATE) .message(MIGRATION_REQUEST_CAN_NOT_BE_DONE) .cause(e) .haltError(); } }
.map(TaskManager.Status::fromString) .map(taskManager::list) .orElse(taskManager.list())); } catch (IllegalArgumentException e) { throw ErrorResponder.builder()
@DELETE @Path("/{encodedPath}/mails") @ApiOperation(value = "Deleting all mails in that mailRepository") @ApiResponses(value = { @ApiResponse(code = HttpStatus.CREATED_201, message = "All mails are deleted", response = TaskIdDto.class), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - unknown action") }) public void defineDeleteAll() { service.delete(MAIL_REPOSITORIES + "/:encodedPath/mails", (request, response) -> { MailRepositoryPath path = decodedRepositoryPath(request); try { Task task = repositoryStoreService.createClearMailRepositoryTask(path); TaskId taskId = taskManager.submit(task); return TaskIdDto.respond(response, taskId); } catch (MailRepositoryStore.MailRepositoryStoreException | MessagingException e) { throw ErrorResponder.builder() .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500) .type(ErrorResponder.ErrorType.SERVER_ERROR) .cause(e) .message("Error while deleting all mails") .haltError(); } }, jsonTransformer); }
service.patch(MAIL_REPOSITORIES + "/:encodedPath/mails", (request, response) -> { Task task = toAllMailReprocessingTask(request); TaskId taskId = taskManager.submit(task); return TaskIdDto.respond(response, taskId); }, jsonTransformer);
service.patch(MAIL_REPOSITORIES + "/:encodedPath/mails/:key", (request, response) -> { Task task = toOneMailReprocessingTask(request); TaskId taskId = taskManager.submit(task); return TaskIdDto.respond(response, taskId); }, jsonTransformer);
private Object deleteMails(Request request, Response response) { String mailQueueName = request.params(MAIL_QUEUE_NAME); Task task = mailQueueFactory.getQueue(mailQueueName) .map(name -> deleteMailsTask(name, sender(request.queryParams(SENDER_QUERY_PARAM)), name(request.queryParams(NAME_QUERY_PARAM)), recipient(request.queryParams(RECIPIENT_QUERY_PARAM)))) .orElseThrow( () -> ErrorResponder.builder() .message(String.format("%s can not be found", mailQueueName)) .statusCode(HttpStatus.NOT_FOUND_404) .type(ErrorResponder.ErrorType.NOT_FOUND) .haltError()); TaskId taskId = taskManager.submit(task); return TaskIdDto.respond(response, taskId); }
CassandraVersionRequest cassandraVersionRequest = CassandraVersionRequest.parse(request.body()); Migration migration = cassandraMigrationService.upgradeToVersion(cassandraVersionRequest.getValue()); TaskId taskId = taskManager.submit(migration); return TaskIdDto.from(taskId); } catch (NullPointerException | IllegalArgumentException e) {
TaskId taskId = taskManager.submit(task); return TaskIdDto.respond(response, taskId); } catch (JsonExtractException e) {