Search in sources :

Example 1 with LoggableComponent

use of org.apache.nifi.controller.LoggableComponent in project nifi by apache.

the class TestStandardProcessScheduler method testProcessorThrowsExceptionOnScheduledRetry.

// Test that if processor throws Exception in @OnScheduled, it keeps getting scheduled
@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, nifiProperties));
    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(controller, variableRegistry), scheduler, controller, nifiProperties, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent);
    rootGroup.addProcessor(procNode);
    scheduler.startProcessor(procNode, true);
    while (!proc.isSucceess()) {
        Thread.sleep(5L);
    }
    assertEquals(3, proc.getOnScheduledInvocationCount());
}
Also used : FailOnScheduledProcessor(org.apache.nifi.controller.scheduling.processors.FailOnScheduledProcessor) Processor(org.apache.nifi.processor.Processor) FailOnScheduledProcessor(org.apache.nifi.controller.scheduling.processors.FailOnScheduledProcessor) AbstractProcessor(org.apache.nifi.processor.AbstractProcessor) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) ProcessorNode(org.apache.nifi.controller.ProcessorNode) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext) ReloadComponent(org.apache.nifi.controller.ReloadComponent) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) LoggableComponent(org.apache.nifi.controller.LoggableComponent) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) Test(org.junit.Test)

Example 2 with LoggableComponent

use of org.apache.nifi.controller.LoggableComponent in project nifi by apache.

the class TestStandardProcessScheduler method setup.

@Before
public void setup() throws InitializationException {
    final Map<String, String> overrideProperties = new HashMap<>();
    overrideProperties.put(NiFiProperties.ADMINISTRATIVE_YIELD_DURATION, "2 millis");
    overrideProperties.put(NiFiProperties.PROCESSOR_SCHEDULING_TIMEOUT, "10 millis");
    this.nifiProperties = NiFiProperties.createBasicNiFiProperties(propsFile, overrideProperties);
    // load the system bundle
    systemBundle = SystemBundle.create(nifiProperties);
    ExtensionManager.discoverExtensions(systemBundle, Collections.emptySet());
    scheduler = new StandardProcessScheduler(new FlowEngine(1, "Unit Test", true), Mockito.mock(FlowController.class), null, stateMgrProvider, nifiProperties);
    scheduler.setSchedulingAgent(SchedulingStrategy.TIMER_DRIVEN, Mockito.mock(SchedulingAgent.class));
    reportingTask = new TestReportingTask();
    final ReportingInitializationContext config = new StandardReportingInitializationContext(UUID.randomUUID().toString(), "Test", SchedulingStrategy.TIMER_DRIVEN, "5 secs", Mockito.mock(ComponentLog.class), null, nifiProperties, null);
    reportingTask.initialize(config);
    final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(null, variableRegistry);
    final TerminationAwareLogger logger = Mockito.mock(TerminationAwareLogger.class);
    final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class);
    final LoggableComponent<ReportingTask> loggableComponent = new LoggableComponent<>(reportingTask, systemBundle.getBundleDetails().getCoordinate(), logger);
    taskNode = new StandardReportingTaskNode(loggableComponent, UUID.randomUUID().toString(), null, scheduler, validationContextFactory, new StandardComponentVariableRegistry(variableRegistry), reloadComponent);
    controller = Mockito.mock(FlowController.class);
    final ConcurrentMap<String, ProcessorNode> processorMap = new ConcurrentHashMap<>();
    Mockito.doAnswer(new Answer<ProcessorNode>() {

        @Override
        public ProcessorNode answer(InvocationOnMock invocation) throws Throwable {
            final String id = invocation.getArgumentAt(0, String.class);
            return processorMap.get(id);
        }
    }).when(controller).getProcessorNode(Mockito.anyString());
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final ProcessorNode procNode = invocation.getArgumentAt(0, ProcessorNode.class);
            processorMap.putIfAbsent(procNode.getIdentifier(), procNode);
            return null;
        }
    }).when(controller).onProcessorAdded(Mockito.any(ProcessorNode.class));
    rootGroup = new MockProcessGroup(controller);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(rootGroup);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) ValidationContextFactory(org.apache.nifi.controller.ValidationContextFactory) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ReportingInitializationContext(org.apache.nifi.reporting.ReportingInitializationContext) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) StandardReportingTaskNode(org.apache.nifi.controller.reporting.StandardReportingTaskNode) FlowController(org.apache.nifi.controller.FlowController) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractReportingTask(org.apache.nifi.reporting.AbstractReportingTask) ReportingTask(org.apache.nifi.reporting.ReportingTask) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) FlowEngine(org.apache.nifi.engine.FlowEngine) ReloadComponent(org.apache.nifi.controller.ReloadComponent) ComponentLog(org.apache.nifi.logging.ComponentLog) LoggableComponent(org.apache.nifi.controller.LoggableComponent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TerminationAwareLogger(org.apache.nifi.controller.TerminationAwareLogger) Before(org.junit.Before)

Example 3 with LoggableComponent

use of org.apache.nifi.controller.LoggableComponent in project nifi by apache.

the class TestStandardProcessScheduler method testProcessorTimeOutNoResponseToInterrupt.

// Test that if processor times out in the @OnScheduled and does not respond to interrupt, it is not scheduled again
@Test(timeout = 10000)
public void testProcessorTimeOutNoResponseToInterrupt() throws InterruptedException {
    final FailOnScheduledProcessor proc = new FailOnScheduledProcessor();
    proc.setDesiredFailureCount(0);
    proc.setOnScheduledSleepDuration(20, TimeUnit.MINUTES, false, 1);
    proc.initialize(new StandardProcessorInitializationContext(UUID.randomUUID().toString(), null, null, null, nifiProperties));
    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(controller, variableRegistry), scheduler, controller, nifiProperties, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent);
    rootGroup.addProcessor(procNode);
    scheduler.startProcessor(procNode, true);
    Thread.sleep(100L);
    assertEquals(1, proc.getOnScheduledInvocationCount());
    Thread.sleep(100L);
    assertEquals(1, proc.getOnScheduledInvocationCount());
    // Allow test to complete.
    proc.setAllowSleepInterrupt(true);
}
Also used : FailOnScheduledProcessor(org.apache.nifi.controller.scheduling.processors.FailOnScheduledProcessor) Processor(org.apache.nifi.processor.Processor) FailOnScheduledProcessor(org.apache.nifi.controller.scheduling.processors.FailOnScheduledProcessor) AbstractProcessor(org.apache.nifi.processor.AbstractProcessor) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) ProcessorNode(org.apache.nifi.controller.ProcessorNode) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext) ReloadComponent(org.apache.nifi.controller.ReloadComponent) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) LoggableComponent(org.apache.nifi.controller.LoggableComponent) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) Test(org.junit.Test)

