Github user mcgilman commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2990#discussion_r217136120
  
    --- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ReportingTaskResource.java
 ---
    @@ -542,6 +547,88 @@ public Response removeReportingTask(
             );
         }
     
    +    /**
    +     * Updates the operational status for the specified ReportingTask with 
the specified values.
    +     *
    +     * @param httpServletRequest  request
    +     * @param id                  The id of the reporting task to update.
    +     * @param requestRunStatus A runStatusEntity.
    +     * @return A reportingTaskEntity.
    +     */
    +    @PUT
    +    @Consumes(MediaType.APPLICATION_JSON)
    +    @Produces(MediaType.APPLICATION_JSON)
    +    @Path("{id}/run-status")
    +    @ApiOperation(
    +            value = "Updates run status of a reporting task",
    +            response = ReportingTaskEntity.class,
    +            authorizations = {
    +                    @Authorization(value = "Write - 
/reporting-tasks/{uuid} or  or /operation/reporting-tasks/{uuid}")
    +            }
    +    )
    +    @ApiResponses(
    +            value = {
    +                    @ApiResponse(code = 400, message = "NiFi was unable to 
complete the request because it was invalid. The request should not be retried 
without modification."),
    +                    @ApiResponse(code = 401, message = "Client could not 
be authenticated."),
    +                    @ApiResponse(code = 403, message = "Client is not 
authorized to make this request."),
    +                    @ApiResponse(code = 404, message = "The specified 
resource could not be found."),
    +                    @ApiResponse(code = 409, message = "The request was 
valid but NiFi was not in the appropriate state to process it. Retrying the 
same request later may be successful.")
    +            }
    +    )
    +    public Response updateRunStatus(
    +            @Context final HttpServletRequest httpServletRequest,
    +            @ApiParam(
    +                    value = "The reporting task id.",
    +                    required = true
    +            )
    +            @PathParam("id") final String id,
    +            @ApiParam(
    +                    value = "The reporting task run status.",
    +                    required = true
    +            ) final ReportingTaskRunStatusEntity requestRunStatus) {
    +
    +        if (requestRunStatus == null) {
    +            throw new IllegalArgumentException("Reporting task run status 
must be specified.");
    +        }
    +
    +        if (requestRunStatus.getRevision() == null) {
    +            throw new IllegalArgumentException("Revision must be 
specified.");
    +        }
    +
    +        requestRunStatus.validateState();
    +
    +        if (isReplicateRequest()) {
    +            return replicate(HttpMethod.PUT, requestRunStatus);
    +        } else if (isDisconnectedFromCluster()) {
    +            
verifyDisconnectedNodeModification(requestRunStatus.isDisconnectedNodeAcknowledged());
    +        }
    +
    +        // handle expects request (usually from the cluster manager)
    +        final Revision requestRevision = 
getRevision(requestRunStatus.getRevision(), id);
    +        // Create DTO to verify if it can be updated.
    +        final ReportingTaskDTO reportingTaskDTO = new ReportingTaskDTO();
    +        reportingTaskDTO.setId(id);
    +        reportingTaskDTO.setState(requestRunStatus.getState());
    +        return withWriteLock(
    +                serviceFacade,
    +                requestRunStatus,
    +                requestRevision,
    +                lookup -> {
    +                    // authorize reporting task
    +                    final Authorizable authorizable = 
lookup.getReportingTask(id).getAuthorizable();
    +                    OperationAuthorizable.authorize(authorizable, 
authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    +                },
    +                () -> 
serviceFacade.verifyUpdateReportingTask(reportingTaskDTO),
    +                (revision, reportingTaskEntity) -> {
    +                    // update the reporting task
    +                    final ReportingTaskEntity entity = 
serviceFacade.updateReportingTask(revision, reportingTaskDTO);
    --- End diff --
    
    We need to recreate this `reportingTaskDTO` using the `reportingTaskEntity` 
due to how we authorize/cache requests during our two phase commit.


---

Reply via email to