org.apache.nifi.processor.Processor Java Examples

The following examples show how to use org.apache.nifi.processor.Processor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NewestFirstPrioritizerTest.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrioritizer() throws InstantiationException, IllegalAccessException {
    final Processor processor = new SimpleProcessor();
    final AtomicLong idGenerator = new AtomicLong(0L);
    final MockProcessSession session = new MockProcessSession(new SharedSessionState(processor, idGenerator), Mockito.mock(Processor.class));

    final MockFlowFile flowFile1 = session.create();
    try {
        Thread.sleep(2); // guarantee the FlowFile entryDate for flowFile2 is different than flowFile1
    } catch (final InterruptedException e) {
    }
    final MockFlowFile flowFile2 = session.create();

    final NewestFlowFileFirstPrioritizer prioritizer = new NewestFlowFileFirstPrioritizer();
    Assert.assertEquals(0, prioritizer.compare(null, null));
    Assert.assertEquals(-1, prioritizer.compare(flowFile1, null));
    Assert.assertEquals(1, prioritizer.compare(null, flowFile1));
    Assert.assertEquals(0, prioritizer.compare(flowFile1, flowFile1));
    Assert.assertEquals(0, prioritizer.compare(flowFile2, flowFile2));
    Assert.assertEquals(1, prioritizer.compare(flowFile1, flowFile2));
    Assert.assertEquals(-1, prioritizer.compare(flowFile2, flowFile1));
}
 
Example #2
Source File: StandardProcessorNode.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void monitorAsyncTask(final Future<?> taskFuture, final Future<?> monitoringFuture, final long completionTimestamp) {
    if (taskFuture.isDone()) {
        monitoringFuture.cancel(false); // stop scheduling this task
    } else if (System.currentTimeMillis() > completionTimestamp) {
        // Task timed out. Request an interrupt of the processor task
        taskFuture.cancel(true);

        // Stop monitoring the processor. We have interrupted the thread so that's all we can do. If the processor responds to the interrupt, then
        // it will be re-scheduled. If it does not, then it will either keep the thread indefinitely or eventually finish, at which point
        // the Processor will begin running.
        monitoringFuture.cancel(false);

        final Processor processor = processorRef.get().getProcessor();
        LOG.warn("Timed out while waiting for OnScheduled of "
            + processor + " to finish. An attempt is made to cancel the task via Thread.interrupt(). However it does not "
            + "guarantee that the task will be canceled since the code inside current OnScheduled operation may "
            + "have been written to ignore interrupts which may result in a runaway thread. This could lead to more issues, "
            + "eventually requiring NiFi to be restarted. This is usually a bug in the target Processor '"
            + processor + "' that needs to be documented, reported and eventually fixed.");
    }
}
 
Example #3
Source File: ProcessorDetails.java    From nifi with Apache License 2.0 6 votes vote down vote up
public ProcessorDetails(final LoggableComponent<Processor> processor) {
    this.processor = processor.getComponent();
    this.componentLog = processor.getLogger();
    this.bundleCoordinate = processor.getBundleCoordinate();

    this.procClass = this.processor.getClass();
    this.triggerWhenEmpty = procClass.isAnnotationPresent(TriggerWhenEmpty.class);
    this.sideEffectFree = procClass.isAnnotationPresent(SideEffectFree.class);
    this.batchSupported = procClass.isAnnotationPresent(SupportsBatching.class);
    this.triggeredSerially = procClass.isAnnotationPresent(TriggerSerially.class);
    this.triggerWhenAnyDestinationAvailable = procClass.isAnnotationPresent(TriggerWhenAnyDestinationAvailable.class);
    this.eventDrivenSupported = procClass.isAnnotationPresent(EventDriven.class) && !triggeredSerially && !triggerWhenEmpty;
    this.executionNodeRestricted = procClass.isAnnotationPresent(PrimaryNodeOnly.class);

    final boolean inputRequirementPresent = procClass.isAnnotationPresent(InputRequirement.class);
    if (inputRequirementPresent) {
        this.inputRequirement = procClass.getAnnotation(InputRequirement.class).value();
    } else {
        this.inputRequirement = InputRequirement.Requirement.INPUT_ALLOWED;
    }
}
 
