markap14 commented on code in PR #7875: URL: https://github.com/apache/nifi/pull/7875#discussion_r1367075338
########## nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerResource.java: ########## @@ -449,6 +455,72 @@ public Response createReportingTask( ); } + /** + * Imports a reporting task snapshot. + */ + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("reporting-tasks/import") + @ApiOperation( + value = "Imports a reporting task snapshot", + response = VersionedReportingTaskImportResponseEntity.class, + authorizations = { + @Authorization(value = "Write - /controller") + } + ) + @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 = 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 importReportingTaskSnapshot( + @Context final HttpServletRequest httpServletRequest, + @ApiParam( + value = "The import request containing the reporting task snapshot to import.", + required = true + ) final VersionedReportingTaskImportRequestEntity importRequestEntity) { + + if (importRequestEntity == null || importRequestEntity.getReportingTaskSnapshot() == null) { + throw new IllegalArgumentException("Reporting task snapshot is required"); + } + + final VersionedReportingTaskSnapshot requestSnapshot = importRequestEntity.getReportingTaskSnapshot(); + serviceFacade.discoverCompatibleBundles(requestSnapshot); + serviceFacade.generateIdentifiersForImport(requestSnapshot, () -> generateUuid()); + + if (isReplicateRequest()) { + return replicate(HttpMethod.POST, importRequestEntity); + } else if (isDisconnectedFromCluster()) { + verifyDisconnectedNodeModification(importRequestEntity.getDisconnectedNodeAcknowledged()); + } + + return withWriteLock( + serviceFacade, + importRequestEntity, + lookup -> { + authorizeController(RequestAction.WRITE); + + final Set<ConfigurableComponent> restrictedComponents = FlowRegistryUtils.getRestrictedComponents(requestSnapshot, serviceFacade); + restrictedComponents.forEach(restrictedComponent -> { + final ComponentAuthorizable restrictedComponentAuthorizable = lookup.getConfigurableComponent(restrictedComponent); + authorizeRestrictions(authorizer, restrictedComponentAuthorizable); + }); + }, + () -> { + // Nothing to verify + }, + (importRequest) -> { + final VersionedReportingTaskSnapshot snapshot = importRequestEntity.getReportingTaskSnapshot(); Review Comment: ```suggestion final VersionedReportingTaskSnapshot snapshot = importRequest.getReportingTaskSnapshot(); ``` -- 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: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org