http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceProvider.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceProvider.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceProvider.java index 0b338fd..40d9357 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceProvider.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceProvider.java @@ -17,22 +17,11 @@ */ package org.apache.nifi.controller.service; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.beans.PropertyDescriptor; -import java.util.Arrays; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - +import org.apache.nifi.bundle.Bundle; import org.apache.nifi.components.state.StateManager; import org.apache.nifi.components.state.StateManagerProvider; import org.apache.nifi.controller.FlowController; +import org.apache.nifi.controller.LoggableComponent; import org.apache.nifi.controller.ProcessScheduler; import org.apache.nifi.controller.ProcessorNode; import org.apache.nifi.controller.ScheduledState; @@ -45,7 +34,8 @@ import org.apache.nifi.controller.service.mock.ServiceB; import org.apache.nifi.controller.service.mock.ServiceC; import org.apache.nifi.groups.ProcessGroup; import org.apache.nifi.groups.StandardProcessGroup; -import org.apache.nifi.logging.ComponentLog; +import org.apache.nifi.nar.ExtensionManager; +import org.apache.nifi.processor.Processor; import org.apache.nifi.processor.StandardValidationContextFactory; import org.apache.nifi.registry.VariableRegistry; import org.apache.nifi.util.NiFiProperties; @@ -54,6 +44,20 @@ import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; +import java.beans.PropertyDescriptor; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + public class TestStandardControllerServiceProvider { private static StateManagerProvider stateManagerProvider = new StateManagerProvider() { @@ -80,14 +84,21 @@ public class TestStandardControllerServiceProvider { }; private static VariableRegistry variableRegistry = VariableRegistry.ENVIRONMENT_SYSTEM_REGISTRY; + private static NiFiProperties niFiProperties; + private static Bundle systemBundle; @BeforeClass public static void setNiFiProps() { System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, TestStandardControllerServiceProvider.class.getResource("/conf/nifi.properties").getFile()); + niFiProperties = NiFiProperties.createBasicNiFiProperties(null, null); + + // load the system bundle + systemBundle = ExtensionManager.createSystemBundle(niFiProperties); + ExtensionManager.discoverExtensions(systemBundle, Collections.emptySet()); } private StandardProcessScheduler createScheduler() { - return new StandardProcessScheduler(null, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null)); + return new StandardProcessScheduler(null, null, stateManagerProvider, variableRegistry, niFiProperties); } private void setProperty(ControllerServiceNode serviceNode, String propName, String propValue) { @@ -104,9 +115,10 @@ public class TestStandardControllerServiceProvider { final ProcessScheduler scheduler = createScheduler(); final StandardControllerServiceProvider provider = - new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null)); + new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties); - final ControllerServiceNode serviceNode = provider.createControllerService(ServiceB.class.getName(), "B", false); + final ControllerServiceNode serviceNode = provider.createControllerService(ServiceB.class.getName(), "B", + systemBundle.getBundleDetails().getCoordinate(), false); provider.enableControllerService(serviceNode); provider.disableControllerService(serviceNode); } @@ -119,10 +131,12 @@ public class TestStandardControllerServiceProvider { final ProcessScheduler scheduler = createScheduler(); final StandardControllerServiceProvider provider = - new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null)); + new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties); - final ControllerServiceNode serviceNodeB = provider.createControllerService(ServiceB.class.getName(), "B", false); - final ControllerServiceNode serviceNodeA = provider.createControllerService(ServiceA.class.getName(), "A", false); + final ControllerServiceNode serviceNodeB = provider.createControllerService(ServiceB.class.getName(), "B", + systemBundle.getBundleDetails().getCoordinate(), false); + final ControllerServiceNode serviceNodeA = provider.createControllerService(ServiceA.class.getName(), "A", + systemBundle.getBundleDetails().getCoordinate(), false); group.addControllerService(serviceNodeA); group.addControllerService(serviceNodeB); @@ -165,10 +179,10 @@ public class TestStandardControllerServiceProvider { * {@link PropertyDescriptor}.isDependentServiceEnableable() as well as * https://issues.apache.org/jira/browse/NIFI-1143 */ - @Test(timeout = 60000) + @Test(timeout = 120000) public void testConcurrencyWithEnablingReferencingServicesGraph() throws InterruptedException { final ProcessScheduler scheduler = createScheduler(); - for (int i = 0; i < 10000; i++) { + for (int i = 0; i < 5000; i++) { testEnableReferencingServicesGraph(scheduler); } } @@ -179,7 +193,7 @@ public class TestStandardControllerServiceProvider { Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup); final StandardControllerServiceProvider provider = - new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null)); + new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties); // build a graph of controller services with dependencies as such: // @@ -193,10 +207,14 @@ public class TestStandardControllerServiceProvider { // So we have to verify that if D is enabled, when we enable its referencing services, // we enable C and B, even if we attempt to enable C before B... i.e., if we try to enable C, we cannot do so // until B is first enabled so ensure that we enable B first. - final ControllerServiceNode serviceNode1 = provider.createControllerService(ServiceA.class.getName(), "1", false); - final ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceA.class.getName(), "2", false); - final ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", false); - final ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", false); + final ControllerServiceNode serviceNode1 = provider.createControllerService(ServiceA.class.getName(), "1", + systemBundle.getBundleDetails().getCoordinate(), false); + final ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceA.class.getName(), "2", + systemBundle.getBundleDetails().getCoordinate(), false); + final ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", + systemBundle.getBundleDetails().getCoordinate(), false); + final ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", + systemBundle.getBundleDetails().getCoordinate(), false); procGroup.addControllerService(serviceNode1); procGroup.addControllerService(serviceNode2); @@ -231,9 +249,11 @@ public class TestStandardControllerServiceProvider { Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup); final StandardControllerServiceProvider provider = - new StandardControllerServiceProvider(controller, null, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null)); - final ControllerServiceNode serviceNode1 = provider.createControllerService(ServiceA.class.getName(), "1", false); - final ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceB.class.getName(), "2", false); + new StandardControllerServiceProvider(controller, null, null, stateManagerProvider, variableRegistry, niFiProperties); + final ControllerServiceNode serviceNode1 = provider.createControllerService(ServiceA.class.getName(), "1", + systemBundle.getBundleDetails().getCoordinate(), false); + final ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceB.class.getName(), "2", + systemBundle.getBundleDetails().getCoordinate(), false); setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "2"); @@ -291,7 +311,8 @@ public class TestStandardControllerServiceProvider { // But we want to ensure that the method returns successfully without throwing a StackOverflowException or anything // like that. nodeMap.clear(); - final ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", false); + final ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", + systemBundle.getBundleDetails().getCoordinate(), false); setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "3"); setProperty(serviceNode3, ServiceA.OTHER_SERVICE.getName(), "1"); nodeMap.put("1", serviceNode1); @@ -316,8 +337,10 @@ public class TestStandardControllerServiceProvider { // Add multiple completely disparate branches. nodeMap.clear(); setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "2"); - final ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", false); - final ControllerServiceNode serviceNode5 = provider.createControllerService(ServiceB.class.getName(), "5", false); + final ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", + systemBundle.getBundleDetails().getCoordinate(), false); + final ControllerServiceNode serviceNode5 = provider.createControllerService(ServiceB.class.getName(), "5", + systemBundle.getBundleDetails().getCoordinate(), false); setProperty(serviceNode3, ServiceA.OTHER_SERVICE.getName(), "4"); nodeMap.put("1", serviceNode1); nodeMap.put("2", serviceNode2); @@ -374,10 +397,10 @@ public class TestStandardControllerServiceProvider { } private ProcessorNode createProcessor(final StandardProcessScheduler scheduler, final ControllerServiceProvider serviceProvider) { - final ProcessorNode procNode = new StandardProcessorNode(new DummyProcessor(), UUID.randomUUID().toString(), - new StandardValidationContextFactory(serviceProvider, null), scheduler, serviceProvider, - NiFiProperties.createBasicNiFiProperties(null, null), - VariableRegistry.EMPTY_REGISTRY, Mockito.mock(ComponentLog.class)); + final LoggableComponent<Processor> dummyProcessor = new LoggableComponent<>(new DummyProcessor(), systemBundle.getBundleDetails().getCoordinate(), null); + final ProcessorNode procNode = new StandardProcessorNode(dummyProcessor, UUID.randomUUID().toString(), + new StandardValidationContextFactory(serviceProvider, null), scheduler, serviceProvider, niFiProperties, + VariableRegistry.EMPTY_REGISTRY); final ProcessGroup group = new StandardProcessGroup(UUID.randomUUID().toString(), serviceProvider, scheduler, null, null, null, variableRegistry); group.addProcessor(procNode); @@ -394,8 +417,9 @@ public class TestStandardControllerServiceProvider { final StandardProcessScheduler scheduler = createScheduler(); final StandardControllerServiceProvider provider = - new StandardControllerServiceProvider(controller, null, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null)); - final ControllerServiceNode serviceNode = provider.createControllerService(ServiceA.class.getName(), "1", false); + new StandardControllerServiceProvider(controller, null, null, stateManagerProvider, variableRegistry, niFiProperties); + final ControllerServiceNode serviceNode = provider.createControllerService(ServiceA.class.getName(), "1", + systemBundle.getBundleDetails().getCoordinate(), false); final ProcessorNode procNode = createProcessor(scheduler, provider); serviceNode.addReference(procNode); @@ -414,16 +438,22 @@ public class TestStandardControllerServiceProvider { StandardProcessScheduler scheduler = createScheduler(); FlowController controller = Mockito.mock(FlowController.class); StandardControllerServiceProvider provider = - new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null)); + new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties); ProcessGroup procGroup = new MockProcessGroup(); Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup); - ControllerServiceNode A = provider.createControllerService(ServiceA.class.getName(), "A", false); - ControllerServiceNode B = provider.createControllerService(ServiceA.class.getName(), "B", false); - ControllerServiceNode C = provider.createControllerService(ServiceA.class.getName(), "C", false); - ControllerServiceNode D = provider.createControllerService(ServiceB.class.getName(), "D", false); - ControllerServiceNode E = provider.createControllerService(ServiceA.class.getName(), "E", false); - ControllerServiceNode F = provider.createControllerService(ServiceB.class.getName(), "F", false); + ControllerServiceNode A = provider.createControllerService(ServiceA.class.getName(), "A", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode B = provider.createControllerService(ServiceA.class.getName(), "B", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode C = provider.createControllerService(ServiceA.class.getName(), "C", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode D = provider.createControllerService(ServiceB.class.getName(), "D", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode E = provider.createControllerService(ServiceA.class.getName(), "E", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode F = provider.createControllerService(ServiceB.class.getName(), "F", + systemBundle.getBundleDetails().getCoordinate(), false); procGroup.addControllerService(A); procGroup.addControllerService(B); @@ -459,15 +489,20 @@ public class TestStandardControllerServiceProvider { StandardProcessScheduler scheduler = createScheduler(); FlowController controller = Mockito.mock(FlowController.class); StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, - stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null)); + stateManagerProvider, variableRegistry, niFiProperties); ProcessGroup procGroup = new MockProcessGroup(); Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup); - ControllerServiceNode A = provider.createControllerService(ServiceC.class.getName(), "A", false); - ControllerServiceNode B = provider.createControllerService(ServiceA.class.getName(), "B", false); - ControllerServiceNode C = provider.createControllerService(ServiceB.class.getName(), "C", false); - ControllerServiceNode D = provider.createControllerService(ServiceA.class.getName(), "D", false); - ControllerServiceNode F = provider.createControllerService(ServiceA.class.getName(), "F", false); + ControllerServiceNode A = provider.createControllerService(ServiceC.class.getName(), "A", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode B = provider.createControllerService(ServiceA.class.getName(), "B", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode C = provider.createControllerService(ServiceB.class.getName(), "C", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode D = provider.createControllerService(ServiceA.class.getName(), "D", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode F = provider.createControllerService(ServiceA.class.getName(), "F", + systemBundle.getBundleDetails().getCoordinate(), false); procGroup.addControllerService(A); procGroup.addControllerService(B); @@ -496,17 +531,24 @@ public class TestStandardControllerServiceProvider { StandardProcessScheduler scheduler = createScheduler(); FlowController controller = Mockito.mock(FlowController.class); StandardControllerServiceProvider provider = - new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null)); + new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties); ProcessGroup procGroup = new MockProcessGroup(); Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup); - ControllerServiceNode serviceNode1 = provider.createControllerService(ServiceA.class.getName(), "1", false); - ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceA.class.getName(), "2", false); - ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", false); - ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", false); - ControllerServiceNode serviceNode5 = provider.createControllerService(ServiceA.class.getName(), "5", false); - ControllerServiceNode serviceNode6 = provider.createControllerService(ServiceB.class.getName(), "6", false); - ControllerServiceNode serviceNode7 = provider.createControllerService(ServiceC.class.getName(), "7", false); + ControllerServiceNode serviceNode1 = provider.createControllerService(ServiceA.class.getName(), "1", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceA.class.getName(), "2", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode serviceNode5 = provider.createControllerService(ServiceA.class.getName(), "5", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode serviceNode6 = provider.createControllerService(ServiceB.class.getName(), "6", + systemBundle.getBundleDetails().getCoordinate(), false); + ControllerServiceNode serviceNode7 = provider.createControllerService(ServiceC.class.getName(), "7", + systemBundle.getBundleDetails().getCoordinate(), false); procGroup.addControllerService(serviceNode1); procGroup.addControllerService(serviceNode2);
http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/local/TestWriteAheadLocalStateProvider.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/local/TestWriteAheadLocalStateProvider.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/local/TestWriteAheadLocalStateProvider.java index ac0b030..d2e4a05 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/local/TestWriteAheadLocalStateProvider.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/local/TestWriteAheadLocalStateProvider.java @@ -32,6 +32,7 @@ import org.apache.nifi.components.state.StateProvider; import org.apache.nifi.components.state.StateProviderInitializationContext; import org.apache.nifi.controller.state.StateMapUpdate; import org.apache.nifi.controller.state.providers.AbstractTestStateProvider; +import org.apache.nifi.logging.ComponentLog; import org.junit.After; import org.junit.Before; import org.wali.WriteAheadRepository; @@ -73,6 +74,11 @@ public class TestWriteAheadLocalStateProvider extends AbstractTestStateProvider public SSLContext getSSLContext() { return null; } + + @Override + public ComponentLog getLogger() { + return null; + } }); } http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/zookeeper/TestZooKeeperStateProvider.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/zookeeper/TestZooKeeperStateProvider.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/zookeeper/TestZooKeeperStateProvider.java index f8e5b60..d09ee1f 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/zookeeper/TestZooKeeperStateProvider.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/zookeeper/TestZooKeeperStateProvider.java @@ -30,6 +30,7 @@ import org.apache.nifi.components.state.StateProvider; import org.apache.nifi.components.state.StateProviderInitializationContext; import org.apache.nifi.components.state.exception.StateTooLargeException; import org.apache.nifi.controller.state.providers.AbstractTestStateProvider; +import org.apache.nifi.logging.ComponentLog; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -84,6 +85,11 @@ public class TestZooKeeperStateProvider extends AbstractTestStateProvider { public SSLContext getSSLContext() { return null; } + + @Override + public ComponentLog getLogger() { + return null; + } }); } http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/fingerprint/FingerprintFactoryTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/fingerprint/FingerprintFactoryTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/fingerprint/FingerprintFactoryTest.java index 965c888..87a372d 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/fingerprint/FingerprintFactoryTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/fingerprint/FingerprintFactoryTest.java @@ -88,6 +88,39 @@ public class FingerprintFactoryTest { } @Test + public void testSameFlowWithDifferentBundleShouldHaveDifferentFingerprints() throws IOException { + final String fp1 = fingerprinter.createFingerprint(getResourceBytes("/nifi/fingerprint/flow3-with-bundle-1.xml"), null); + assertTrue(fp1.contains("org.apache.nifinifi-standard-nar1.0")); + + final String fp2 = fingerprinter.createFingerprint(getResourceBytes("/nifi/fingerprint/flow3-with-bundle-2.xml"), null); + assertTrue(fp2.contains("org.apache.nifinifi-standard-nar2.0")); + + assertNotEquals(fp1, fp2); + } + + @Test + public void testSameFlowAndOneHasNoBundleShouldHaveDifferentFingerprints() throws IOException { + final String fp1 = fingerprinter.createFingerprint(getResourceBytes("/nifi/fingerprint/flow3-with-bundle-1.xml"), null); + assertTrue(fp1.contains("org.apache.nifinifi-standard-nar1.0")); + + final String fp2 = fingerprinter.createFingerprint(getResourceBytes("/nifi/fingerprint/flow3-with-no-bundle.xml"), null); + assertTrue(fp2.contains("MISSING_BUNDLE")); + + assertNotEquals(fp1, fp2); + } + + @Test + public void testSameFlowAndOneHasMissingBundleShouldHaveDifferentFingerprints() throws IOException { + final String fp1 = fingerprinter.createFingerprint(getResourceBytes("/nifi/fingerprint/flow3-with-bundle-1.xml"), null); + assertTrue(fp1.contains("org.apache.nifinifi-standard-nar1.0")); + + final String fp2 = fingerprinter.createFingerprint(getResourceBytes("/nifi/fingerprint/flow3-with-missing-bundle.xml"), null); + assertTrue(fp2.contains("missingmissingmissing")); + + assertNotEquals(fp1, fp2); + } + + @Test public void testSchemaValidation() throws IOException { FingerprintFactory fp = new FingerprintFactory(null, getValidatingDocumentBuilder()); final String fingerprint = fp.createFingerprint(getResourceBytes("/nifi/fingerprint/validating-flow.xml"), null); http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.controller.ControllerService ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.controller.ControllerService b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.controller.ControllerService index bd6a4f3..373a1f8 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.controller.ControllerService +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.controller.ControllerService @@ -13,3 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. org.apache.nifi.controller.service.util.TestControllerService +org.apache.nifi.controller.service.mock.ServiceA +org.apache.nifi.controller.service.mock.ServiceB +org.apache.nifi.controller.service.mock.ServiceC +org.apache.nifi.controller.service.mock.ServiceD \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.processor.Processor ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.processor.Processor b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.processor.Processor index fca1c19..56740ff 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.processor.Processor +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.processor.Processor @@ -13,4 +13,5 @@ # See the License for the specific language governing permissions and # limitations under the License. org.apache.nifi.test.processors.ModifiesClasspathProcessor -org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor \ No newline at end of file +org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor +org.apache.nifi.controller.service.mock.DummyProcessor \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.reporting.ReportingTask ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.reporting.ReportingTask b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.reporting.ReportingTask new file mode 100644 index 0000000..9adea75 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/META-INF/services/org.apache.nifi.reporting.ReportingTask @@ -0,0 +1,15 @@ +# 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. +org.apache.nifi.controller.service.mock.DummyReportingTask \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/nifi.properties ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/nifi.properties b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/nifi.properties index 445f459..109ddbc 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/nifi.properties +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/nifi.properties @@ -14,7 +14,6 @@ # limitations under the License. # Core Properties # -nifi.version=nifi-test 3.0.0 nifi.flow.configuration.file=./target/flow.xml.gz nifi.flow.configuration.archive.dir=./target/archive/ nifi.flowcontroller.autoResumeState=true http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/scale-positions-flow-0.7.0.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/scale-positions-flow-0.7.0.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/scale-positions-flow-0.7.0.xml index 609d049..7ebad50 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/scale-positions-flow-0.7.0.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/scale-positions-flow-0.7.0.xml @@ -27,7 +27,7 @@ <position x="686.0" y="542.0"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ExtractText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -101,7 +101,7 @@ <position x="1122.363037109375" y="895.7132568359375"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ReplaceText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -143,7 +143,7 @@ <position x="690.0" y="676.0"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.RouteOnAttribute</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -168,7 +168,7 @@ <position x="1058.489013671875" y="545.9861450195312"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.RouteOnAttribute</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -195,7 +195,7 @@ <position x="224.6471710205078" y="1028.7507019042969"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ExtractText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -269,7 +269,7 @@ <position x="1129.363037109375" y="1164.7132568359375"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.RouteOnAttribute</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -294,7 +294,7 @@ <position x="1125.363037109375" y="1030.7132568359375"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ExtractText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -368,7 +368,7 @@ <position x="1051.489013671875" y="276.98614501953125"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ReplaceText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -410,7 +410,7 @@ <position x="1740.591796875" y="1481.1141967773438"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ExtractText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -484,7 +484,7 @@ <position x="297.56959533691406" y="276.02215576171875"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ReplaceText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -526,7 +526,7 @@ <position x="682.0" y="271.0"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.GenerateFlowFile</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>1 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -559,7 +559,7 @@ <position x="228.6471710205078" y="1162.7507019042969"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.RouteOnAttribute</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -586,7 +586,7 @@ <position x="300.56959533691406" y="411.02215576171875"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ExtractText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -660,7 +660,7 @@ <position x="1740.0157470703125" y="1346.1141967773438"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ReplaceText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -702,7 +702,7 @@ <position x="1054.489013671875" y="411.98614501953125"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ExtractText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -776,7 +776,7 @@ <position x="304.56959533691406" y="545.0221557617188"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.RouteOnAttribute</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -803,7 +803,7 @@ <position x="1740.9559326171875" y="1615.1141967773438"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.RouteOnAttribute</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -830,7 +830,7 @@ <position x="683.0" y="407.0"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ReplaceText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -872,7 +872,7 @@ <position x="221.6471710205078" y="893.7507019042969"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ReplaceText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -936,7 +936,7 @@ <position x="-699.489013671875" y="-244.98614501953125"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ExtractText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -1010,7 +1010,7 @@ <position x="493.489013671875" y="81.98614501953125"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.ReplaceText</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> @@ -1052,7 +1052,7 @@ <position x="878.489013671875" y="408.98614501953125"/> <styles/> <comment/> - <class>org.apache.nifi.processors.standard.RouteOnAttribute</class> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/logback-test.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/logback-test.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/logback-test.xml index 4d47050..5a64b9f 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/logback-test.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/logback-test.xml @@ -31,6 +31,7 @@ <logger name="org.apache.nifi" level="INFO"/> <logger name="org.apache.nifi.controller.service.mock" level="ERROR"/> + <logger name="org.apache.nifi.controller.service.StandardControllerServiceProvider" level="WARN" /> <logger name="StandardProcessSession.claims" level="INFO" /> http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi-with-remote.properties ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi-with-remote.properties b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi-with-remote.properties index 445f459..109ddbc 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi-with-remote.properties +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi-with-remote.properties @@ -14,7 +14,6 @@ # limitations under the License. # Core Properties # -nifi.version=nifi-test 3.0.0 nifi.flow.configuration.file=./target/flow.xml.gz nifi.flow.configuration.archive.dir=./target/archive/ nifi.flowcontroller.autoResumeState=true http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi.properties ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi.properties b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi.properties index fc29cd7..b64bdd3 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi.properties +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi.properties @@ -14,7 +14,6 @@ # limitations under the License. # Core Properties # -nifi.version=nifi-test 3.0.0 nifi.flow.configuration.file=./target/flow.xml.gz nifi.flow.configuration.archive.dir=./target/archive/ nifi.flowcontroller.autoResumeState=true http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-bundle-1.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-bundle-1.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-bundle-1.xml new file mode 100644 index 0000000..24ae13e --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-bundle-1.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + 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. +--> +<flowController> + <maxThreadCount>15</maxThreadCount> + <rootGroup> + <id>e3909250-331d-420b-a9b3-cc54ad459401</id> + <name>NiFi Flow</name> + <position x="0.0" y="0.0"/> + <style/> + <comment/> + <processor> + <id>d89ada5d-35fb-44ff-83f1-4cc00b48b2df</id> + <name>GenerateFlowFile</name> + <position x="0.0" y="0.0"/> + <style>processor</style> + <comment/> + <class>org.apache.nifi.processors.standard.GenerateFlowFile</class> + <bundle> + <group>org.apache.nifi</group> + <artifact>nifi-standard-nar</artifact> + <version>1.0</version> + </bundle> + <maxConcurrentTasks>1</maxConcurrentTasks> + <schedulingPeriod>0 sec</schedulingPeriod> + <penalizationPeriod>30 sec</penalizationPeriod> + <yieldPeriod>1 sec</yieldPeriod> + <bulletinLevel>WARN</bulletinLevel> + <lossTolerant>false</lossTolerant> + <scheduledState>STOPPED</scheduledState> + <schedulingStrategy>TIMER_DRIVEN</schedulingStrategy> + <executionNode>ALL</executionNode> + <runDurationNanos>0</runDurationNanos> + <property> + <name>file.size</name> + <value>5</value> + </property> + <annotationData/> + </processor> + </rootGroup> +</flowController> http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-bundle-2.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-bundle-2.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-bundle-2.xml new file mode 100644 index 0000000..09c4c1e --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-bundle-2.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + 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. +--> +<flowController> + <maxThreadCount>15</maxThreadCount> + <rootGroup> + <id>e3909250-331d-420b-a9b3-cc54ad459401</id> + <name>NiFi Flow</name> + <position x="0.0" y="0.0"/> + <style/> + <comment/> + <processor> + <id>d89ada5d-35fb-44ff-83f1-4cc00b48b2df</id> + <name>GenerateFlowFile</name> + <position x="0.0" y="0.0"/> + <style>processor</style> + <comment/> + <class>org.apache.nifi.processors.standard.GenerateFlowFile</class> + <bundle> + <group>org.apache.nifi</group> + <artifact>nifi-standard-nar</artifact> + <version>2.0</version> + </bundle> + <maxConcurrentTasks>1</maxConcurrentTasks> + <schedulingPeriod>0 sec</schedulingPeriod> + <penalizationPeriod>30 sec</penalizationPeriod> + <yieldPeriod>1 sec</yieldPeriod> + <bulletinLevel>WARN</bulletinLevel> + <lossTolerant>false</lossTolerant> + <scheduledState>STOPPED</scheduledState> + <schedulingStrategy>TIMER_DRIVEN</schedulingStrategy> + <executionNode>ALL</executionNode> + <runDurationNanos>0</runDurationNanos> + <property> + <name>file.size</name> + <value>5</value> + </property> + <annotationData/> + </processor> + </rootGroup> +</flowController> http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-missing-bundle.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-missing-bundle.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-missing-bundle.xml new file mode 100644 index 0000000..7dc3001 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-missing-bundle.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + 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. +--> +<flowController> + <maxThreadCount>15</maxThreadCount> + <rootGroup> + <id>e3909250-331d-420b-a9b3-cc54ad459401</id> + <name>NiFi Flow</name> + <position x="0.0" y="0.0"/> + <style/> + <comment/> + <processor> + <id>d89ada5d-35fb-44ff-83f1-4cc00b48b2df</id> + <name>GenerateFlowFile</name> + <position x="0.0" y="0.0"/> + <style>processor</style> + <comment/> + <class>org.apache.nifi.processors.standard.GenerateFlowFile</class> + <bundle> + <group>missing</group> + <artifact>missing</artifact> + <version>missing</version> + </bundle> + <maxConcurrentTasks>1</maxConcurrentTasks> + <schedulingPeriod>0 sec</schedulingPeriod> + <penalizationPeriod>30 sec</penalizationPeriod> + <yieldPeriod>1 sec</yieldPeriod> + <bulletinLevel>WARN</bulletinLevel> + <lossTolerant>false</lossTolerant> + <scheduledState>STOPPED</scheduledState> + <schedulingStrategy>TIMER_DRIVEN</schedulingStrategy> + <executionNode>ALL</executionNode> + <runDurationNanos>0</runDurationNanos> + <property> + <name>file.size</name> + <value>5</value> + </property> + <annotationData/> + </processor> + </rootGroup> +</flowController> http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-no-bundle.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-no-bundle.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-no-bundle.xml new file mode 100644 index 0000000..5a320cb --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow3-with-no-bundle.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + 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. +--> +<flowController> + <maxThreadCount>15</maxThreadCount> + <rootGroup> + <id>e3909250-331d-420b-a9b3-cc54ad459401</id> + <name>NiFi Flow</name> + <position x="0.0" y="0.0"/> + <style/> + <comment/> + <processor> + <id>d89ada5d-35fb-44ff-83f1-4cc00b48b2df</id> + <name>GenerateFlowFile</name> + <position x="0.0" y="0.0"/> + <style>processor</style> + <comment/> + <class>org.apache.nifi.processors.standard.GenerateFlowFile</class> + <maxConcurrentTasks>1</maxConcurrentTasks> + <schedulingPeriod>0 sec</schedulingPeriod> + <penalizationPeriod>30 sec</penalizationPeriod> + <yieldPeriod>1 sec</yieldPeriod> + <bulletinLevel>WARN</bulletinLevel> + <lossTolerant>false</lossTolerant> + <scheduledState>STOPPED</scheduledState> + <schedulingStrategy>TIMER_DRIVEN</schedulingStrategy> + <executionNode>ALL</executionNode> + <runDurationNanos>0</runDurationNanos> + <property> + <name>file.size</name> + <value>5</value> + </property> + <annotationData/> + </processor> + </rootGroup> +</flowController> http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow4-with-different-bundle.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow4-with-different-bundle.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow4-with-different-bundle.xml new file mode 100644 index 0000000..eec5b6f --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow4-with-different-bundle.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + 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. +--> +<flowController> + <maxThreadCount>15</maxThreadCount> + <rootGroup> + <id>e3909250-331d-420b-a9b3-cc54ad459401</id> + <name>NiFi Flow</name> + <position x="0.0" y="0.0"/> + <style/> + <comment/> + <processor> + <id>d89ada5d-35fb-44ff-83f1-4cc00b48b2df</id> + <name>GenerateFlowFile</name> + <position x="0.0" y="0.0"/> + <style>processor</style> + <comment/> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> + <bundle> + <group>default</group> + <artifact>system</artifact> + <version>v2</version> + </bundle> + <maxConcurrentTasks>1</maxConcurrentTasks> + <schedulingPeriod>0 sec</schedulingPeriod> + <penalizationPeriod>30 sec</penalizationPeriod> + <yieldPeriod>1 sec</yieldPeriod> + <bulletinLevel>WARN</bulletinLevel> + <lossTolerant>false</lossTolerant> + <scheduledState>STOPPED</scheduledState> + <schedulingStrategy>TIMER_DRIVEN</schedulingStrategy> + <executionNode>ALL</executionNode> + <runDurationNanos>0</runDurationNanos> + <property> + <name>file.size</name> + <value>5</value> + </property> + <annotationData/> + </processor> + </rootGroup> +</flowController> http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow4.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow4.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow4.xml new file mode 100644 index 0000000..a0bfd6e --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow4.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + 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. +--> +<flowController> + <maxThreadCount>15</maxThreadCount> + <rootGroup> + <id>e3909250-331d-420b-a9b3-cc54ad459401</id> + <name>NiFi Flow</name> + <position x="0.0" y="0.0"/> + <style/> + <comment/> + <processor> + <id>d89ada5d-35fb-44ff-83f1-4cc00b48b2df</id> + <name>GenerateFlowFile</name> + <position x="0.0" y="0.0"/> + <style>processor</style> + <comment/> + <class>org.apache.nifi.controller.service.mock.DummyProcessor</class> + <bundle> + <group>default</group> + <artifact>system</artifact> + <version>unversioned</version> + </bundle> + <maxConcurrentTasks>1</maxConcurrentTasks> + <schedulingPeriod>0 sec</schedulingPeriod> + <penalizationPeriod>30 sec</penalizationPeriod> + <yieldPeriod>1 sec</yieldPeriod> + <bulletinLevel>WARN</bulletinLevel> + <lossTolerant>false</lossTolerant> + <scheduledState>STOPPED</scheduledState> + <schedulingStrategy>TIMER_DRIVEN</schedulingStrategy> + <executionNode>ALL</executionNode> + <runDurationNanos>0</runDurationNanos> + <property> + <name>file.size</name> + <value>5</value> + </property> + <annotationData/> + </processor> + </rootGroup> +</flowController> http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/validating-flow.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/validating-flow.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/validating-flow.xml index a762dc9..123266d 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/validating-flow.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/validating-flow.xml @@ -30,6 +30,11 @@ </styles> <comment>write a file</comment> <class>org.apache.nifi.processors.standard.PutFile</class> + <bundle> + <group>org.apache.nifi</group> + <artifact>nifi-standard-nar</artifact> + <version>1.1.0</version> + </bundle> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>3000 millisecond</penalizationPeriod> @@ -76,6 +81,11 @@ </styles> <comment/> <class>org.apache.nifi.processors.standard.GetFile</class> + <bundle> + <group>org.apache.nifi</group> + <artifact>nifi-standard-nar</artifact> + <version>1.1.0</version> + </bundle> <maxConcurrentTasks>1</maxConcurrentTasks> <schedulingPeriod>0 sec</schedulingPeriod> <penalizationPeriod>30 sec</penalizationPeriod> http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/pom.xml index abd7f7f..7f9b84b 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/pom.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/pom.xml @@ -35,4 +35,19 @@ <artifactId>nifi-framework-api</artifactId> </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-plugin</artifactId> + <configuration> + <excludes combine.children="append"> + <exclude>src/test/resources/nars/nar-with-versioning/META-INF/MANIFEST.MF</exclude> + <exclude>src/test/resources/nars/nar-without-versioning/META-INF/MANIFEST.MF</exclude> + <exclude>src/test/resources/nars/nar-without-dependency/META-INF/MANIFEST.MF</exclude> + </excludes> + </configuration> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ConfigurableComponentInitializer.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ConfigurableComponentInitializer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ConfigurableComponentInitializer.java new file mode 100644 index 0000000..9a1149c --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ConfigurableComponentInitializer.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.init; + +import org.apache.nifi.components.ConfigurableComponent; +import org.apache.nifi.reporting.InitializationException; + +/** + * 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() + * + */ +public interface ConfigurableComponentInitializer { + + /** + * Initializes a configurable component to the point that you can call + * getPropertyDescriptors() on it + * + * @param component the component to initialize + * @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); +} http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ConfigurableComponentInitializerFactory.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ConfigurableComponentInitializerFactory.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ConfigurableComponentInitializerFactory.java new file mode 100644 index 0000000..f6ab922 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ConfigurableComponentInitializerFactory.java @@ -0,0 +1,44 @@ +/* + * 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.init; + +import org.apache.nifi.components.ConfigurableComponent; +import org.apache.nifi.controller.ControllerService; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.reporting.ReportingTask; + +public class ConfigurableComponentInitializerFactory { + + /** + * Returns a ConfigurableComponentInitializer for the type of component. + * Currently Processor, ControllerService and ReportingTask are supported. + * + * @param componentClass the class that requires a ConfigurableComponentInitializer + * @return a ConfigurableComponentInitializer capable of initializing that specific type of class + */ + public static ConfigurableComponentInitializer createComponentInitializer(final Class<? extends ConfigurableComponent> componentClass) { + if (Processor.class.isAssignableFrom(componentClass)) { + return new ProcessorInitializer(); + } else if (ControllerService.class.isAssignableFrom(componentClass)) { + return new ControllerServiceInitializer(); + } else if (ReportingTask.class.isAssignableFrom(componentClass)) { + return new ReportingTaskingInitializer(); + } + + return null; + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ControllerServiceInitializer.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ControllerServiceInitializer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ControllerServiceInitializer.java new file mode 100644 index 0000000..5939b96 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ControllerServiceInitializer.java @@ -0,0 +1,59 @@ +/* + * 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.init; + +import org.apache.nifi.annotation.lifecycle.OnShutdown; +import org.apache.nifi.components.ConfigurableComponent; +import org.apache.nifi.controller.ControllerService; +import org.apache.nifi.controller.ControllerServiceInitializationContext; +import org.apache.nifi.logging.ComponentLog; +import org.apache.nifi.mock.MockComponentLogger; +import org.apache.nifi.mock.MockConfigurationContext; +import org.apache.nifi.mock.MockControllerServiceInitializationContext; +import org.apache.nifi.nar.ExtensionManager; +import org.apache.nifi.nar.NarCloseable; +import org.apache.nifi.reporting.InitializationException; + +/** + * Initializes a ControllerService using a MockControllerServiceInitializationContext + * + * + */ +public class ControllerServiceInitializer implements ConfigurableComponentInitializer { + + @Override + public void initialize(ConfigurableComponent component) throws InitializationException { + ControllerService controllerService = (ControllerService) component; + ControllerServiceInitializationContext context = new MockControllerServiceInitializationContext(); + try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), context.getIdentifier())) { + controllerService.initialize(context); + } + } + + @Override + public void teardown(ConfigurableComponent component) { + try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), component.getIdentifier())) { + ControllerService controllerService = (ControllerService) component; + + final ComponentLog logger = new MockComponentLogger(); + final MockConfigurationContext context = new MockConfigurationContext(); + ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, controllerService, logger, context); + } finally { + ExtensionManager.removeInstanceClassLoaderIfExists(component.getIdentifier()); + } + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ProcessorInitializer.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ProcessorInitializer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ProcessorInitializer.java new file mode 100644 index 0000000..3274f6e --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ProcessorInitializer.java @@ -0,0 +1,58 @@ +/* + * 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.init; + +import org.apache.nifi.annotation.lifecycle.OnShutdown; +import org.apache.nifi.components.ConfigurableComponent; +import org.apache.nifi.logging.ComponentLog; +import org.apache.nifi.mock.MockComponentLogger; +import org.apache.nifi.mock.MockProcessContext; +import org.apache.nifi.mock.MockProcessorInitializationContext; +import org.apache.nifi.nar.ExtensionManager; +import org.apache.nifi.nar.NarCloseable; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.processor.ProcessorInitializationContext; + +/** + * Initializes a Processor using a MockProcessorInitializationContext + * + * + */ +public class ProcessorInitializer implements ConfigurableComponentInitializer { + + @Override + public void initialize(ConfigurableComponent component) { + Processor processor = (Processor) component; + ProcessorInitializationContext initializationContext = new MockProcessorInitializationContext(); + try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), initializationContext.getIdentifier())) { + processor.initialize(initializationContext); + } + } + + @Override + public void teardown(ConfigurableComponent component) { + Processor processor = (Processor) component; + try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), component.getIdentifier())) { + + final ComponentLog logger = new MockComponentLogger(); + final MockProcessContext context = new MockProcessContext(); + ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, processor, logger, context); + } finally { + ExtensionManager.removeInstanceClassLoaderIfExists(component.getIdentifier()); + } + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/d90cf846/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ReflectionUtils.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ReflectionUtils.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ReflectionUtils.java new file mode 100644 index 0000000..22420bd --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/init/ReflectionUtils.java @@ -0,0 +1,133 @@ +/* + * 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.init; + +import org.apache.nifi.logging.ComponentLog; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * This class is a copy of org.apache.nifi.util.ReflectionUtils. Ultimately the + * documentation generation component should be moved to a place where it can + * depend on this directly instead of copying it in. + * + * + */ +public class ReflectionUtils { + + private final static Logger LOG = LoggerFactory.getLogger(ReflectionUtils.class); + + /** + * Invokes all methods on the given instance that have been annotated with + * the given annotation. If the signature of the method that is defined in + * <code>instance</code> uses 1 or more parameters, those parameters must be + * specified by the <code>args</code> parameter. However, if more arguments + * are supplied by the <code>args</code> parameter than needed, the extra + * arguments will be ignored. + * + * @param annotation annotation + * @param instance instance + * @param logger the ComponentLog to use for logging any errors. If null, + * will use own logger, but that will not generate bulletins or easily tie + * to the Processor's log messages. + * @param args args + * @return <code>true</code> if all appropriate methods were invoked and + * returned without throwing an Exception, <code>false</code> if one of the + * methods threw an Exception or could not be invoked; if <code>false</code> + * is returned, an error will have been logged. + */ + public static boolean quietlyInvokeMethodsWithAnnotation( + final Class<? extends Annotation> annotation, final Object instance, final ComponentLog logger, final Object... args) { + + for (final Method method : instance.getClass().getMethods()) { + if (method.isAnnotationPresent(annotation)) { + + final boolean isAccessible = method.isAccessible(); + method.setAccessible(true); + + try { + final Class<?>[] argumentTypes = method.getParameterTypes(); + if (argumentTypes.length > args.length) { + if (logger == null) { + LOG.error("Unable to invoke method {} on {} because method expects {} parameters but only {} were given", + new Object[]{method.getName(), instance, argumentTypes.length, args.length}); + } else { + logger.error("Unable to invoke method {} on {} because method expects {} parameters but only {} were given", + new Object[]{method.getName(), instance, argumentTypes.length, args.length}); + } + + return false; + } + + for (int i = 0; i < argumentTypes.length; i++) { + final Class<?> argType = argumentTypes[i]; + if (!argType.isAssignableFrom(args[i].getClass())) { + if (logger == null) { + LOG.error("Unable to invoke method {} on {} because method parameter {} is expected to be of type {} but argument passed was of type {}", + new Object[]{method.getName(), instance, i, argType, args[i].getClass()}); + } else { + logger.error("Unable to invoke method {} on {} because method parameter {} is expected to be of type {} but argument passed was of type {}", + new Object[]{method.getName(), instance, i, argType, args[i].getClass()}); + } + + return false; + } + } + + try { + if (argumentTypes.length == args.length) { + method.invoke(instance, args); + } else { + final Object[] argsToPass = new Object[argumentTypes.length]; + for (int i = 0; i < argsToPass.length; i++) { + argsToPass[i] = args[i]; + } + + method.invoke(instance, argsToPass); + } + } catch (final InvocationTargetException ite) { + if (logger == null) { + LOG.error("Unable to invoke method {} on {} due to {}", new Object[]{method.getName(), instance, ite.getCause()}); + LOG.error("", ite.getCause()); + } else { + logger.error("Unable to invoke method {} on {} due to {}", new Object[]{method.getName(), instance, ite.getCause()}); + } + } catch (final IllegalAccessException | IllegalArgumentException t) { + if (logger == null) { + LOG.error("Unable to invoke method {} on {} due to {}", new Object[]{method.getName(), instance, t}); + LOG.error("", t); + } else { + logger.error("Unable to invoke method {} on {} due to {}", new Object[]{method.getName(), instance, t}); + } + + return false; + } + } finally { + if (!isAccessible) { + method.setAccessible(false); + } + } + } + } + + return true; + } +}
