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

The following examples show how to use org.apache.nifi.groups.ProcessGroup#updateFlow() . 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: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessGroup updateProcessGroupFlow(final String groupId, final VersionedFlowSnapshot proposedSnapshot, final VersionControlInformationDTO versionControlInformation,
                                           final String componentIdSeed, final boolean verifyNotModified, final boolean updateSettings, final boolean updateDescendantVersionedFlows) {

    final ProcessGroup group = locateProcessGroup(flowController, groupId);
    group.updateFlow(proposedSnapshot, componentIdSeed, verifyNotModified, updateSettings, updateDescendantVersionedFlows);
    group.findAllRemoteProcessGroups().forEach(RemoteProcessGroup::initialize);

    // process group being updated may not be versioned
    if (versionControlInformation != null) {
        final StandardVersionControlInformation svci = StandardVersionControlInformation.Builder.fromDto(versionControlInformation)
                .flowSnapshot(proposedSnapshot.getFlowContents())
                .build();
        group.setVersionControlInformation(svci, Collections.emptyMap());
    }

    group.onComponentModified();

    return group;
}
 
Example 2
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterCreatedWithNullValueOnImportWithSensitivePropertyReference() {
    // Create a processor with a sensitive property
    final ProcessorNode processor = createProcessorNode(UsernamePasswordProcessor.class);
    processor.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "#{secret-param}"));

    // 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(processor), Collections.singleton(parameter));

    // Create child group
    final ProcessGroup innerGroup = getFlowController().getFlowManager().createProcessGroup("inner-group-id");
    innerGroup.setName("Inner Group");
    getRootGroup().addProcessGroup(innerGroup);

    final ParameterReferenceManager parameterReferenceManager = new StandardParameterReferenceManager(getFlowController().getFlowManager());
    final ParameterContext parameterContext = new StandardParameterContext("param-context-id", "parameter-context", parameterReferenceManager, null);
    innerGroup.setParameterContext(parameterContext);

    assertTrue(parameterContext.getParameters().isEmpty());

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

    final Collection<Parameter> parameters = parameterContext.getParameters().values();
    assertEquals(1, parameters.size());

    final Parameter firstParameter = parameters.iterator().next();
    assertEquals("secret-param", firstParameter.getDescriptor().getName());
    assertTrue(firstParameter.getDescriptor().isSensitive());
    assertNull(firstParameter.getValue());
}
 
Example 3
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterContextCreatedOnImportWithSensitivePropertyReference() {
    // Create a processor with a sensitive property
    final ProcessorNode processor = createProcessorNode(UsernamePasswordProcessor.class);
    processor.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "#{secret-param}"));

    // 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(processor), Collections.singleton(parameter));

    // Create child group
    final ProcessGroup innerGroup = getFlowController().getFlowManager().createProcessGroup("inner-group-id");
    innerGroup.setName("Inner Group");
    getRootGroup().addProcessGroup(innerGroup);

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

    final ParameterContext parameterContext = innerGroup.getParameterContext();
    assertNotNull(parameterContext);

    final Collection<Parameter> parameters = parameterContext.getParameters().values();
    assertEquals(1, parameters.size());

    final Parameter firstParameter = parameters.iterator().next();
    assertEquals("secret-param", firstParameter.getDescriptor().getName());
    assertTrue(firstParameter.getDescriptor().isSensitive());
    assertNull(firstParameter.getValue());
}
 
Example 4
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testChangeVersionFromParameterToExplicitValueSensitiveProperty() {
    // Create a processor with a sensitive property
    final ProcessorNode initialProcessor = createProcessorNode(UsernamePasswordProcessor.class);
    initialProcessor.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "#{secret-param}"));

    // 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(initialProcessor), Collections.singleton(parameter));


    // Update processor to have an explicit value for the second version of the flow.
    initialProcessor.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "secret-value"));
    final VersionedFlowSnapshot versionedFlowExplicitValue = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(initialProcessor), 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(versionedFlowWithParameterReference, null, true, true, true);

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

    // Update the flow to new version that uses explicit value.
    innerGroup.updateFlow(versionedFlowExplicitValue, 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();
    assertNull(nodeInGroupWithNoValue.getProperty(UsernamePasswordProcessor.PASSWORD).getRawValue());
}
 
