Java Code Examples for org.apache.nifi.groups.ProcessGroup#addControllerService()

The following examples show how to use org.apache.nifi.groups.ProcessGroup#addControllerService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ControllerServiceLoader.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public static Map<ControllerServiceNode, Element> loadControllerServices(final List<Element> serviceElements, final FlowController controller,
                                                                         final ProcessGroup parentGroup, final StringEncryptor encryptor) {

    final Map<ControllerServiceNode, Element> nodeMap = new HashMap<>();
    for (final Element serviceElement : serviceElements) {
        final ControllerServiceNode serviceNode = createControllerService(controller, serviceElement, encryptor);
        if (parentGroup == null) {
            controller.addRootControllerService(serviceNode);
        } else {
            parentGroup.addControllerService(serviceNode);
        }

        // We need to clone the node because it will be used in a separate thread below, and
        // Element is not thread-safe.
        nodeMap.put(serviceNode, (Element) serviceElement.cloneNode(true));
    }
    for (final Map.Entry<ControllerServiceNode, Element> entry : nodeMap.entrySet()) {
        configureControllerService(entry.getKey(), entry.getValue(), encryptor);
    }

    return nodeMap;
}
 
Example 2
Source File: ControllerServiceLoader.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static Map<ControllerServiceNode, Element> loadControllerServices(final List<Element> serviceElements, final FlowController controller,
                                                                         final ProcessGroup parentGroup, final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) {

    final Map<ControllerServiceNode, Element> nodeMap = new HashMap<>();
    for (final Element serviceElement : serviceElements) {
        final ControllerServiceNode serviceNode = createControllerService(controller, serviceElement, encryptor, encodingVersion);
        if (parentGroup == null) {
            controller.getFlowManager().addRootControllerService(serviceNode);
        } else {
            parentGroup.addControllerService(serviceNode);
        }

        // We need to clone the node because it will be used in a separate thread below, and
        // Element is not thread-safe.
        nodeMap.put(serviceNode, (Element) serviceElement.cloneNode(true));
    }
    for (final Map.Entry<ControllerServiceNode, Element> entry : nodeMap.entrySet()) {
        configureControllerService(entry.getKey(), entry.getValue(), encryptor, encodingVersion);
    }

    return nodeMap;
}
 
Example 3
Source File: StandardControllerServiceDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ControllerServiceNode createControllerService(final ControllerServiceDTO controllerServiceDTO) {
    // ensure the type is specified
    if (controllerServiceDTO.getType() == null) {
        throw new IllegalArgumentException("The controller service type must be specified.");
    }

    try {
        // create the controller service
        final ControllerServiceNode controllerService = serviceProvider.createControllerService(controllerServiceDTO.getType(), controllerServiceDTO.getId(), true);

        // ensure we can perform the update
        verifyUpdate(controllerService, controllerServiceDTO);

        // perform the update
        configureControllerService(controllerService, controllerServiceDTO);

        final String groupId = controllerServiceDTO.getParentGroupId();
        if (groupId == null) {
            flowController.addRootControllerService(controllerService);
        } else {
            final ProcessGroup group;
            if (groupId.equals(ROOT_GROUP_ID_ALIAS)) {
                group = flowController.getGroup(flowController.getRootGroupId());
            } else {
                group = flowController.getGroup(flowController.getRootGroupId()).findProcessGroup(groupId);
            }

            if (group == null) {
                throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
            }

            group.addControllerService(controllerService);
        }

        return controllerService;
    } catch (final ControllerServiceInstantiationException csie) {
        throw new NiFiCoreException(csie.getMessage(), csie);
    }
}
 
Example 4
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * The successful processor start with ControllerService dependency.
 */
@Test
public void validateStartSucceedsOnProcessorWithEnabledService() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);

    ControllerServiceNode testServiceNode = fc.createControllerService(TestService.class.getName(), "foo", true);
    testGroup.addControllerService(testServiceNode);

    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    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);

    Thread.sleep(500);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);
}
 
