You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2022/11/20 22:06:35 UTC

[nifi] branch main updated: NIFI-10828 Adding new REST API endpoint for exposing versioned flow details

This is an automated email from the ASF dual-hosted git repository.

mattyb149 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 4fe65f1b81 NIFI-10828 Adding new REST API endpoint for exposing versioned flow details
4fe65f1b81 is described below

commit 4fe65f1b81659140d773a8484c09ab4d20e115d3
Author: Bence Simon <bs...@apache.org>
AuthorDate: Thu Nov 17 15:42:12 2022 +0100

    NIFI-10828 Adding new REST API endpoint for exposing versioned flow details
    
    NIFI-10828 Fixing documentation
    
    Signed-off-by: Matthew Burgess <ma...@apache.org>
    
    This closes #6674
---
 .../org/apache/nifi/web/NiFiServiceFacade.java     | 11 ++++++
 .../apache/nifi/web/StandardNiFiServiceFacade.java | 10 ++++--
 .../java/org/apache/nifi/web/api/FlowResource.java | 39 ++++++++++++++++++++++
 .../org/apache/nifi/web/dao/FlowRegistryDAO.java   |  2 ++
 .../nifi/web/dao/impl/StandardFlowRegistryDAO.java | 14 ++++++++
 5 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
index 287b7d9205..b60e8a891a 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
@@ -2473,6 +2473,17 @@ public interface NiFiServiceFacade {
      */
     Set<VersionedFlowEntity> getFlowsForUser(String registryClientId, String bucketId);
 
+
+    /**
+     * Returns the details of a versioned flow from a given bucket of a given registry.
+     *
+     * @param registryClientId registry client id
+     * @param bucketId bucket id
+     * @param flowId flow id
+     * @return the flow details
+     */
+    VersionedFlowEntity getFlowForUser(String registryClientId, String bucketId, String flowId);
+
     /**
      * Gets the versions of the specified registry, bucket, and flow for the current user.
      *
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
index 30c03dc06e..ea080ebe63 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
@@ -3211,14 +3211,20 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
     }
 
     @Override
-    public Set<VersionedFlowEntity> getFlowsForUser(String registryClientId, String bucketId) {
+    public Set<VersionedFlowEntity> getFlowsForUser(final String registryClientId, final String bucketId) {
         return flowRegistryDAO.getFlowsForUser(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), registryClientId, bucketId).stream()
                 .map(rf -> createVersionedFlowEntity(registryClientId, rf))
                 .collect(Collectors.toSet());
     }
 
     @Override
-    public Set<VersionedFlowSnapshotMetadataEntity> getFlowVersionsForUser(String registryClientId, String bucketId, String flowId) {
+    public VersionedFlowEntity getFlowForUser(final String registryClientId, final String bucketId, final String flowId) {
+        final RegisteredFlow flow = flowRegistryDAO.getFlowForUser(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), registryClientId, bucketId, flowId);
+        return createVersionedFlowEntity(registryClientId, flow);
+    }
+
+    @Override
+    public Set<VersionedFlowSnapshotMetadataEntity> getFlowVersionsForUser(final String registryClientId, final String bucketId, final String flowId) {
         return flowRegistryDAO.getFlowVersionsForUser(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), registryClientId, bucketId, flowId).stream()
                 .map(md -> createVersionedFlowSnapshotMetadataEntity(registryClientId, md))
                 .collect(Collectors.toSet());
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
index befaee69a2..b297192d3a 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
@@ -1756,6 +1756,45 @@ public class FlowResource extends ApplicationResource {
         return flowEntity.getVersionedFlow() == null ? "" : flowEntity.getVersionedFlow().getFlowName();
     }
 
+    @GET
+    @Consumes(MediaType.WILDCARD)
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("registries/{registry-id}/buckets/{bucket-id}/flows/{flow-id}/details")
+    @ApiOperation(value = "Gets the details of a flow from the specified registry and bucket for the specified flow for the current user",
+            response = VersionedFlowEntity.class,
+            authorizations = {
+                    @Authorization(value = "Read - /flow")
+            })
+    @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 getDetails(
+            @ApiParam(
+                    value = "The registry client id.",
+                    required = true
+            )
+            @PathParam("registry-id") String registryId,
+            @ApiParam(
+                    value = "The bucket id.",
+                    required = true
+            )
+            @PathParam("bucket-id") String bucketId,
+            @ApiParam(
+                    value = "The flow id.",
+                    required = true
+            )
+            @PathParam("flow-id") String flowId) {
+
+        authorizeFlow();
+
+        final VersionedFlowEntity flowDetails = serviceFacade.getFlowForUser(registryId, bucketId, flowId);
+        return generateOkResponse(flowDetails).build();
+    }
+
     @GET
     @Consumes(MediaType.WILDCARD)
     @Produces(MediaType.APPLICATION_JSON)
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/FlowRegistryDAO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/FlowRegistryDAO.java
index 0e2accd1ca..f6195d4f01 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/FlowRegistryDAO.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/FlowRegistryDAO.java
@@ -42,6 +42,8 @@ public interface FlowRegistryDAO {
 
     Set<RegisteredFlow> getFlowsForUser(FlowRegistryClientUserContext context, String registryId, String bucketId);
 
+    RegisteredFlow getFlowForUser(FlowRegistryClientUserContext context, String registryId, String bucketId, String flowId);
+
     Set<RegisteredFlowSnapshotMetadata> getFlowVersionsForUser(FlowRegistryClientUserContext context, String registryId, String bucketId, String flowId);
 
     FlowRegistryClientNode removeFlowRegistry(String registryId);
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowRegistryDAO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowRegistryDAO.java
index 5551c267a8..3e30e31ca0 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowRegistryDAO.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowRegistryDAO.java
@@ -140,6 +140,20 @@ public class StandardFlowRegistryDAO extends ComponentDAO implements FlowRegistr
         }
     }
 
+    @Override
+    public RegisteredFlow getFlowForUser(final FlowRegistryClientUserContext context, final String registryId, final String bucketId, final String flowId) {
+        try {
+            final FlowRegistryClientNode flowRegistry = flowController.getFlowManager().getFlowRegistryClient(registryId);
+            if (flowRegistry == null) {
+                throw new IllegalArgumentException("The specified registry id is unknown to this NiFi.");
+            }
+
+            return flowRegistry.getFlow(context, bucketId, flowId);
+        } catch (final IOException | FlowRegistryException ioe) {
+            throw new NiFiCoreException("Unable to obtain listing of flows for bucket with ID " + bucketId + ": " + ioe, ioe);
+        }
+    }
+
     @Override
     public Set<RegisteredFlowSnapshotMetadata> getFlowVersionsForUser(final FlowRegistryClientUserContext context, final String registryId, final String bucketId, final String flowId) {
         try {