Search in sources :

Example 11 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class TestProcessorLifecycle method validateStartSucceedsOnProcessorWithEnabledService.

/**
 * The successful processor start with ControllerService dependency.
 */
@Test
public void validateStartSucceedsOnProcessorWithEnabledService() 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(), "foo", fcsb.getSystemBundle().getBundleDetails().getCoordinate(), null, true);
    testGroup.addControllerService(testServiceNode);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testGroup.addProcessor(testProcNode);
    properties.put("S", testServiceNode.getIdentifier());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    testProcessor.withService = true;
    this.noop(testProcessor);
    ProcessScheduler ps = fc.getProcessScheduler();
    ps.enableControllerService(testServiceNode);
    ps.startProcessor(testProcNode, true);
    Thread.sleep(500);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);
}
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 12 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode 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 13 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class TestStandardProcessScheduler method validateDisablingOfTheFailedService.

@Test
public void validateDisablingOfTheFailedService() throws Exception {
    final StandardProcessScheduler scheduler = createScheduler();
    final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateMgrProvider, variableRegistry, nifiProperties);
    final ControllerServiceNode serviceNode = provider.createControllerService(FailingService.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
    scheduler.enableControllerService(serviceNode);
    Thread.sleep(1000);
    scheduler.shutdown();
    /*
         * Because it was never disabled it will remain active since its
         * enabling is being retried. This may actually be a bug in the
         * scheduler since it probably has to shut down all components (disable
         * services, shut down processors etc) before shutting down itself
         */
    assertTrue(serviceNode.isActive());
    assertTrue(serviceNode.getState() == ControllerServiceState.ENABLING);
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) StandardControllerServiceNode(org.apache.nifi.controller.service.StandardControllerServiceNode) StandardControllerServiceProvider(org.apache.nifi.controller.service.StandardControllerServiceProvider) Test(org.junit.Test)

Example 14 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class TestStandardProcessScheduler method validateDisabledServiceCantBeDisabled.

/**
 * Validates the atomic nature of ControllerServiceNode.disable(..) method
 * which must never trigger @OnDisabled, regardless of how many threads may
 * have a reference to the underlying ProcessScheduler and
 * ControllerServiceNode.
 */
@Test
public void validateDisabledServiceCantBeDisabled() throws Exception {
    final StandardProcessScheduler scheduler = createScheduler();
    final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateMgrProvider, variableRegistry, nifiProperties);
    final ControllerServiceNode serviceNode = provider.createControllerService(SimpleTestService.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
    final SimpleTestService ts = (SimpleTestService) serviceNode.getControllerServiceImplementation();
    final ExecutorService executor = Executors.newCachedThreadPool();
    final AtomicBoolean asyncFailed = new AtomicBoolean();
    for (int i = 0; i < 1000; i++) {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    scheduler.disableControllerService(serviceNode);
                    assertFalse(serviceNode.isActive());
                } catch (final Exception e) {
                    e.printStackTrace();
                    asyncFailed.set(true);
                }
            }
        });
    }
    // need to sleep a while since we are emulating async invocations on
    // method that is also internally async
    Thread.sleep(500);
    executor.shutdown();
    assertFalse(asyncFailed.get());
    assertEquals(0, ts.disableInvocationCount());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) StandardControllerServiceNode(org.apache.nifi.controller.service.StandardControllerServiceNode) StandardControllerServiceProvider(org.apache.nifi.controller.service.StandardControllerServiceProvider) ExecutorService(java.util.concurrent.ExecutorService) InitializationException(org.apache.nifi.reporting.InitializationException) ProcessException(org.apache.nifi.processor.exception.ProcessException) Test(org.junit.Test)

Example 15 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode 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

ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)88 HashSet (java.util.HashSet)29 ProcessGroup (org.apache.nifi.groups.ProcessGroup)26 HashMap (java.util.HashMap)25 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)25 ArrayList (java.util.ArrayList)24 Map (java.util.Map)24 LinkedHashSet (java.util.LinkedHashSet)22 Test (org.junit.Test)19 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)18 ProcessorNode (org.apache.nifi.controller.ProcessorNode)18 ConfiguredComponent (org.apache.nifi.controller.ConfiguredComponent)17 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)17 Set (java.util.Set)16 Connection (org.apache.nifi.connectable.Connection)16 List (java.util.List)15 Port (org.apache.nifi.connectable.Port)15 Label (org.apache.nifi.controller.label.Label)15 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)15 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)15