You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2022/05/10 14:50:31 UTC

[nifi] branch support/nifi-1.16 updated (9d0e92eb34 -> 3815e7b03e)

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

joewitt pushed a change to branch support/nifi-1.16
in repository https://gitbox.apache.org/repos/asf/nifi.git


    from 9d0e92eb34 NIFI-10005
     new 814de79874 NIFI-10004: Allow loading .class files that are relative to the NAR directory, in addition to the .jar / .nar files
     new 211371890e NIFI-10006 Upgraded async from 2.6.3 to 2.6.4 for Registry
     new 3815e7b03e NIFI-9991 Fix: The asn1 StandardRecordModelIteratorProvider's interator returns only the first object read from the input stream.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/nifi/jasn1/JASN1RecordReader.java   |  1 -
 .../jasn1/StandardRecordModelIteratorProvider.java | 59 ++++++++++++++++------
 .../src/main/package-lock.json                     | 12 ++---
 nifi-stateless/nifi-stateless-bootstrap/pom.xml    | 19 +++++--
 .../stateless/bootstrap/StatelessBootstrap.java    | 34 ++++++++++++-
 .../bootstrap/TestStatelessBootstrap.java          | 40 ++++++++-------
 .../org/apache/nifi/stateless/FakeBootstrap.class  | 19 +------
 7 files changed, 119 insertions(+), 65 deletions(-)
 copy nifi-nar-bundles/nifi-kafka-bundle/nifi-kafka-1-0-processors/src/test/java/org/apache/nifi/processors/kafka/pubsub/KafkaProcessorUtilsTest.java => nifi-stateless/nifi-stateless-bootstrap/src/test/java/org/apache/nifi/stateless/bootstrap/TestStatelessBootstrap.java (57%)
 copy nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.EncryptContent/additionalDetails.html => nifi-stateless/nifi-stateless-bootstrap/src/test/resources/test-lib/org/apache/nifi/stateless/FakeBootstrap.class (57%)


[nifi] 01/03: NIFI-10004: Allow loading .class files that are relative to the NAR directory, in addition to the .jar / .nar files

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joewitt pushed a commit to branch support/nifi-1.16
in repository https://gitbox.apache.org/repos/asf/nifi.git

commit 814de798746663e72949fa090c4682cc261f558f
Author: Mark Payne <ma...@hotmail.com>
AuthorDate: Mon May 9 11:35:48 2022 -0400

    NIFI-10004: Allow loading .class files that are relative to the NAR directory, in addition to the .jar / .nar files
    
    NIFI-10004: When determining classname from a file, consider File.separator instead of just /
    Signed-off-by: Matthew Burgess <ma...@apache.org>
    
    This closes #6026
---
 nifi-stateless/nifi-stateless-bootstrap/pom.xml    | 19 ++++++---
 .../stateless/bootstrap/StatelessBootstrap.java    | 34 +++++++++++++++-
 .../bootstrap/TestStatelessBootstrap.java          | 45 ++++++++++++++++++++++
 .../org/apache/nifi/stateless/FakeBootstrap.class  | 13 +++++++
 4 files changed, 105 insertions(+), 6 deletions(-)

diff --git a/nifi-stateless/nifi-stateless-bootstrap/pom.xml b/nifi-stateless/nifi-stateless-bootstrap/pom.xml
index 3204dfe4a5..3805c4047d 100644
--- a/nifi-stateless/nifi-stateless-bootstrap/pom.xml
+++ b/nifi-stateless/nifi-stateless-bootstrap/pom.xml
@@ -74,8 +74,17 @@
             <optional>true</optional>
         </dependency>
     </dependencies>
