Search in sources :

Example 6 with ProcessScheduler

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

the class TestProcessorLifecycle method validateStartFailsOnInvalidProcessorWithDisabledService.

/**
 * Validate that processor will not be validated on failing
 * ControllerService validation (not enabled).
 */
@Test(expected = IllegalStateException.class)
public void validateStartFailsOnInvalidProcessorWithDisabledService() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ControllerServiceNode testServiceNode = fc.createControllerService(TestService.class.getName(), "serv", fcsb.getSystemBundle().getBundleDetails().getCoordinate(), null, true);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    properties.put("S", testServiceNode.getIdentifier());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    testProcessor.withService = true;
    ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNode, true);
    fail();
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Test(org.junit.Test)

Example 7 with ProcessScheduler

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

the class TestProcessorLifecycle method validateProcessorDeletion.

/**
 * Test deletion of processor when connected to another
 *
 * @throws Exception exception
 */
@Test
public void validateProcessorDeletion() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ProcessorNode testProcNodeA = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNodeA.setProperties(properties);
    testGroup.addProcessor(testProcNodeA);
    ProcessorNode testProcNodeB = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNodeB.setProperties(properties);
    testGroup.addProcessor(testProcNodeB);
    Collection<String> relationNames = new ArrayList<>();
    relationNames.add("relation");
    Connection connection = fc.createConnection(UUID.randomUUID().toString(), Connection.class.getName(), testProcNodeA, testProcNodeB, relationNames);
    testGroup.addConnection(connection);
    ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNodeA, true);
    ps.startProcessor(testProcNodeB, true);
    try {
        testGroup.removeProcessor(testProcNodeA);
        fail();
    } catch (Exception e) {
    // should throw exception because processor running
    }
    try {
        testGroup.removeProcessor(testProcNodeB);
        fail();
    } catch (Exception e) {
    // should throw exception because processor running
    }
    ps.stopProcessor(testProcNodeB);
    Thread.sleep(100);
    try {
        testGroup.removeProcessor(testProcNodeA);
        fail();
    } catch (Exception e) {
    // should throw exception because destination processor running
    }
    try {
        testGroup.removeProcessor(testProcNodeB);
        fail();
    } catch (Exception e) {
    // should throw exception because source processor running
    }
    ps.stopProcessor(testProcNodeA);
    Thread.sleep(100);
    testGroup.removeProcessor(testProcNodeA);
    testGroup.removeProcessor(testProcNodeB);
    testGroup.shutdown();
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ArrayList(java.util.ArrayList) Connection(org.apache.nifi.connectable.Connection) ProcessException(org.apache.nifi.processor.exception.ProcessException) Test(org.junit.Test)

Example 8 with ProcessScheduler

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

the class TestStandardProcessSession method createFlowFileQueueSpy.

private FlowFileQueue createFlowFileQueueSpy(Connection connection) {
    final FlowFileSwapManager swapManager = Mockito.mock(FlowFileSwapManager.class);
    final ProcessScheduler processScheduler = Mockito.mock(ProcessScheduler.class);
    final StandardFlowFileQueue actualQueue = new StandardFlowFileQueue("1", connection, flowFileRepo, provenanceRepo, null, processScheduler, swapManager, null, 10000);
    return Mockito.spy(actualQueue);
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) StandardFlowFileQueue(org.apache.nifi.controller.StandardFlowFileQueue)

Example 9 with ProcessScheduler

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

the class TestStandardRootGroupPort method createRootGroupPort.

private RootGroupPort createRootGroupPort(NiFiProperties nifiProperties) {
    final BulletinRepository bulletinRepository = mock(BulletinRepository.class);
    final ProcessScheduler processScheduler = null;
    final Authorizer authorizer = mock(Authorizer.class);
    doAnswer(invocation -> {
        final AuthorizationRequest request = invocation.getArgumentAt(0, AuthorizationRequest.class);
        if ("node1@nifi.test".equals(request.getIdentity())) {
            return AuthorizationResult.approved();
        }
        return AuthorizationResult.denied();
    }).when(authorizer).authorize(any(AuthorizationRequest.class));
    final ProcessGroup processGroup = mock(ProcessGroup.class);
    doReturn("process-group-id").when(processGroup).getIdentifier();
    return new StandardRootGroupPort("id", "name", processGroup, TransferDirection.SEND, ConnectableType.INPUT_PORT, authorizer, bulletinRepository, processScheduler, true, nifiProperties);
}
Also used : BulletinRepository(org.apache.nifi.reporting.BulletinRepository) ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) AuthorizationRequest(org.apache.nifi.authorization.AuthorizationRequest) Authorizer(org.apache.nifi.authorization.Authorizer) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 10 with ProcessScheduler

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

the class TestProcessorLifecycle method validateProcessorCanBeStoppedWhenOnScheduledBlocksIndefinitelyUninterruptable.

/**
 * Validates that the Processor can be stopped when @OnScheduled blocks
 * indefinitely and written to ignore thread interrupts
 */
@Test
public void validateProcessorCanBeStoppedWhenOnScheduledBlocksIndefinitelyUninterruptable() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest(NiFiProperties.PROCESSOR_SCHEDULING_TIMEOUT, "1 sec");
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    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.blockingUninterruptableOnUnschedule(testProcessor);
    ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNode, true);
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), 3000L);
    ps.stopProcessor(testProcNode);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState(), 4000L);
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Test(org.junit.Test)

Aggregations

ProcessScheduler (org.apache.nifi.controller.ProcessScheduler)16 ProcessGroup (org.apache.nifi.groups.ProcessGroup)15 ProcessorNode (org.apache.nifi.controller.ProcessorNode)14 Test (org.junit.Test)14 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 AuthorizationRequest (org.apache.nifi.authorization.AuthorizationRequest)1 Authorizer (org.apache.nifi.authorization.Authorizer)1 Connection (org.apache.nifi.connectable.Connection)1 StandardFlowFileQueue (org.apache.nifi.controller.StandardFlowFileQueue)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1 BulletinRepository (org.apache.nifi.reporting.BulletinRepository)1 Ignore (org.junit.Ignore)1