NIFI-7312: Enable search in variable registry of root process group

This closes #4303.

Signed-off-by: Mark Payne <markap14@hotmail.com>
This commit is contained in:
Peter Gyori 2020-05-22 16:08:51 +02:00 committed by Mark Payne
parent e31c323aa7
commit 91dd59dbdf
8 changed files with 184 additions and 49 deletions

View File

@ -88,10 +88,8 @@ public class ControllerSearchService {
final ComponentSearchResultEnricher groupResultEnricher = resultEnricherFactory.getProcessGroupResultEnricher(scope, user);
if (appliesToGroupFilter(searchQuery, scope)) {
if (scope.getParent() != null) {
searchComponentType(Collections.singletonList(scope), user, searchQuery, matcherForProcessGroup, groupResultEnricher, results.getProcessGroupResults());
}
searchComponentType(Collections.singletonList(scope), user, searchQuery, matcherForProcessGroup, groupResultEnricher, results.getProcessGroupResults());
searchComponentType(scope.getProcessors(), user, searchQuery, matcherForProcessor, resultEnricher, results.getProcessorResults());
searchComponentType(scope.getConnections(), user, searchQuery, matcherForConnection, resultEnricher, results.getConnectionResults());
searchComponentType(scope.getRemoteProcessGroups(), user, searchQuery, matcherForRemoteProcessGroup, resultEnricher, results.getRemoteProcessGroupResults());

View File

@ -29,9 +29,13 @@ public class ProcessGroupSearchResultEnricher extends AbstractComponentSearchRes
@Override
public ComponentSearchResultDTO enrich(final ComponentSearchResultDTO input) {
input.setGroupId(processGroup.getParent().getIdentifier());
input.setParentGroup(buildResultGroup(processGroup.getParent(), user));
input.setVersionedGroup(buildVersionedGroup(processGroup.getParent(), user));
if (processGroup.getParent() != null) {
input.setGroupId(processGroup.getParent().getIdentifier());
input.setParentGroup(buildResultGroup(processGroup.getParent(), user));
input.setVersionedGroup(buildVersionedGroup(processGroup.getParent(), user));
} else {
input.setGroupId(processGroup.getIdentifier());
}
return input;
}
}

View File

@ -62,8 +62,8 @@ import static org.apache.nifi.web.controller.ComponentMockUtil.getRootProcessGro
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:nifi-web-api-test-context.xml", "classpath:nifi-web-api-context.xml"})
public abstract class AbstractControllerSearchIntegrationTest {
protected static final String ROOT_PROCESSOR_GROUP_ID = "rootId";
protected static final String ROOT_PROCESSOR_GROUP_NAME = "rootName";
protected static final String ROOT_PROCESSOR_GROUP_ID = "3b9a7e60-0172-1000-5f1e-10cbc0c4d5f1";
protected static final String ROOT_PROCESSOR_GROUP_NAME = "NiFi Flow";
protected static final boolean AUTHORIZED = true;
protected static final boolean NOT_AUTHORIZED = false;
@ -110,6 +110,10 @@ public abstract class AbstractControllerSearchIntegrationTest {
return givenProcessGroup(getRootProcessGroup(ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME, "", AUTHORIZED, NOT_UNDER_VERSION_CONTROL));
}
protected ProcessGroupSetup givenRootProcessGroup(String comments) {
return givenProcessGroup(getRootProcessGroup(ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME, comments, AUTHORIZED, NOT_UNDER_VERSION_CONTROL));
}
protected ProcessGroupSetup givenProcessGroup(final ProcessGroup processGroup) {
return new ProcessGroupSetup(processGroup);
}

View File

@ -90,6 +90,26 @@ public class ControllerSearchServiceFilterTest extends AbstractControllerSearchI
.validate(results);
}
@Test
public void testGroupWhenRoot() {
// given
givenRootProcessGroup()
.withProcessor(getProcessorNode("workingProcessor1", "processor1Name", AUTHORIZED));
givenProcessGroup(getChildProcessGroup("child1", "child1Name", "", getProcessGroup(ROOT_PROCESSOR_GROUP_ID), AUTHORIZED, NOT_UNDER_VERSION_CONTROL))
.withProcessor(getProcessorNode("workingProcessor2", "processor1Name", AUTHORIZED));
// when:
// Cannot use "group:NiFi flow" as filter since the scope is only considered until the first space in the query
whenExecuteSearch("group:NiFi processor1Name");
// then
thenResultConsists()
.ofProcessor(getSimpleResult("workingProcessor1", "processor1Name", ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME, "Name: processor1Name"))
.ofProcessor(getSimpleResult("workingProcessor2", "processor1Name", "child1", "child1", "child1Name", "Name: processor1Name"))
.validate(results);
}
@Test
public void testGroupWhenHasChildGroup() {
// given

View File

@ -54,6 +54,56 @@ import static org.apache.nifi.web.controller.ComponentMockUtil.getRemoteProcessG
public class ControllerSearchServiceIntegrationTest extends AbstractControllerSearchIntegrationTest {
@Test
public void testSearchForRootBasedOnID() {
// given
givenRootProcessGroup();
// when
whenExecuteSearch(ROOT_PROCESSOR_GROUP_ID.substring(2, 7));
// then
thenResultConsists()
.ofProcessGroup(getSimpleResult(ROOT_PROCESSOR_GROUP_ID,
ROOT_PROCESSOR_GROUP_NAME,
ROOT_PROCESSOR_GROUP_ID,
null,
null,
"Id: " + ROOT_PROCESSOR_GROUP_ID))
.validate(results);
}
@Test
public void testSearchForRootBasedOnNameAndComments() {
// given
final String commentForRoot = "test comment for " + ROOT_PROCESSOR_GROUP_NAME + " process group";
final String searchQuery = ROOT_PROCESSOR_GROUP_NAME;
final String processor2Id = "processor2";
final String processor2Name = "NAME2";
final String processor2Comment = "This comment is a test comment containing " + ROOT_PROCESSOR_GROUP_NAME;
givenRootProcessGroup(commentForRoot)
.withProcessor(getProcessorNode("processor1", "name1", AUTHORIZED))
.withProcessor(getProcessorNode(processor2Id, processor2Name, processor2Comment,
Optional.of("versionId"), SchedulingStrategy.TIMER_DRIVEN, ExecutionNode.ALL, ScheduledState.RUNNING, ValidationStatus.VALID,
new HashSet<>(),"Processor", Mockito.mock(Processor.class), new HashMap<>(), AUTHORIZED));
// when
whenExecuteSearch(searchQuery);
// then
thenResultConsists()
.ofProcessGroup(getSimpleResult(ROOT_PROCESSOR_GROUP_ID,
ROOT_PROCESSOR_GROUP_NAME,
ROOT_PROCESSOR_GROUP_ID,
null,
null,
"Name: " + ROOT_PROCESSOR_GROUP_NAME,
"Comments: " + commentForRoot))
.ofProcessor(getSimpleResultFromRoot(processor2Id, processor2Name, "Comments: " + processor2Comment))
.validate(results);
}
@Test
public void testSearchBasedOnBasicAttributes() {
// given
@ -365,6 +415,44 @@ public class ControllerSearchServiceIntegrationTest extends AbstractControllerSe
.validate(results);
}
@Test
public void testSearchBasedOnVariableRegistryInRoot() {
// given
givenRootProcessGroup();
final ProcessGroup childProcessGroup = getChildProcessGroup("childGroup", "childGroupName", "", getProcessGroup(ROOT_PROCESSOR_GROUP_ID), AUTHORIZED, NOT_UNDER_VERSION_CONTROL);
givenProcessGroup(childProcessGroup);
final Map<VariableDescriptor, String> variablesRoot = new HashMap<>();
variablesRoot.put(new VariableDescriptor.Builder("variableName1").build(), "variableValue1");
final ComponentVariableRegistry variableRegistryRoot = Mockito.mock(ComponentVariableRegistry.class);
Mockito.when(variableRegistryRoot.getVariableMap()).thenReturn(variablesRoot);
Mockito.when(getProcessGroup(ROOT_PROCESSOR_GROUP_ID).getVariableRegistry()).thenReturn(variableRegistryRoot);
final Map<VariableDescriptor, String> variablesChild = new HashMap<>();
variablesChild.put(new VariableDescriptor.Builder("variableName2").build(), "variableValue2");
final ComponentVariableRegistry variableRegistryChild = Mockito.mock(ComponentVariableRegistry.class);
Mockito.when(variableRegistryChild.getVariableMap()).thenReturn(variablesChild);
Mockito.when(childProcessGroup.getVariableRegistry()).thenReturn(variableRegistryChild);
// when
whenExecuteSearch("variableValue");
// then
thenResultConsists()
.ofProcessGroup(getSimpleResult(ROOT_PROCESSOR_GROUP_ID,
ROOT_PROCESSOR_GROUP_NAME,
ROOT_PROCESSOR_GROUP_ID,
null,
null,
"Variable Value: " + "variableValue1"))
.ofProcessGroup(getSimpleResultFromRoot("childGroup", "childGroupName", "Variable Value: variableValue2"))
.validate(results);
}
@Test
public void testSearchBasedOnConnectionAttributes() {
// given

View File

@ -69,7 +69,7 @@ public class ControllerSearchServiceRegressionTest extends AbstractControllerSea
public void testTextOmniMatch() {
// given
final String omniMatch = "omniMatch";
final ProcessGroup rootProcessGroup = getRootProcessGroup(ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME, "root_no_find_omniMatch", true, false);
final ProcessGroup rootProcessGroup = getRootProcessGroup(ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME, "root_comments_omniMatch", true, false);
final ProcessorNode processor1 = getProcessorNode(
"proc1_id_omniMatch",
@ -265,6 +265,13 @@ public class ControllerSearchServiceRegressionTest extends AbstractControllerSea
"Variable Value: processgroup1_variable2_value_omniMatch"
);
final ComponentSearchResultDTO rootProcessGroupResult = getSimpleResult(ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME,
ROOT_PROCESSOR_GROUP_ID,
null,
null,
"Comments: root_comments_omniMatch"
);
final RemoteProcessGroup remoteProcessGroup1 = getRemoteProcessGroup(
"remoteprocessgroup1_id_omniMatch",
"remoteprocessgroup1_name_omniMatch",
@ -347,6 +354,7 @@ public class ControllerSearchServiceRegressionTest extends AbstractControllerSea
.ofLabel(label1Result)
.ofControllerServiceNode(controllerServiceNode1Result)
.ofProcessGroup(processGroup1Result)
.ofProcessGroup(rootProcessGroupResult)
.ofRemoteProcessGroup(remoteProcessGroup1Result)
.ofParameterContext(parameterContext1Result)
.ofParameter(parameterResults1)
@ -364,7 +372,7 @@ public class ControllerSearchServiceRegressionTest extends AbstractControllerSea
// then
thenResultConsists()
.ofProcessor(getSimpleResult("foobarId", "foobar", "rootId", "rootId", "rootName", "Id: foobarId", "Name: foobar"))
.ofProcessor(getSimpleResultFromRoot("foobarId", "foobar", "Id: foobarId", "Name: foobar"))
.validate(results);
}

View File

@ -170,13 +170,7 @@ public class ControllerSearchServiceTest {
testSubject.search(searchQuery, results);
// then
thenFollowingGroupsAreSearched(Arrays.asList(
PROCESS_GROUP_FIRST_LEVEL_A,
PROCESS_GROUP_SECOND_LEVEL_A,
PROCESS_GROUP_FIRST_LEVEL_B,
PROCESS_GROUP_SECOND_LEVEL_B_1,
PROCESS_GROUP_SECOND_LEVEL_B_2));
thenContentOfTheFollowingGroupsAreSearched(processGroups.keySet());
thenFollowingGroupsAndTheirContentsAreSearched(processGroups.keySet());
}
@Test
@ -191,6 +185,7 @@ public class ControllerSearchServiceTest {
testSubject.search(searchQuery, results);
// The authorization is not transitive, children groups might be good candidates.
thenFollowingGroupsAreSearched(Arrays.asList(
PROCESS_GROUP_ROOT,
PROCESS_GROUP_FIRST_LEVEL_A,
PROCESS_GROUP_SECOND_LEVEL_A,
PROCESS_GROUP_SECOND_LEVEL_B_1,
@ -246,13 +241,7 @@ public class ControllerSearchServiceTest {
testSubject.search(searchQuery, results);
// then
thenFollowingGroupsAreSearched(Arrays.asList(
PROCESS_GROUP_FIRST_LEVEL_A,
PROCESS_GROUP_SECOND_LEVEL_A,
PROCESS_GROUP_FIRST_LEVEL_B,
PROCESS_GROUP_SECOND_LEVEL_B_1,
PROCESS_GROUP_SECOND_LEVEL_B_2));
thenContentOfTheFollowingGroupsAreSearched(processGroups.keySet());
thenFollowingGroupsAndTheirContentsAreSearched(processGroups.keySet());
}
@ -335,13 +324,7 @@ public class ControllerSearchServiceTest {
testSubject.search(searchQuery, results);
// then
thenFollowingGroupsAreSearched(Arrays.asList(
PROCESS_GROUP_FIRST_LEVEL_A,
PROCESS_GROUP_SECOND_LEVEL_A,
PROCESS_GROUP_FIRST_LEVEL_B,
PROCESS_GROUP_SECOND_LEVEL_B_1,
PROCESS_GROUP_SECOND_LEVEL_B_2));
thenContentOfTheFollowingGroupsAreSearched(processGroups.keySet());
thenFollowingGroupsAndTheirContentsAreSearched(processGroups.keySet());
}
@Test
@ -616,6 +599,11 @@ public class ControllerSearchServiceTest {
Mockito.verify(matcherForParameter, Mockito.never()).match(Mockito.any(Parameter.class), Mockito.any(SearchQuery.class));
}
private void thenFollowingGroupsAndTheirContentsAreSearched(final Collection<String> searchedProcessGroups) {
thenFollowingGroupsAreSearched(searchedProcessGroups);
thenContentOfTheFollowingGroupsAreSearched(searchedProcessGroups);
}
private void thenFollowingGroupsAreSearched(final Collection<String> searchedProcessGroups) {
for (final String processGroup : searchedProcessGroups) {
Mockito.verify(matcherForProcessGroup, Mockito.times(1)).match(processGroups.get(processGroup), searchQuery);

View File

@ -24,7 +24,6 @@ import org.apache.nifi.parameter.ParameterContext;
import org.apache.nifi.registry.flow.VersionControlInformation;
import org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@ -58,26 +57,10 @@ public class ComponentSearchResultEnricherTest {
@Mock
private ParameterContext parameterContext;
@Before
public void setUp() {
Mockito.when(processGroup.getIdentifier()).thenReturn(IDENTIFIER);
Mockito.when(processGroup.getName()).thenReturn(NAME);
Mockito.when(processGroup.isAuthorized(authorizer, RequestAction.READ, user)).thenReturn(true);
Mockito.when(processGroup.getVersionControlInformation()).thenReturn(Mockito.mock(VersionControlInformation.class));
Mockito.when(processGroup.getParent()).thenReturn(parentProcessGroup);
Mockito.when(parentProcessGroup.getIdentifier()).thenReturn(PARENT_IDENTIFIER);
Mockito.when(parentProcessGroup.getName()).thenReturn(PARENT_NAME);
Mockito.when(parentProcessGroup.isAuthorized(authorizer, RequestAction.READ, user)).thenReturn(true);
Mockito.when(parentProcessGroup.getVersionControlInformation()).thenReturn(Mockito.mock(VersionControlInformation.class));
Mockito.when(parameterContext.getIdentifier()).thenReturn(CONTEXT_IDENTIFIER);
Mockito.when(parameterContext.getName()).thenReturn(CONTEXT_NAME);
}
@Test
public void testGeneralEnrichment() {
// given
givenProcessGroup();
final GeneralComponentSearchResultEnricher testSubject = new GeneralComponentSearchResultEnricher(processGroup, user, authorizer);
final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
@ -100,6 +83,7 @@ public class ComponentSearchResultEnricherTest {
@Test
public void testProcessGroupEnrichment() {
// given
givenProcessGroup();
final ProcessGroupSearchResultEnricher testSubject = new ProcessGroupSearchResultEnricher(processGroup, user, authorizer);
final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
@ -121,6 +105,7 @@ public class ComponentSearchResultEnricherTest {
@Test
public void testParameterEnriching() {
// given
givenProcessGroup();
final ParameterSearchResultEnricher testSubject = new ParameterSearchResultEnricher(parameterContext);
final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
@ -136,6 +121,46 @@ public class ComponentSearchResultEnricherTest {
thenVersionedGroupIsNotSet(result);
}
@Test
public void testRootProcessGroupEnrichment() {
// given
givenRootProcessGroup();
final ProcessGroupSearchResultEnricher testSubject = new ProcessGroupSearchResultEnricher(processGroup, user, authorizer);
final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
// when
testSubject.enrich(result);
// then
Assert.assertEquals(IDENTIFIER, result.getGroupId());
Assert.assertNull(result.getId());
Assert.assertNull(result.getParentGroup());
thenVersionedGroupIsNotSet(result);
Assert.assertNull(result.getName());
Assert.assertNull(result.getMatches());
}
private void givenProcessGroup() {
Mockito.when(processGroup.getIdentifier()).thenReturn(IDENTIFIER);
Mockito.when(processGroup.getName()).thenReturn(NAME);
Mockito.when(processGroup.isAuthorized(authorizer, RequestAction.READ, user)).thenReturn(true);
Mockito.when(processGroup.getVersionControlInformation()).thenReturn(Mockito.mock(VersionControlInformation.class));
Mockito.when(processGroup.getParent()).thenReturn(parentProcessGroup);
Mockito.when(parentProcessGroup.getIdentifier()).thenReturn(PARENT_IDENTIFIER);
Mockito.when(parentProcessGroup.getName()).thenReturn(PARENT_NAME);
Mockito.when(parentProcessGroup.isAuthorized(authorizer, RequestAction.READ, user)).thenReturn(true);
Mockito.when(parentProcessGroup.getVersionControlInformation()).thenReturn(Mockito.mock(VersionControlInformation.class));
Mockito.when(parameterContext.getIdentifier()).thenReturn(CONTEXT_IDENTIFIER);
Mockito.when(parameterContext.getName()).thenReturn(CONTEXT_NAME);
}
private void givenRootProcessGroup() {
Mockito.when(processGroup.getIdentifier()).thenReturn(IDENTIFIER);
Mockito.when(processGroup.getParent()).thenReturn(null);
}
private void thenIdentifierIsNotSet(final ComponentSearchResultDTO result) {
Assert.assertNull(result.getGroupId());
}