-
-  <scm>
-    <tag>nifi-1.16.0-RC3</tag>
-  </scm>
-</project>
\ No newline at end of file
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+                <configuration>
+                    <excludes combine.children="append">
+                        <exclude>src/test/resources/FakeBootstrap.class</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/nifi-stateless/nifi-stateless-bootstrap/src/main/java/org/apache/nifi/stateless/bootstrap/StatelessBootstrap.java b/nifi-stateless/nifi-stateless-bootstrap/src/main/java/org/apache/nifi/stateless/bootstrap/StatelessBootstrap.java
index b0e6ba6795..78187454fa 100644
--- a/nifi-stateless/nifi-stateless-bootstrap/src/main/java/org/apache/nifi/stateless/bootstrap/StatelessBootstrap.java
+++ b/nifi-stateless/nifi-stateless-bootstrap/src/main/java/org/apache/nifi/stateless/bootstrap/StatelessBootstrap.java
@@ -158,6 +158,8 @@ public class StatelessBootstrap {
             filesAllowed.add(file.getName());
         }
 
+        findClassNamesInDirectory(narDirectory, narDirectory, classesAllowed, filesAllowed);
+
         final File java11Directory = new File(narDirectory, "java11");
         final File[] java11DirectoryFiles = java11Directory.listFiles();
         if (java11DirectoryFiles != null) {
@@ -174,7 +176,7 @@ public class StatelessBootstrap {
             javaHomeFilenames.add(file.getName());
         }
 
-        logger.debug("The following JAR files will be explicitly allowed to be loaded by Stateless Extensions ClassLoaders from parent {}: {}", parent, filesAllowed);
+        logger.debug("The following class/JAR files will be explicitly allowed to be loaded by Stateless Extensions ClassLoaders from parent {}: {}", parent, filesAllowed);
         logger.debug("The following JAR/JMOD files from ${JAVA_HOME} will be explicitly allowed to be loaded by Stateless Extensions ClassLoaders from parent {}: {}", parent, javaHomeFilenames);
         logger.debug("The final list of classes allowed to be loaded by Stateless Extension ClassLoaders from parent {}: {}", parent, classesAllowed);
 
@@ -258,6 +260,36 @@ public class StatelessBootstrap {
         }
     }
 
