Search in sources :

Example 6 with FlowController

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

the class StandardControllerServiceProviderIT method testEnableReferencingServicesGraph.

public void testEnableReferencingServicesGraph(final StandardProcessScheduler scheduler) {
    final FlowController controller = Mockito.mock(FlowController.class);
    final ProcessGroup procGroup = new MockProcessGroup(controller);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);
    final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties);
    // build a graph of controller services with dependencies as such:
    // 
    // A -> B -> D
    // C ---^----^
    // 
    // In other words, A references B, which references D.
    // AND
    // C references B and D.
    // 
    // So we have to verify that if D is enabled, when we enable its referencing services,
    // we enable C and B, even if we attempt to enable C before B... i.e., if we try to enable C, we cannot do so
    // until B is first enabled so ensure that we enable B first.
    final ControllerServiceNode serviceNode1 = provider.createControllerService(ServiceA.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
    final ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceA.class.getName(), "2", systemBundle.getBundleDetails().getCoordinate(), null, false);
    final ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", systemBundle.getBundleDetails().getCoordinate(), null, false);
    final ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", systemBundle.getBundleDetails().getCoordinate(), null, false);
    procGroup.addControllerService(serviceNode1);
    procGroup.addControllerService(serviceNode2);
    procGroup.addControllerService(serviceNode3);
    procGroup.addControllerService(serviceNode4);
    setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "2");
    setProperty(serviceNode2, ServiceA.OTHER_SERVICE.getName(), "4");
    setProperty(serviceNode3, ServiceA.OTHER_SERVICE.getName(), "2");
    setProperty(serviceNode3, ServiceA.OTHER_SERVICE_2.getName(), "4");
    provider.enableControllerService(serviceNode4);
    provider.enableReferencingServices(serviceNode4);
    // Verify that the services are either ENABLING or ENABLED, and wait for all of them to become ENABLED.
    // Note that we set a timeout of 10 seconds, in case a bug occurs and the services never become ENABLED.
    final Set<ControllerServiceState> validStates = new HashSet<>();
    validStates.add(ControllerServiceState.ENABLED);
    validStates.add(ControllerServiceState.ENABLING);
    while (serviceNode3.getState() != ControllerServiceState.ENABLED || serviceNode2.getState() != ControllerServiceState.ENABLED || serviceNode1.getState() != ControllerServiceState.ENABLED) {
        assertTrue(validStates.contains(serviceNode3.getState()));
        assertTrue(validStates.contains(serviceNode2.getState()));
        assertTrue(validStates.contains(serviceNode1.getState()));
    }
}
Also used : ServiceB(org.apache.nifi.controller.service.mock.ServiceB) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ProcessGroup(org.apache.nifi.groups.ProcessGroup) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) FlowController(org.apache.nifi.controller.FlowController) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) HashSet(java.util.HashSet)

Example 7 with FlowController

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

the class TestStandardControllerServiceProvider method testEnableDisableWithReference.

@Test(timeout = 10000)
public void testEnableDisableWithReference() {
    final ProcessGroup group = new MockProcessGroup(controller);
    final FlowController controller = Mockito.mock(FlowController.class);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(group);
    final StandardProcessScheduler scheduler = createScheduler();
    final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties);
    final ControllerServiceNode serviceNodeB = provider.createControllerService(ServiceB.class.getName(), "B", systemBundle.getBundleDetails().getCoordinate(), null, false);
    final ControllerServiceNode serviceNodeA = provider.createControllerService(ServiceA.class.getName(), "A", systemBundle.getBundleDetails().getCoordinate(), null, false);
    group.addControllerService(serviceNodeA);
    group.addControllerService(serviceNodeB);
    setProperty(serviceNodeA, ServiceA.OTHER_SERVICE.getName(), "B");
    try {
        provider.enableControllerService(serviceNodeA);
        Assert.fail("Was able to enable Service A but Service B is disabled.");
    } catch (final IllegalStateException expected) {
    }
    provider.enableControllerService(serviceNodeB);
    provider.enableControllerService(serviceNodeA);
    try {
        provider.disableControllerService(serviceNodeB);
        Assert.fail("Was able to disable Service B but Service A is enabled and references B");
    } catch (final IllegalStateException expected) {
    }
    provider.disableControllerService(serviceNodeA);
    waitForServiceState(serviceNodeA, ControllerServiceState.DISABLED);
    provider.disableControllerService(serviceNodeB);
    waitForServiceState(serviceNodeB, ControllerServiceState.DISABLED);
}
Also used : ServiceB(org.apache.nifi.controller.service.mock.ServiceB) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) 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)