Example 5
Source File: TestStandardControllerServiceProvider.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void validateEnableServices() {
    StandardProcessScheduler scheduler = createScheduler();
    FlowController controller = Mockito.mock(FlowController.class);
    StandardControllerServiceProvider provider =
            new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null));
    ProcessGroup procGroup = new MockProcessGroup();
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);

    ControllerServiceNode A = provider.createControllerService(ServiceA.class.getName(), "A", false);
    ControllerServiceNode B = provider.createControllerService(ServiceA.class.getName(), "B", false);
    ControllerServiceNode C = provider.createControllerService(ServiceA.class.getName(), "C", false);
    ControllerServiceNode D = provider.createControllerService(ServiceB.class.getName(), "D", false);
    ControllerServiceNode E = provider.createControllerService(ServiceA.class.getName(), "E", false);
    ControllerServiceNode F = provider.createControllerService(ServiceB.class.getName(), "F", 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());
}
 
Example 6
Source File: TestStandardControllerServiceProvider.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * This test is similar to the above, but different combination of service
 * dependencies
 *
 */
@Test
public void validateEnableServices2() {
    StandardProcessScheduler scheduler = createScheduler();
    FlowController controller = Mockito.mock(FlowController.class);
    StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null,
            stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null));
    ProcessGroup procGroup = new MockProcessGroup();
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);

    ControllerServiceNode A = provider.createControllerService(ServiceC.class.getName(), "A", false);
    ControllerServiceNode B = provider.createControllerService(ServiceA.class.getName(), "B", false);
    ControllerServiceNode C = provider.createControllerService(ServiceB.class.getName(), "C", false);
    ControllerServiceNode D = provider.createControllerService(ServiceA.class.getName(), "D", false);
    ControllerServiceNode F = provider.createControllerService(ServiceA.class.getName(), "F", false);

    procGroup.addControllerService(A);
    procGroup.addControllerService(B);
    procGroup.addControllerService(C);
    procGroup.addControllerService(D);
    procGroup.addControllerService(F);

    setProperty(A, ServiceC.REQ_SERVICE_1.getName(), "B");
    setProperty(A, ServiceC.REQ_SERVICE_2.getName(), "D");
    setProperty(B, ServiceA.OTHER_SERVICE.getName(), "C");

    setProperty(F, ServiceA.OTHER_SERVICE.getName(), "D");
    setProperty(D, ServiceA.OTHER_SERVICE.getName(), "C");

    provider.enableControllerServices(Arrays.asList(C, F, A, B, D));

    assertTrue(A.isActive());
    assertTrue(B.isActive());
    assertTrue(C.isActive());
    assertTrue(D.isActive());
    assertTrue(F.isActive());
}
 
Example 7
Source File: TestFlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteProcessGroup() {
    ProcessGroup pg = controller.createProcessGroup("my-process-group");
    pg.setName("my-process-group");
    ControllerServiceNode cs = controller.createControllerService("org.apache.nifi.NonExistingControllerService", "my-controller-service", false);
    pg.addControllerService(cs);
    controller.getRootGroup().addProcessGroup(pg);
    controller.getRootGroup().removeProcessGroup(pg);
    pg.getControllerServices(true);
    assertTrue(pg.getControllerServices(true).isEmpty());
}
 
Example 8
Source File: TestFlowController.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteProcessGroup() {
    ProcessGroup pg = controller.getFlowManager().createProcessGroup("my-process-group");
    pg.setName("my-process-group");
    ControllerServiceNode cs = controller.getFlowManager().createControllerService("org.apache.nifi.NonExistingControllerService", "my-controller-service",
            systemBundle.getBundleDetails().getCoordinate(), null, false, true);
    pg.addControllerService(cs);
    controller.getFlowManager().getRootGroup().addProcessGroup(pg);
    controller.getFlowManager().getRootGroup().removeProcessGroup(pg);
    pg.getControllerServices(true);
    assertTrue(pg.getControllerServices(true).isEmpty());
}
 
Example 9
Source File: TestStandardControllerServiceProvider.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
public void testEnableReferencingServicesGraph(final ProcessScheduler scheduler) {
    final ProcessGroup procGroup = new MockProcessGroup();
    final FlowController controller = Mockito.mock(FlowController.class);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);

    final StandardControllerServiceProvider provider =
            new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null));

    // 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", false);
    final ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceA.class.getName(), "2", false);
    final ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", false);
    final ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", 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()));
    }
}
 
