Search in sources :

Example 71 with ProcessorNode

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

the class TestProcessorLifecycle method validateLifecycleOperationOrderWithConcurrentCallsToStartStop.

/**
 * Concurrency test that is basically hammers on both stop and start
 * operation validating their idempotency.
 */
@Test
@Ignore
public void validateLifecycleOperationOrderWithConcurrentCallsToStartStop() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    final ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    // sets the scenario for the processor to run
    this.noop(testProcessor);
    final ProcessScheduler ps = fc.getProcessScheduler();
    ExecutorService executor = Executors.newFixedThreadPool(100);
    int startCallsCount = 10000;
    final CountDownLatch countDownCounter = new CountDownLatch(startCallsCount);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState());
    final Random random = new Random();
    for (int i = 0; i < startCallsCount / 2; i++) {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                LockSupport.parkNanos(random.nextInt(9000000));
                ps.stopProcessor(testProcNode);
                countDownCounter.countDown();
            }
        });
    }
    for (int i = 0; i < startCallsCount / 2; i++) {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                LockSupport.parkNanos(random.nextInt(9000000));
                ps.startProcessor(testProcNode, true);
                countDownCounter.countDown();
            }
        });
    }
    assertTrue(countDownCounter.await(1000000, TimeUnit.MILLISECONDS));
    String previousOperation = null;
    for (String operationName : testProcessor.operationNames) {
        if (previousOperation == null || previousOperation.equals("@OnStopped")) {
            assertEquals("@OnScheduled", operationName);
        } else if (previousOperation.equals("@OnScheduled")) {
            assertEquals("@OnUnscheduled", operationName);
        } else if (previousOperation.equals("@OnUnscheduled")) {
            assertTrue(operationName.equals("@OnStopped") || operationName.equals("@OnScheduled"));
        }
        previousOperation = operationName;
    }
    executor.shutdownNow();
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) Random(java.util.Random) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 72 with ProcessorNode

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

the class TestProcessorLifecycle method validateIdempotencyOfProcessorStartOperation.

/**
 * Will validate the idempotent nature of processor start operation which
 * can be called multiple times without any side-effects.
 */
@Test
public void validateIdempotencyOfProcessorStartOperation() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    final ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    // sets the scenario for the processor to run
    this.noop(testProcessor);
    final ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNode, true);
    ps.startProcessor(testProcNode, true);
    ps.startProcessor(testProcNode, true);
    Thread.sleep(500);
    assertCondition(() -> testProcessor.operationNames.size() == 1);
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Test(org.junit.Test)

Example 73 with ProcessorNode

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

the class StandardFlowSerializerTest method testSerializationEscapingAndFiltering.

@Test
public void testSerializationEscapingAndFiltering() throws Exception {
    final ProcessorNode dummy = controller.createProcessor(DummyScheduledProcessor.class.getName(), UUID.randomUUID().toString(), systemBundle.getBundleDetails().getCoordinate());
    dummy.setComments(RAW_COMMENTS);
    controller.getRootGroup().addProcessor(dummy);
    // serialize the controller
    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    serializer.serialize(controller, os, ScheduledStateLookup.IDENTITY_LOOKUP);
    // verify the results contain the serialized string
    final String serializedFlow = os.toString(StandardCharsets.UTF_8.name());
    assertTrue(serializedFlow.contains(SERIALIZED_COMMENTS));
    assertFalse(serializedFlow.contains(RAW_COMMENTS));
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) DummyScheduledProcessor(org.apache.nifi.controller.DummyScheduledProcessor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 74 with ProcessorNode

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

the class TestStandardControllerServiceProvider method createProcessor.

private ProcessorNode createProcessor(final StandardProcessScheduler scheduler, final ControllerServiceProvider serviceProvider) {
    final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.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, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent);
    final ProcessGroup group = new StandardProcessGroup(UUID.randomUUID().toString(), serviceProvider, scheduler, null, null, Mockito.mock(FlowController.class), new MutableVariableRegistry(variableRegistry));
    group.addProcessor(procNode);
    procNode.setProcessGroup(group);
    return procNode;
}
Also used : Processor(org.apache.nifi.processor.Processor) DummyProcessor(org.apache.nifi.controller.service.mock.DummyProcessor) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) StandardProcessGroup(org.apache.nifi.groups.StandardProcessGroup) ReloadComponent(org.apache.nifi.controller.ReloadComponent) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) LoggableComponent(org.apache.nifi.controller.LoggableComponent) ProcessorNode(org.apache.nifi.controller.ProcessorNode) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessGroup(org.apache.nifi.groups.StandardProcessGroup) MutableVariableRegistry(org.apache.nifi.registry.variable.MutableVariableRegistry) FlowController(org.apache.nifi.controller.FlowController) DummyProcessor(org.apache.nifi.controller.service.mock.DummyProcessor) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode)

Example 75 with ProcessorNode

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

the class TestStandardControllerServiceProvider method testEnableReferencingComponents.

@Test
public void testEnableReferencingComponents() {
    final ProcessGroup procGroup = new MockProcessGroup(controller);
    final FlowController controller = Mockito.mock(FlowController.class);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);
    final StandardProcessScheduler scheduler = createScheduler();
    final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, null, null, stateManagerProvider, variableRegistry, niFiProperties);
    final ControllerServiceNode serviceNode = provider.createControllerService(ServiceA.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
    final ProcessorNode procNode = createProcessor(scheduler, provider);
    serviceNode.addReference(procNode);
    // procNode.setScheduledState(ScheduledState.STOPPED);
    provider.unscheduleReferencingComponents(serviceNode);
    assertEquals(ScheduledState.STOPPED, procNode.getScheduledState());
    // procNode.setScheduledState(ScheduledState.RUNNING);
    provider.unscheduleReferencingComponents(serviceNode);
    assertEquals(ScheduledState.STOPPED, procNode.getScheduledState());
}
Also used : ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ProcessorNode(org.apache.nifi.controller.ProcessorNode) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessGroup(org.apache.nifi.groups.StandardProcessGroup) FlowController(org.apache.nifi.controller.FlowController) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessScheduler(org.apache.nifi.controller.scheduling.StandardProcessScheduler) Test(org.junit.Test)

Aggregations

ProcessorNode (org.apache.nifi.controller.ProcessorNode)88 ProcessGroup (org.apache.nifi.groups.ProcessGroup)45 Port (org.apache.nifi.connectable.Port)25 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)23 Connection (org.apache.nifi.connectable.Connection)22 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)22 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)22 HashSet (java.util.HashSet)20 Funnel (org.apache.nifi.connectable.Funnel)20 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)20 RootGroupPort (org.apache.nifi.remote.RootGroupPort)20 HashMap (java.util.HashMap)19 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)18 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)17 FlowController (org.apache.nifi.controller.FlowController)17 Map (java.util.Map)16 Connectable (org.apache.nifi.connectable.Connectable)16 ReportingTaskNode (org.apache.nifi.controller.ReportingTaskNode)16 LinkedHashSet (java.util.LinkedHashSet)15