+    static void findClassNamesInDirectory(final File file, final File baseDirectory, final Set<String> classNames, final Set<String> fileNames) {
+        if (file.isDirectory()) {
+            final File[] children = file.listFiles();
+            if (children != null) {
+                for (final File child : children) {
+                    findClassNamesInDirectory(child, baseDirectory, classNames, fileNames);
+                }
+            }
+
+            return;
+        }
+
+        final String filename = file.getName();
+        if (filename.endsWith(".class")) {
+            final String absolutePath = file.getAbsolutePath();
+            final String baseDirectoryPath = baseDirectory.getAbsolutePath();
+            if (!absolutePath.startsWith(baseDirectoryPath)) {
+                return;
+            }
+
+            final File relativeFile = baseDirectory.toPath().relativize(file.toPath()).toFile();
+            final String relativePath = relativeFile.getPath();
+
+            final int lastIndex = relativePath.lastIndexOf(".class");
+            final String className = relativePath.substring(0, lastIndex).replace(File.separator, ".");
+            classNames.add(className);
+            fileNames.add(filename);
+        }
+    }
+
     private static void findClassesInJmod(final File file, final Set<String> classNames) throws IOException {
         if (!file.getName().endsWith(".jmod") || !file.isFile() || !file.exists()) {
             return;
diff --git a/nifi-stateless/nifi-stateless-bootstrap/src/test/java/org/apache/nifi/stateless/bootstrap/TestStatelessBootstrap.java b/nifi-stateless/nifi-stateless-bootstrap/src/test/java/org/apache/nifi/stateless/bootstrap/TestStatelessBootstrap.java
new file mode 100644
index 0000000000..10204ecaef
--- /dev/null
+++ b/nifi-stateless/nifi-stateless-bootstrap/src/test/java/org/apache/nifi/stateless/bootstrap/TestStatelessBootstrap.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.stateless.bootstrap;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class TestStatelessBootstrap {
+
+    @Test
+    public void testAllowsClassFiles() {
+        final File libDir = new File("src/test/resources/test-lib");
+
+        final Set<String> classNames = new HashSet<>();
+        final Set<String> fileNames = new HashSet<>();
+        StatelessBootstrap.findClassNamesInDirectory(libDir, libDir, classNames, fileNames);
+
+        assertEquals(1, classNames.size());
+        assertEquals(1, fileNames.size());
+        assertTrue(classNames.contains("org.apache.nifi.stateless.FakeBootstrap"));
+        assertTrue(fileNames.contains("FakeBootstrap.class"));
+    }
+
+}
diff --git a/nifi-stateless/nifi-stateless-bootstrap/src/test/resources/test-lib/org/apache/nifi/stateless/FakeBootstrap.class b/nifi-stateless/nifi-stateless-bootstrap/src/test/resources/test-lib/org/apache/nifi/stateless/FakeBootstrap.class
new file mode 100644
index 0000000000..c7b780c34f
--- /dev/null
+++ b/nifi-stateless/nifi-stateless-bootstrap/src/test/resources/test-lib/org/apache/nifi/stateless/FakeBootstrap.class
@@ -0,0 +1,13 @@
+
+      Licensed to the Apache Software Foundation (ASF) under one or more
+      contributor license agreements.  See the NOTICE file distributed with
+      this work for additional information regarding copyright ownership.
+      The ASF licenses this file to You under the Apache License, Version 2.0
+      (the "License"); you may not use this file except in compliance with
+      the License.  You may obtain a copy of the License at
+          http://www.apache.org/licenses/LICENSE-2.0
+      Unless required by applicable law or agreed to in writing, software
+      distributed under the License is distributed on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      See the License for the specific language governing permissions and
+      limitations under the License.


[nifi] 03/03: NIFI-9991 Fix: The asn1 StandardRecordModelIteratorProvider's interator returns only the first object read from the input stream.

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joewitt pushed a commit to branch support/nifi-1.16
in repository https://gitbox.apache.org/repos/asf/nifi.git

commit 3815e7b03e18d3a36b06d457509a8cfd9c07d9c4
Author: Tamas Palfy <ta...@gmail.com>
AuthorDate: Thu May 5 17:45:26 2022 +0200

    NIFI-9991 Fix: The asn1 StandardRecordModelIteratorProvider's interator returns only the first object read from the input stream.
    
    This closes #6019.
    
    Signed-off-by: Peter Turcsanyi <tu...@apache.org>
---
 .../org/apache/nifi/jasn1/JASN1RecordReader.java   |  1 -
 .../jasn1/StandardRecordModelIteratorProvider.java | 59 ++++++++++++++++------
 2 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/JASN1RecordReader.java b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/JASN1RecordReader.java
index 0111b70abc..d189efcb64 100644
--- a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/JASN1RecordReader.java
+++ b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/JASN1RecordReader.java
@@ -144,7 +144,6 @@ public class JASN1RecordReader implements RecordReader {
             } else {
                 return null;
             }
-
         });
     }
 
