use of org.opensearch.ingest.IngestService in project OpenSearch by opensearch-project.
the class GeoIpProcessorNonIngestNodeIT method assertDatabaseLoadStatus.
private void assertDatabaseLoadStatus(final String node, final boolean loaded) {
final IngestService ingestService = internalCluster().getInstance(IngestService.class, node);
final GeoIpProcessor.Factory factory = (GeoIpProcessor.Factory) ingestService.getProcessorFactories().get("geoip");
for (final DatabaseReaderLazyLoader loader : factory.databaseReaders().values()) {
if (loaded) {
assertNotNull(loader.databaseReader.get());
} else {
assertNull(loader.databaseReader.get());
}
}
}
use of org.opensearch.ingest.IngestService in project OpenSearch by opensearch-project.
the class TransportBulkActionIngestTests method testFindDefaultPipelineFromTemplateMatch.
public void testFindDefaultPipelineFromTemplateMatch() {
Exception exception = new Exception("fake exception");
ClusterState state = clusterService.state();
ImmutableOpenMap.Builder<String, IndexTemplateMetadata> templateMetadataBuilder = ImmutableOpenMap.builder();
templateMetadataBuilder.put("template1", IndexTemplateMetadata.builder("template1").patterns(Arrays.asList("missing_index")).order(1).settings(Settings.builder().put(IndexSettings.DEFAULT_PIPELINE.getKey(), "pipeline1").build()).build());
templateMetadataBuilder.put("template2", IndexTemplateMetadata.builder("template2").patterns(Arrays.asList("missing_*")).order(2).settings(Settings.builder().put(IndexSettings.DEFAULT_PIPELINE.getKey(), "pipeline2").build()).build());
templateMetadataBuilder.put("template3", IndexTemplateMetadata.builder("template3").patterns(Arrays.asList("missing*")).order(3).build());
templateMetadataBuilder.put("template4", IndexTemplateMetadata.builder("template4").patterns(Arrays.asList("nope")).order(4).settings(Settings.builder().put(IndexSettings.DEFAULT_PIPELINE.getKey(), "pipeline4").build()).build());
Metadata metadata = mock(Metadata.class);
when(state.metadata()).thenReturn(metadata);
when(state.getMetadata()).thenReturn(metadata);
when(metadata.templates()).thenReturn(templateMetadataBuilder.build());
when(metadata.getTemplates()).thenReturn(templateMetadataBuilder.build());
when(metadata.indices()).thenReturn(ImmutableOpenMap.of());
IndexRequest indexRequest = new IndexRequest("missing_index").id("id");
indexRequest.source(emptyMap());
AtomicBoolean responseCalled = new AtomicBoolean(false);
AtomicBoolean failureCalled = new AtomicBoolean(false);
singleItemBulkWriteAction.execute(null, indexRequest, ActionListener.wrap(response -> responseCalled.set(true), e -> {
assertThat(e, sameInstance(exception));
failureCalled.set(true);
}));
assertEquals("pipeline2", indexRequest.getPipeline());
verify(ingestService).executeBulkRequest(eq(1), bulkDocsItr.capture(), failureHandler.capture(), completionHandler.capture(), any(), eq(Names.WRITE));
}
use of org.opensearch.ingest.IngestService in project OpenSearch by opensearch-project.
the class TransportBulkActionIngestTests method testSingleItemBulkActionIngestLocal.
public void testSingleItemBulkActionIngestLocal() throws Exception {
Exception exception = new Exception("fake exception");
IndexRequest indexRequest = new IndexRequest("index").id("id");
indexRequest.source(emptyMap());
indexRequest.setPipeline("testpipeline");
AtomicBoolean responseCalled = new AtomicBoolean(false);
AtomicBoolean failureCalled = new AtomicBoolean(false);
singleItemBulkWriteAction.execute(null, indexRequest, ActionListener.wrap(response -> {
responseCalled.set(true);
}, e -> {
assertThat(e, sameInstance(exception));
failureCalled.set(true);
}));
// check failure works, and passes through to the listener
// haven't executed yet
assertFalse(action.isExecuted);
assertFalse(responseCalled.get());
assertFalse(failureCalled.get());
verify(ingestService).executeBulkRequest(eq(1), bulkDocsItr.capture(), failureHandler.capture(), completionHandler.capture(), any(), eq(Names.WRITE));
completionHandler.getValue().accept(null, exception);
assertTrue(failureCalled.get());
// now check success
// this is done by the real pipeline execution service when processing
indexRequest.setPipeline(IngestService.NOOP_PIPELINE_NAME);
completionHandler.getValue().accept(DUMMY_WRITE_THREAD, null);
assertTrue(action.isExecuted);
// listener would only be called by real index action, not our mocked one
assertFalse(responseCalled.get());
verifyNoInteractions(transportService);
}
use of org.opensearch.ingest.IngestService in project OpenSearch by opensearch-project.
the class TransportBulkActionIngestTests method testFindDefaultPipelineFromV2TemplateMatch.
public void testFindDefaultPipelineFromV2TemplateMatch() {
Exception exception = new Exception("fake exception");
ComposableIndexTemplate t1 = new ComposableIndexTemplate(Collections.singletonList("missing_*"), new Template(Settings.builder().put(IndexSettings.DEFAULT_PIPELINE.getKey(), "pipeline2").build(), null, null), null, null, null, null, null);
ClusterState state = clusterService.state();
Metadata metadata = Metadata.builder().put("my-template", t1).build();
when(state.metadata()).thenReturn(metadata);
when(state.getMetadata()).thenReturn(metadata);
IndexRequest indexRequest = new IndexRequest("missing_index").id("id");
indexRequest.source(emptyMap());
AtomicBoolean responseCalled = new AtomicBoolean(false);
AtomicBoolean failureCalled = new AtomicBoolean(false);
singleItemBulkWriteAction.execute(null, indexRequest, ActionListener.wrap(response -> responseCalled.set(true), e -> {
assertThat(e, sameInstance(exception));
failureCalled.set(true);
}));
assertEquals("pipeline2", indexRequest.getPipeline());
verify(ingestService).executeBulkRequest(eq(1), bulkDocsItr.capture(), failureHandler.capture(), completionHandler.capture(), any(), eq(Names.WRITE));
}
use of org.opensearch.ingest.IngestService in project OpenSearch by opensearch-project.
the class TransportBulkActionIngestTests method setupAction.
@Before
public void setupAction() {
// initialize captors, which must be members to use @Capture because of generics
threadPool = mock(ThreadPool.class);
final ExecutorService direct = OpenSearchExecutors.newDirectExecutorService();
when(threadPool.executor(anyString())).thenReturn(direct);
bulkDocsItr = ArgumentCaptor.forClass(Iterable.class);
failureHandler = ArgumentCaptor.forClass(BiConsumer.class);
completionHandler = ArgumentCaptor.forClass(BiConsumer.class);
remoteResponseHandler = ArgumentCaptor.forClass(TransportResponseHandler.class);
// setup services that will be called by action
transportService = mock(TransportService.class);
clusterService = mock(ClusterService.class);
localIngest = true;
// setup nodes for local and remote
DiscoveryNode localNode = mock(DiscoveryNode.class);
when(localNode.isIngestNode()).thenAnswer(stub -> localIngest);
when(clusterService.localNode()).thenReturn(localNode);
remoteNode1 = mock(DiscoveryNode.class);
remoteNode2 = mock(DiscoveryNode.class);
nodes = mock(DiscoveryNodes.class);
ImmutableOpenMap<String, DiscoveryNode> ingestNodes = ImmutableOpenMap.<String, DiscoveryNode>builder(2).fPut("node1", remoteNode1).fPut("node2", remoteNode2).build();
when(nodes.getIngestNodes()).thenReturn(ingestNodes);
when(nodes.getMinNodeVersion()).thenReturn(VersionUtils.randomCompatibleVersion(random(), Version.CURRENT));
ClusterState state = mock(ClusterState.class);
when(state.getNodes()).thenReturn(nodes);
Metadata metadata = Metadata.builder().indices(ImmutableOpenMap.<String, IndexMetadata>builder().putAll(MapBuilder.<String, IndexMetadata>newMapBuilder().put(WITH_DEFAULT_PIPELINE, IndexMetadata.builder(WITH_DEFAULT_PIPELINE).settings(settings(Version.CURRENT).put(IndexSettings.DEFAULT_PIPELINE.getKey(), "default_pipeline").build()).putAlias(AliasMetadata.builder(WITH_DEFAULT_PIPELINE_ALIAS).build()).numberOfShards(1).numberOfReplicas(1).build()).put(".system", IndexMetadata.builder(".system").settings(settings(Version.CURRENT)).system(true).numberOfShards(1).numberOfReplicas(0).build()).map()).build()).build();
when(state.getMetadata()).thenReturn(metadata);
when(state.metadata()).thenReturn(metadata);
when(clusterService.state()).thenReturn(state);
doAnswer(invocation -> {
ClusterChangedEvent event = mock(ClusterChangedEvent.class);
when(event.state()).thenReturn(state);
((ClusterStateApplier) invocation.getArguments()[0]).applyClusterState(event);
return null;
}).when(clusterService).addStateApplier(any(ClusterStateApplier.class));
// setup the mocked ingest service for capturing calls
ingestService = mock(IngestService.class);
action = new TestTransportBulkAction();
singleItemBulkWriteAction = new TestSingleItemBulkWriteAction(action);
// call on construction of action
reset(transportService);
}
Aggregations