forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
853 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
server/src/main/java/org/elasticsearch/action/bulk/SimulateBulkAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.bulk; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.transport.TransportRequestOptions; | ||
|
||
public class SimulateBulkAction extends ActionType<BulkResponse> { | ||
|
||
public static final SimulateBulkAction INSTANCE = new SimulateBulkAction(); | ||
public static final String NAME = "indices:admin/simulate/bulk"; | ||
|
||
private static final TransportRequestOptions TRANSPORT_REQUEST_OPTIONS = TransportRequestOptions.of( | ||
null, | ||
TransportRequestOptions.Type.BULK | ||
); | ||
|
||
private SimulateBulkAction() { | ||
super(NAME, BulkResponse::new); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
server/src/main/java/org/elasticsearch/action/bulk/SimulateBulkRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.bulk; | ||
|
||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.ingest.IngestService; | ||
import org.elasticsearch.ingest.Pipeline; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* This extends BulkRequest with support for providing substitute pipeline definitions. | ||
*/ | ||
public class SimulateBulkRequest extends BulkRequest { | ||
// Non-private for unit testing | ||
Map<String, Object> pipelineSubstitutions = Map.of(); | ||
|
||
public SimulateBulkRequest() { | ||
super(); | ||
} | ||
|
||
public SimulateBulkRequest(StreamInput in) throws IOException { | ||
super(in); | ||
this.pipelineSubstitutions = in.readMap(); | ||
} | ||
|
||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeGenericMap(pipelineSubstitutions); | ||
} | ||
|
||
public void setPipelineSubstitutions(Map<String, Object> pipelineSubstitutions) { | ||
this.pipelineSubstitutions = pipelineSubstitutions; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public Map<String, Pipeline> getPipelineSubstitutions(IngestService ingestService) throws Exception { | ||
Map<String, Pipeline> parsedPipelineSubstitutions = new HashMap<>(); | ||
if (pipelineSubstitutions != null) { | ||
for (Map.Entry<String, Object> entry : pipelineSubstitutions.entrySet()) { | ||
String pipelineId = entry.getKey(); | ||
Pipeline pipeline = Pipeline.create( | ||
pipelineId, | ||
(Map<String, Object>) entry.getValue(), | ||
ingestService.getProcessorFactories(), | ||
ingestService.getScriptService() | ||
); | ||
parsedPipelineSubstitutions.put(pipelineId, pipeline); | ||
} | ||
} | ||
return parsedPipelineSubstitutions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
server/src/main/java/org/elasticsearch/action/bulk/TransportSimulateBulkAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.bulk; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.DocWriteRequest; | ||
import org.elasticsearch.action.index.IndexRequest; | ||
import org.elasticsearch.action.ingest.SimulateIndexResponse; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.client.internal.node.NodeClient; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.util.concurrent.AtomicArray; | ||
import org.elasticsearch.index.IndexNotFoundException; | ||
import org.elasticsearch.index.IndexingPressure; | ||
import org.elasticsearch.indices.SystemIndices; | ||
import org.elasticsearch.ingest.IngestService; | ||
import org.elasticsearch.ingest.SimulateIngestService; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class TransportSimulateBulkAction extends TransportBulkAction { | ||
@Inject | ||
public TransportSimulateBulkAction( | ||
ThreadPool threadPool, | ||
TransportService transportService, | ||
ClusterService clusterService, | ||
IngestService ingestService, | ||
NodeClient client, | ||
ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver, | ||
IndexingPressure indexingPressure, | ||
SystemIndices systemIndices | ||
) { | ||
super( | ||
SimulateBulkAction.NAME, | ||
threadPool, | ||
transportService, | ||
clusterService, | ||
ingestService, | ||
client, | ||
actionFilters, | ||
indexNameExpressionResolver, | ||
indexingPressure, | ||
systemIndices, | ||
System::nanoTime | ||
); | ||
} | ||
|
||
@Override | ||
protected void indexData( | ||
Task task, | ||
BulkRequest bulkRequest, | ||
String executorName, | ||
ActionListener<BulkResponse> listener, | ||
AtomicArray<BulkItemResponse> responses, | ||
Set<String> autoCreateIndices, | ||
Map<String, IndexNotFoundException> indicesThatCannotBeCreated, | ||
long startTime | ||
) { | ||
for (int i = 0; i < bulkRequest.requests.size(); i++) { | ||
DocWriteRequest<?> request = bulkRequest.requests.get(i); | ||
responses.set( | ||
i, | ||
BulkItemResponse.success( | ||
0, | ||
DocWriteRequest.OpType.CREATE, | ||
new SimulateIndexResponse( | ||
request.index(), | ||
((IndexRequest) request).source(), | ||
((IndexRequest) request).getContentType(), | ||
((IndexRequest) request).getExecutedPipelines() | ||
) | ||
) | ||
); | ||
} | ||
listener.onResponse(new BulkResponse(responses.toArray(new BulkItemResponse[responses.length()]), buildTookInMillis(startTime))); | ||
} | ||
|
||
@Override | ||
protected IngestService getIngestService(BulkRequest request) { | ||
IngestService rawIngestService = super.getIngestService(request); | ||
return new SimulateIngestService(rawIngestService, request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.