Example 4 with LoggableComponent

use of org.apache.nifi.controller.LoggableComponent in project nifi by apache.

the class TestStandardProcessScheduler method testProcessorTimeOutRespondsToInterrupt.

// Test that if processor times out in the @OnScheduled but responds to interrupt, it keeps getting scheduled
@Test(timeout = 1000000)
public void testProcessorTimeOutRespondsToInterrupt() throws InterruptedException {
    final FailOnScheduledProcessor proc = new FailOnScheduledProcessor();
    proc.setDesiredFailureCount(0);
    proc.setOnScheduledSleepDuration(20, TimeUnit.MINUTES, true, 1);
    proc.initialize(new StandardProcessorInitializationContext(UUID.randomUUID().toString(), null, null, null, nifiProperties));
    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(controller, variableRegistry), scheduler, controller, nifiProperties, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent);
    rootGroup.addProcessor(procNode);
    scheduler.startProcessor(procNode, true);
    while (!proc.isSucceess()) {
        Thread.sleep(5L);
    }
    // The first time that the processor's @OnScheduled method is called, it will sleep for 20 minutes. The scheduler should interrupt
    // that thread and then try again. The second time, the Processor will not sleep because setOnScheduledSleepDuration was called
    // above with iterations = 1
    assertEquals(2, proc.getOnScheduledInvocationCount());
}
Also used : FailOnScheduledProcessor(org.apache.nifi.controller.scheduling.processors.FailOnScheduledProcessor) Processor(org.apache.nifi.processor.Processor) FailOnScheduledProcessor(org.apache.nifi.controller.scheduling.processors.FailOnScheduledProcessor) AbstractProcessor(org.apache.nifi.processor.AbstractProcessor) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) ProcessorNode(org.apache.nifi.controller.ProcessorNode) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext) ReloadComponent(org.apache.nifi.controller.ReloadComponent) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) LoggableComponent(org.apache.nifi.controller.LoggableComponent) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) Test(org.junit.Test)

