private Response<BackfillPayload> getBackfill(RequestContext rc, String id) { final boolean includeStatuses = rc.request().parameter("status").orElse("true").equals("true"); final Optional<Backfill> backfillOpt; try { backfillOpt = storage.backfill(id); } catch (IOException e) { final String message = String.format("Couldn't read backfill %s. ", id); log.warn(message, e); return Response.forStatus(Status.INTERNAL_SERVER_ERROR.withReasonPhrase("Error in internal storage")); } if (!backfillOpt.isPresent()) { return Response.forStatus(Status.NOT_FOUND); } final Backfill backfill = backfillOpt.get(); if (includeStatuses) { final List<RunStateData> statuses = retrieveBackfillStatuses(backfill); return Response.forPayload(BackfillPayload.create( backfill, Optional.of(RunStateDataPayload.create(statuses)))); } else { return Response.forPayload(BackfillPayload.create(backfill, Optional.empty())); } }
private CompletionStage<Response<ByteString>> haltBackfill(String id, RequestContext rc, RequestAuthenticator authenticator) { final AuthContext authContext = authenticator.authenticate(rc.request()); try { // TODO: run in transction final Optional<Backfill> backfillOptional = storage.backfill(id); if (backfillOptional.isPresent()) { final Backfill backfill = backfillOptional.get(); workflowActionAuthorizer.authorizeWorkflowAction(authContext, backfill.workflowId()); storage.storeBackfill(backfill.builder().halted(true).build()); return haltActiveBackfillInstances(backfill, rc.requestScopedClient()); } else { return CompletableFuture.completedFuture( Response.forStatus(Status.NOT_FOUND.withReasonPhrase("backfill not found"))); } } catch (IOException e) { return CompletableFuture.completedFuture(Response.forStatus( Status.INTERNAL_SERVER_ERROR .withReasonPhrase("could not halt backfill: " + e.getMessage()))); } }