Search in sources :

Example 76 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class ControllerSearchServiceTest method testSearchInThirdLevelParentNotAuthorizedWithVersionControl.

@Test
public void testSearchInThirdLevelParentNotAuthorizedWithVersionControl() {
    // root level PG
    final ProcessGroup rootProcessGroup = setupMockedProcessGroup("root", null, true, variableRegistry, null);
    // first level PGs
    final VersionControlInformation versionControlInformation = setupVC();
    final ProcessGroup firstLevelAProcessGroup = setupMockedProcessGroup("firstLevelA", rootProcessGroup, true, variableRegistry, versionControlInformation);
    final ProcessGroup firstLevelBProcessGroup = setupMockedProcessGroup("firstLevelB", rootProcessGroup, true, variableRegistry, null);
    // second level PGs
    final ProcessGroup secondLevelAProcessGroup = setupMockedProcessGroup("secondLevelA", firstLevelAProcessGroup, true, variableRegistry, null);
    final ProcessGroup secondLevelBProcessGroup = setupMockedProcessGroup("secondLevelB", firstLevelBProcessGroup, true, variableRegistry, null);
    // third level PGs - not authorized
    final ProcessGroup thirdLevelAProcessGroup = setupMockedProcessGroup("thirdLevelA", secondLevelAProcessGroup, false, variableRegistry, null);
    final ProcessGroup thirdLevelBProcessGroup = setupMockedProcessGroup("thirdLevelB", secondLevelAProcessGroup, false, variableRegistry, null);
    // link PGs together
    Mockito.doReturn(new HashSet<ProcessGroup>() {

        {
            add(firstLevelAProcessGroup);
            add(firstLevelBProcessGroup);
        }
    }).when(rootProcessGroup).getProcessGroups();
    Mockito.doReturn(new HashSet<ProcessGroup>() {

        {
            add(secondLevelAProcessGroup);
        }
    }).when(firstLevelAProcessGroup).getProcessGroups();
    Mockito.doReturn(new HashSet<ProcessGroup>() {

        {
            add(secondLevelBProcessGroup);
        }
    }).when(firstLevelBProcessGroup).getProcessGroups();
    Mockito.doReturn(new HashSet<ProcessGroup>() {

        {
            add(thirdLevelAProcessGroup);
            add(thirdLevelBProcessGroup);
        }
    }).when(secondLevelAProcessGroup).getProcessGroups();
    // setup processor
    setupMockedProcessor("foobar", thirdLevelAProcessGroup, true, variableRegistry);
    // perform search
    service.search(searchResultsDTO, "foo", rootProcessGroup);
    assertTrue(searchResultsDTO.getProcessorResults().size() == 1);
    assertTrue(searchResultsDTO.getProcessorResults().get(0).getId().equals("foobarId"));
    assertTrue(searchResultsDTO.getProcessorResults().get(0).getParentGroup().getId().equals("thirdLevelAId"));
    assertTrue(searchResultsDTO.getProcessorResults().get(0).getParentGroup().getName() == null);
    assertTrue(searchResultsDTO.getProcessorResults().get(0).getVersionedGroup() != null);
    assertTrue(searchResultsDTO.getProcessorResults().get(0).getVersionedGroup().getId().equals("firstLevelAId"));
    assertTrue(searchResultsDTO.getProcessorResults().get(0).getVersionedGroup().getName().equals("firstLevelA"));
}
Also used : VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Test(org.junit.Test)

Example 77 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class ControllerSearchServiceTest method setupMockedProcessGroup.

/**
 * Mocks ProcessGroup due to isAuthorized(). The final class StandardProcessGroup can't be used.
 *
 * @param processGroupName Desired process group name
 * @param parent           The parent process group
 * @param authorizedToRead Can the process group data be read?
 * @param variableRegistry The variable registry
 * @param versionControlInformation The version control information
 * @return Mocked process group
 */
private static ProcessGroup setupMockedProcessGroup(final String processGroupName, final ProcessGroup parent, boolean authorizedToRead, final VariableRegistry variableRegistry, final VersionControlInformation versionControlInformation) {
    final String processGroupId = processGroupName + "Id";
    final ProcessGroup processGroup = mock(ProcessGroup.class);
    Mockito.doReturn(processGroupId).when(processGroup).getIdentifier();
    // not actually searching based on versioned component id
    Mockito.doReturn(Optional.ofNullable(null)).when(processGroup).getVersionedComponentId();
    Mockito.doReturn(processGroupName).when(processGroup).getName();
    Mockito.doReturn(parent).when(processGroup).getParent();
    Mockito.doReturn(versionControlInformation).when(processGroup).getVersionControlInformation();
    Mockito.doReturn(variableRegistry).when(processGroup).getVariableRegistry();
    Mockito.doReturn(parent == null).when(processGroup).isRootGroup();
    // override process group's access rights
    Mockito.doReturn(authorizedToRead).when(processGroup).isAuthorized(any(Authorizer.class), eq(RequestAction.READ), any(NiFiUser.class));
    return processGroup;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) Authorizer(org.apache.nifi.authorization.Authorizer) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 78 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class TestStandardRemoteProcessGroupDAO method testVerifyUpdateInputPort.

