Skip to content

Commit e638233

Browse files
authored
Add a function to SearchPipelineService to check if system generated factory enabled or not. (opensearch-project#19545)
Signed-off-by: Bo Zhang <bzhangam@amazon.com>
1 parent 39dc09b commit e638233

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7777
- Delegate primitive write methods with ByteSizeCachingDirectory wrapped IndexOutput ([#19432](https://github.com/opensearch-project/OpenSearch/pull/19432))
7878
- Bump opensearch-protobufs dependency to 0.18.0 and update transport-grpc module compatibility ([#19447](https://github.com/opensearch-project/OpenSearch/issues/19447))
7979
- Bump opensearch-protobufs dependency to 0.19.0 ([#19453](https://github.com/opensearch-project/OpenSearch/issues/19453))
80-
80+
- Add a function to SearchPipelineService to check if system generated factory enabled or not ([#19545](https://github.com/opensearch-project/OpenSearch/pull/19545))
8181
### Fixed
8282
- Fix unnecessary refreshes on update preparation failures ([#15261](https://github.com/opensearch-project/OpenSearch/issues/15261))
8383
- Fix NullPointerException in segment replicator ([#18997](https://github.com/opensearch-project/OpenSearch/pull/18997))

server/src/main/java/org/opensearch/search/pipeline/SearchPipelineService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class SearchPipelineService implements ClusterStateApplier, ReportingServ
7979
public static final String SEARCH_PIPELINE_ORIGIN = "search_pipeline";
8080
public static final String AD_HOC_PIPELINE_ID = "_ad_hoc_pipeline";
8181
public static final String NOOP_PIPELINE_ID = "_none";
82+
public static final String ALL = "*";
8283
private static final int MAX_PIPELINE_ID_BYTES = 512;
8384
private static final Logger logger = LogManager.getLogger(SearchPipelineService.class);
8485
private final ClusterService clusterService;
@@ -643,4 +644,9 @@ static class PipelineHolder {
643644
this.pipeline = Objects.requireNonNull(pipeline);
644645
}
645646
}
647+
648+
public boolean isSystemGeneratedFactoryEnabled(String factoryName) {
649+
return enabledSystemGeneratedFactories != null
650+
&& (enabledSystemGeneratedFactories.contains(ALL) || enabledSystemGeneratedFactories.contains(factoryName));
651+
}
646652
}

server/src/test/java/org/opensearch/search/pipeline/SearchPipelineServiceTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.util.concurrent.atomic.AtomicReference;
5757
import java.util.function.Consumer;
5858

59+
import static org.opensearch.search.pipeline.SearchPipelineService.ENABLED_SYSTEM_GENERATED_FACTORIES_SETTING;
5960
import static org.mockito.ArgumentMatchers.anyString;
6061
import static org.mockito.Mockito.mock;
6162
import static org.mockito.Mockito.when;
@@ -1640,4 +1641,25 @@ private SearchResponse createDefaultSearchResponse() {
16401641
return new SearchResponse(sections, null, 0, 0, 0, 0, null, null);
16411642
}
16421643

1644+
public void testIsSystemGeneratedFactoryEnabled_whenAllEnabled_thenTrue() throws Exception {
1645+
SearchPipelineService service = createWithSystemGeneratedProcessors();
1646+
enabledAllSystemGeneratedFactories(service);
1647+
1648+
assertTrue(service.isSystemGeneratedFactoryEnabled("dummy_factory"));
1649+
}
1650+
1651+
public void testIsSystemGeneratedFactoryEnabled_whenEnabled_thenTrue() {
1652+
SearchPipelineService service = createWithSystemGeneratedProcessors();
1653+
service.getClusterService()
1654+
.getClusterSettings()
1655+
.applySettings(Settings.builder().putList(ENABLED_SYSTEM_GENERATED_FACTORIES_SETTING.getKey(), "dummy_factory").build());
1656+
1657+
assertTrue(service.isSystemGeneratedFactoryEnabled("dummy_factory"));
1658+
}
1659+
1660+
public void testIsSystemGeneratedFactoryEnabled_whenNotEnabled_thenFalse() {
1661+
SearchPipelineService service = createWithSystemGeneratedProcessors();
1662+
1663+
assertFalse(service.isSystemGeneratedFactoryEnabled("dummy_factory"));
1664+
}
16431665
}

server/src/test/java/org/opensearch/search/pipeline/SearchPipelineTestCase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import java.util.concurrent.ExecutorService;
4545
import java.util.function.Consumer;
4646

47+
import static org.opensearch.search.pipeline.SearchPipelineService.ALL;
48+
import static org.opensearch.search.pipeline.SearchPipelineService.ENABLED_SYSTEM_GENERATED_FACTORIES_SETTING;
4749
import static org.mockito.ArgumentMatchers.anyString;
4850
import static org.mockito.Mockito.mock;
4951
import static org.mockito.Mockito.when;
@@ -712,9 +714,9 @@ SearchSourceBuilder createDefaultSearchSourceBuilder() {
712714
return SearchSourceBuilder.searchSource().size(10);
713715
}
714716

715-
void enabledAllSystemGeneratedFactories(SearchPipelineService service) throws Exception {
717+
void enabledAllSystemGeneratedFactories(SearchPipelineService service) {
716718
service.getClusterService()
717719
.getClusterSettings()
718-
.applySettings(Settings.builder().putList("cluster.search.enabled_system_generated_factories", "*").build());
720+
.applySettings(Settings.builder().putList(ENABLED_SYSTEM_GENERATED_FACTORIES_SETTING.getKey(), ALL).build());
719721
}
720722
}

0 commit comments

Comments
 (0)