briansolo1985 commented on code in PR #9800:
URL: https://github.com/apache/nifi/pull/9800#discussion_r2000520000


##########
minifi/minifi-assembly/src/main/assembly/dependencies.xml:
##########
@@ -50,11 +50,13 @@
                 <include>org.apache.nifi:nifi-runtime</include>
                 <include>org.apache.nifi:nifi-server-api</include>
                 <include>org.apache.nifi:nifi-stateless-api</include>
-                <include>org.apache.nifi:*:nar</include>

Review Comment:
   Is this line removed by accident?



##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-nar-unloader/src/main/java/org/apache/nifi/minifi/nar/NarAutoUnloadService.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.minifi.nar;
+
+import org.apache.nifi.nar.ExtensionManager;
+import org.apache.nifi.nar.NarLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.File;
+
+public class NarAutoUnloadService {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(NarAutoUnloadService.class);
+    private static final String UNPACKED_POSTFIX = "-unpacked";
+
+    private final ExtensionManager extensionManager;
+    private final File extensionWorkDirectory;
+    private final NarLoader narLoader;
+
+    public NarAutoUnloadService(ExtensionManager extensionManager, File 
extensionWorkDirectory, NarLoader narLoader) {
+        this.extensionManager = extensionManager;
+        this.extensionWorkDirectory = extensionWorkDirectory;
+        this.narLoader = narLoader;
+    }
+
+    public void unloadNarFile(String fileName) {
+        if (isSupported(fileName)) {
+            File narWorkingDirectory = new File(extensionWorkDirectory, 
fileName + UNPACKED_POSTFIX);
+            extensionManager.getAllBundles().stream()
+                    .filter(bundle -> 
bundle.getBundleDetails().getWorkingDirectory().getPath().equals(narWorkingDirectory.getPath()))
+                    .findFirst()
+                    .ifPresentOrElse(narLoader::unload, () -> LOGGER.warn("NAR 
bundle not found for " + fileName));

Review Comment:
   We could use a placeholder in the log message instead of string concatenation



##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-nar-unloader/src/test/java/org/apache/nifi/minifi/nar/NarAutoUnloadServiceTest.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.minifi.nar;
+
+import java.io.File;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import org.apache.nifi.bundle.Bundle;
+import org.apache.nifi.bundle.BundleDetails;
+import org.apache.nifi.nar.ExtensionManager;
+import org.apache.nifi.nar.NarLoader;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+
+@ExtendWith(MockitoExtension.class)
+public class NarAutoUnloadServiceTest {
+
+    private static final String SUPPORTED_FILENAME = "test.nar";
+    private static final String UNPACKED_POSTFIX = "-unpacked";
+
+    @Mock
+    private ExtensionManager extensionManager;
+    @Mock
+    private NarLoader narLoader;
+    private File extensionWorkDirectory;
+
+    private NarAutoUnloadService victim;
+
+    @BeforeEach

Review Comment:
   Thanks for covering with test cases



##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-nar-unloader/src/main/java/org/apache/nifi/minifi/nar/NarAutoUnloader.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.minifi.nar;
+
+import static java.util.Objects.requireNonNull;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NarAutoUnloader {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(NarAutoUnloader.class);
+
+    private final NarAutoUnloaderTaskFactory narAutoUnloaderTaskFactory;
+
+    private volatile NarAutoUnloaderTask narAutoUnLoaderTask;
+    private volatile boolean started = false;
+
+    public NarAutoUnloader(NarAutoUnloaderTaskFactory 
narAutoUnloaderTaskFactory) {
+        this.narAutoUnloaderTaskFactory = 
requireNonNull(narAutoUnloaderTaskFactory);
+    }
+
+    public synchronized void start() throws Exception {

Review Comment:
   If we use synchronized we don't need to mark the class member with the 
volatile keyword, as the correct access is already guaranteed.



##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-nar-unloader/src/main/java/org/apache/nifi/minifi/nar/NarAutoUnloader.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.minifi.nar;
+
+import static java.util.Objects.requireNonNull;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NarAutoUnloader {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(NarAutoUnloader.class);
+
+    private final NarAutoUnloaderTaskFactory narAutoUnloaderTaskFactory;
+
+    private volatile NarAutoUnloaderTask narAutoUnLoaderTask;
+    private volatile boolean started = false;
+
+    public NarAutoUnloader(NarAutoUnloaderTaskFactory 
narAutoUnloaderTaskFactory) {
+        this.narAutoUnloaderTaskFactory = 
requireNonNull(narAutoUnloaderTaskFactory);
+    }
+
+    public synchronized void start() throws Exception {
+        if (!started) {
+            narAutoUnLoaderTask = 
narAutoUnloaderTaskFactory.createNarAutoUnloaderTask();
+
+            LOGGER.info("Starting NAR Auto-Unloader Thread for directory {}", 
narAutoUnLoaderTask.getAutoLoadPath());
+
+            Thread autoUnloaderThread = new Thread(narAutoUnLoaderTask);

Review Comment:
   What do you think about using virtual threads here? The called service will 
be in waiting state for most of the cases, so it seems to be a good fit.
   `Thread.ofVirtual().name("NAR Auto-Unloader").start(narAutoUnLoaderTask);`



##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-nar-unloader/src/main/java/org/apache/nifi/minifi/nar/NarAutoUnloaderTask.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.minifi.nar;
+
+import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
+import static java.util.Objects.requireNonNull;
+
+import java.nio.file.Path;
+import java.nio.file.WatchEvent;
+import java.nio.file.WatchKey;
+import java.nio.file.WatchService;
+import java.util.concurrent.TimeUnit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NarAutoUnloaderTask implements Runnable {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(NarAutoUnloaderTask.class);
+    private static final long POLL_INTERVAL_MS = 5000;
+

Review Comment:
   There seems to be a redundant line here and in line 42 as well



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