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

The following examples show how to use org.apache.nifi.groups.ProcessGroup#setName() . 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 localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessGroup updateProcessGroup(ProcessGroupDTO processGroupDTO) {
    final ProcessGroup group = locateProcessGroup(flowController, processGroupDTO.getId());

    final String name = processGroupDTO.getName();
    final String comments = processGroupDTO.getComments();

    if (isNotNull(name)) {
        group.setName(name);
    }
    if (isNotNull(processGroupDTO.getPosition())) {
        group.setPosition(new Position(processGroupDTO.getPosition().getX(), processGroupDTO.getPosition().getY()));
    }
    if (isNotNull(comments)) {
        group.setComments(comments);
    }

    return group;
}
 
Example 2
Source File: FlowController.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the process group corresponding to the specified DTO. Any field
 * in DTO that is <code>null</code> (with the exception of the required ID)
 * will be ignored.
 *
 * @param dto group
 * @throws ProcessorInstantiationException
 *
 * @throws IllegalStateException if no process group can be found with the
 * ID of DTO or with the ID of the DTO's parentGroupId, if the template ID
 * specified is invalid, or if the DTO's Parent Group ID changes but the
 * parent group has incoming or outgoing connections
 *
 * @throws NullPointerException if the DTO or its ID is null
 */
public void updateProcessGroup(final ProcessGroupDTO dto) throws ProcessorInstantiationException {
    final ProcessGroup group = lookupGroup(requireNonNull(dto).getId());

    final String name = dto.getName();
    final PositionDTO position = dto.getPosition();
    final String comments = dto.getComments();

    if (name != null) {
        group.setName(name);
    }
    if (position != null) {
        group.setPosition(toPosition(position));
    }
    if (comments != null) {
        group.setComments(comments);
    }
}
 
Example 3
Source File: StandardProcessGroupDAO.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessGroup createProcessGroup(String parentGroupId, ProcessGroupDTO processGroup) {
    if (processGroup.getParentGroupId() != null && !flowController.areGroupsSame(processGroup.getParentGroupId(), parentGroupId)) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the Process Group is being added.");
    }

    // get the parent group
    ProcessGroup parentGroup = locateProcessGroup(flowController, parentGroupId);

    // create the process group
    ProcessGroup group = flowController.createProcessGroup(processGroup.getId());
    group.setName(processGroup.getName());
    if (processGroup.getPosition() != null) {
        group.setPosition(new Position(processGroup.getPosition().getX(), processGroup.getPosition().getY()));
    }

    // add the process group
    group.setParent(parentGroup);
    parentGroup.addProcessGroup(group);

    return group;
}
 
Example 4
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 5
Source File: StandardProcessGroupIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testComponentsAffectedByVariableOverridden() {
    final ProcessGroup child = getFlowController().getFlowManager().createProcessGroup("child");
    child.setName("Child");
    child.setVariables(Collections.singletonMap("number", "5"));

    getRootGroup().setVariables(Collections.singletonMap("number", "1"));
    getRootGroup().addProcessGroup(child);

    final ProcessorNode processor = createProcessorNode(NumberRefProcessor.class);
    processor.setProperties(Collections.singletonMap(NumberRefProcessor.NUMBER.getName(), "${number}"));
    moveProcessor(processor, child);

    final Set<ComponentNode> componentsAffected = child.getComponentsAffectedByVariable("number");
    assertEquals(1, componentsAffected.size());
    assertTrue(componentsAffected.contains(processor));

    final Set<ComponentNode> rootAffected = getRootGroup().getComponentsAffectedByVariable("number");
    assertTrue(rootAffected.isEmpty());

    processor.setScheduldingPeriod("1 hour");
    child.startProcessor(processor, false);

    getRootGroup().setVariables(Collections.singletonMap("number", "2"));

    try {
        child.setVariables(Collections.singletonMap("number", "10"));
        Assert.fail("Updated variable that is referenced by a running processor");
    } catch (final IllegalStateException ise) {
        // Expected
    }

    child.stopProcessor(processor);
}
 
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 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 8
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 9
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 10
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 11
Source File: StandardFlowSynchronizer.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the process group corresponding to the specified DTO. Any field
 * in DTO that is <code>null</code> (with the exception of the required ID)
 * will be ignored.
 *
 * @throws IllegalStateException if no process group can be found with the
 * ID of DTO or with the ID of the DTO's parentGroupId, if the template ID
 * specified is invalid, or if the DTO's Parent Group ID changes but the
 * parent group has incoming or outgoing connections
 *
 * @throws NullPointerException if the DTO or its ID is null
 */
