make the rest pass
Original commit: elastic/x-pack-elasticsearch@3d60f13994
This commit is contained in:
parent
9886ecab5c
commit
ef7d216b4e
|
@ -103,13 +103,13 @@ public class ExecutableIndexAction extends ExecutableAction<IndexAction> {
|
||||||
bulkRequest.add(indexRequest);
|
bulkRequest.add(indexRequest);
|
||||||
}
|
}
|
||||||
BulkResponse bulkResponse = client.bulk(bulkRequest);
|
BulkResponse bulkResponse = client.bulk(bulkRequest);
|
||||||
XContentBuilder jsonBuilder = jsonBuilder().startObject().startArray("items");
|
XContentBuilder jsonBuilder = jsonBuilder().startArray();
|
||||||
for (BulkItemResponse item : bulkResponse) {
|
for (BulkItemResponse item : bulkResponse) {
|
||||||
IndexResponse response = item.getResponse();
|
IndexResponse response = item.getResponse();
|
||||||
indexResponseToXContent(jsonBuilder, response);
|
indexResponseToXContent(jsonBuilder, response);
|
||||||
}
|
}
|
||||||
jsonBuilder.endArray().endObject();
|
jsonBuilder.endArray();
|
||||||
return new IndexAction.Result.Success(new XContentSource(jsonBuilder.bytes()));
|
return new IndexAction.Result.Success(new XContentSource(jsonBuilder.bytes(), XContentType.JSON));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void indexResponseToXContent(XContentBuilder builder, IndexResponse response) throws IOException {
|
static void indexResponseToXContent(XContentBuilder builder, IndexResponse response) throws IOException {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.watcher.support.xcontent;
|
package org.elasticsearch.watcher.support.xcontent;
|
||||||
|
|
||||||
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.ElasticsearchParseException;
|
import org.elasticsearch.ElasticsearchParseException;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.collect.Tuple;
|
import org.elasticsearch.common.collect.Tuple;
|
||||||
|
@ -22,15 +23,22 @@ import java.util.Map;
|
||||||
public class XContentSource implements ToXContent {
|
public class XContentSource implements ToXContent {
|
||||||
|
|
||||||
private final BytesReference bytes;
|
private final BytesReference bytes;
|
||||||
private XContentType contentType;
|
private final XContentType contentType;
|
||||||
private Object data;
|
private Object data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new XContentSource out of the given bytes reference.
|
* Constructs a new XContentSource out of the given bytes reference.
|
||||||
*/
|
*/
|
||||||
public XContentSource(BytesReference bytes) throws ElasticsearchParseException {
|
public XContentSource(BytesReference bytes, XContentType xContentType) throws ElasticsearchParseException {
|
||||||
|
if (xContentType == null) {
|
||||||
|
throw new IllegalArgumentException("xContentType must not be null");
|
||||||
|
}
|
||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
assert XContentFactory.xContentType(bytes) != null;
|
this.contentType = xContentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XContentSource(BytesReference bytes) {
|
||||||
|
this(bytes, XContentFactory.xContentType(bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,8 +88,7 @@ public class XContentSource implements ToXContent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
XContentType xContentType = contentType();
|
try (XContentParser parser = parser()) {
|
||||||
try (XContentParser parser = xContentType.xContent().createParser(bytes)) {
|
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
XContentHelper.copyCurrentStructure(builder.generator(), parser);
|
XContentHelper.copyCurrentStructure(builder.generator(), parser);
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -89,30 +96,25 @@ public class XContentSource implements ToXContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XContentParser parser() throws IOException {
|
public XContentParser parser() throws IOException {
|
||||||
XContentType xContentType = contentType();
|
return contentType.xContent().createParser(bytes);
|
||||||
return xContentType.xContent().createParser(bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static XContentSource readFrom(StreamInput in) throws IOException {
|
public static XContentSource readFrom(StreamInput in) throws IOException {
|
||||||
return new XContentSource(in.readBytesReference());
|
return new XContentSource(in.readBytesReference(), XContentType.readFrom(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeTo(XContentSource source, StreamOutput out) throws IOException {
|
public static void writeTo(XContentSource source, StreamOutput out) throws IOException {
|
||||||
out.writeBytesReference(source.bytes);
|
out.writeBytesReference(source.bytes);
|
||||||
}
|
XContentType.writeTo(source.contentType, out);
|
||||||
|
|
||||||
private XContentType contentType() {
|
|
||||||
if (contentType == null) {
|
|
||||||
contentType = XContentFactory.xContentType(bytes);
|
|
||||||
}
|
|
||||||
return contentType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object data() {
|
private Object data() {
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
Tuple<XContentType, Object> tuple = WatcherXContentUtils.convertToObject(bytes);
|
try (XContentParser parser = parser()) {
|
||||||
this.contentType = tuple.v1();
|
data = WatcherXContentUtils.readValue(parser, parser.nextToken());
|
||||||
this.data = tuple.v2();
|
} catch (IOException ex) {
|
||||||
|
throw new ElasticsearchException("failed to read value", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,14 +144,14 @@ public class IndexActionTests extends ElasticsearchIntegrationTest {
|
||||||
assertThat(result, instanceOf(IndexAction.Result.Success.class));
|
assertThat(result, instanceOf(IndexAction.Result.Success.class));
|
||||||
IndexAction.Result.Success successResult = (IndexAction.Result.Success) result;
|
IndexAction.Result.Success successResult = (IndexAction.Result.Success) result;
|
||||||
XContentSource response = successResult.response();
|
XContentSource response = successResult.response();
|
||||||
assertThat(successResult.toString(), response.getValue("items.0.created"), equalTo((Object)Boolean.TRUE));
|
assertThat(successResult.toString(), response.getValue("0.created"), equalTo((Object)Boolean.TRUE));
|
||||||
assertThat(successResult.toString(), response.getValue("items.0.version"), equalTo((Object) 1));
|
assertThat(successResult.toString(), response.getValue("0.version"), equalTo((Object) 1));
|
||||||
assertThat(successResult.toString(), response.getValue("items.0.type").toString(), equalTo("test-type"));
|
assertThat(successResult.toString(), response.getValue("0.type").toString(), equalTo("test-type"));
|
||||||
assertThat(successResult.toString(), response.getValue("items.0.index").toString(), equalTo("test-index"));
|
assertThat(successResult.toString(), response.getValue("0.index").toString(), equalTo("test-index"));
|
||||||
assertThat(successResult.toString(), response.getValue("items.1.created"), equalTo((Object)Boolean.TRUE));
|
assertThat(successResult.toString(), response.getValue("1.created"), equalTo((Object)Boolean.TRUE));
|
||||||
assertThat(successResult.toString(), response.getValue("items.1.version"), equalTo((Object) 1));
|
assertThat(successResult.toString(), response.getValue("1.version"), equalTo((Object) 1));
|
||||||
assertThat(successResult.toString(), response.getValue("items.1.type").toString(), equalTo("test-type"));
|
assertThat(successResult.toString(), response.getValue("1.type").toString(), equalTo("test-type"));
|
||||||
assertThat(successResult.toString(), response.getValue("items.1.index").toString(), equalTo("test-index"));
|
assertThat(successResult.toString(), response.getValue("1.index").toString(), equalTo("test-index"));
|
||||||
|
|
||||||
refresh(); //Manually refresh to make sure data is available
|
refresh(); //Manually refresh to make sure data is available
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class TriggeredWatchStoreTests extends ElasticsearchTestCase {
|
||||||
state = ShardRoutingState.UNASSIGNED;
|
state = ShardRoutingState.UNASSIGNED;
|
||||||
}
|
}
|
||||||
indexRoutingTableBuilder.addIndexShard(new IndexShardRoutingTable.Builder(new ShardId(indexName, 0), false)
|
indexRoutingTableBuilder.addIndexShard(new IndexShardRoutingTable.Builder(new ShardId(indexName, 0), false)
|
||||||
.addShard(new ImmutableShardRouting(indexName, 0, "_node_id", null, true, state, 1))
|
.addShard(new ImmutableShardRouting(indexName, 0, "_node_id", null, null, true, state, 1, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "")))
|
||||||
.build());
|
.build());
|
||||||
indexRoutingTableBuilder.addReplica();
|
indexRoutingTableBuilder.addReplica();
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class WatchStoreTests extends ElasticsearchTestCase {
|
||||||
metaDateBuilder.put(IndexMetaData.builder(WatchStore.INDEX).settings(settings).numberOfShards(1).numberOfReplicas(1));
|
metaDateBuilder.put(IndexMetaData.builder(WatchStore.INDEX).settings(settings).numberOfShards(1).numberOfReplicas(1));
|
||||||
IndexRoutingTable.Builder indexRoutingTableBuilder = IndexRoutingTable.builder(WatchStore.INDEX);
|
IndexRoutingTable.Builder indexRoutingTableBuilder = IndexRoutingTable.builder(WatchStore.INDEX);
|
||||||
indexRoutingTableBuilder.addIndexShard(new IndexShardRoutingTable.Builder(new ShardId(WatchStore.INDEX, 0), false)
|
indexRoutingTableBuilder.addIndexShard(new IndexShardRoutingTable.Builder(new ShardId(WatchStore.INDEX, 0), false)
|
||||||
.addShard(new ImmutableShardRouting(WatchStore.INDEX, 0, "_node_id", null, true, ShardRoutingState.UNASSIGNED, 1))
|
.addShard(new ImmutableShardRouting(WatchStore.INDEX, 0, "_node_id", null, null, true, ShardRoutingState.UNASSIGNED, 1, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "")))
|
||||||
.build());
|
.build());
|
||||||
indexRoutingTableBuilder.addReplica();
|
indexRoutingTableBuilder.addReplica();
|
||||||
routingTableBuilder.add(indexRoutingTableBuilder.build());
|
routingTableBuilder.add(indexRoutingTableBuilder.build());
|
||||||
|
|
Loading…
Reference in New Issue