Java Code Examples for org.apache.nifi.controller.ProcessorNode#setProperties()

The following examples show how to use org.apache.nifi.controller.ProcessorNode#setProperties() . 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: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    final ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    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);
    ps.startProcessor(testProcNode);
    ps.startProcessor(testProcNode);

    Thread.sleep(500);
    assertEquals(1, testProcessor.operationNames.size());
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
}
 
Example 2
Source File: ProcessorLifecycleIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 FlowManagerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    flowManager = fcsb.getFlowManager();

    ProcessGroup testGroup = flowManager.createProcessGroup(UUID.randomUUID().toString());
    final ProcessorNode testProcNode = flowManager.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);

    testProcNode.performValidation();
    processScheduler.startProcessor(testProcNode, true);
    processScheduler.startProcessor(testProcNode, true);
    processScheduler.startProcessor(testProcNode, true);

    Thread.sleep(500);
    assertCondition(() -> testProcessor.operationNames.size() == 1);
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
}
 
Example 3
Source File: ParametersIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testParameterSubstitutionWithinELWhenELIsSupported() throws ExecutionException, InterruptedException {
    final ProcessorNode generate = createProcessorNode(GenerateProcessor.class);
    final ProcessorNode updateAttribute = createProcessorNode(UpdateAttributeWithEL.class);
    final ProcessorNode terminate = getTerminateProcessor();

    final Connection generatedFlowFileConnection = connect(generate, updateAttribute, REL_SUCCESS);
    final Connection updatedAttributeConnection = connect(updateAttribute, terminate, REL_SUCCESS);

    final ParameterReferenceManager referenceManager = new StandardParameterReferenceManager(getFlowController().getFlowManager());
    final ParameterContext parameterContext = new StandardParameterContext(UUID.randomUUID().toString(), "param-context", referenceManager, null);
    parameterContext.setParameters(Collections.singletonMap("test", new Parameter(new ParameterDescriptor.Builder().name("test").build(), "unit")));

    getRootGroup().setParameterContext(parameterContext);
    updateAttribute.setProperties(Collections.singletonMap("test", "${#{test}:toUpper()}"));

    triggerOnce(generate);
    triggerOnce(updateAttribute);

    final FlowFileQueue flowFileQueue = updatedAttributeConnection.getFlowFileQueue();
    final FlowFileRecord flowFileRecord = flowFileQueue.poll(Collections.emptySet());

    assertEquals("UNIT", flowFileRecord.getAttribute("test"));
}
 
Example 4
Source File: ParametersIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testParameterSubstitutionWithinELWhenELNotSupported() throws ExecutionException, InterruptedException {
    final ProcessorNode generate = createProcessorNode(GenerateProcessor.class);
    final ProcessorNode updateAttribute = createProcessorNode(UpdateAttributeNoEL.class);
    final ProcessorNode terminate = getTerminateProcessor();

    final Connection generatedFlowFileConnection = connect(generate, updateAttribute, REL_SUCCESS);
    final Connection updatedAttributeConnection = connect(updateAttribute, terminate, REL_SUCCESS);

    final ParameterReferenceManager referenceManager = new StandardParameterReferenceManager(getFlowController().getFlowManager());
    final ParameterContext parameterContext = new StandardParameterContext(UUID.randomUUID().toString(), "param-context", referenceManager, null);
    parameterContext.setParameters(Collections.singletonMap("test", new Parameter(new ParameterDescriptor.Builder().name("test").build(), "unit")));

    getRootGroup().setParameterContext(parameterContext);
    updateAttribute.setProperties(Collections.singletonMap("test", "${#{test}:toUpper()}"));

    triggerOnce(generate);
    triggerOnce(updateAttribute);

    final FlowFileQueue flowFileQueue = updatedAttributeConnection.getFlowFileQueue();
    final FlowFileRecord flowFileRecord = flowFileQueue.poll(Collections.emptySet());

    assertEquals("${unit:toUpper()}", flowFileRecord.getAttribute("test"));
}
 
Example 5
Source File: ProcessorLifecycleIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that the Processor can be stopped when @OnScheduled blocks
 * indefinitely and written to ignore thread interrupts
 */