private void updateProcessGroup(final ProcessGroup group, final ProcessGroupDTO dto, final ParameterContextManager parameterContextManager) {
    final String name = dto.getName();
    final PositionDTO position = dto.getPosition();
    final String comments = dto.getComments();
    final String flowfileConcurrencyName = dto.getFlowfileConcurrency();
    final String flowfileOutboundPolicyName = dto.getFlowfileOutboundPolicy();

    if (name != null) {
        group.setName(name);
    }
    if (position != null) {
        group.setPosition(toPosition(position));
    }
    if (comments != null) {
        group.setComments(comments);
    }

    if (flowfileConcurrencyName == null) {
        group.setFlowFileConcurrency(FlowFileConcurrency.UNBOUNDED);
    } else {
        group.setFlowFileConcurrency(FlowFileConcurrency.valueOf(flowfileConcurrencyName));
    }

    if (flowfileOutboundPolicyName == null) {
        group.setFlowFileOutboundPolicy(FlowFileOutboundPolicy.STREAM_WHEN_AVAILABLE);
    } else {
        group.setFlowFileOutboundPolicy(FlowFileOutboundPolicy.valueOf(flowfileOutboundPolicyName));
    }

    final ParameterContextReferenceEntity parameterContextReference = dto.getParameterContext();
    if (parameterContextReference != null && parameterContextReference.getId() != null) {
        final String parameterContextId = parameterContextReference.getId();
        final ParameterContext parameterContext = parameterContextManager.getParameterContext(parameterContextId);
        if (!Objects.equals(parameterContext, group.getParameterContext())) {
            group.setParameterContext(parameterContext);
        }
    }

}
 
Example 12
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessGroup createProcessGroup(String parentGroupId, ProcessGroupDTO processGroup) {
    final FlowManager flowManager = flowController.getFlowManager();
    if (processGroup.getParentGroupId() != null && !flowManager.areGroupsSame(processGroup.getParentGroupId(), parentGroupId)) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the Process Group is being added.");
    }

    // get the parent group
    ProcessGroup parentGroup = locateProcessGroup(flowController, parentGroupId);

    // create the process group
    ProcessGroup group = flowManager.createProcessGroup(processGroup.getId());
    if (processGroup.getName() != null) {
        group.setName(processGroup.getName());
    }
    if (processGroup.getPosition() != null) {
        group.setPosition(new Position(processGroup.getPosition().getX(), processGroup.getPosition().getY()));
    }

    final ParameterContextReferenceEntity parameterContextReference = processGroup.getParameterContext();
    if (parameterContextReference != null && parameterContextReference.getId() != null) {
        final ParameterContext parameterContext = flowController.getFlowManager().getParameterContextManager().getParameterContext(parameterContextReference.getId());
        group.setParameterContext(parameterContext);
    }

    // add the process group
    group.setParent(parentGroup);
    parentGroup.addProcessGroup(group);

    return group;
}
 
Example 13
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 14
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testLocalModificationWhenSensitivePropReferencesParameter() {
    // Create a processor with a sensitive property
    final ProcessorNode processor = createProcessorNode(UsernamePasswordProcessor.class);
    processor.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "password"));

    // Create a VersionedFlowSnapshot that contains the processor
    final VersionedFlowSnapshot versionedFlowWithExplicitValue = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(processor), null);

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

    // Move processor into the child group
    moveProcessor(processor, innerGroup);

    // Verify that there are no differences between the versioned flow and the Process Group
    Set<FlowDifference> differences = getLocalModifications(innerGroup, versionedFlowWithExplicitValue);
    assertEquals(0, differences.size());

    // Change the value of the sensitive property from one explicit value to another. Verify no local modifications.
    processor.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "secret"));
    differences = getLocalModifications(innerGroup, versionedFlowWithExplicitValue);
    assertEquals(0, differences.size());

    // Change the value of the sensitive property to now reference a parameter. There should be one local modification.
    processor.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "#{secret-parameter}"));
    differences = getLocalModifications(innerGroup, versionedFlowWithExplicitValue);
    assertEquals(1, differences.size());
    assertEquals(DifferenceType.PROPERTY_PARAMETERIZED, differences.iterator().next().getDifferenceType());

    // Create a Versioned Flow that contains the Parameter Reference.
    final VersionedFlowSnapshot versionedFlowWithParameterReference = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(processor), null);

    // Ensure no difference between the current configuration and the versioned flow
    differences = getLocalModifications(innerGroup, versionedFlowWithParameterReference);
    assertEquals(0, differences.size());

    processor.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "secret"));
    differences = getLocalModifications(innerGroup, versionedFlowWithParameterReference);
    assertEquals(1, differences.size());
    assertEquals(DifferenceType.PROPERTY_PARAMETERIZATION_REMOVED, differences.iterator().next().getDifferenceType());
}
 
