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"));
}
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;
}
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);
}
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());
}
}
}
}
}
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);
}
}
Aggregations