Example #4
Source File: StandardExtensionDiscoveringManager.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Loads extensions from the specified bundle.
 *
 * @param bundle from which to load extensions
 */
@SuppressWarnings("unchecked")
private void loadExtensions(final Bundle bundle) {
    for (final Map.Entry<Class, Set<Class>> entry : definitionMap.entrySet()) {
        final boolean isControllerService = ControllerService.class.equals(entry.getKey());
        final boolean isProcessor = Processor.class.equals(entry.getKey());
        final boolean isReportingTask = ReportingTask.class.equals(entry.getKey());

        final ServiceLoader<?> serviceLoader = ServiceLoader.load(entry.getKey(), bundle.getClassLoader());
        for (final Object o : serviceLoader) {
            try {
                loadExtension(o, entry.getKey(), bundle);
            } catch (Exception e) {
                logger.warn("Failed to register extension {} due to: {}" , new Object[]{o.getClass().getCanonicalName(), e.getMessage()});
                if (logger.isDebugEnabled()) {
                    logger.debug("", e);
                }
            }
        }

        classLoaderBundleLookup.put(bundle.getClassLoader(), bundle);
    }
}
 
Example #5
Source File: CommonTest.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void validateServiceIsLocatableViaServiceLoader() {
    ServiceLoader<Processor> loader = ServiceLoader.<Processor> load(Processor.class);
    Iterator<Processor> iter = loader.iterator();
    boolean pubJmsPresent = false;
    boolean consumeJmsPresent = false;
    while (iter.hasNext()) {
        Processor p = iter.next();
        if (p.getClass().getSimpleName().equals(PublishJMS.class.getSimpleName())) {
            pubJmsPresent = true;
        } else if (p.getClass().getSimpleName().equals(ConsumeJMS.class.getSimpleName())) {
            consumeJmsPresent = true;
        }

    }
    assertTrue(pubJmsPresent);
    assertTrue(consumeJmsPresent);
}
 
Example #6
Source File: ExtensionBuilder.java    From nifi with Apache License 2.0 6 votes vote down vote up
private ProcessorNode createProcessorNode(final LoggableComponent<Processor> processor, final boolean creationSuccessful) {
    final ComponentVariableRegistry componentVarRegistry = new StandardComponentVariableRegistry(this.variableRegistry);
    final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(serviceProvider, componentVarRegistry);

    final ProcessorNode procNode;
    if (creationSuccessful) {
        procNode = new StandardProcessorNode(processor, identifier, validationContextFactory, processScheduler, serviceProvider,
                componentVarRegistry, reloadComponent, extensionManager, validationTrigger);
    } else {
        final String simpleClassName = type.contains(".") ? StringUtils.substringAfterLast(type, ".") : type;
        final String componentType = "(Missing) " + simpleClassName;
        procNode = new StandardProcessorNode(processor, identifier, validationContextFactory, processScheduler, serviceProvider,
                componentType, type, componentVarRegistry, reloadComponent, extensionManager, validationTrigger, true);
    }

    applyDefaultSettings(procNode);
    return procNode;
}
 
Example #7
Source File: StandardProcessorTestRunner.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
StandardProcessorTestRunner(final Processor processor) {
    this.processor = processor;
    this.idGenerator = new AtomicLong(0L);
    this.sharedState = new SharedSessionState(processor, idGenerator);
    this.flowFileQueue = sharedState.getFlowFileQueue();
    this.sessionFactory = new MockSessionFactory(sharedState, processor);
    this.processorStateManager = new MockStateManager(processor);
    this.variableRegistry = new MockVariableRegistry();
    this.context = new MockProcessContext(processor, processorStateManager, variableRegistry);

    final MockProcessorInitializationContext mockInitContext = new MockProcessorInitializationContext(processor, context);
    processor.initialize(mockInitContext);
    logger =  mockInitContext.getLogger();

    try {
        ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, processor);
    } catch (final Exception e) {
        Assert.fail("Could not invoke methods annotated with @OnAdded annotation due to: " + e);
    }

    triggerSerially = null != processor.getClass().getAnnotation(TriggerSerially.class);

    ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class, processor);
}
 