Example 8 with FlowController

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

the class TestStandardControllerServiceProvider method testDisableControllerService.

@Test
public void testDisableControllerService() {
    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, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties);
    final ControllerServiceNode serviceNode = provider.createControllerService(ServiceB.class.getName(), "B", systemBundle.getBundleDetails().getCoordinate(), null, false);
    provider.enableControllerService(serviceNode);
    provider.disableControllerService(serviceNode);
}
Also used : ServiceB(org.apache.nifi.controller.service.mock.ServiceB) 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)

Example 9 with FlowController

use of org.apache.nifi.controller.FlowController 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)

Example 10 with FlowController

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

the class TestStandardControllerServiceProvider method validateEnableServices.

@Test
public void validateEnableServices() {
    StandardProcessScheduler scheduler = createScheduler();
    FlowController controller = Mockito.mock(FlowController.class);
    StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties);
    ProcessGroup procGroup = new MockProcessGroup(controller);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);
    ControllerServiceNode A = provider.createControllerService(ServiceA.class.getName(), "A", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode B = provider.createControllerService(ServiceA.class.getName(), "B", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode C = provider.createControllerService(ServiceA.class.getName(), "C", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode D = provider.createControllerService(ServiceB.class.getName(), "D", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode E = provider.createControllerService(ServiceA.class.getName(), "E", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode F = provider.createControllerService(ServiceB.class.getName(), "F", systemBundle.getBundleDetails().getCoordinate(), null, false);
    procGroup.addControllerService(A);
    procGroup.addControllerService(B);
    procGroup.addControllerService(C);
    procGroup.addControllerService(D);
    procGroup.addControllerService(E);
    procGroup.addControllerService(F);
    setProperty(A, ServiceA.OTHER_SERVICE.getName(), "B");
    setProperty(B, ServiceA.OTHER_SERVICE.getName(), "D");
    setProperty(C, ServiceA.OTHER_SERVICE.getName(), "B");
    setProperty(C, ServiceA.OTHER_SERVICE_2.getName(), "D");
    setProperty(E, ServiceA.OTHER_SERVICE.getName(), "A");
    setProperty(E, ServiceA.OTHER_SERVICE_2.getName(), "F");
    provider.enableControllerServices(Arrays.asList(A, B, C, D, E, F));
    assertTrue(A.isActive());
    assertTrue(B.isActive());
    assertTrue(C.isActive());
    assertTrue(D.isActive());
    assertTrue(E.isActive());
    assertTrue(F.isActive());
}
Also used : ServiceB(org.apache.nifi.controller.service.mock.ServiceB) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) 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

FlowController (org.apache.nifi.controller.FlowController)16 ProcessGroup (org.apache.nifi.groups.ProcessGroup)10 Test (org.junit.Test)9 MockProcessGroup (org.apache.nifi.controller.service.mock.MockProcessGroup)7 StandardProcessScheduler (org.apache.nifi.controller.scheduling.StandardProcessScheduler)6 ServiceA (org.apache.nifi.controller.service.mock.ServiceA)6 ServiceB (org.apache.nifi.controller.service.mock.ServiceB)6 StandardProcessGroup (org.apache.nifi.groups.StandardProcessGroup)6 AuditService (org.apache.nifi.admin.service.AuditService)3 Authorizer (org.apache.nifi.authorization.Authorizer)3 FlowFileEventRepository (org.apache.nifi.controller.repository.FlowFileEventRepository)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 AuthorizationRequest (org.apache.nifi.authorization.AuthorizationRequest)2 ProcessorNode (org.apache.nifi.controller.ProcessorNode)2 ServiceC (org.apache.nifi.controller.service.mock.ServiceC)2 StringEncryptor (org.apache.nifi.encrypt.StringEncryptor)2 VolatileBulletinRepository (org.apache.nifi.events.VolatileBulletinRepository)2