Example 10
Source File: TestStandardControllerServiceProvider.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void validateEnableServicesWithDisabledMissingService() {
    StandardProcessScheduler scheduler = createScheduler();
    FlowController controller = Mockito.mock(FlowController.class);
    StandardControllerServiceProvider provider =
            new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null));
    ProcessGroup procGroup = new MockProcessGroup();
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);

    ControllerServiceNode serviceNode1 = provider.createControllerService(ServiceA.class.getName(), "1", false);
    ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceA.class.getName(), "2", false);
    ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", false);
    ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", false);
    ControllerServiceNode serviceNode5 = provider.createControllerService(ServiceA.class.getName(), "5", false);
    ControllerServiceNode serviceNode6 = provider.createControllerService(ServiceB.class.getName(), "6", false);
    ControllerServiceNode serviceNode7 = provider.createControllerService(ServiceC.class.getName(), "7", false);

    procGroup.addControllerService(serviceNode1);
    procGroup.addControllerService(serviceNode2);
    procGroup.addControllerService(serviceNode3);
    procGroup.addControllerService(serviceNode4);
    procGroup.addControllerService(serviceNode5);
    procGroup.addControllerService(serviceNode6);
    procGroup.addControllerService(serviceNode7);

    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");
    setProperty(serviceNode5, ServiceA.OTHER_SERVICE.getName(), "6");
    setProperty(serviceNode7, ServiceC.REQ_SERVICE_1.getName(), "2");
    setProperty(serviceNode7, ServiceC.REQ_SERVICE_2.getName(), "3");

    provider.enableControllerServices(Arrays.asList(
            serviceNode1, serviceNode2, serviceNode3, serviceNode4, serviceNode5, serviceNode7));
    assertFalse(serviceNode1.isActive());
    assertFalse(serviceNode2.isActive());
    assertFalse(serviceNode3.isActive());
    assertFalse(serviceNode4.isActive());
    assertFalse(serviceNode5.isActive());
    assertFalse(serviceNode6.isActive());

    provider.enableControllerService(serviceNode6);
    provider.enableControllerServices(Arrays.asList(
            serviceNode1, serviceNode2, serviceNode3, serviceNode4, serviceNode5));

    assertTrue(serviceNode1.isActive());
    assertTrue(serviceNode2.isActive());
    assertTrue(serviceNode3.isActive());
    assertTrue(serviceNode4.isActive());
    assertTrue(serviceNode5.isActive());
    assertTrue(serviceNode6.isActive());
}
 
Example 11
Source File: StandardControllerServiceDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ControllerServiceNode createControllerService(final ControllerServiceDTO controllerServiceDTO) {
    // ensure the type is specified
    if (controllerServiceDTO.getType() == null) {
        throw new IllegalArgumentException("The controller service type must be specified.");
    }

    try {
        // create the controller service
        final ExtensionManager extensionManager = serviceProvider.getExtensionManager();
        final FlowManager flowManager = flowController.getFlowManager();
        final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(extensionManager, controllerServiceDTO.getType(), controllerServiceDTO.getBundle());
        final ControllerServiceNode controllerService = flowManager.createControllerService(controllerServiceDTO.getType(), controllerServiceDTO.getId(), bundleCoordinate,
            Collections.emptySet(), true, true);

        // ensure we can perform the update
        verifyUpdate(controllerService, controllerServiceDTO);

        // perform the update
        configureControllerService(controllerService, controllerServiceDTO);

        final String groupId = controllerServiceDTO.getParentGroupId();
        if (groupId == null) {
            flowManager.addRootControllerService(controllerService);
        } else {
            final ProcessGroup group;
            if (groupId.equals(FlowManager.ROOT_GROUP_ID_ALIAS)) {
                group = flowManager.getRootGroup();
            } else {
                group = flowManager.getRootGroup().findProcessGroup(groupId);
            }

            if (group == null) {
                throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
            }

            group.addControllerService(controllerService);
        }

        return controllerService;
    } catch (final ControllerServiceInstantiationException csie) {
        throw new NiFiCoreException(csie.getMessage(), csie);
    }
}
 