Example #8
Source File: JMSConnectionFactoryProviderTest.java    From solace-integration-guides with Apache License 2.0 6 votes vote down vote up
@Test
public void validateFullConfigWithUserLib() throws Exception {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
    JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
    runner.addControllerService("cfProvider", cfProvider);
    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI, "myhost:1234");

    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH,
            new File("test-lib").getAbsolutePath()); // see README in 'test-lib' dir for more info
    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
            "org.apache.nifi.jms.testcflib.TestConnectionFactory");
    runner.setProperty(cfProvider, "Foo", "foo");
    runner.setProperty(cfProvider, "Bar", "3");

    runner.enableControllerService(cfProvider);
    runner.assertValid(cfProvider);
    ConnectionFactory cf = cfProvider.getConnectionFactory();
    assertNotNull(cf);
    assertEquals("org.apache.nifi.jms.testcflib.TestConnectionFactory", cf.getClass().getName());
    assertEquals("myhost", this.get("getHost", cf));
    assertEquals(1234, ((Integer) this.get("getPort", cf)).intValue());
    assertEquals("foo", this.get("getFoo", cf));
    assertEquals(3, ((Integer) this.get("getBar", cf)).intValue());
}
 
Example #9
Source File: StandardProcessorNode.java    From nifi with Apache License 2.0 6 votes vote down vote up
public Set<Relationship> getUndefinedRelationships() {
    final Set<Relationship> undefined = new HashSet<>();
    final Set<Relationship> relationships;
    final Processor processor = processorRef.get().getProcessor();
    try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(getExtensionManager(), processor.getClass(), processor.getIdentifier())) {
        relationships = processor.getRelationships();
    }

    if (relationships == null) {
        return undefined;
    }
    for (final Relationship relation : relationships) {
        final Set<Connection> connectionSet = this.connections.get(relation);
        if (connectionSet == null || connectionSet.isEmpty()) {
            undefined.add(relation);
        }
    }
    return undefined;
}
 
Example #10
Source File: TestStandardProcessScheduler.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 10000)
public void testProcessorThrowsExceptionOnScheduledRetry() throws InterruptedException {
    final FailOnScheduledProcessor proc = new FailOnScheduledProcessor();
    proc.setDesiredFailureCount(3);

    proc.initialize(new StandardProcessorInitializationContext(UUID.randomUUID().toString(), null, null, null, KerberosConfig.NOT_CONFIGURED));
    final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class);
    final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(proc, systemBundle.getBundleDetails().getCoordinate(), null);

    final ProcessorNode procNode = new StandardProcessorNode(loggableComponent, UUID.randomUUID().toString(),
        new StandardValidationContextFactory(serviceProvider, variableRegistry),
        scheduler, serviceProvider, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent, extensionManager, new SynchronousValidationTrigger());

    procNode.performValidation();
    rootGroup.addProcessor(procNode);

    scheduler.startProcessor(procNode, true);
    while (!proc.isSucceess()) {
        Thread.sleep(5L);
    }

    assertEquals(3, proc.getOnScheduledInvocationCount());
}
 
Example #11
Source File: JMSConnectionFactoryProviderTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void dynamicPropertiesSetOnSingleTestBrokerConnectionFactory() throws InitializationException {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));

    JMSConnectionFactoryProviderForTest cfProvider = new JMSConnectionFactoryProviderForTest();
    runner.addControllerService(controllerServiceId, cfProvider);

    runner.setVariable("test", "dynamicValue");

    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, SINGLE_TEST_BROKER);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CLIENT_LIBRARIES, dummyResource);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, TEST_CONNECTION_FACTORY_IMPL);
    runner.setProperty(cfProvider, "dynamicProperty", "${test}");

    runner.enableControllerService(cfProvider);

    assertEquals(cfProvider.getConfiguredProperties(), ImmutableMap.of("dynamicProperty", "dynamicValue", "hostName", HOSTNAME, "port", PORT));
}
 
