tpalfy commented on code in PR #7191:
URL: https://github.com/apache/nifi/pull/7191#discussion_r1185305618
##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java:
##########
@@ -4597,6 +4611,246 @@ public Response deleteReplaceProcessGroupRequest(
return deleteFlowUpdateRequest("replace-requests", replaceRequestId,
disconnectedNodeAcknowledged.booleanValue());
}
+ // -------------
+ // flow-analysis
+ // -------------
+
+ /**
+ * Submits a request to run a flow analysis.
+ *
+ * @param processGroupId The id of the process group representing (a part
of) the flow to be analyzed
+ * @return An AnalyzeFlowRequestEntity
+ */
+ @POST
+ @Consumes(MediaType.WILDCARD)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("flow-analysis/{processGroupId}")
+ @ApiOperation(
+ value = "Executes a flow analysis for components within a given
process group",
+ response = AnalyzeFlowRequestEntity.class,
+ authorizations = {
+ @Authorization(value = "Read - /process-groups/{uuid} - For this
and all encapsulated process groups")
+ })
+ @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 submitAnalyzeFlowRequest(
+ @ApiParam(
+ value = "The id of the process group representing (a part of) the
flow to be analyzed.",
+ required = true
+ )
+ @PathParam("processGroupId")
+ final String processGroupId
+ ) {
+ if (isReplicateRequest()) {
+ return replicate(HttpMethod.POST);
+ }
+
+ NiFiUser user = NiFiUserUtils.getNiFiUser();
+
+ ProcessGroupEntity requestProcessGroupEntity = new
ProcessGroupEntity();
+ requestProcessGroupEntity.setId(processGroupId);
+
+ return withWriteLock(
+ serviceFacade,
+ requestProcessGroupEntity,
+ lookup -> {
+ final ProcessGroupAuthorizable processGroup =
lookup.getProcessGroup(processGroupId);
+ processGroup.getAuthorizable().authorize(authorizer,
RequestAction.READ, user);
+ },
+ null,
+ (processGroupEntity) -> {
+ String analyzedGroupId = processGroupEntity.getId();
+
+ final String requestId = generateUuid();
+ final AsynchronousWebRequest<String, Void>
analyzeFlowAsyncWebRequest = new StandardAsynchronousWebRequest<>(
+ requestId,
+ analyzedGroupId,
+ analyzedGroupId,
+ user,
+ Collections.singletonList(new
StandardUpdateStep("Analyze Process Group"))
+ );
+
+ // Submit the request to be performed in the background
+ final Consumer<AsynchronousWebRequest<String, Void>>
analyzeFlowTask = asyncRequest -> {
+ try {
+ serviceFacade.analyzeProcessGroup(analyzedGroupId);
+ asyncRequest.markStepComplete();
+ } catch (final Exception e) {
+ logger.error("Failed to run flow analysis on process
group " + processGroupId, e);
+ asyncRequest.fail("Failed to run flow analysis on
process group " + processGroupId + " due to " + e);
+ }
+ };
+ flowAnalysisAsyncRequestManager.submitRequest(
+ FLOW_ANALYSIS_REQUEST_TYPE,
+ requestId,
+ analyzeFlowAsyncWebRequest,
+ analyzeFlowTask
+ );
+
+ return
generateOkResponse(createAnalyzeFlowRequestEntity(analyzeFlowAsyncWebRequest,
requestId)).build();
+ }
+ );
+ }
+
+ /**
+ * Checks the status of an outstanding request for a flow analysis.
+ *
+ * @param requestId The id of flow analysis request
+ * @return An analyzeFlowRequestEntity
+ */
+ @GET
+ @Consumes(MediaType.WILDCARD)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("flow-analysis/{requestId}")
Review Comment:
The overlap is kind of intentional. These 3 methods are really the CURD
(without U) of the flow analysis requests.
But I see the point that the POST needs a group id, the GET and the DELETE
needs a request id.
So maybe the paths should be these instead:
```java
@POST
@Path("{id}/flow-analysis")
@GET
@Path("flow-analysis/{requestId}")
@DELETE
@Path("flow-analysis/{requestId}")
```
I.e. leave the GET and DELETE as they are and change the POST instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]