@Test
public void validateProcessorCanBeStoppedWhenOnScheduledBlocksIndefinitelyUninterruptable() throws Exception {
    final FlowManagerAndSystemBundle fcsb = this.buildFlowControllerForTest(NiFiProperties.PROCESSOR_SCHEDULING_TIMEOUT, "1 sec");
    flowManager = fcsb.getFlowManager();

    ProcessGroup testGroup = flowManager.createProcessGroup(UUID.randomUUID().toString());
    ProcessorNode testProcNode = flowManager.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);

    testProcNode.performValidation();
    processScheduler.startProcessor(testProcNode, true);
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), MEDIUM_DELAY_TOLERANCE);
    processScheduler.stopProcessor(testProcNode);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState(), MEDIUM_DELAY_TOLERANCE);
}
 
Example 6
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Validate that processor will not be validated on failing
 * ControllerService validation (not enabled).
 */
@Test(expected = IllegalStateException.class)
public void validateStartFailsOnInvalidProcessorWithDisabledService() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);

    ControllerServiceNode testServiceNode = fc.createControllerService(TestService.class.getName(), "serv", true);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());

    properties.put("S", testServiceNode.getIdentifier());
    testProcNode.setProperties(properties);

    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    testProcessor.withService = true;

    ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNode);
    fail();
}
 
Example 7
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that the Processor can be stopped when @OnScheduled blocks
 * indefinitely but written to react to thread interrupts
 */
@Test
public void validateProcessorCanBeStoppedWhenOnScheduledBlocksIndefinitelyInterruptable() throws Exception {
    this.fc = buildFlowControllerForTest(NiFiProperties.PROCESSOR_SCHEDULING_TIMEOUT, "5 sec");
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    // sets the scenario for the processor to run
    this.blockingInterruptableOnUnschedule(testProcessor);
    ProcessScheduler ps = fc.getProcessScheduler();

    ps.startProcessor(testProcNode);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    ps.stopProcessor(testProcNode);
    Thread.sleep(100);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STOPPING);
    Thread.sleep(4000);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
}
 
Example 8
Source File: ProcessorLifecycleIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that stop calls are harmless and idempotent if processor is not
 * in STARTING or RUNNING state.
 */
@Test
public void validateStopCallsAreMeaninglessIfProcessorNotStarted() throws Exception {
    final FlowManagerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    flowManager = fcsb.getFlowManager();
    ProcessGroup testGroup = flowManager.createProcessGroup(UUID.randomUUID().toString());
    final ProcessorNode testProcNode = flowManager.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(),
            fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState());
    // sets the scenario for the processor to run
    int randomDelayLimit = 3000;
    this.randomOnTriggerDelay(testProcessor, randomDelayLimit);

    processScheduler.stopProcessor(testProcNode);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState());
    assertTrue(testProcessor.operationNames.isEmpty());
}
 
Example 9
Source File: ParametersIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testSensitivePropertyNotAccessibleFromWithinEL() {
    final ProcessorNode usernamePassword = createProcessorNode(UsernamePasswordProcessor.class);

    final ParameterReferenceManager referenceManager = new StandardParameterReferenceManager(getFlowController().getFlowManager());
    final ParameterContext parameterContext = new StandardParameterContext(UUID.randomUUID().toString(), "param-context", referenceManager, null);
    parameterContext.setParameters(Collections.singletonMap("pass", new Parameter(new ParameterDescriptor.Builder().name("pass").sensitive(true).build(), "secret")));

    getRootGroup().setParameterContext(parameterContext);

    final Map<String, String> properties = new HashMap<>();
    properties.put("username", "${#{pass}}");

    try {
        usernamePassword.setProperties(properties);
        Assert.fail("Was able to set properties when referencing sensitive parameter from within EL");
    } catch (final IllegalArgumentException iae) {
        // Expected. Since the parameter is sensitive, it may referenced by a sensitive property
    }
}
 
Example 10
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that Processor is eventually started once invocation of
 *
 * @OnSchedule stopped throwing exceptions.
 */
@Test
public void validateProcessScheduledAfterAdministrativeDelayDueToTheOnScheduledException() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();

    // sets the scenario for the processor to run
    this.noop(testProcessor);
    testProcessor.generateExceptionOnScheduled = true;
    testProcessor.keepFailingOnScheduledTimes = 2;
    ProcessScheduler ps = fc.getProcessScheduler();

    ps.startProcessor(testProcNode);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    Thread.sleep(100);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);
    ps.stopProcessor(testProcNode);
    Thread.sleep(500);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
}
 