Example #12
Source File: JMSConnectionFactoryProviderTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClientLibResourcesLoaded() throws InitializationException {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
    runner.setValidateExpressionUsage(true);

    JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
    runner.addControllerService(controllerServiceId, cfProvider);

    runner.setVariable("broker.uri", SINGLE_TEST_BROKER_WITH_SCHEME_AND_IP);
    runner.setVariable("client.lib", allDummyResources);

    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, "${broker.uri}");
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CLIENT_LIBRARIES, "${client.lib}");
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, TEST_CONNECTION_FACTORY_IMPL);

    runner.assertValid(cfProvider);

    ClassLoader loader = runner.getClass().getClassLoader();
    Assert.assertNotNull(loader.getResource(DUMMY_CONF));
    Assert.assertNotNull(loader.getResource(DUMMY_JAR_1));
    Assert.assertNotNull(loader.getResource(DUMMY_JAR_2));
}
 
Example #13
Source File: JMSConnectionFactoryProviderTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void propertiesSetOnMultipleTibcoBrokersConnectionFactory() throws InitializationException {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));

    JMSConnectionFactoryProviderForTest cfProvider = new JMSConnectionFactoryProviderForTest();
    runner.addControllerService(controllerServiceId, cfProvider);

    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, MULTIPLE_TIBCO_BROKERS);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CLIENT_LIBRARIES, dummyResource);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, TIBCO_CONNECTION_FACTORY_IMPL);

    runner.enableControllerService(cfProvider);

    assertEquals(cfProvider.getConfiguredProperties(), ImmutableMap.of("serverUrl", MULTIPLE_TIBCO_BROKERS));
}
 
Example #14
Source File: TestStandardRemoteGroupPort.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void setupMockProcessSession() {
    // Construct a RemoteGroupPort as a processor to use NiFi mock library.
    final Processor remoteGroupPort = mock(Processor.class);
    final Set<Relationship> relationships = new HashSet<>();
    relationships.add(Relationship.ANONYMOUS);
    when(remoteGroupPort.getRelationships()).thenReturn(relationships);
    when(remoteGroupPort.getIdentifier()).thenReturn("remote-group-port-id");

    sessionState = new SharedSessionState(remoteGroupPort, new AtomicLong(0));
    processSession = new MockProcessSession(sessionState, remoteGroupPort);
    processContext = new MockProcessContext(remoteGroupPort);
}
 
Example #15
Source File: AbstractDocumentationWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
private List<WritesAttribute> getWritesAttributes(Processor processor) {
    List<WritesAttribute> attributes = new ArrayList<>();

    WritesAttributes writesAttributes = processor.getClass().getAnnotation(WritesAttributes.class);
    if (writesAttributes != null) {
        Collections.addAll(attributes, writesAttributes.value());
    }

    WritesAttribute writeAttribute = processor.getClass().getAnnotation(WritesAttribute.class);
    if (writeAttribute != null) {
        attributes.add(writeAttribute);
    }

    return attributes;
}
 
Example #16
Source File: JMSConnectionFactoryProviderTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void validWithSingleTibcoBroker() throws InitializationException {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));

    JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
    runner.addControllerService(controllerServiceId, cfProvider);

    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, SINGLE_TIBCO_BROKER);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CLIENT_LIBRARIES, dummyResource);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, TIBCO_CONNECTION_FACTORY_IMPL);

    runner.assertValid(cfProvider);
}
 
Example #17
Source File: JMSConnectionFactoryProviderTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void validWithSingleActiveMqBroker() throws InitializationException {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));

    JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
    runner.addControllerService(controllerServiceId, cfProvider);

    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, SINGLE_ACTIVEMQ_BROKER);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CLIENT_LIBRARIES, dummyResource);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, ACTIVEMQ_CONNECTION_FACTORY_IMPL);

    runner.assertValid(cfProvider);
}
 