diff --git a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/StandardRecordModelIteratorProvider.java b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/StandardRecordModelIteratorProvider.java
index ea73c89389..8e4c106f62 100644
--- a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/StandardRecordModelIteratorProvider.java
+++ b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/StandardRecordModelIteratorProvider.java
@@ -35,24 +35,32 @@ public class StandardRecordModelIteratorProvider implements RecordModelIteratorP
     @Override
     @SuppressWarnings("unchecked")
     public Iterator<BerType> iterator(InputStream inputStream, ComponentLog logger, Class<? extends BerType> rootClass, String recordField, Field seqOfField) {
-        final BerType model;
-        try {
-            model = rootClass.getDeclaredConstructor().newInstance();
-        } catch (ReflectiveOperationException e) {
-            throw new RuntimeException("Failed to instantiate " + rootClass.getCanonicalName(), e);
-        }
+        if (StringUtils.isEmpty(recordField)) {
+            return new Iterator<BerType>() {
+                @Override
+                public boolean hasNext() {
+                    boolean hasNext;
 
-        try {
-            final int decode = model.decode(inputStream);
-            logger.debug("Decoded {} bytes into {}", new Object[]{decode, model.getClass()});
-        } catch (IOException e) {
-            throw new RuntimeException("Failed to decode " + rootClass.getCanonicalName(), e);
-        }
+                    try {
+                        hasNext = inputStream.available() > 0;
+                    } catch (IOException e) {
+                        hasNext = false;
+                    }
 
-        final List<BerType> recordModels;
-        if (StringUtils.isEmpty(recordField)) {
-            recordModels = Collections.singletonList(model);
+                    return hasNext;
+                }
+
+                @Override
+                public BerType next() {
+                    final BerType model = decode(inputStream, logger, rootClass);
+
+                    return model;
+                }
+            };
         } else {
+            final BerType model = decode(inputStream, logger, rootClass);
+
+            final List<BerType> recordModels;
             try {
                 final Method recordModelGetter = rootClass.getMethod(JASN1Utils.toGetterMethod(recordField));
                 final BerType readPointModel = (BerType) recordModelGetter.invoke(model);
@@ -65,8 +73,27 @@ public class StandardRecordModelIteratorProvider implements RecordModelIteratorP
             } catch (ReflectiveOperationException e) {
                 throw new RuntimeException("Failed to get record models due to " + e, e);
             }
+
+            return recordModels.iterator();
+        }
+    }
+
+    private BerType decode(InputStream inputStream, ComponentLog logger, Class<? extends BerType> rootClass) {
+        final BerType model;
+
+        try {
+            model = rootClass.getDeclaredConstructor().newInstance();
+        } catch (ReflectiveOperationException e) {
+            throw new RuntimeException("Failed to instantiate " + rootClass.getCanonicalName(), e);
+        }
+
+        try {
+            final int decode = model.decode(inputStream);
+            logger.debug("Decoded {} bytes into {}", new Object[]{decode, model.getClass()});
+        } catch (IOException e) {
+            throw new RuntimeException("Failed to decode " + rootClass.getCanonicalName(), e);
         }
 
-        return recordModels.iterator();
+        return model;
     }
 }


[nifi] 02/03: NIFI-10006 Upgraded async from 2.6.3 to 2.6.4 for Registry

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joewitt pushed a commit to branch support/nifi-1.16
in repository https://gitbox.apache.org/repos/asf/nifi.git

commit 211371890ee961a5472f41d8959e8f9a84ba8b49
Author: dependabot[bot] <49...@users.noreply.github.com>
AuthorDate: Fri Apr 29 16:46:16 2022 +0000

    NIFI-10006 Upgraded async from 2.6.3 to 2.6.4 for Registry
    
    Bumps [async](https://github.com/caolan/async) from 2.6.3 to 2.6.4.
    - [Release notes](https://github.com/caolan/async/releases)
    - [Changelog](https://github.com/caolan/async/blob/v2.6.4/CHANGELOG.md)
    - [Commits](https://github.com/caolan/async/compare/v2.6.3...v2.6.4)
    
    ---
    updated-dependencies:
    - dependency-name: async
      dependency-type: indirect
    ...
    
    This closes #6007
    
    Signed-off-by: David Handermann <ex...@apache.org>
---
 .../nifi-registry-web-ui/src/main/package-lock.json          | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/nifi-registry/nifi-registry-core/nifi-registry-web-ui/src/main/package-lock.json b/nifi-registry/nifi-registry-core/nifi-registry-web-ui/src/main/package-lock.json
index 3668cbab78..65e6ed5bac 100644
--- a/nifi-registry/nifi-registry-core/nifi-registry-web-ui/src/main/package-lock.json
+++ b/nifi-registry/nifi-registry-core/nifi-registry-web-ui/src/main/package-lock.json
@@ -2783,9 +2783,9 @@
             }
         },
         "node_modules/async": {
-            "version": "2.6.3",
-            "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz",
-            "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==",
+            "version": "2.6.4",
+            "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz",
+            "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==",
             "dev": true,
             "dependencies": {
                 "lodash": "^4.17.14"
@@ -17664,9 +17664,9 @@
             "dev": true
         },
         "async": {
-            "version": "2.6.3",
-            "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz",
-            "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==",
+            "version": "2.6.4",
+            "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz",
+            "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==",
             "dev": true,
             "requires": {
                 "lodash": "^4.17.14"