Example 5
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testChangeVersionFromParamReferenceToAnotherParamReferenceIsLocalModification() {
    // Create a processor with a sensitive property and create a versioned flow for it.
    final ProcessorNode initialProcessor = createProcessorNode(UsernamePasswordProcessor.class);
    final Map<String, String> initialProperties = new HashMap<>();
    initialProperties.put(UsernamePasswordProcessor.USERNAME.getName(), "user");
    initialProperties.put(UsernamePasswordProcessor.PASSWORD.getName(), "#{secret-param}");
    initialProcessor.setProperties(initialProperties);

    final VersionedFlowSnapshot initialVersionSnapshot = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(initialProcessor), null);

    // Update processor to have a different explicit value for both sensitive and non-sensitive properties and create a versioned flow for it.
    final Map<String, String> updatedProperties = new HashMap<>();
    updatedProperties.put(UsernamePasswordProcessor.USERNAME.getName(), "user");
    updatedProperties.put(UsernamePasswordProcessor.PASSWORD.getName(), "#{other-param}");
    initialProcessor.setProperties(updatedProperties);

    final VersionedFlowSnapshot updatedVersionSnapshot = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(initialProcessor), 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);

    // Import the flow into our newly created group
    innerGroup.updateFlow(initialVersionSnapshot, null, true, true, true);

    final Set<FlowDifference> localModifications = getLocalModifications(innerGroup, updatedVersionSnapshot);
    assertEquals(1, localModifications.size());
    assertEquals(DifferenceType.PROPERTY_CHANGED, localModifications.iterator().next().getDifferenceType());
}
 
Example 6
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 7
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 8
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testChangeVersionFromExplicitToExplicitValueDoesNotChangeSensitiveProperty() {
    // Create a processor with a sensitive property and create a versioned flow for it.
    final ProcessorNode initialProcessor = createProcessorNode(UsernamePasswordProcessor.class);
    final Map<String, String> initialProperties = new HashMap<>();
    initialProperties.put(UsernamePasswordProcessor.USERNAME.getName(), "user");
    initialProperties.put(UsernamePasswordProcessor.PASSWORD.getName(), "pass");
    initialProcessor.setProperties(initialProperties);

    final VersionedFlowSnapshot initialVersionSnapshot = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(initialProcessor), null);

    // Update processor to have a different explicit value for both sensitive and non-sensitive properties and create a versioned flow for it.
    final Map<String, String> updatedProperties = new HashMap<>();
    updatedProperties.put(UsernamePasswordProcessor.USERNAME.getName(), "other");
    updatedProperties.put(UsernamePasswordProcessor.PASSWORD.getName(), "pass");
    initialProcessor.setProperties(updatedProperties);

    final VersionedFlowSnapshot updatedVersionSnapshot = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(initialProcessor), 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);

    // Import the flow into our newly created group
    innerGroup.updateFlow(initialVersionSnapshot, null, true, true, true);

    final ProcessorNode initialImportedProcessor = innerGroup.getProcessors().iterator().next();
    assertEquals("user", initialImportedProcessor.getProperty(UsernamePasswordProcessor.USERNAME).getRawValue());
    assertNull("pass", initialImportedProcessor.getProperty(UsernamePasswordProcessor.PASSWORD).getRawValue());

    // Update the sensitive property to "pass"
    initialImportedProcessor.setProperties(initialProperties);
    assertEquals("pass", initialImportedProcessor.getProperty(UsernamePasswordProcessor.PASSWORD).getRawValue());

    // Update the flow to new version
    innerGroup.updateFlow(updatedVersionSnapshot, 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 updatedImportedProcessor = innerGroup.getProcessors().iterator().next();
    assertEquals("other", updatedImportedProcessor.getProperty(UsernamePasswordProcessor.USERNAME).getRawValue());
    assertEquals("pass", updatedImportedProcessor.getProperty(UsernamePasswordProcessor.PASSWORD).getRawValue());
}