Example #18
Source File: JNDIConnectionFactoryProviderTest.java    From solace-integration-guides with Apache License 2.0 5 votes vote down vote up
@Test
public void validateNotValidForNonExistingLibPath() throws Exception {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
    JNDIConnectionFactoryProvider cfProvider = new JNDIConnectionFactoryProvider();
    runner.addControllerService("cfProvider", cfProvider);
    runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.BROKER_URI, "myhost:1234");
    runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.JNDI_CF_LOOKUP, "ConnectonFactory");

    runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, "foo");
    runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
            "org.apache.nifi.jms.testcflib.TestConnectionFactory");
    runner.assertNotValid(cfProvider);
}
 
Example #19
Source File: StandardProcessorNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Relationship> getRelationships() {
    final Processor processor = processorRef.get().getProcessor();
    try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(getExtensionManager(), processor.getClass(), processor.getIdentifier())) {
        return getProcessor().getRelationships();
    }
}
 
Example #20
Source File: StandardProcessorNode.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public StandardProcessorNode(final Processor processor, final String uuid,
                             final ValidationContextFactory validationContextFactory, final ProcessScheduler scheduler,
                             final ControllerServiceProvider controllerServiceProvider, final NiFiProperties nifiProperties,
                             final VariableRegistry variableRegistry, final ComponentLog logger) {

    this(processor, uuid, validationContextFactory, scheduler, controllerServiceProvider,
        processor.getClass().getSimpleName(), processor.getClass().getCanonicalName(), nifiProperties, variableRegistry, logger);
}
 
Example #21
Source File: FlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private Processor instantiateProcessor(final String type, final String identifier) throws ProcessorInstantiationException {
    Processor processor;

    final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        final ClassLoader detectedClassLoaderForType = ExtensionManager.getClassLoader(type, identifier);
        final Class<?> rawClass;
        if (detectedClassLoaderForType == null) {
            // try to find from the current class loader
            rawClass = Class.forName(type);
        } else {
            // try to find from the registered classloader for that type
            rawClass = Class.forName(type, true, ExtensionManager.getClassLoader(type, identifier));
        }

        Thread.currentThread().setContextClassLoader(detectedClassLoaderForType);
        final Class<? extends Processor> processorClass = rawClass.asSubclass(Processor.class);
        processor = processorClass.newInstance();
        final ComponentLog componentLogger = new SimpleProcessLogger(identifier, processor);
        final ProcessorInitializationContext ctx = new StandardProcessorInitializationContext(identifier, componentLogger, this, this, nifiProperties);
        processor.initialize(ctx);

        LogRepositoryFactory.getRepository(identifier).setLogger(componentLogger);
        return processor;
    } catch (final Throwable t) {
        throw new ProcessorInstantiationException(type, t);
    } finally {
        if (ctxClassLoader != null) {
            Thread.currentThread().setContextClassLoader(ctxClassLoader);
        }
    }
}
 
Example #22
Source File: ConfigurableComponentInitializerFactory.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #23
Source File: ProcessorNode.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public ProcessorNode(final Processor processor, final String id,
                     final ValidationContextFactory validationContextFactory, final ControllerServiceProvider serviceProvider,
                     final String componentType, final String componentCanonicalClass, final VariableRegistry variableRegistry,
                     final ComponentLog logger) {
    super(processor, id, validationContextFactory, serviceProvider, componentType, componentCanonicalClass, variableRegistry, logger);
    this.scheduledState = new AtomicReference<>(ScheduledState.STOPPED);
}
 
Example #24
Source File: JMSConnectionFactoryProviderTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void validWithMultipleActiveMqBrokers() throws InitializationException {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));

    JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
    runner.addControllerService(controllerServiceId, cfProvider);

    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, MULTIPLE_ACTIVEMQ_BROKERS);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CLIENT_LIBRARIES, dummyResource);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, ACTIVEMQ_CONNECTION_FACTORY_IMPL);

    runner.assertValid(cfProvider);
}
 
Example #25
Source File: JMSConnectionFactoryProviderTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void validateNotValidForNonDirectoryPath() throws Exception {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
    JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
    runner.addControllerService("cfProvider", cfProvider);
    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI, "myhost:1234");

    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, "pom.xml");
    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
            "org.apache.nifi.jms.testcflib.TestConnectionFactory");
    runner.assertNotValid(cfProvider);
}
 
