use of org.apache.nifi.processor.ProcessorInitializationContext in project kylo by Teradata.
the class SpringSecurityContextLoader method create.
/**
* Creates a new Security Context Loader from the specified processor context.
*
* @param processorContext the processor initialization context
* @return the Security Context Loader
*/
@Nonnull
public static SpringSecurityContextLoader create(@Nonnull final ProcessorInitializationContext processorContext) {
final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton(ProcessorInitializationContext.class.getName(), processorContext);
final GenericApplicationContext context = new GenericApplicationContext(beanFactory);
context.refresh();
return create(context);
}
use of org.apache.nifi.processor.ProcessorInitializationContext in project nifi by apache.
the class TestStandardProcessorNode method createProcessorNode.
private StandardProcessorNode createProcessorNode(final Processor processor, final ReloadComponent reloadComponent) {
final String uuid = UUID.randomUUID().toString();
final ValidationContextFactory validationContextFactory = createValidationContextFactory();
final NiFiProperties niFiProperties = NiFiProperties.createBasicNiFiProperties("src/test/resources/conf/nifi.properties", null);
final ProcessScheduler processScheduler = Mockito.mock(ProcessScheduler.class);
final TerminationAwareLogger componentLog = Mockito.mock(TerminationAwareLogger.class);
final Bundle systemBundle = SystemBundle.create(niFiProperties);
ExtensionManager.discoverExtensions(systemBundle, Collections.emptySet());
ExtensionManager.createInstanceClassLoader(processor.getClass().getName(), uuid, systemBundle, null);
ProcessorInitializationContext initContext = new StandardProcessorInitializationContext(uuid, componentLog, null, null, null);
processor.initialize(initContext);
final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(processor, systemBundle.getBundleDetails().getCoordinate(), componentLog);
return new StandardProcessorNode(loggableComponent, uuid, validationContextFactory, processScheduler, null, niFiProperties, new StandardComponentVariableRegistry(variableRegistry), reloadComponent);
}
use of org.apache.nifi.processor.ProcessorInitializationContext in project nifi by apache.
the class TestStandardProcessorNode method testStart.
@Test(timeout = 10000)
public void testStart() throws InterruptedException {
final ProcessorThatThrowsExceptionOnScheduled processor = new ProcessorThatThrowsExceptionOnScheduled();
final String uuid = UUID.randomUUID().toString();
ProcessorInitializationContext initContext = new StandardProcessorInitializationContext(uuid, null, null, null, null);
processor.initialize(initContext);
final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class);
final BundleCoordinate coordinate = Mockito.mock(BundleCoordinate.class);
final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(processor, coordinate, null);
final StandardProcessorNode procNode = new StandardProcessorNode(loggableComponent, uuid, createValidationContextFactory(), null, null, NiFiProperties.createBasicNiFiProperties(null, null), new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent);
final ScheduledExecutorService taskScheduler = new FlowEngine(1, "TestClasspathResources", true);
final StandardProcessContext processContext = new StandardProcessContext(procNode, null, null, null, () -> false);
final SchedulingAgentCallback schedulingAgentCallback = new SchedulingAgentCallback() {
@Override
public void onTaskComplete() {
}
@Override
public Future<?> scheduleTask(final Callable<?> task) {
return taskScheduler.submit(task);
}
@Override
public void trigger() {
Assert.fail("Should not have completed");
}
};
procNode.start(taskScheduler, 20000L, processContext, schedulingAgentCallback, true);
Thread.sleep(1000L);
assertEquals(1, processor.onScheduledCount);
assertEquals(1, processor.onUnscheduledCount);
assertEquals(1, processor.onStoppedCount);
}
use of org.apache.nifi.processor.ProcessorInitializationContext in project nifi by apache.
the class ITConsumeKafka method validateConsumerRetainer.
@Test
public void validateConsumerRetainer() throws Exception {
// skip if on windows
assumeFalse(isWindowsEnvironment());
final ConsumerPool consumerPool = mock(ConsumerPool.class);
final ConsumeKafka processor = new ConsumeKafka() {
@Override
protected ConsumerPool createConsumerPool(ProcessContext context, ComponentLog log) {
return consumerPool;
}
};
final ComponentLog logger = mock(ComponentLog.class);
final ProcessorInitializationContext initializationContext = mock(ProcessorInitializationContext.class);
when(initializationContext.getLogger()).thenReturn(logger);
processor.initialize(initializationContext);
final ProcessContext processContext = mock(ProcessContext.class);
final PropertyValue heartbeatInternalMsConfig = mock(PropertyValue.class);
when(heartbeatInternalMsConfig.isSet()).thenReturn(true);
when(heartbeatInternalMsConfig.asInteger()).thenReturn(100);
when(processContext.getProperty(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG)).thenReturn(heartbeatInternalMsConfig);
processor.onScheduled(processContext);
// retainConsumers should be called at least 1 time if it passed longer than heartbeat interval milliseconds.
Thread.sleep(200);
verify(consumerPool, atLeast(1)).retainConsumers();
processor.stopConnectionRetainer();
// After stopping connection retainer, it shouldn't interact with consumerPool.
Thread.sleep(200);
verifyNoMoreInteractions(consumerPool);
}
use of org.apache.nifi.processor.ProcessorInitializationContext in project nifi by apache.
the class TestJmsConsumer method testMap2FlowFileTextMessage.
@Test
public void testMap2FlowFileTextMessage() throws Exception {
TestRunner runner = TestRunners.newTestRunner(GetJMSQueue.class);
TextMessage textMessage = new ActiveMQTextMessage();
String payload = "Hello world!";
textMessage.setText(payload);
ProcessContext context = runner.getProcessContext();
ProcessSession session = runner.getProcessSessionFactory().createSession();
ProcessorInitializationContext pic = new MockProcessorInitializationContext(runner.getProcessor(), (MockProcessContext) runner.getProcessContext());
JmsProcessingSummary summary = JmsConsumer.map2FlowFile(context, session, textMessage, true, pic.getLogger());
assertEquals("TextMessage content length should equal to FlowFile content size", payload.length(), summary.getLastFlowFile().getSize());
final byte[] buffer = new byte[payload.length()];
runner.clearTransferState();
session.read(summary.getLastFlowFile(), new InputStreamCallback() {
@Override
public void process(InputStream in) throws IOException {
StreamUtils.fillBuffer(in, buffer, false);
}
});
String contentString = new String(buffer, "UTF-8");
assertEquals("", payload, contentString);
}
Aggregations