Remove PROTOTYPEs from ingest

This commit is contained in:
Nik Everett 2016-03-30 21:42:16 -04:00
parent b7b65b93d1
commit f8a67a2622
5 changed files with 36 additions and 50 deletions

View File

@ -187,7 +187,6 @@
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]IngestActionFilter.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]IngestProxyActionFilter.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]PutPipelineTransportAction.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]SimulateDocumentBaseResult.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]SimulateExecutionService.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]SimulatePipelineRequest.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]SimulatePipelineRequestBuilder.java" checks="LineLength" />

View File

@ -25,52 +25,35 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.ingest.core.IngestDocument;
import java.io.IOException;
import java.util.Collections;
/**
* Holds the end result of what a pipeline did to sample document provided via the simulate api.
*/
public final class SimulateDocumentBaseResult implements SimulateDocumentResult<SimulateDocumentBaseResult> {
private static final SimulateDocumentBaseResult PROTOTYPE = new SimulateDocumentBaseResult(new WriteableIngestDocument(new IngestDocument(Collections.emptyMap(), Collections.emptyMap())));
private WriteableIngestDocument ingestDocument;
private Exception failure;
private final WriteableIngestDocument ingestDocument;
private final Exception failure;
public SimulateDocumentBaseResult(IngestDocument ingestDocument) {
this.ingestDocument = new WriteableIngestDocument(ingestDocument);
}
private SimulateDocumentBaseResult(WriteableIngestDocument ingestDocument) {
this.ingestDocument = ingestDocument;
failure = null;
}
public SimulateDocumentBaseResult(Exception failure) {
ingestDocument = null;
this.failure = failure;
}
public IngestDocument getIngestDocument() {
if (ingestDocument == null) {
return null;
}
return ingestDocument.getIngestDocument();
}
public Exception getFailure() {
return failure;
}
public static SimulateDocumentBaseResult readSimulateDocumentSimpleResult(StreamInput in) throws IOException {
return PROTOTYPE.readFrom(in);
}
@Override
public SimulateDocumentBaseResult readFrom(StreamInput in) throws IOException {
/**
* Read from a stream.
*/
public SimulateDocumentBaseResult(StreamInput in) throws IOException {
if (in.readBoolean()) {
Exception exception = in.readThrowable();
return new SimulateDocumentBaseResult(exception);
ingestDocument = null;
failure = in.readThrowable();
} else {
ingestDocument = new WriteableIngestDocument(in);
failure = null;
}
return new SimulateDocumentBaseResult(new WriteableIngestDocument(in));
}
@Override
@ -84,6 +67,17 @@ public final class SimulateDocumentBaseResult implements SimulateDocumentResult<
}
}
public IngestDocument getIngestDocument() {
if (ingestDocument == null) {
return null;
}
return ingestDocument.getIngestDocument();
}
public Exception getFailure() {
return failure;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();

View File

@ -24,7 +24,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
@ -32,31 +31,21 @@ import java.util.List;
* this result class holds the intermediate result each processor did to the sample document.
*/
public final class SimulateDocumentVerboseResult implements SimulateDocumentResult<SimulateDocumentVerboseResult> {
private static final SimulateDocumentVerboseResult PROTOTYPE = new SimulateDocumentVerboseResult(Collections.emptyList());
private final List<SimulateProcessorResult> processorResults;
public SimulateDocumentVerboseResult(List<SimulateProcessorResult> processorResults) {
this.processorResults = processorResults;
}
public List<SimulateProcessorResult> getProcessorResults() {
return processorResults;
}
public static SimulateDocumentVerboseResult readSimulateDocumentVerboseResultFrom(StreamInput in) throws IOException {
return PROTOTYPE.readFrom(in);
}
@Override
public SimulateDocumentVerboseResult readFrom(StreamInput in) throws IOException {
/**
* Read from a stream.
*/
public SimulateDocumentVerboseResult(StreamInput in) throws IOException {
int size = in.readVInt();
List<SimulateProcessorResult> processorResults = new ArrayList<>();
processorResults = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
processorResults.add(new SimulateProcessorResult(in));
}
return new SimulateDocumentVerboseResult(processorResults);
}
@Override
@ -67,6 +56,10 @@ public final class SimulateDocumentVerboseResult implements SimulateDocumentResu
}
}
public List<SimulateProcessorResult> getProcessorResults() {
return processorResults;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();

View File

@ -79,9 +79,9 @@ public class SimulatePipelineResponse extends ActionResponse implements ToXConte
for (int i = 0; i < responsesLength; i++) {
SimulateDocumentResult<?> simulateDocumentResult;
if (verbose) {
simulateDocumentResult = SimulateDocumentVerboseResult.readSimulateDocumentVerboseResultFrom(in);
simulateDocumentResult = new SimulateDocumentVerboseResult(in);
} else {
simulateDocumentResult = SimulateDocumentBaseResult.readSimulateDocumentSimpleResult(in);
simulateDocumentResult = new SimulateDocumentBaseResult(in);
}
results.add(simulateDocumentResult);
}

View File

@ -45,7 +45,7 @@ public class SimulateDocumentSimpleResultTests extends ESTestCase {
BytesStreamOutput out = new BytesStreamOutput();
simulateDocumentBaseResult.writeTo(out);
StreamInput streamInput = StreamInput.wrap(out.bytes());
SimulateDocumentBaseResult otherSimulateDocumentBaseResult = SimulateDocumentBaseResult.readSimulateDocumentSimpleResult(streamInput);
SimulateDocumentBaseResult otherSimulateDocumentBaseResult = new SimulateDocumentBaseResult(streamInput);
assertThat(otherSimulateDocumentBaseResult.getIngestDocument(), equalTo(simulateDocumentBaseResult.getIngestDocument()));
if (isFailure) {