Example 11
Source File: ControllerServiceReferenceIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testReferenceCounts() {
    final String FIRST_PROPERTY = "Counter Service";
    final String SECOND_PROPERTY = "Another Counter Service";

    final ControllerServiceNode serviceNode = createControllerServiceNode(LongValidatingControllerService.class.getName());
    serviceNode.setProperties(Collections.singletonMap(LongValidatingControllerService.DELAY.getName(), "250 millis"));

    final ProcessorNode counter = createProcessorNode(MultipleControllerServiceReferencingProcessor.class);
    final Map<String, String> properties = new HashMap<>();

    // Add a reference of the service node in the first property of the processor
    properties.put(FIRST_PROPERTY, serviceNode.getIdentifier());
    counter.setProperties(properties);
    assertEquals(1, serviceNode.getReferences().getReferencingComponents().size());

    // Add another reference of the same service node in the second property of the processor
    properties.put(SECOND_PROPERTY, serviceNode.getIdentifier());
    counter.setProperties(properties);
    assertEquals(1, serviceNode.getReferences().getReferencingComponents().size());

    // Remove the reference of the service node from the first property of the processor
    properties.put(FIRST_PROPERTY, null);
    counter.setProperties(properties);
    // The counter should still be one because the service node is still referenced by the processor in its second property
    assertEquals(1, serviceNode.getReferences().getReferencingComponents().size());

    // Remove also the reference of the service node from the second property of the processor
    properties.put(SECOND_PROPERTY, null);
    counter.setProperties(properties);
    // The counter should become 0 because now the service node is not reference anymore in any processor property
    assertEquals(0, serviceNode.getReferences().getReferencingComponents().size());
}
 
Example 12
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that processor can be stopped before start sequence finished.
 */
@Test
public void validateProcessorUnscheduledAndStoppedWhenStopIsCalledBeforeProcessorFullyStarted() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();

    // sets the scenario for the processor to run
    int delay = 2000;
    this.longRunningOnSchedule(testProcessor, delay);
    ProcessScheduler ps = fc.getProcessScheduler();

    ps.startProcessor(testProcNode);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);

    ps.stopProcessor(testProcNode);
    Thread.sleep(100);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STOPPING);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
    Thread.sleep(1000);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);

    assertEquals(2, testProcessor.operationNames.size());
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
    assertEquals("@OnUnscheduled", testProcessor.operationNames.get(1));
}
 
Example 13
Source File: ControllerServiceReferenceIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testCallingControllerService() throws ExecutionException, InterruptedException {
    final ProcessorNode counter = createProcessorNode(ControllerServiceReferencingProcessor.class.getName());

    final ControllerServiceNode serviceNode = createControllerServiceNode(CounterControllerService.class.getName());
    assertSame(ValidationStatus.VALID, serviceNode.performValidation());
    getFlowController().getControllerServiceProvider().enableControllerService(serviceNode).get();

    counter.setAutoTerminatedRelationships(Collections.singleton(REL_SUCCESS));
    counter.setProperties(Collections.singletonMap("Counter Service", serviceNode.getIdentifier()));

    triggerOnce(counter);

    assertEquals(1, ((Counter) serviceNode.getControllerServiceImplementation()).getValue());
}
 
Example 14
Source File: ParametersIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterReferenceCounts() {
    final ProcessorNode updateAttribute = createProcessorNode(UpdateAttributeWithEL.class);

    final ParameterReferenceManager referenceManager = new StandardParameterReferenceManager(getFlowController().getFlowManager());
    final ParameterContext parameterContext = new StandardParameterContext(UUID.randomUUID().toString(), "param-context", referenceManager, null);
    parameterContext.setParameters(Collections.singletonMap("test", new Parameter(new ParameterDescriptor.Builder().name("test").build(), "unit")));

    getRootGroup().setParameterContext(parameterContext);

    final Map<String, String> properties = new HashMap<>();
    properties.put("test", "#{test} #{test}");
    updateAttribute.setProperties(properties);

    final Set<String> allParamNames = Collections.singleton("test");

    Set<String> referencedParameters = updateAttribute.getReferencedParameterNames();
    assertEquals(allParamNames, referencedParameters);

    properties.put("test", "#{test} #{test} #{test}");
    updateAttribute.setProperties(properties);
    referencedParameters = updateAttribute.getReferencedParameterNames();
    assertEquals(allParamNames, referencedParameters);

    properties.put("test", null);
    updateAttribute.setProperties(properties);
    referencedParameters = updateAttribute.getReferencedParameterNames();
    assertEquals(Collections.emptySet(), referencedParameters);

    properties.put("test", "#{test}");
    updateAttribute.setProperties(properties);
    referencedParameters = updateAttribute.getReferencedParameterNames();
    assertEquals(allParamNames, referencedParameters);
}
 