Example 12
Source File: StandardControllerServiceProviderIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
public void testEnableReferencingServicesGraph(final StandardProcessScheduler scheduler) throws InterruptedException, ExecutionException {
    final FlowController controller = Mockito.mock(FlowController.class);

    final ProcessGroup procGroup = new MockProcessGroup(controller);
    final FlowManager flowManager = Mockito.mock(FlowManager.class);
    Mockito.when(controller.getFlowManager()).thenReturn(flowManager);

    Mockito.when(flowManager.getGroup(Mockito.anyString())).thenReturn(procGroup);
    Mockito.when(controller.getExtensionManager()).thenReturn(extensionManager);

    final ControllerServiceProvider serviceProvider = new StandardControllerServiceProvider(controller, scheduler, null);

    // 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 = createControllerService(ServiceA.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), serviceProvider);
    final ControllerServiceNode serviceNode2 = createControllerService(ServiceA.class.getName(), "2", systemBundle.getBundleDetails().getCoordinate(), serviceProvider);
    final ControllerServiceNode serviceNode3 = createControllerService(ServiceA.class.getName(), "3", systemBundle.getBundleDetails().getCoordinate(), serviceProvider);
    final ControllerServiceNode serviceNode4 = createControllerService(ServiceB.class.getName(), "4", systemBundle.getBundleDetails().getCoordinate(), serviceProvider);

    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");

    serviceNode4.performValidation();
    serviceProvider.enableControllerService(serviceNode4).get();
    serviceProvider.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()));
    }
}
 