Example 5 with LoggableComponent

use of org.apache.nifi.controller.LoggableComponent in project nifi by apache.

the class TestStandardProcessScheduler method testDisableControllerServiceWithProcessorTryingToStartUsingIt.

@Test(timeout = 60000)
public void testDisableControllerServiceWithProcessorTryingToStartUsingIt() throws InterruptedException {
    final String uuid = UUID.randomUUID().toString();
    final Processor proc = new ServiceReferencingProcessor();
    proc.initialize(new StandardProcessorInitializationContext(uuid, null, null, null, null));
    final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class);
    final StandardControllerServiceProvider serviceProvider = new StandardControllerServiceProvider(controller, scheduler, null, Mockito.mock(StateManagerProvider.class), variableRegistry, nifiProperties);
    final ControllerServiceNode service = serviceProvider.createControllerService(NoStartServiceImpl.class.getName(), "service", systemBundle.getBundleDetails().getCoordinate(), null, true);
    rootGroup.addControllerService(service);
    final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(proc, systemBundle.getBundleDetails().getCoordinate(), null);
    final ProcessorNode procNode = new StandardProcessorNode(loggableComponent, uuid, new StandardValidationContextFactory(serviceProvider, variableRegistry), scheduler, serviceProvider, nifiProperties, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent);
    rootGroup.addProcessor(procNode);
    Map<String, String> procProps = new HashMap<>();
    procProps.put(ServiceReferencingProcessor.SERVICE_DESC.getName(), service.getIdentifier());
    procNode.setProperties(procProps);
    scheduler.enableControllerService(service);
    scheduler.startProcessor(procNode, true);
    Thread.sleep(25L);
    scheduler.stopProcessor(procNode);
    assertTrue(service.isActive());
    assertTrue(service.getState() == ControllerServiceState.ENABLING);
    scheduler.disableControllerService(service);
    assertTrue(service.getState() == ControllerServiceState.DISABLING);
    assertFalse(service.isActive());
    while (service.getState() != ControllerServiceState.DISABLED) {
        Thread.sleep(5L);
    }
    assertTrue(service.getState() == ControllerServiceState.DISABLED);
}
Also used : Processor(org.apache.nifi.processor.Processor) FailOnScheduledProcessor(org.apache.nifi.controller.scheduling.processors.FailOnScheduledProcessor) AbstractProcessor(org.apache.nifi.processor.AbstractProcessor) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext) ReloadComponent(org.apache.nifi.controller.ReloadComponent) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) LoggableComponent(org.apache.nifi.controller.LoggableComponent) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) StandardControllerServiceNode(org.apache.nifi.controller.service.StandardControllerServiceNode) StandardControllerServiceProvider(org.apache.nifi.controller.service.StandardControllerServiceProvider) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) StateManagerProvider(org.apache.nifi.components.state.StateManagerProvider) Test(org.junit.Test)

Aggregations

LoggableComponent (org.apache.nifi.controller.LoggableComponent)8 StandardValidationContextFactory (org.apache.nifi.processor.StandardValidationContextFactory)8 StandardComponentVariableRegistry (org.apache.nifi.registry.variable.StandardComponentVariableRegistry)8 ProcessorNode (org.apache.nifi.controller.ProcessorNode)6 ReloadComponent (org.apache.nifi.controller.ReloadComponent)6 StandardProcessorNode (org.apache.nifi.controller.StandardProcessorNode)6 Processor (org.apache.nifi.processor.Processor)5 FailOnScheduledProcessor (org.apache.nifi.controller.scheduling.processors.FailOnScheduledProcessor)4 AbstractProcessor (org.apache.nifi.processor.AbstractProcessor)4 StandardProcessorInitializationContext (org.apache.nifi.processor.StandardProcessorInitializationContext)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ControllerService (org.apache.nifi.controller.ControllerService)2 FlowController (org.apache.nifi.controller.FlowController)2 TerminationAwareLogger (org.apache.nifi.controller.TerminationAwareLogger)2 ValidationContextFactory (org.apache.nifi.controller.ValidationContextFactory)2 MockProcessGroup (org.apache.nifi.controller.service.mock.MockProcessGroup)2 ComponentLog (org.apache.nifi.logging.ComponentLog)2 ComponentVariableRegistry (org.apache.nifi.registry.ComponentVariableRegistry)2