exceptionfactory commented on a change in pull request #5630:
URL: https://github.com/apache/nifi/pull/5630#discussion_r783357953



##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerFacade.java
##########
@@ -564,6 +577,62 @@ private boolean implementsServiceType(final Class 
serviceType, final Class type)
         return 
dtoFactory.fromDocumentedTypes(getExtensionManager().getExtensions(ReportingTask.class),
 bundleGroupFilter, bundleArtifactFilter, typeFilter);
     }
 
+
+    /**
+     * Gets the RuntimeManifest for this overall NiFi instance.
+     *
+     * @return the runtime manifest
+     */
+    public RuntimeManifest getRuntimeManifest() {
+        final ExtensionManager extensionManager = getExtensionManager();
+        final Set<Bundle> allBundles = extensionManager.getAllBundles();
+
+        final Bundle frameworkBundle = 
NarClassLoadersHolder.getInstance().getFrameworkBundle();
+        final BundleDetails frameworkDetails = 
frameworkBundle.getBundleDetails();
+        final Date frameworkBuildDate = 
frameworkDetails.getBuildTimestampDate();
+
+        final BuildInfo buildInfo = new BuildInfo();
+        buildInfo.setVersion(frameworkDetails.getCoordinate().getVersion());
+        buildInfo.setRevision(frameworkDetails.getBuildRevision());
+        buildInfo.setCompiler(frameworkDetails.getBuildJdk());
+        buildInfo.setTimestamp(frameworkBuildDate == null ? null : 
frameworkBuildDate.getTime());
+
+        final RuntimeManifestBuilder manifestBuilder = new 
StandardRuntimeManifestBuilder()
+                .identifier("nifi")
+                .runtimeType("nifi")
+                .version(buildInfo.getVersion())
+                
.schedulingDefaults(SchedulingDefaultsFactory.getNifiSchedulingDefaults())
+                .buildInfo(buildInfo);
+
+        for (final Bundle bundle : allBundles) {
+            getExtensionManifest(bundle).ifPresent(em -> 
manifestBuilder.addBundle(em));
+        }
+
+        return manifestBuilder.build();
+    }
+
+    private Optional<ExtensionManifest> getExtensionManifest(final Bundle 
bundle) {
+        final BundleDetails bundleDetails = bundle.getBundleDetails();
+        final File manifestFile = new 
File(bundleDetails.getWorkingDirectory(), 
"META-INF/docs/extension-manifest.xml");
+        if (!manifestFile.exists()) {
+            logger.warn("Unable to find extension manifest for [{}] at 
[{}]...", bundleDetails.getCoordinate(), manifestFile.getAbsolutePath());
+            return Optional.empty();
+        }
+
+        try (final InputStream inputStream = new 
FileInputStream(manifestFile)) {
+            final ExtensionManifest extensionManifest = 
extensionManifestParser.parse(inputStream);
+            // Newer NARs will have these fields populated in 
extension-manifest.xml, but older NARs will not, so we can
+            // set the values from the BundleCoordinate which already has the 
group, artifact id, and version
+            
extensionManifest.setGroupId(bundleDetails.getCoordinate().getGroup());
+            
extensionManifest.setArtifactId(bundleDetails.getCoordinate().getId());
+            
extensionManifest.setVersion(bundleDetails.getCoordinate().getVersion());
+            return Optional.of(extensionManifest);
+        } catch (final IOException e) {
+            logger.error("Unable to load extension manifest for: " + 
bundleDetails.getCoordinate(), e);

Review comment:
       This should be changed to use placeholder variables:
   ```suggestion
               logger.error("Unable to load extension manifest for bundle {}", 
bundleDetails.getCoordinate(), e);
   ```

##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
##########
@@ -1358,6 +1359,41 @@ public Response getReportingTaskTypes(
         return generateOkResponse(entity).build();
     }
 
+    @GET
+    @Consumes(MediaType.WILDCARD)
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("runtime-manifest")
+    @ApiOperation(
+            value = "Retrieves the runtime manifest for this NiFi instance.",
+            notes = NON_GUARANTEED_ENDPOINT,
+            response = RuntimeManifest.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 = 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 getRuntimeManifest() throws InterruptedException {
+
+        authorizeFlow();
+
+        if (isReplicateRequest()) {
+            return replicate(HttpMethod.GET);
+        }

Review comment:
       Should this request be replicated to other cluster nodes?

##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerFacade.java
##########
@@ -564,6 +577,62 @@ private boolean implementsServiceType(final Class 
serviceType, final Class type)
         return 
dtoFactory.fromDocumentedTypes(getExtensionManager().getExtensions(ReportingTask.class),
 bundleGroupFilter, bundleArtifactFilter, typeFilter);
     }
 
+
+    /**
+     * Gets the RuntimeManifest for this overall NiFi instance.
+     *
+     * @return the runtime manifest
+     */
+    public RuntimeManifest getRuntimeManifest() {
+        final ExtensionManager extensionManager = getExtensionManager();
+        final Set<Bundle> allBundles = extensionManager.getAllBundles();
+
+        final Bundle frameworkBundle = 
NarClassLoadersHolder.getInstance().getFrameworkBundle();
+        final BundleDetails frameworkDetails = 
frameworkBundle.getBundleDetails();
+        final Date frameworkBuildDate = 
frameworkDetails.getBuildTimestampDate();
+
+        final BuildInfo buildInfo = new BuildInfo();
+        buildInfo.setVersion(frameworkDetails.getCoordinate().getVersion());
+        buildInfo.setRevision(frameworkDetails.getBuildRevision());
+        buildInfo.setCompiler(frameworkDetails.getBuildJdk());
+        buildInfo.setTimestamp(frameworkBuildDate == null ? null : 
frameworkBuildDate.getTime());
+
+        final RuntimeManifestBuilder manifestBuilder = new 
StandardRuntimeManifestBuilder()
+                .identifier("nifi")
+                .runtimeType("nifi")

Review comment:
       Is the value of `nifi` important for any other consuming service?  What 
do you think about promoting the value to a static variable?

##########
File path: nifi-manifest/nifi-runtime-manifest-core/pom.xml
##########
@@ -44,5 +44,10 @@
             <artifactId>nifi-extension-manifest-parser</artifactId>
             <version>1.16.0-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>

Review comment:
       Is this additional dependency necessary?




-- 
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]


Reply via email to