Example 13
Source File: TestStandardControllerServiceProvider.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void validateEnableServices() {
    final FlowManager flowManager = Mockito.mock(FlowManager.class);

    StandardProcessScheduler scheduler = createScheduler();
    FlowController controller = Mockito.mock(FlowController.class);
    Mockito.when(controller.getFlowManager()).thenReturn(flowManager);

    StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null);
    ProcessGroup procGroup = new MockProcessGroup(controller);

    Mockito.when(flowManager.getGroup(Mockito.anyString())).thenReturn(procGroup);
    Mockito.when(controller.getExtensionManager()).thenReturn(extensionManager);

    ControllerServiceNode A = createControllerService(ServiceA.class.getName(), "A", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode B = createControllerService(ServiceA.class.getName(), "B", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode C = createControllerService(ServiceA.class.getName(), "C", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode D = createControllerService(ServiceB.class.getName(), "D", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode E = createControllerService(ServiceA.class.getName(), "E", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode F = createControllerService(ServiceB.class.getName(), "F", systemBundle.getBundleDetails().getCoordinate(), provider);

    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");

    final List<ControllerServiceNode> serviceNodes = Arrays.asList(A, B, C, D, E, F);
    serviceNodes.stream().forEach(ControllerServiceNode::performValidation);
    provider.enableControllerServices(serviceNodes);

    assertTrue(A.isActive());
    assertTrue(B.isActive());
    assertTrue(C.isActive());
    assertTrue(D.isActive());
    assertTrue(E.isActive());
    assertTrue(F.isActive());
}
 
Example 14
Source File: TestStandardControllerServiceProvider.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * This test is similar to the above, but different combination of service
 * dependencies
 *
 */
@Test
public void validateEnableServices2() {
    final FlowManager flowManager = Mockito.mock(FlowManager.class);

    StandardProcessScheduler scheduler = createScheduler();
    FlowController controller = Mockito.mock(FlowController.class);
    Mockito.when(controller.getFlowManager()).thenReturn(flowManager);

    StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null);
    ProcessGroup procGroup = new MockProcessGroup(controller);

    Mockito.when(flowManager.getGroup(Mockito.anyString())).thenReturn(procGroup);
    Mockito.when(controller.getExtensionManager()).thenReturn(extensionManager);

    ControllerServiceNode A = createControllerService(ServiceC.class.getName(), "A", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode B = createControllerService(ServiceA.class.getName(), "B", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode C = createControllerService(ServiceB.class.getName(), "C", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode D = createControllerService(ServiceA.class.getName(), "D", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode F = createControllerService(ServiceA.class.getName(), "F", systemBundle.getBundleDetails().getCoordinate(), provider);

    procGroup.addControllerService(A);
    procGroup.addControllerService(B);
    procGroup.addControllerService(C);
    procGroup.addControllerService(D);
    procGroup.addControllerService(F);

    setProperty(A, ServiceC.REQ_SERVICE_1.getName(), "B");
    setProperty(A, ServiceC.REQ_SERVICE_2.getName(), "D");
    setProperty(B, ServiceA.OTHER_SERVICE.getName(), "C");

    setProperty(F, ServiceA.OTHER_SERVICE.getName(), "D");
    setProperty(D, ServiceA.OTHER_SERVICE.getName(), "C");

    final List<ControllerServiceNode> services = Arrays.asList(C, F, A, B, D);
    services.forEach(ControllerServiceNode::performValidation);

    provider.enableControllerServices(services);

    assertTrue(A.isActive());
    assertTrue(B.isActive());
    assertTrue(C.isActive());
    assertTrue(D.isActive());
    assertTrue(F.isActive());
}
 
Example 15
Source File: TestStandardControllerServiceProvider.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void validateEnableServicesWithDisabledMissingService() {
    final FlowManager flowManager = Mockito.mock(FlowManager.class);

    StandardProcessScheduler scheduler = createScheduler();
    FlowController controller = Mockito.mock(FlowController.class);
    Mockito.when(controller.getFlowManager()).thenReturn(flowManager);

    StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null);
    ProcessGroup procGroup = new MockProcessGroup(controller);

    Mockito.when(flowManager.getGroup(Mockito.anyString())).thenReturn(procGroup);
    Mockito.when(controller.getExtensionManager()).thenReturn(extensionManager);

    ControllerServiceNode serviceNode1 = createControllerService(ServiceA.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode serviceNode2 = createControllerService(ServiceA.class.getName(), "2", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode serviceNode3 = createControllerService(ServiceA.class.getName(), "3", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode serviceNode4 = createControllerService(ServiceB.class.getName(), "4", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode serviceNode5 = createControllerService(ServiceA.class.getName(), "5", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode serviceNode6 = createControllerService(ServiceB.class.getName(), "6", systemBundle.getBundleDetails().getCoordinate(), provider);
    ControllerServiceNode serviceNode7 = createControllerService(ServiceC.class.getName(), "7", systemBundle.getBundleDetails().getCoordinate(), provider);

    procGroup.addControllerService(serviceNode1);
    procGroup.addControllerService(serviceNode2);
    procGroup.addControllerService(serviceNode3);
    procGroup.addControllerService(serviceNode4);
    procGroup.addControllerService(serviceNode5);
    procGroup.addControllerService(serviceNode6);
    procGroup.addControllerService(serviceNode7);

    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");
    setProperty(serviceNode5, ServiceA.OTHER_SERVICE.getName(), "6");
    setProperty(serviceNode7, ServiceC.REQ_SERVICE_1.getName(), "2");
    setProperty(serviceNode7, ServiceC.REQ_SERVICE_2.getName(), "3");

    final List<ControllerServiceNode> allBut6 = Arrays.asList(serviceNode1, serviceNode2, serviceNode3, serviceNode4, serviceNode5, serviceNode7);
    allBut6.stream().forEach(ControllerServiceNode::performValidation);

    provider.enableControllerServices(allBut6);
    assertFalse(serviceNode1.isActive());
    assertFalse(serviceNode2.isActive());
    assertFalse(serviceNode3.isActive());
    assertFalse(serviceNode4.isActive());
    assertFalse(serviceNode5.isActive());
    assertFalse(serviceNode6.isActive());

    serviceNode6.performValidation();
    provider.enableControllerService(serviceNode6);

    provider.enableControllerServices(Arrays.asList(
            serviceNode1, serviceNode2, serviceNode3, serviceNode4, serviceNode5));

    assertTrue(serviceNode1.isActive());
    assertTrue(serviceNode2.isActive());
    assertTrue(serviceNode3.isActive());
    assertTrue(serviceNode4.isActive());
    assertTrue(serviceNode5.isActive());
    assertTrue(serviceNode6.isActive());
}