Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ingest pipeline _simulate api with empty docs never returns a res… #52937

Merged
merged 5 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public void execute(SimulatePipelineRequest.Parsed request, ActionListener<Simul
final AtomicInteger counter = new AtomicInteger();
final List<SimulateDocumentResult> responses =
new CopyOnWriteArrayList<>(new SimulateDocumentBaseResult[request.getDocuments().size()]);

if (request.getDocuments().isEmpty()) {
l.onResponse(new SimulatePipelineResponse(request.getPipeline().getId(),
gaobinlong marked this conversation as resolved.
Show resolved Hide resolved
request.isVerbose(), responses));
return;
}

int iter = 0;
for (IngestDocument ingestDocument : request.getDocuments()) {
final int index = iter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,15 @@ static Parsed parse(Map<String, Object> config, boolean verbose, IngestService i
private static List<IngestDocument> parseDocs(Map<String, Object> config) {
List<Map<String, Object>> docs =
ConfigurationUtils.readList(null, null, config, Fields.DOCS);
if (docs.isEmpty()) {
throw new IllegalArgumentException("must specify at least one document in [docs]");
}
List<IngestDocument> ingestDocumentList = new ArrayList<>();
for (Map<String, Object> dataMap : docs) {
for (Object object : docs) {
if ((object instanceof Map) == false) {
throw new IllegalArgumentException("malformed [docs] section, should include an inner object");
}
Map<String, Object> dataMap = (Map<String, Object>) object;
Map<String, Object> document = ConfigurationUtils.readMap(null, null,
dataMap, Fields.SOURCE);
String index = ConfigurationUtils.readStringOrIntProperty(null, null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.action.ingest;

import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.ingest.CompoundProcessor;
import org.elasticsearch.ingest.IngestDocument;
Expand All @@ -45,6 +46,7 @@
import static org.elasticsearch.ingest.IngestDocument.MetaData.ROUTING;
import static org.elasticsearch.ingest.IngestDocument.MetaData.VERSION;
import static org.elasticsearch.ingest.IngestDocument.MetaData.VERSION_TYPE;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -216,4 +218,33 @@ public void testNonExistentPipelineId() {
() -> SimulatePipelineRequest.parseWithPipelineId(pipelineId, requestContent, false, ingestService));
assertThat(e.getMessage(), equalTo("pipeline [" + pipelineId + "] does not exist"));
}

public void testNotValidDocs() {
Map<String, Object> requestContent = new HashMap<>();
List<Map<String, Object>> docs = new ArrayList<>();
Map<String, Object> pipelineConfig = new HashMap<>();
List<Map<String, Object>> processors = new ArrayList<>();
pipelineConfig.put("processors", processors);
requestContent.put(Fields.DOCS, docs);
requestContent.put(Fields.PIPELINE, pipelineConfig);
Exception e1 = expectThrows(IllegalArgumentException.class,
() -> SimulatePipelineRequest.parse(requestContent, false, ingestService));
assertThat(e1.getMessage(), equalTo("must specify at least one document in [docs]"));

List<String> stringList = new ArrayList<>();
stringList.add("test");
pipelineConfig.put("processors", processors);
requestContent.put(Fields.DOCS, stringList);
requestContent.put(Fields.PIPELINE, pipelineConfig);
Exception e2 = expectThrows(IllegalArgumentException.class,
() -> SimulatePipelineRequest.parse(requestContent, false, ingestService));
assertThat(e2.getMessage(), equalTo("malformed [docs] section, should include an inner object"));

docs.add(new HashMap<>());
requestContent.put(Fields.DOCS, docs);
requestContent.put(Fields.PIPELINE, pipelineConfig);
Exception e3 = expectThrows(ElasticsearchParseException.class,
() -> SimulatePipelineRequest.parse(requestContent, false, ingestService));
assertThat(e3.getMessage(), containsString("required property is missing"));
}
}