Example 15
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 16
Source File: StandardFlowSynchronizer.java    From nifi with Apache License 2.0 4 votes vote down vote up
private ProcessGroup addProcessGroup(final FlowController controller, final ProcessGroup parentGroup, final Element processGroupElement,
        final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) {

    // get the parent group ID
    final String parentId = (parentGroup == null) ? null : parentGroup.getIdentifier();
    final FlowManager flowManager = controller.getFlowManager();

    // add the process group
    final ProcessGroupDTO processGroupDTO = FlowFromDOMFactory.getProcessGroup(parentId, processGroupElement, encryptor, encodingVersion);
    final ProcessGroup processGroup = flowManager.createProcessGroup(processGroupDTO.getId());
    processGroup.setComments(processGroupDTO.getComments());
    processGroup.setVersionedComponentId(processGroupDTO.getVersionedComponentId());
    processGroup.setPosition(toPosition(processGroupDTO.getPosition()));
    processGroup.setName(processGroupDTO.getName());
    processGroup.setParent(parentGroup);
    if (parentGroup == null) {
        controller.setRootGroup(processGroup);
    } else {
        parentGroup.addProcessGroup(processGroup);
    }

    final String flowfileConcurrencyName = processGroupDTO.getFlowfileConcurrency();
    final String flowfileOutboundPolicyName = processGroupDTO.getFlowfileOutboundPolicy();
    if (flowfileConcurrencyName == null) {
        processGroup.setFlowFileConcurrency(FlowFileConcurrency.UNBOUNDED);
    } else {
        processGroup.setFlowFileConcurrency(FlowFileConcurrency.valueOf(flowfileConcurrencyName));
    }

    if (flowfileOutboundPolicyName == null) {
        processGroup.setFlowFileOutboundPolicy(FlowFileOutboundPolicy.STREAM_WHEN_AVAILABLE);
    } else {
        processGroup.setFlowFileOutboundPolicy(FlowFileOutboundPolicy.valueOf(flowfileOutboundPolicyName));
    }


    final String parameterContextId = getString(processGroupElement, "parameterContextId");
    if (parameterContextId != null) {
        final ParameterContext parameterContext = controller.getFlowManager().getParameterContextManager().getParameterContext(parameterContextId);
        processGroup.setParameterContext(parameterContext);
    }

    addVariables(processGroupElement, processGroup);
    addVersionControlInfo(processGroup, processGroupDTO, controller);
    addControllerServices(processGroupElement, processGroup, controller, encodingVersion);
    addProcessors(processGroupElement, processGroup, controller, encodingVersion);
    addInputPorts(processGroupElement, processGroup, controller);
    addOutputPorts(processGroupElement, processGroup, controller);
    addFunnels(processGroupElement, processGroup, controller);
    addLabels(processGroupElement, processGroup, controller);
    addNestedProcessGroups(processGroupElement, processGroup, controller, encodingVersion);
    addRemoteProcessGroups(processGroupElement, processGroup, controller);
    addConnections(processGroupElement, processGroup, controller);
    addTemplates(processGroupElement, processGroup);

    return processGroup;
}
 
Example 17
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());
}
 
Example 18
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessGroup updateProcessGroup(ProcessGroupDTO processGroupDTO) {
    final ProcessGroup group = locateProcessGroup(flowController, processGroupDTO.getId());

    final String name = processGroupDTO.getName();
    final String comments = processGroupDTO.getComments();
    final String concurrencyName = processGroupDTO.getFlowfileConcurrency();
    final FlowFileConcurrency flowFileConcurrency = concurrencyName == null ? null : FlowFileConcurrency.valueOf(concurrencyName);

    final String outboundPolicyName = processGroupDTO.getFlowfileOutboundPolicy();
    final FlowFileOutboundPolicy flowFileOutboundPolicy = outboundPolicyName == null ? null : FlowFileOutboundPolicy.valueOf(outboundPolicyName);

    final ParameterContextReferenceEntity parameterContextReference = processGroupDTO.getParameterContext();
    if (parameterContextReference != null) {
        final String parameterContextId = parameterContextReference.getId();
        if (parameterContextId == null) {
            group.setParameterContext(null);
        } else {
            final ParameterContext parameterContext = flowController.getFlowManager().getParameterContextManager().getParameterContext(parameterContextId);
            if (parameterContext == null) {
                throw new IllegalStateException("Cannot set Process Group's Parameter Context because no Parameter Context exists with ID " + parameterContextId);
            }

            group.setParameterContext(parameterContext);
        }
    }

    if (isNotNull(name)) {
        group.setName(name);
    }
    if (isNotNull(processGroupDTO.getPosition())) {
        group.setPosition(new Position(processGroupDTO.getPosition().getX(), processGroupDTO.getPosition().getY()));
        final ProcessGroup parent = group.getParent();
        if (parent != null) {
            parent.onComponentModified();
        }
    }
    if (isNotNull(comments)) {
        group.setComments(comments);
    }
    if (flowFileConcurrency != null) {
        group.setFlowFileConcurrency(flowFileConcurrency);
    }
    if (flowFileOutboundPolicy != null) {
        group.setFlowFileOutboundPolicy(flowFileOutboundPolicy);
    }
    group.onComponentModified();
    return group;
}