@Test
public void testVerifyUpdateInputPort() {
    final StandardRemoteProcessGroupDAO dao = new StandardRemoteProcessGroupDAO();
    final String remoteProcessGroupId = "remote-process-group-id";
    final String remoteProcessGroupInputPortId = "remote-process-group-input-port-id";
    final FlowController flowController = mock(FlowController.class);
    final ProcessGroup processGroup = mock(ProcessGroup.class);
    final RemoteProcessGroup remoteProcessGroup = mock(RemoteProcessGroup.class);
    final RemoteGroupPort remoteGroupPort = mock(RemoteGroupPort.class);
    dao.setFlowController(flowController);
    when(flowController.getGroup(any())).thenReturn(processGroup);
    when(processGroup.findRemoteProcessGroup(eq(remoteProcessGroupId))).thenReturn(remoteProcessGroup);
    when(remoteProcessGroup.getInputPort(remoteProcessGroupInputPortId)).thenReturn(remoteGroupPort);
    when(remoteGroupPort.getName()).thenReturn("remote-group-port");
    final RemoteProcessGroupPortDTO dto = new RemoteProcessGroupPortDTO();
    dto.setGroupId(remoteProcessGroupId);
    dto.setId(remoteProcessGroupInputPortId);
    dto.setTargetId(remoteProcessGroupInputPortId);
    final BatchSettingsDTO batchSettings = new BatchSettingsDTO();
    dto.setBatchSettings(batchSettings);
    // Empty input values should pass validation.
    dao.verifyUpdateInputPort(remoteProcessGroupId, dto);
    // Concurrent tasks
    dto.setConcurrentlySchedulableTaskCount(0);
    validate(dao, dto, "Concurrent tasks", "positive integer");
    dto.setConcurrentlySchedulableTaskCount(2);
    validate(dao, dto);
    // Batch count
    batchSettings.setCount(-1);
    validate(dao, dto, "Batch count", "positive integer");
    batchSettings.setCount(0);
    validate(dao, dto);
    batchSettings.setCount(1000);
    validate(dao, dto);
    // Batch size
    batchSettings.setSize("AB");
    validate(dao, dto, "Batch size", "Data Size");
    batchSettings.setSize("10 days");
    validate(dao, dto, "Batch size", "Data Size");
    batchSettings.setSize("300MB");
    validate(dao, dto);
    // Batch duration
    batchSettings.setDuration("AB");
    validate(dao, dto, "Batch duration", "Time Unit");
    batchSettings.setDuration("10 KB");
    validate(dao, dto, "Batch duration", "Time Unit");
    batchSettings.setDuration("10 secs");
    validate(dao, dto);
}
Also used : BatchSettingsDTO(org.apache.nifi.web.api.dto.BatchSettingsDTO) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) FlowController(org.apache.nifi.controller.FlowController) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) Test(org.junit.Test)

Example 79 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class StandardSnippetDAO method lookupSensitiveProcessorProperties.

private void lookupSensitiveProcessorProperties(final Set<ProcessorDTO> processors) {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
    // go through each processor
    for (final ProcessorDTO processorDTO : processors) {
        final ProcessorConfigDTO processorConfig = processorDTO.getConfig();
        // ensure that some property configuration have been specified
        if (processorConfig != null && processorConfig.getProperties() != null) {
            final Map<String, String> processorProperties = processorConfig.getProperties();
            // find the corresponding processor
            final ProcessorNode processorNode = rootGroup.findProcessor(processorDTO.getId());
            if (processorNode == null) {
                throw new IllegalArgumentException(String.format("Unable to create snippet because Processor '%s' could not be found", processorDTO.getId()));
            }
            // look for sensitive properties get the actual value
            for (Entry<PropertyDescriptor, String> entry : processorNode.getProperties().entrySet()) {
                final PropertyDescriptor descriptor = entry.getKey();
                if (descriptor.isSensitive()) {
                    processorProperties.put(descriptor.getName(), entry.getValue());
                }
            }
        }
    }
}
Also used : ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 80 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class StandardSnippetDAO method verifyUpdateSnippetComponent.

@Override
public void verifyUpdateSnippetComponent(SnippetDTO snippetDTO) {
    final Snippet snippet = locateSnippet(snippetDTO.getId());
    // if the group is changing move it
    if (snippetDTO.getParentGroupId() != null && !snippet.getParentGroupId().equals(snippetDTO.getParentGroupId())) {
        // get the current process group
        final ProcessGroup processGroup = flowController.getGroup(snippet.getParentGroupId());
        if (processGroup == null) {
            throw new IllegalArgumentException("The specified parent process group could not be found.");
        }
        // get the new process group
        final ProcessGroup newProcessGroup = flowController.getGroup(snippetDTO.getParentGroupId());
        if (newProcessGroup == null) {
            throw new IllegalArgumentException("The new process group could not be found.");
        }
        // perform the verification
        processGroup.verifyCanMove(snippet, newProcessGroup);
    }
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) Snippet(org.apache.nifi.controller.Snippet) StandardSnippet(org.apache.nifi.controller.StandardSnippet)

Aggregations

ProcessGroup (org.apache.nifi.groups.ProcessGroup)185 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)97 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)68 ProcessorNode (org.apache.nifi.controller.ProcessorNode)50 Port (org.apache.nifi.connectable.Port)40 RootGroupPort (org.apache.nifi.remote.RootGroupPort)37 Connection (org.apache.nifi.connectable.Connection)36 ArrayList (java.util.ArrayList)35 InstantiatedVersionedProcessGroup (org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup)35 Test (org.junit.Test)35 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)34 HashSet (java.util.HashSet)32 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)32 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)29 FlowController (org.apache.nifi.controller.FlowController)27 Connectable (org.apache.nifi.connectable.Connectable)26 VersionControlInformation (org.apache.nifi.registry.flow.VersionControlInformation)25 Funnel (org.apache.nifi.connectable.Funnel)24 List (java.util.List)22 Label (org.apache.nifi.controller.label.Label)22