Example 15
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Validates the processors start/stop sequence where the order of
 * operations can only be @OnScheduled, @OnUnscheduled, @OnStopped.
 */
@Test
@Ignore
public void validateSuccessfullAndOrderlyShutdown() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();

    // sets the scenario for the processor to run
    int randomDelayLimit = 3000;
    this.randomOnTriggerDelay(testProcessor, randomDelayLimit);

    testProcNode.setMaxConcurrentTasks(4);
    testProcNode.setScheduldingPeriod("500 millis");
    testProcNode.setAutoTerminatedRelationships(Collections.singleton(new Relationship.Builder().name("success").build()));

    testGroup.addProcessor(testProcNode);

    fc.startProcessGroup(testGroup.getIdentifier());
    Thread.sleep(2000); // let it run for a while
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);

    fc.stopAllProcessors();

    Thread.sleep(randomDelayLimit); // up to randomDelayLimit, otherwise next assertion may fail as the processor still executing

    // validates that regardless of how many running tasks, lifecycle
    // operation are invoked atomically (once each).
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
    // . . . hence only 3 operations must be in the list
    assertEquals(3, testProcessor.operationNames.size());
    // . . . and ordered as @OnScheduled, @OnUnscheduled, @OnStopped
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
    assertEquals("@OnUnscheduled", testProcessor.operationNames.get(1));
    assertEquals("@OnStopped", testProcessor.operationNames.get(2));
}
 
Example 16
Source File: ProcessorParameterTokenIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void verifyText(final ProcessorNode procNode, final String text, final String password, final String expectedOutput) throws ExecutionException, InterruptedException {
    final Map<String, String> properties = new HashMap<>();
    properties.put(WriteText.TEXT.getName(), text);
    properties.put(WriteText.PASSWORD.getName(), password);

    procNode.setProperties(properties);
    triggerOnce(procNode);

    final WriteText writeText = (WriteText) procNode.getProcessor();
    final String textWritten = writeText.getTextLastWritten();

    assertEquals("For input text <" + text+ "> and password <" + password + ">, expected output was <" + expectedOutput + "> but got <" + textWritten + ">", expectedOutput, textWritten);
}
 
Example 17
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testChangeVersionFromExplicitValueToParameterSensitiveProperty() {
    // Create a processor with a sensitive property
    final ProcessorNode processorWithParamRef = createProcessorNode(UsernamePasswordProcessor.class);
    processorWithParamRef.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "#{secret-param}"));

    final ProcessorNode processorWithExplicitValue = createProcessorNode(UsernamePasswordProcessor.class);
    processorWithExplicitValue.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "secret-value"));


    // Create a VersionedFlowSnapshot that contains the processor
    final Parameter parameter = new Parameter(new ParameterDescriptor.Builder().name("secret-param").sensitive(true).build(), null);
    final VersionedFlowSnapshot versionedFlowWithParameterReference = createFlowSnapshot(Collections.emptyList(),
        Collections.singletonList(processorWithParamRef), Collections.singleton(parameter));

    final VersionedFlowSnapshot versionedFlowExplicitValue = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(processorWithExplicitValue), null);

    // Create child group and update to the first version of the flow, with parameter ref
    final ProcessGroup innerGroup = getFlowController().getFlowManager().createProcessGroup("inner-group-id");
    innerGroup.setName("Inner Group");
    getRootGroup().addProcessGroup(innerGroup);

    innerGroup.updateFlow(versionedFlowExplicitValue, null, true, true, true);

    final ProcessorNode nodeInGroupWithRef = innerGroup.getProcessors().iterator().next();
    assertNotNull(nodeInGroupWithRef.getProperty(UsernamePasswordProcessor.PASSWORD));


    // Update the flow to new version that uses explicit value.
    innerGroup.updateFlow(versionedFlowWithParameterReference, null, true, true, true);

    // Updated flow has sensitive property that no longer references parameter. Now is an explicit value, so it should be unset
    final ProcessorNode nodeInGroupWithNoValue = innerGroup.getProcessors().iterator().next();
    assertEquals("#{secret-param}", nodeInGroupWithNoValue.getProperty(UsernamePasswordProcessor.PASSWORD).getRawValue());
}
 
