diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/ConfigurableComponentInitializer.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/ConfigurableComponentInitializer.java index bd07ab54d8..ad21f2124a 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/ConfigurableComponentInitializer.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/ConfigurableComponentInitializer.java @@ -20,7 +20,7 @@ import org.apache.nifi.components.ConfigurableComponent; import org.apache.nifi.reporting.InitializationException; /** - * An interface for initializing a ConfigurableComponent. It is up to the + * An interface for initializing and tearing down a ConfigurableComponent. It is up to the * implementer to call "init" so that you can call * ConfigurableComponent.getPropertyDescriptors() * @@ -35,4 +35,11 @@ public interface ConfigurableComponentInitializer { * @throws InitializationException if the component could not be initialized */ void initialize(ConfigurableComponent component) throws InitializationException; + + /** + * Calls the lifecycle methods that should be called when a flow is shutdown. + * + * @param component the component to initialize + */ + void teardown(ConfigurableComponent component); } diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java index 7c32bf8004..327da045f2 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java @@ -114,6 +114,8 @@ public class DocGenerator { try (final OutputStream output = new BufferedOutputStream(new FileOutputStream(baseDocumenationFile))) { writer.write(component, output, hasAdditionalInfo(directory)); } + + initializer.teardown(component); } /** diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ControllerServiceInitializer.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ControllerServiceInitializer.java index 976c7a5ea4..441033c090 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ControllerServiceInitializer.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ControllerServiceInitializer.java @@ -16,7 +16,6 @@ */ package org.apache.nifi.documentation.init; -import org.apache.nifi.annotation.lifecycle.OnRemoved; import org.apache.nifi.annotation.lifecycle.OnShutdown; import org.apache.nifi.components.ConfigurableComponent; import org.apache.nifi.controller.ControllerService; @@ -42,11 +41,17 @@ public class ControllerServiceInitializer implements ConfigurableComponentInitia try (NarCloseable narCloseable = NarCloseable.withNarLoader()) { controllerService.initialize(new MockControllerServiceInitializationContext()); + } + } + + @Override + public void teardown(ConfigurableComponent component) { + try (NarCloseable narCloseable = NarCloseable.withNarLoader()) { + ControllerService controllerService = (ControllerService) component; final ProcessorLog logger = new MockProcessorLogger(); final MockConfigurationContext context = new MockConfigurationContext(); - ReflectionUtils.quietlyInvokeMethodsWithAnnotations(OnRemoved.class, null, controllerService, logger, context); - ReflectionUtils.quietlyInvokeMethodsWithAnnotations(OnShutdown.class, null, controllerService, logger, context); + ReflectionUtils.quietlyInvokeMethodsWithAnnotations(OnShutdown.class, org.apache.nifi.processor.annotation.OnShutdown.class, controllerService, logger, context); } } } diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ProcessorInitializer.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ProcessorInitializer.java index 7f3357c30f..7a0752d3b9 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ProcessorInitializer.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ProcessorInitializer.java @@ -16,7 +16,6 @@ */ package org.apache.nifi.documentation.init; -import org.apache.nifi.annotation.lifecycle.OnRemoved; import org.apache.nifi.annotation.lifecycle.OnShutdown; import org.apache.nifi.components.ConfigurableComponent; import org.apache.nifi.documentation.ConfigurableComponentInitializer; @@ -40,11 +39,17 @@ public class ProcessorInitializer implements ConfigurableComponentInitializer { Processor processor = (Processor) component; try (NarCloseable narCloseable = NarCloseable.withNarLoader()) { processor.initialize(new MockProcessorInitializationContext()); + } + } + + @Override + public void teardown(ConfigurableComponent component) { + Processor processor = (Processor) component; + try (NarCloseable narCloseable = NarCloseable.withNarLoader()) { final ProcessorLog logger = new MockProcessorLogger(); final MockProcessContext context = new MockProcessContext(); - ReflectionUtils.quietlyInvokeMethodsWithAnnotations(OnRemoved.class, null, processor, logger, context); - ReflectionUtils.quietlyInvokeMethodsWithAnnotations(OnShutdown.class, null, processor, logger, context); + ReflectionUtils.quietlyInvokeMethodsWithAnnotations(OnShutdown.class, org.apache.nifi.processor.annotation.OnShutdown.class, processor, logger, context); } } } diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ReportingTaskingInitializer.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ReportingTaskingInitializer.java index 90642e4828..e9642e3cd9 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ReportingTaskingInitializer.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ReportingTaskingInitializer.java @@ -16,7 +16,6 @@ */ package org.apache.nifi.documentation.init; -import org.apache.nifi.annotation.lifecycle.OnRemoved; import org.apache.nifi.annotation.lifecycle.OnShutdown; import org.apache.nifi.components.ConfigurableComponent; import org.apache.nifi.documentation.ConfigurableComponentInitializer; @@ -40,10 +39,16 @@ public class ReportingTaskingInitializer implements ConfigurableComponentInitial ReportingTask reportingTask = (ReportingTask) component; try (NarCloseable narCloseable = NarCloseable.withNarLoader()) { reportingTask.initialize(new MockReportingInitializationContext()); + } + } + + @Override + public void teardown(ConfigurableComponent component) { + ReportingTask reportingTask = (ReportingTask) component; + try (NarCloseable narCloseable = NarCloseable.withNarLoader()) { final MockConfigurationContext context = new MockConfigurationContext(); - ReflectionUtils.quietlyInvokeMethodsWithAnnotations(OnRemoved.class, null, reportingTask, new MockProcessorLogger(), context); - ReflectionUtils.quietlyInvokeMethodsWithAnnotations(OnShutdown.class, null, reportingTask, new MockProcessorLogger(), context); + ReflectionUtils.quietlyInvokeMethodsWithAnnotations(OnShutdown.class, org.apache.nifi.processor.annotation.OnShutdown.class, reportingTask, new MockProcessorLogger(), context); } } } diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java index d85e19b7e5..ae04f46b53 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java @@ -58,6 +58,7 @@ public class HtmlDocumentationWriterTest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(controllerService, baos, false); + initializer.teardown(controllerService); String results = new String(baos.toByteArray()); XmlValidator.assertXmlValid(results); @@ -77,8 +78,8 @@ public class HtmlDocumentationWriterTest { assertContains(results, "Sensitive Property: true"); // verify the right OnRemoved and OnShutdown methods were called - Assert.assertEquals(1, controllerService.getOnRemovedArgs()); - Assert.assertEquals(1, controllerService.getOnRemovedNoArgs()); + Assert.assertEquals(0, controllerService.getOnRemovedArgs()); + Assert.assertEquals(0, controllerService.getOnRemovedNoArgs()); Assert.assertEquals(1, controllerService.getOnShutdownArgs()); Assert.assertEquals(1, controllerService.getOnShutdownNoArgs()); @@ -96,6 +97,7 @@ public class HtmlDocumentationWriterTest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(reportingTask, baos, false); + initializer.teardown(reportingTask); String results = new String(baos.toByteArray()); XmlValidator.assertXmlValid(results); @@ -113,8 +115,8 @@ public class HtmlDocumentationWriterTest { assertContains(results, "false"); // verify the right OnRemoved and OnShutdown methods were called - Assert.assertEquals(1, reportingTask.getOnRemovedArgs()); - Assert.assertEquals(1, reportingTask.getOnRemovedNoArgs()); + Assert.assertEquals(0, reportingTask.getOnRemovedArgs()); + Assert.assertEquals(0, reportingTask.getOnRemovedNoArgs()); Assert.assertEquals(1, reportingTask.getOnShutdownArgs()); Assert.assertEquals(1, reportingTask.getOnShutdownNoArgs()); diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java index fda81fd4e7..447e2e9ccd 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java @@ -44,6 +44,7 @@ public class ProcessorDocumentationWriterTest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(processor, baos, false); + initializer.teardown(processor); String results = new String(baos.toByteArray()); XmlValidator.assertXmlValid(results); @@ -74,8 +75,8 @@ public class ProcessorDocumentationWriterTest { assertNotContains(results, "Additional Details..."); // verify the right OnRemoved and OnShutdown methods were called - Assert.assertEquals(1, processor.getOnRemovedArgs()); - Assert.assertEquals(1, processor.getOnRemovedNoArgs()); + Assert.assertEquals(0, processor.getOnRemovedArgs()); + Assert.assertEquals(0, processor.getOnRemovedNoArgs()); Assert.assertEquals(1, processor.getOnShutdownArgs()); Assert.assertEquals(1, processor.getOnShutdownNoArgs()); @@ -92,6 +93,7 @@ public class ProcessorDocumentationWriterTest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(processor, baos, false); + initializer.teardown(processor); String results = new String(baos.toByteArray()); XmlValidator.assertXmlValid(results); @@ -121,6 +123,7 @@ public class ProcessorDocumentationWriterTest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(processor, baos, false); + initializer.teardown(processor); String results = new String(baos.toByteArray()); XmlValidator.assertXmlValid(results);