Skip to content

Commit

Permalink
NIFI-13052 allow CRON driven components to be searchable
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes apache#8655.
  • Loading branch information
mosermw authored and pvillard31 committed Apr 16, 2024
1 parent 63fa036 commit 7fdaa5f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions nifi-docs/src/main/asciidoc/user-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,8 @@ The supported keywords are the following:

** *timer*: Adds Processors to the result list where the Scheduling Strategy is "Timer Driven".

** *cron*: Adds Processors to the result list where the Scheduling Strategy is "CRON Driven".

- *Execution*

** *primary:* Adds Processors to the result list that are set to run on the primary node only (whether if the Processor is currently running or not).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@

import java.util.List;

import static org.apache.nifi.scheduling.SchedulingStrategy.CRON_DRIVEN;
import static org.apache.nifi.scheduling.SchedulingStrategy.TIMER_DRIVEN;

public class SchedulingMatcher implements AttributeMatcher<ProcessorNode> {
private static final String SEARCH_TERM_TIMER = "timer";
private static final String SEARCH_TERM_CRON = "cron";

private static final String MATCH_PREFIX = "Scheduling strategy: ";
private static final String MATCH_TIMER = "Timer driven";
private static final String MATCH_CRON = "CRON driven";

@Override
public void match(final ProcessorNode component, final SearchQuery query, final List<String> matches) {
Expand All @@ -38,6 +41,8 @@ public void match(final ProcessorNode component, final SearchQuery query, final

if (TIMER_DRIVEN.equals(schedulingStrategy) && StringUtils.containsIgnoreCase(SEARCH_TERM_TIMER, searchTerm)) {
matches.add(MATCH_PREFIX + MATCH_TIMER);
} else if (CRON_DRIVEN.equals(schedulingStrategy) && StringUtils.containsIgnoreCase(SEARCH_TERM_CRON, searchTerm)) {
matches.add(MATCH_PREFIX + MATCH_CRON);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public class SchedulingMatcherTest extends AbstractAttributeMatcherTest {
private ProcessorNode component;

@Test
public void testWhenKeywordAppearsAndNotEvent() {
public void testWhenKeywordAppearsAndNotTimer() {
// given
final SchedulingMatcher testSubject = new SchedulingMatcher();
givenSchedulingStrategy(SchedulingStrategy.TIMER_DRIVEN);
givenSearchTerm("event");
givenSchedulingStrategy(SchedulingStrategy.CRON_DRIVEN);
givenSearchTerm("timer");

// when
testSubject.match(component, searchQuery, matches);
Expand All @@ -42,11 +42,11 @@ public void testWhenKeywordAppearsAndNotEvent() {
}

@Test
public void testWhenKeywordDoesNotAppearAndEvent() {
public void testWhenKeywordDoesNotAppearAndTimer() {
// given
final SchedulingMatcher testSubject = new SchedulingMatcher();
givenSchedulingStrategy(SchedulingStrategy.TIMER_DRIVEN);
givenSearchTerm("event");
givenSearchTerm("cron");

// when
testSubject.match(component, searchQuery, matches);
Expand All @@ -69,6 +69,20 @@ public void testWhenKeywordAppearsAndTimer() {
thenMatchConsistsOf("Scheduling strategy: Timer driven");
}

@Test
public void testWhenKeywordAppearsAndCron() {
// given
final SchedulingMatcher testSubject = new SchedulingMatcher();
givenSchedulingStrategy(SchedulingStrategy.CRON_DRIVEN);
givenSearchTerm("cron");

// when
testSubject.match(component, searchQuery, matches);

// then
thenMatchConsistsOf("Scheduling strategy: CRON driven");
}

private void givenSchedulingStrategy(final SchedulingStrategy schedulingStrategy) {
Mockito.when(component.getSchedulingStrategy()).thenReturn(schedulingStrategy);
}
Expand Down

0 comments on commit 7fdaa5f

Please sign in to comment.