Example 18
Source File: ParametersIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testParametersInELFromNewPropertyValueAndText() throws ExecutionException, InterruptedException {
    final ProcessorNode generate = createProcessorNode(GenerateProcessor.class);
    final ProcessorNode updateAttribute = createProcessorNode(UpdateAttributeCreateOwnProperty.class);
    final ProcessorNode terminate = getTerminateProcessor();

    final Connection generatedFlowFileConnection = connect(generate, updateAttribute, REL_SUCCESS);
    final Connection updatedAttributeConnection = connect(updateAttribute, terminate, REL_SUCCESS);

    final ParameterReferenceManager referenceManager = new StandardParameterReferenceManager(getFlowController().getFlowManager());
    final ParameterContext parameterContext = new StandardParameterContext(UUID.randomUUID().toString(), "param-context", referenceManager, null);
    parameterContext.setParameters(Collections.singletonMap("test", new Parameter(new ParameterDescriptor.Builder().name("test").build(), "unit")));

    getRootGroup().setParameterContext(parameterContext);

    final Map<String, String> properties = new HashMap<>();
    properties.put("bar", "${#{test}:toUpper()}");
    updateAttribute.setProperties(properties);

    triggerOnce(generate);
    triggerOnce(updateAttribute);

    final FlowFileQueue flowFileQueue = updatedAttributeConnection.getFlowFileQueue();
    final FlowFileRecord flowFileRecord = flowFileQueue.poll(Collections.emptySet());

    assertEquals("UNIT", flowFileRecord.getAttribute("bar"));
}
 
Example 19
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testImportFlowWithProcessorAndControllerService() throws ExecutionException, InterruptedException {
    // Build a Versioned Flow that consists of a Controller Service and a Processor
    // that references that Controller Service.
    final ControllerServiceNode controllerService = createControllerServiceNode(LongValidatingControllerService.class);
    controllerService.setProperties(Collections.singletonMap(LongValidatingControllerService.DELAY.getName(), "250 millis"));

    final ProcessorNode processor = createProcessorNode(NopServiceReferencingProcessor.class);
    processor.setAutoTerminatedRelationships(Collections.singleton(REL_SUCCESS));
    processor.setProperties(Collections.singletonMap(NopServiceReferencingProcessor.SERVICE.getName(), controllerService.getIdentifier()));

    final VersionedFlowSnapshot proposedFlow = createFlowSnapshot(Collections.singletonList(controllerService), Collections.singletonList(processor), null);

    // Create an Inner Process Group and update it to match the Versioned Flow.
    final ProcessGroup innerGroup = getFlowController().getFlowManager().createProcessGroup("inner-group-id");
    innerGroup.setName("Inner Group");
    getRootGroup().addProcessGroup(innerGroup);

    innerGroup.updateFlow(proposedFlow, null, false, true, false);

    // Ensure that the controller service is valid and enable it.
    final Set<ControllerServiceNode> serviceNodes = innerGroup.findAllControllerServices();
    assertEquals(1, serviceNodes.size());

    final ControllerServiceNode serviceNode = serviceNodes.iterator().next();
    final ValidationStatus validationStatus = serviceNode.performValidation();
    assertEquals(ValidationStatus.VALID, validationStatus);
    getFlowController().getControllerServiceProvider().enableControllerService(serviceNode).get();
    assertTrue(serviceNode.isActive());

    // Ensure that the processor is valid.
    final List<ProcessorNode> processorNodes = innerGroup.findAllProcessors();
    assertEquals(1, processorNodes.size());

    final ProcessorNode procNode = processorNodes.get(0);
    final ValidationStatus procValidationStatus = procNode.performValidation();
    final Collection<ValidationResult> validationErrors = procNode.getValidationErrors();
    System.out.println(validationErrors);
    assertEquals(Collections.emptyList(), validationErrors);
    assertEquals(ValidationStatus.VALID, procValidationStatus);

    // Ensure that the reference to the controller service was properly updated
    final String referencedServiceId = procNode.getEffectivePropertyValue(NopServiceReferencingProcessor.SERVICE);
    assertEquals(serviceNode.getIdentifier(), referencedServiceId);
    assertNotEquals("service-id", referencedServiceId);
}
 
Example 20
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Concurrency test that is basically hammers on both stop and start
 * operation validating their idempotency.
 */
@Test
@Ignore
public void validateLifecycleOperationOrderWithConcurrentCallsToStartStop() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    final ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    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);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
    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);
                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();
}