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

briansolo1985 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 74091e1540 NIFI-13812 [MiNiFi][C2] Add component type into Agent 
Manifest Hash calculation
74091e1540 is described below

commit 74091e1540cd6d6a92db5ff9ac71c838d160cc9e
Author: Ferenc Erdei <[email protected]>
AuthorDate: Fri Sep 27 16:14:47 2024 +0200

    NIFI-13812 [MiNiFi][C2] Add component type into Agent Manifest Hash 
calculation
    
    Signed-off-by: Ferenc Kis <[email protected]>
    
    This closes #9320.
---
 .../c2/client/service/ManifestHashProvider.java    | 36 +++++++++++++++++++---
 .../src/main/resources/conf/logback.xml            |  1 +
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git 
a/c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/ManifestHashProvider.java
 
b/c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/ManifestHashProvider.java
index 4def4970fb..0c34e4f3c3 100644
--- 
a/c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/ManifestHashProvider.java
+++ 
b/c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/ManifestHashProvider.java
@@ -23,13 +23,21 @@ import java.io.ObjectOutputStream;
 import java.nio.charset.StandardCharsets;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
 import org.apache.nifi.c2.protocol.api.SupportedOperation;
 import org.apache.nifi.c2.protocol.component.api.Bundle;
+import org.apache.nifi.c2.protocol.component.api.ComponentManifest;
+import org.apache.nifi.c2.protocol.component.api.DefinedType;
+
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
 
 public class ManifestHashProvider {
     private String currentBundles = null;
@@ -39,12 +47,13 @@ public class ManifestHashProvider {
 
     public String calculateManifestHash(List<Bundle> loadedBundles, 
Set<SupportedOperation> supportedOperations) {
         String bundleString = loadedBundles.stream()
-            .map(bundle -> bundle.getGroup() + bundle.getArtifact() + 
bundle.getVersion())
-            .sorted()
-            .collect(Collectors.joining(","));
+                .map(this::getComponentCoordinates)
+                .flatMap(Collection::stream)
+                .sorted()
+                .collect(Collectors.joining(","));
         int hashCode = Objects.hash(bundleString, supportedOperations);
         if (hashCode != currentHashCode
-            || !(Objects.equals(bundleString, currentBundles) && 
Objects.equals(supportedOperations, currentSupportedOperations))) {
+                || !(Objects.equals(bundleString, currentBundles) && 
Objects.equals(supportedOperations, currentSupportedOperations))) {
             byte[] bytes;
             try {
                 bytes = 
MessageDigest.getInstance("SHA-512").digest(getBytes(supportedOperations, 
bundleString));
@@ -78,4 +87,23 @@ public class ManifestHashProvider {
         }
         return builder.toString();
     }
+
+    private List<String> getComponentCoordinates(Bundle bundle) {
+        ComponentManifest componentManifest = bundle.getComponentManifest();
+
+        List<String> coordinates = componentManifest == null
+                ? emptyList()
+                : Stream.of(componentManifest.getProcessors(),
+                        componentManifest.getApis(),
+                        componentManifest.getControllerServices(),
+                        componentManifest.getReportingTasks())
+                .filter(Objects::nonNull)
+                .flatMap(List::stream)
+                .map(DefinedType::getType)
+                .map(type -> bundle.getGroup() + bundle.getArtifact() + 
bundle.getVersion() + type).toList();
+
+        return coordinates.isEmpty()
+                ? singletonList(bundle.getGroup() + bundle.getArtifact() + 
bundle.getVersion())
+                : coordinates;
+    }
 }
diff --git 
a/minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-resources/src/main/resources/conf/logback.xml
 
b/minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-resources/src/main/resources/conf/logback.xml
index 2f1cab15d9..7d922449c2 100644
--- 
a/minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-resources/src/main/resources/conf/logback.xml
+++ 
b/minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-resources/src/main/resources/conf/logback.xml
@@ -78,6 +78,7 @@
     <logger name="org.apache.nifi.processors" level="WARN"/>
     <logger name="org.apache.nifi.processors.standard.LogAttribute" 
level="INFO"/>
     <logger 
name="org.apache.nifi.controller.repository.StandardProcessSession" 
level="WARN" />
+    <logger name="org.apache.nifi.manifest.StandardRuntimeManifestService" 
level="ERROR" />
 
     <!-- Logger for managing logging statements for jetty -->
     <logger name="org.eclipse.jetty" level="INFO"/>

Reply via email to