[
https://issues.apache.org/jira/browse/NIFI-5673?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16671894#comment-16671894
]
ASF GitHub Bot commented on NIFI-5673:
--------------------------------------
Github user markap14 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/3119#discussion_r230119940
--- Diff:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-nar-loading-utils/src/main/java/org/apache/nifi/nar/NarAutoLoaderTask.java
---
@@ -0,0 +1,187 @@
+/*
+ * 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.nar;
+
+import org.apache.nifi.bundle.BundleDetails;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.StandardWatchEventKinds;
+import java.nio.file.WatchEvent;
+import java.nio.file.WatchKey;
+import java.nio.file.WatchService;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * The runnable task that polls the WatchService for new NAR files found
in the auto-load directory.
+ *
+ * Each new NAR file found will be passed to the NarLoader to be unpacked
and loaded into the ExtensionManager.
+ *
+ */
+public class NarAutoLoaderTask implements Runnable {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(NarAutoLoaderTask.class);
+
+ private static final long MIN_FILE_AGE = 5000;
+
+ private final Path autoLoadPath;
+ private final WatchService watchService;
+ private final long pollIntervalMillis;
+ private final NarLoader narLoader;
+ private final List<File> candidateNars;
+
+ private NarLoadResult prevLoadResult;
+ private volatile boolean stopped = false;
+
+ private NarAutoLoaderTask(final Builder builder) {
+ this.autoLoadPath = builder.autoLoadPath;
+ this.watchService = builder.watchService;
+ this.pollIntervalMillis = builder.pollIntervalMillis;
+ this.narLoader = builder.narLoader;
+ this.candidateNars = new ArrayList<>();
+ this.prevLoadResult = null;
+ }
+
+ @Override
+ public void run() {
+ while (!stopped) {
+ WatchKey key;
+ try {
+ LOGGER.debug("Polling for new NARs at {}", new
Object[]{autoLoadPath});
+ key = watchService.poll(pollIntervalMillis,
TimeUnit.MILLISECONDS);
+ } catch (InterruptedException x) {
+ LOGGER.info("WatchService interrupted, returning...");
+ return;
+ }
+
+ // Key comes back as null when there are no new create events,
but we still want to continue processing
+ // so we can consider files added to the candidateNars list in
previous iterations
+
+ if (key != null) {
+ for (WatchEvent<?> event : key.pollEvents()) {
+ final WatchEvent.Kind<?> kind = event.kind();
+ if (kind == StandardWatchEventKinds.OVERFLOW) {
--- End diff --
StandardWatchEventKinds has 4 different Kinds: OVERFLOW, ENTRY_CREATE,
ENTRY_DELETE, ENTRY_MODIFY. It looks like here we process ENTRY_CREATE,
ENTRY_DELETE, and ENTRY_MODIFY the same way, trying to load the file. I think
we should `continue` here for all events unless `kind ==
StandardWatchEventKinds.ENTRY_CREATE`, no?
> Support auto loading of new NARs
> --------------------------------
>
> Key: NIFI-5673
> URL: https://issues.apache.org/jira/browse/NIFI-5673
> Project: Apache NiFi
> Issue Type: Improvement
> Reporter: Bryan Bende
> Assignee: Bryan Bende
> Priority: Minor
>
> We should be able to detect when new NARs have been added to any of the NAR
> directories and automatically load them and make the components available for
> use without restarting the whole NiFi instance.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)