From 55d4b1c09990a9cff8a235fe65a0056879e6355a Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Fri, 12 Dec 2014 10:00:40 -0500 Subject: [PATCH 1/2] NIFI-164: Add shutdown() method to ContentRepository and implement in FileSystemRepository and VolatileContentRepository to cleanup executors; call shutdown() from FlowController shutdown method --- .../java/org/apache/nifi/controller/FlowController.java | 4 ++++ .../nifi/controller/repository/FileSystemRepository.java | 6 ++++++ .../controller/repository/VolatileContentRepository.java | 5 +++++ .../nifi/controller/repository/ContentRepository.java | 6 ++++++ 4 files changed, 21 insertions(+) diff --git a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java index 20c50b5763..e1abe4eaa2 100644 --- a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java +++ b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java @@ -1050,6 +1050,10 @@ public class FlowController implements EventAccess, ControllerServiceProvider, H processScheduler.shutdown(); } + if ( contentRepository != null ) { + contentRepository.shutdown(); + } + if ( provenanceEventRepository != null ) { try { provenanceEventRepository.close(); diff --git a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java index ba74295122..5fbbfd5533 100644 --- a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java +++ b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java @@ -223,6 +223,12 @@ public class FileSystemRepository implements ContentRepository { this.contentClaimManager = claimManager; } + @Override + public void shutdown() { + executor.shutdown(); + containerCleanupExecutor.shutdown(); + } + private static double getRatio(final String value) { final String trimmed = value.trim(); final String percentage = trimmed.substring(0, trimmed.length() - 1); diff --git a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java index e14ec5dcea..99e3655e1d 100644 --- a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java +++ b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java @@ -137,6 +137,11 @@ public class VolatileContentRepository implements ContentRepository { public void initialize(final ContentClaimManager claimManager) { this.claimManager = claimManager; } + + @Override + public void shutdown() { + executor.shutdown(); + } /** * Specifies a Backup Repository where data should be written if this diff --git a/nifi-api/src/main/java/org/apache/nifi/controller/repository/ContentRepository.java b/nifi-api/src/main/java/org/apache/nifi/controller/repository/ContentRepository.java index 7012cb3a48..d66b8a6499 100644 --- a/nifi-api/src/main/java/org/apache/nifi/controller/repository/ContentRepository.java +++ b/nifi-api/src/main/java/org/apache/nifi/controller/repository/ContentRepository.java @@ -45,6 +45,12 @@ public interface ContentRepository { */ void initialize(ContentClaimManager claimManager) throws IOException; + /** + * Shuts down the Content Repository, freeing any resources that may be held. + * This is called when an administrator shuts down NiFi. + */ + void shutdown(); + /** * Returns the names of all Containers that exist for this Content * Repository From d57861d8b5283483b5721f5c4be3ce285ea6bcf4 Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Fri, 12 Dec 2014 10:19:20 -0500 Subject: [PATCH 2/2] NIFI-164: Fixed MockContentRepository that existed in a unit test --- .../controller/repository/TestStandardProcessSession.java | 4 ++++ .../apache/nifi/provenance/VolatileProvenanceRepository.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/nar-bundles/framework-bundle/framework/core/src/test/java/org/apache/nifi/controller/repository/TestStandardProcessSession.java b/nar-bundles/framework-bundle/framework/core/src/test/java/org/apache/nifi/controller/repository/TestStandardProcessSession.java index 060bbd9d95..1ff63c545b 100644 --- a/nar-bundles/framework-bundle/framework/core/src/test/java/org/apache/nifi/controller/repository/TestStandardProcessSession.java +++ b/nar-bundles/framework-bundle/framework/core/src/test/java/org/apache/nifi/controller/repository/TestStandardProcessSession.java @@ -977,6 +977,10 @@ public class TestStandardProcessSession { private ConcurrentMap claimantCounts = new ConcurrentHashMap<>(); + @Override + public void shutdown() { + } + public Set getExistingClaims() { final Set claims = new HashSet<>(); diff --git a/nar-bundles/volatile-provenance-repository-bundle/volatile-provenance-repository/src/main/java/org/apache/nifi/provenance/VolatileProvenanceRepository.java b/nar-bundles/volatile-provenance-repository-bundle/volatile-provenance-repository/src/main/java/org/apache/nifi/provenance/VolatileProvenanceRepository.java index 9de26613aa..f4f9d127c0 100644 --- a/nar-bundles/volatile-provenance-repository-bundle/volatile-provenance-repository/src/main/java/org/apache/nifi/provenance/VolatileProvenanceRepository.java +++ b/nar-bundles/volatile-provenance-repository-bundle/volatile-provenance-repository/src/main/java/org/apache/nifi/provenance/VolatileProvenanceRepository.java @@ -169,6 +169,8 @@ public class VolatileProvenanceRepository implements ProvenanceEventRepository { @Override public void close() throws IOException { + queryExecService.shutdownNow(); + scheduledExecService.shutdown(); } @Override