Example #26
Source File: JMSConnectionFactoryProviderTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test(expected = AssertionError.class)
public void validateFailsIfURINotHostPortAndNotActiveMQ() throws Exception {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
    JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
    runner.addControllerService("cfProvider", cfProvider);
    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI, "myhost");

    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, "test-lib");
    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
            "org.apache.nifi.jms.testcflib.TestConnectionFactory");
    runner.enableControllerService(cfProvider);
    runner.assertNotValid(cfProvider);
}
 
Example #27
Source File: JMSConnectionFactoryProviderTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void validateNotValidForNonExistingLibPath() throws Exception {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
    JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
    runner.addControllerService("cfProvider", cfProvider);
    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI, "myhost:1234");

    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, "foo");
    runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
            "org.apache.nifi.jms.testcflib.TestConnectionFactory");
    runner.assertNotValid(cfProvider);
}
 
Example #28
Source File: DirectInjectionExtensionManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
public void injectExtension(final Object extension) {
    final Class<?> extensionType;
    if (extension instanceof Processor) {
        extensionType = Processor.class;
    } else if (extension instanceof ControllerService) {
        extensionType = ControllerService.class;
    } else if (extension instanceof ReportingTask) {
        extensionType = ReportingTask.class;
    } else {
        throw new IllegalArgumentException("Given extension is not a Processor, Controller Service, or Reporting Task");
    }

    super.loadExtension(extension, extensionType, INTEGRATION_TEST_BUNDLE);
}
 
Example #29
Source File: StandardProcessorNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Causes the processor not to be scheduled for some period of time. This
 * duration can be obtained and set via the
 * {@link #getYieldPeriod(TimeUnit)} and
 * {@link #setYieldPeriod(String)}.
 */
@Override
public void yield() {
    final Processor processor = processorRef.get().getProcessor();
    final long yieldMillis = getYieldPeriod(TimeUnit.MILLISECONDS);
    yield(yieldMillis, TimeUnit.MILLISECONDS);

    final String yieldDuration = (yieldMillis > 1000) ? (yieldMillis / 1000) + " seconds"
            : yieldMillis + " milliseconds";
    LoggerFactory.getLogger(processor.getClass()).debug(
            "{} has chosen to yield its resources; will not be scheduled to run again for {}", processor,
            yieldDuration);
}
 
Example #30
Source File: ParametersIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void testEscaping(final Class<? extends Processor> updateAttributeClass) throws ExecutionException, InterruptedException {
    final ProcessorNode generate = createProcessorNode(GenerateProcessor.class);
    final ProcessorNode updateAttribute = createProcessorNode(updateAttributeClass);

    connect(generate, updateAttribute, REL_SUCCESS);
    final Connection terminateConnection = connect(updateAttribute, getTerminateProcessor(), REL_SUCCESS);

    final ParameterReferenceManager referenceManager = new StandardParameterReferenceManager(getFlowController().getFlowManager());
    final ParameterContext parameterContext = new StandardParameterContext(UUID.randomUUID().toString(), "param-context", referenceManager, null);
    parameterContext.setParameters(Collections.singletonMap("test", new Parameter(new ParameterDescriptor.Builder().name("test").build(), "unit")));

    getRootGroup().setParameterContext(parameterContext);

    final Map<String, String> properties = new HashMap<>();
    properties.put("1pound", "#{test}");
    properties.put("2pound", "##{test}");
    properties.put("3pound", "###{test}");
    properties.put("4pound", "####{test}");
    properties.put("5pound", "#####{test}");

    updateAttribute.setProperties(properties);

    triggerOnce(generate);
    triggerOnce(updateAttribute);

    final FlowFileRecord flowFile = terminateConnection.getFlowFileQueue().poll(Collections.emptySet());
    assertEquals("unit", flowFile.getAttribute("1pound"));
    assertEquals("#{test}", flowFile.getAttribute("2pound"));
    assertEquals("#unit", flowFile.getAttribute("3pound"));
    assertEquals("##{test}", flowFile.getAttribute("4pound"));
    assertEquals("##unit", flowFile.getAttribute("5pound"));
}