diff --git a/x-pack/plugin/ccr/qa/multi-cluster-with-security/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexSecurityIT.java b/x-pack/plugin/ccr/qa/multi-cluster-with-security/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexSecurityIT.java index b11ac6f6f608b..960fedb988cf8 100644 --- a/x-pack/plugin/ccr/qa/multi-cluster-with-security/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexSecurityIT.java +++ b/x-pack/plugin/ccr/qa/multi-cluster-with-security/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexSecurityIT.java @@ -145,15 +145,13 @@ private static void refresh(String index) throws IOException { private static void followIndex(String leaderIndex, String followIndex) throws IOException { final Request request = new Request("POST", "/" + followIndex + "/_xpack/ccr/_follow"); - request.addParameter("leader_index", leaderIndex); - request.addParameter("idle_shard_retry_delay", "10ms"); + request.setJsonEntity("{\"leader_index\": \"" + leaderIndex + "\", \"idle_shard_retry_delay\": \"10ms\"}"); assertOK(client().performRequest(request)); } private static void createAndFollowIndex(String leaderIndex, String followIndex) throws IOException { final Request request = new Request("POST", "/" + followIndex + "/_xpack/ccr/_create_and_follow"); - request.addParameter("leader_index", leaderIndex); - request.addParameter("idle_shard_retry_delay", "10ms"); + request.setJsonEntity("{\"leader_index\": \"" + leaderIndex + "\", \"idle_shard_retry_delay\": \"10ms\"}"); assertOK(client().performRequest(request)); } diff --git a/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java b/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java index 8e637f7dbc183..cd3d92f2fb31c 100644 --- a/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java +++ b/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java @@ -95,15 +95,13 @@ private static void refresh(String index) throws IOException { private static void followIndex(String leaderIndex, String followIndex) throws IOException { final Request request = new Request("POST", "/" + followIndex + "/_xpack/ccr/_follow"); - request.addParameter("leader_index", leaderIndex); - request.addParameter("idle_shard_retry_delay", "10ms"); + request.setJsonEntity("{\"leader_index\": \"" + leaderIndex + "\", \"idle_shard_retry_delay\": \"10ms\"}"); assertOK(client().performRequest(request)); } private static void createAndFollowIndex(String leaderIndex, String followIndex) throws IOException { final Request request = new Request("POST", "/" + followIndex + "/_xpack/ccr/_create_and_follow"); - request.addParameter("leader_index", leaderIndex); - request.addParameter("idle_shard_retry_delay", "10ms"); + request.setJsonEntity("{\"leader_index\": \"" + leaderIndex + "\", \"idle_shard_retry_delay\": \"10ms\"}"); assertOK(client().performRequest(request)); } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/CreateAndFollowIndexAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/CreateAndFollowIndexAction.java index 14d4cf69d5d83..01558b91e9f09 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/CreateAndFollowIndexAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/CreateAndFollowIndexAction.java @@ -278,7 +278,7 @@ protected Boolean newResponse(boolean acknowledged) { @Override public ClusterState execute(ClusterState currentState) throws Exception { - String followIndex = request.getFollowRequest().getFollowIndex(); + String followIndex = request.getFollowRequest().getFollowerIndex(); IndexMetaData currentIndex = currentState.metaData().index(followIndex); if (currentIndex != null) { throw new ResourceAlreadyExistsException(currentIndex.getIndex()); @@ -286,7 +286,7 @@ public ClusterState execute(ClusterState currentState) throws Exception { MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData()); IndexMetaData.Builder imdBuilder = IndexMetaData.builder(followIndex); - + // Copy all settings, but overwrite a few settings. Settings.Builder settingsBuilder = Settings.builder(); settingsBuilder.put(leaderIndexMetaData.getSettings()); @@ -295,7 +295,7 @@ public ClusterState execute(ClusterState currentState) throws Exception { settingsBuilder.put(IndexMetaData.SETTING_INDEX_PROVIDED_NAME, followIndex); settingsBuilder.put(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey(), true); imdBuilder.settings(settingsBuilder); - + // Copy mappings from leader IMD to follow IMD for (ObjectObjectCursor cursor : leaderIndexMetaData.getMappings()) { imdBuilder.putMapping(cursor.value); @@ -309,21 +309,21 @@ public ClusterState execute(ClusterState currentState) throws Exception { ClusterState updatedState = builder.build(); RoutingTable.Builder routingTableBuilder = RoutingTable.builder(updatedState.routingTable()) - .addAsNew(updatedState.metaData().index(request.getFollowRequest().getFollowIndex())); + .addAsNew(updatedState.metaData().index(request.getFollowRequest().getFollowerIndex())); updatedState = allocationService.reroute( ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(), - "follow index [" + request.getFollowRequest().getFollowIndex() + "] created"); - + "follow index [" + request.getFollowRequest().getFollowerIndex() + "] created"); + logger.info("[{}] creating index, cause [ccr_create_and_follow], shards [{}]/[{}]", followIndex, followIMD.getNumberOfShards(), followIMD.getNumberOfReplicas()); - + return updatedState; } }); } private void initiateFollowing(Request request, ActionListener listener) { - activeShardsObserver.waitForActiveShards(new String[]{request.followRequest.getFollowIndex()}, + activeShardsObserver.waitForActiveShards(new String[]{request.followRequest.getFollowerIndex()}, ActiveShardCount.DEFAULT, request.timeout(), result -> { if (result) { client.execute(FollowIndexAction.INSTANCE, request.getFollowRequest(), ActionListener.wrap( @@ -338,7 +338,7 @@ private void initiateFollowing(Request request, ActionListener listene @Override protected ClusterBlockException checkBlock(Request request, ClusterState state) { - return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, request.getFollowRequest().getFollowIndex()); + return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, request.getFollowRequest().getFollowerIndex()); } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/FollowIndexAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/FollowIndexAction.java index f91b6c3f76a66..9223a6d35d03f 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/FollowIndexAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/FollowIndexAction.java @@ -22,12 +22,18 @@ import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.ObjectParser; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexingSlowLog; import org.elasticsearch.index.SearchSlowLog; @@ -76,10 +82,51 @@ public Response newResponse() { return new Response(); } - public static class Request extends ActionRequest { + public static class Request extends ActionRequest implements ToXContentObject { + + private static final ParseField LEADER_INDEX_FIELD = new ParseField("leader_index"); + private static final ParseField FOLLOWER_INDEX_FIELD = new ParseField("follower_index"); + private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, true, + (args, followerIndex) -> { + if (args[1] != null) { + followerIndex = (String) args[1]; + } + return new Request((String) args[0], followerIndex, (Integer) args[2], (Integer) args[3], (Long) args[4], + (Integer) args[5], (Integer) args[6], (TimeValue) args[7], (TimeValue) args[8]); + }); + + static { + PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), LEADER_INDEX_FIELD); + PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), FOLLOWER_INDEX_FIELD); + PARSER.declareInt(ConstructingObjectParser.optionalConstructorArg(), ShardFollowTask.MAX_BATCH_OPERATION_COUNT); + PARSER.declareInt(ConstructingObjectParser.optionalConstructorArg(), ShardFollowTask.MAX_CONCURRENT_READ_BATCHES); + PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), ShardFollowTask.MAX_BATCH_SIZE_IN_BYTES); + PARSER.declareInt(ConstructingObjectParser.optionalConstructorArg(), ShardFollowTask.MAX_CONCURRENT_WRITE_BATCHES); + PARSER.declareInt(ConstructingObjectParser.optionalConstructorArg(), ShardFollowTask.MAX_WRITE_BUFFER_SIZE); + PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(), + (p, c) -> TimeValue.parseTimeValue(p.text(), ShardFollowTask.RETRY_TIMEOUT.getPreferredName()), + ShardFollowTask.RETRY_TIMEOUT, ObjectParser.ValueType.STRING); + PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(), + (p, c) -> TimeValue.parseTimeValue(p.text(), ShardFollowTask.IDLE_SHARD_RETRY_DELAY.getPreferredName()), + ShardFollowTask.IDLE_SHARD_RETRY_DELAY, ObjectParser.ValueType.STRING); + } + + public static Request fromXContent(XContentParser parser, String followerIndex) throws IOException { + Request request = PARSER.parse(parser, followerIndex); + if (followerIndex != null) { + if (request.followerIndex == null) { + request.followerIndex = followerIndex; + } else { + if (request.followerIndex.equals(followerIndex) == false) { + throw new IllegalArgumentException("provided follower_index is not equal"); + } + } + } + return request; + } private String leaderIndex; - private String followIndex; + private String followerIndex; private int maxBatchOperationCount; private int maxConcurrentReadBatches; private long maxOperationSizeInBytes; @@ -88,9 +135,37 @@ public static class Request extends ActionRequest { private TimeValue retryTimeout; private TimeValue idleShardRetryDelay; - public Request(String leaderIndex, String followIndex, int maxBatchOperationCount, int maxConcurrentReadBatches, - long maxOperationSizeInBytes, int maxConcurrentWriteBatches, int maxWriteBufferSize, + public Request(String leaderIndex, String followerIndex, Integer maxBatchOperationCount, Integer maxConcurrentReadBatches, + Long maxOperationSizeInBytes, Integer maxConcurrentWriteBatches, Integer maxWriteBufferSize, TimeValue retryTimeout, TimeValue idleShardRetryDelay) { + if (leaderIndex == null) { + throw new IllegalArgumentException("leader_index is missing"); + } + if (followerIndex == null) { + throw new IllegalArgumentException("follower_index is missing"); + } + if (maxBatchOperationCount == null) { + maxBatchOperationCount = ShardFollowNodeTask.DEFAULT_MAX_BATCH_OPERATION_COUNT; + } + if (maxConcurrentReadBatches == null) { + maxConcurrentReadBatches = ShardFollowNodeTask.DEFAULT_MAX_CONCURRENT_READ_BATCHES; + } + if (maxOperationSizeInBytes == null) { + maxOperationSizeInBytes = ShardFollowNodeTask.DEFAULT_MAX_BATCH_SIZE_IN_BYTES; + } + if (maxConcurrentWriteBatches == null) { + maxConcurrentWriteBatches = ShardFollowNodeTask.DEFAULT_MAX_CONCURRENT_WRITE_BATCHES; + } + if (maxWriteBufferSize == null) { + maxWriteBufferSize = ShardFollowNodeTask.DEFAULT_MAX_WRITE_BUFFER_SIZE; + } + if (retryTimeout == null) { + retryTimeout = ShardFollowNodeTask.DEFAULT_RETRY_TIMEOUT; + } + if (idleShardRetryDelay == null) { + idleShardRetryDelay = ShardFollowNodeTask.DEFAULT_IDLE_SHARD_RETRY_DELAY; + } + if (maxBatchOperationCount < 1) { throw new IllegalArgumentException("maxBatchOperationCount must be larger than 0"); } @@ -107,15 +182,15 @@ public Request(String leaderIndex, String followIndex, int maxBatchOperationCoun throw new IllegalArgumentException("maxWriteBufferSize must be larger than 0"); } - this.leaderIndex = Objects.requireNonNull(leaderIndex); - this.followIndex = Objects.requireNonNull(followIndex); + this.leaderIndex = leaderIndex; + this.followerIndex = followerIndex; this.maxBatchOperationCount = maxBatchOperationCount; this.maxConcurrentReadBatches = maxConcurrentReadBatches; this.maxOperationSizeInBytes = maxOperationSizeInBytes; this.maxConcurrentWriteBatches = maxConcurrentWriteBatches; this.maxWriteBufferSize = maxWriteBufferSize; - this.retryTimeout = Objects.requireNonNull(retryTimeout); - this.idleShardRetryDelay = Objects.requireNonNull(idleShardRetryDelay); + this.retryTimeout = retryTimeout; + this.idleShardRetryDelay = idleShardRetryDelay; } Request() { @@ -125,8 +200,8 @@ public String getLeaderIndex() { return leaderIndex; } - public String getFollowIndex() { - return followIndex; + public String getFollowerIndex() { + return followerIndex; } public int getMaxBatchOperationCount() { @@ -142,7 +217,7 @@ public ActionRequestValidationException validate() { public void readFrom(StreamInput in) throws IOException { super.readFrom(in); leaderIndex = in.readString(); - followIndex = in.readString(); + followerIndex = in.readString(); maxBatchOperationCount = in.readVInt(); maxConcurrentReadBatches = in.readVInt(); maxOperationSizeInBytes = in.readVLong(); @@ -156,7 +231,7 @@ public void readFrom(StreamInput in) throws IOException { public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(leaderIndex); - out.writeString(followIndex); + out.writeString(followerIndex); out.writeVInt(maxBatchOperationCount); out.writeVInt(maxConcurrentReadBatches); out.writeVLong(maxOperationSizeInBytes); @@ -166,6 +241,24 @@ public void writeTo(StreamOutput out) throws IOException { out.writeOptionalTimeValue(idleShardRetryDelay); } + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + { + builder.field(LEADER_INDEX_FIELD.getPreferredName(), leaderIndex); + builder.field(FOLLOWER_INDEX_FIELD.getPreferredName(), followerIndex); + builder.field(ShardFollowTask.MAX_BATCH_OPERATION_COUNT.getPreferredName(), maxBatchOperationCount); + builder.field(ShardFollowTask.MAX_BATCH_SIZE_IN_BYTES.getPreferredName(), maxOperationSizeInBytes); + builder.field(ShardFollowTask.MAX_WRITE_BUFFER_SIZE.getPreferredName(), maxWriteBufferSize); + builder.field(ShardFollowTask.MAX_CONCURRENT_READ_BATCHES.getPreferredName(), maxConcurrentReadBatches); + builder.field(ShardFollowTask.MAX_CONCURRENT_WRITE_BATCHES.getPreferredName(), maxConcurrentWriteBatches); + builder.field(ShardFollowTask.RETRY_TIMEOUT.getPreferredName(), retryTimeout.getStringRep()); + builder.field(ShardFollowTask.IDLE_SHARD_RETRY_DELAY.getPreferredName(), idleShardRetryDelay.getStringRep()); + } + builder.endObject(); + return builder; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -179,12 +272,12 @@ public boolean equals(Object o) { Objects.equals(retryTimeout, request.retryTimeout) && Objects.equals(idleShardRetryDelay, request.idleShardRetryDelay) && Objects.equals(leaderIndex, request.leaderIndex) && - Objects.equals(followIndex, request.followIndex); + Objects.equals(followerIndex, request.followerIndex); } @Override public int hashCode() { - return Objects.hash(leaderIndex, followIndex, maxBatchOperationCount, maxConcurrentReadBatches, maxOperationSizeInBytes, + return Objects.hash(leaderIndex, followerIndex, maxBatchOperationCount, maxConcurrentReadBatches, maxOperationSizeInBytes, maxConcurrentWriteBatches, maxWriteBufferSize, retryTimeout, idleShardRetryDelay); } } @@ -229,7 +322,7 @@ public TransportAction(Settings settings, ThreadPool threadPool, TransportServic @Override protected void doExecute(Request request, ActionListener listener) { ClusterState localClusterState = clusterService.state(); - IndexMetaData followIndexMetadata = localClusterState.getMetaData().index(request.followIndex); + IndexMetaData followIndexMetadata = localClusterState.getMetaData().index(request.followerIndex); String[] indices = new String[]{request.leaderIndex}; Map> remoteClusterIndices = remoteClusterService.groupClusterIndices(indices, s -> false); @@ -390,7 +483,7 @@ static void validate(Request request, IndexMetaData leaderIndex, IndexMetaData f throw new IllegalArgumentException("leader index [" + request.leaderIndex + "] does not exist"); } if (followIndex == null) { - throw new IllegalArgumentException("follow index [" + request.followIndex + "] does not exist"); + throw new IllegalArgumentException("follow index [" + request.followerIndex + "] does not exist"); } if (leaderIndex.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), false) == false) { throw new IllegalArgumentException("leader index [" + request.leaderIndex + "] does not have soft deletes enabled"); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowIndexAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowIndexAction.java index 6804ce8ecb72c..845b06987db3f 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowIndexAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowIndexAction.java @@ -7,13 +7,11 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.ccr.action.ShardFollowNodeTask; -import org.elasticsearch.xpack.ccr.action.ShardFollowTask; import java.io.IOException; @@ -38,32 +36,9 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient return channel -> client.execute(INSTANCE, request, new RestToXContentListener<>(channel)); } - static Request createRequest(RestRequest restRequest) { - int maxBatchOperationCount = ShardFollowNodeTask.DEFAULT_MAX_BATCH_OPERATION_COUNT; - if (restRequest.hasParam(ShardFollowTask.MAX_BATCH_OPERATION_COUNT.getPreferredName())) { - maxBatchOperationCount = Integer.valueOf(restRequest.param(ShardFollowTask.MAX_BATCH_OPERATION_COUNT.getPreferredName())); + static Request createRequest(RestRequest restRequest) throws IOException { + try (XContentParser parser = restRequest.contentOrSourceParamParser()) { + return Request.fromXContent(parser, restRequest.param("index")); } - int maxConcurrentReadBatches = ShardFollowNodeTask.DEFAULT_MAX_CONCURRENT_READ_BATCHES; - if (restRequest.hasParam(ShardFollowTask.MAX_CONCURRENT_READ_BATCHES.getPreferredName())) { - maxConcurrentReadBatches = Integer.valueOf(restRequest.param(ShardFollowTask.MAX_CONCURRENT_READ_BATCHES.getPreferredName())); - } - long maxBatchSizeInBytes = ShardFollowNodeTask.DEFAULT_MAX_BATCH_SIZE_IN_BYTES; - if (restRequest.hasParam(ShardFollowTask.MAX_BATCH_SIZE_IN_BYTES.getPreferredName())) { - maxBatchSizeInBytes = Long.valueOf(restRequest.param(ShardFollowTask.MAX_BATCH_SIZE_IN_BYTES.getPreferredName())); - } - int maxConcurrentWriteBatches = ShardFollowNodeTask.DEFAULT_MAX_CONCURRENT_WRITE_BATCHES; - if (restRequest.hasParam(ShardFollowTask.MAX_CONCURRENT_WRITE_BATCHES.getPreferredName())) { - maxConcurrentWriteBatches = Integer.valueOf(restRequest.param(ShardFollowTask.MAX_CONCURRENT_WRITE_BATCHES.getPreferredName())); - } - int maxWriteBufferSize = ShardFollowNodeTask.DEFAULT_MAX_WRITE_BUFFER_SIZE; - if (restRequest.hasParam(ShardFollowTask.MAX_WRITE_BUFFER_SIZE.getPreferredName())) { - maxWriteBufferSize = Integer.parseInt(restRequest.param(ShardFollowTask.MAX_WRITE_BUFFER_SIZE.getPreferredName())); - } - TimeValue retryTimeout = restRequest.paramAsTime(ShardFollowTask.RETRY_TIMEOUT.getPreferredName(), - ShardFollowNodeTask.DEFAULT_RETRY_TIMEOUT); - TimeValue idleShardRetryTimeout = restRequest.paramAsTime(ShardFollowTask.IDLE_SHARD_RETRY_DELAY.getPreferredName(), - ShardFollowNodeTask.DEFAULT_IDLE_SHARD_RETRY_DELAY); - return new Request(restRequest.param("leader_index"), restRequest.param("index"), maxBatchOperationCount, maxConcurrentReadBatches, - maxBatchSizeInBytes, maxConcurrentWriteBatches, maxWriteBufferSize, retryTimeout, idleShardRetryTimeout); } } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/ShardChangesIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/ShardChangesIT.java index 12151261e4bed..38a46a2437f6a 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/ShardChangesIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/ShardChangesIT.java @@ -438,7 +438,7 @@ public void testFollowIndex_lowMaxTranslogBytes() throws Exception { client().prepareIndex("index1", "doc", Integer.toString(i)).setSource(source, XContentType.JSON).get(); } - final FollowIndexAction.Request followRequest = new FollowIndexAction.Request("index1", "index2", 1024, 1, 1024, + final FollowIndexAction.Request followRequest = new FollowIndexAction.Request("index1", "index2", 1024, 1, 1024L, 1, 10240, TimeValue.timeValueMillis(500), TimeValue.timeValueMillis(10)); final CreateAndFollowIndexAction.Request createAndFollowRequest = new CreateAndFollowIndexAction.Request(followRequest); client().execute(CreateAndFollowIndexAction.INSTANCE, createAndFollowRequest).get(); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowIndexRequestTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowIndexRequestTests.java index ac5bc9b74626e..7202f7202c643 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowIndexRequestTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowIndexRequestTests.java @@ -6,9 +6,12 @@ package org.elasticsearch.xpack.ccr.action; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.test.AbstractStreamableTestCase; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.test.AbstractStreamableXContentTestCase; -public class FollowIndexRequestTests extends AbstractStreamableTestCase { +import java.io.IOException; + +public class FollowIndexRequestTests extends AbstractStreamableXContentTestCase { @Override protected FollowIndexAction.Request createBlankInstance() { @@ -20,6 +23,16 @@ protected FollowIndexAction.Request createTestInstance() { return createTestRequest(); } + @Override + protected FollowIndexAction.Request doParseInstance(XContentParser parser) throws IOException { + return FollowIndexAction.Request.fromXContent(parser, null); + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } + static FollowIndexAction.Request createTestRequest() { return new FollowIndexAction.Request(randomAlphaOfLength(4), randomAlphaOfLength(4), randomIntBetween(1, Integer.MAX_VALUE), randomIntBetween(1, Integer.MAX_VALUE), randomNonNegativeLong(), randomIntBetween(1, Integer.MAX_VALUE), diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.create_and_follow_index.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.create_and_follow_index.json index 236e8e6759cb1..56e87dd0d8c8a 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.create_and_follow_index.json +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.create_and_follow_index.json @@ -9,16 +9,13 @@ "index": { "type": "string", "required": true, - "description": "The name of the index that follows the leader index." - } - }, - "params": { - "leader_index": { - "type": "string", - "required": true, - "description": "The name of the index to read the changes from." + "description": "The name of the follower index" } } + }, + "body": { + "description" : "The name of the leader index and other optional ccr related parameters", + "required" : true } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.follow_index.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.follow_index.json index 9decf2537bdec..1d03eb0839b15 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.follow_index.json +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.follow_index.json @@ -9,16 +9,13 @@ "index": { "type": "string", "required": true, - "description": "The name of the index that follows to leader index." - } - }, - "params": { - "leader_index": { - "type": "string", - "required": true, - "description": "The name of the index to read the changes from." + "description": "The name of the follower index." } } + }, + "body": { + "description" : "The name of the leader index and other optional ccr related parameters", + "required" : true } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.unfollow_index.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.unfollow_index.json index d7aab3d6c08fa..394e81b249abe 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.unfollow_index.json +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.ccr.unfollow_index.json @@ -9,10 +9,8 @@ "index": { "type": "string", "required": true, - "description": "The name of the follow index that should stop following its leader index." + "description": "The name of the follower index that should stop following its leader index." } - }, - "params": { } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ccr/follow_and_unfollow.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ccr/follow_and_unfollow.yml index 74b5d7e756c8f..f39c0edca5ced 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ccr/follow_and_unfollow.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ccr/follow_and_unfollow.yml @@ -17,8 +17,9 @@ - do: xpack.ccr.create_and_follow_index: - leader_index: foo index: bar + body: + leader_index: foo - is_true: follow_index_created - is_true: follow_index_shards_acked - is_true: index_following_started @@ -30,8 +31,9 @@ - do: xpack.ccr.follow_index: - leader_index: foo index: bar + body: + leader_index: foo - is_true: acknowledged - do: