Skip to content

Commit

Permalink
Renamed FollowExisting* internal names to just Follow*
Browse files Browse the repository at this point in the history
and fixed tests
  • Loading branch information
martijnvg committed May 15, 2018
1 parent 9bb2413 commit d79989a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.elasticsearch.threadpool.ExecutorBuilder;
import org.elasticsearch.threadpool.FixedExecutorBuilder;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.ccr.action.FollowExistingIndexAction;
import org.elasticsearch.xpack.ccr.action.FollowIndexAction;
import org.elasticsearch.xpack.ccr.action.CreateAndFollowIndexAction;
import org.elasticsearch.xpack.ccr.action.ShardChangesAction;
import org.elasticsearch.xpack.ccr.action.ShardFollowNodeTask;
Expand All @@ -44,7 +44,7 @@
import org.elasticsearch.xpack.ccr.action.bulk.BulkShardOperationsAction;
import org.elasticsearch.xpack.ccr.action.bulk.TransportBulkShardOperationsAction;
import org.elasticsearch.xpack.ccr.index.engine.FollowingEngineFactory;
import org.elasticsearch.xpack.ccr.rest.RestFollowExistingIndexAction;
import org.elasticsearch.xpack.ccr.rest.RestFollowIndexAction;
import org.elasticsearch.xpack.ccr.rest.RestCreateAndFollowIndexAction;
import org.elasticsearch.xpack.ccr.rest.RestUnfollowIndexAction;
import org.elasticsearch.xpack.core.XPackPlugin;
Expand Down Expand Up @@ -92,7 +92,7 @@ public List<PersistentTasksExecutor<?>> getPersistentTasksExecutor(ClusterServic

return Arrays.asList(
new ActionHandler<>(ShardChangesAction.INSTANCE, ShardChangesAction.TransportAction.class),
new ActionHandler<>(FollowExistingIndexAction.INSTANCE, FollowExistingIndexAction.TransportAction.class),
new ActionHandler<>(FollowIndexAction.INSTANCE, FollowIndexAction.TransportAction.class),
new ActionHandler<>(UnfollowIndexAction.INSTANCE, UnfollowIndexAction.TransportAction.class),
new ActionHandler<>(BulkShardOperationsAction.INSTANCE, TransportBulkShardOperationsAction.class),
new ActionHandler<>(CreateAndFollowIndexAction.INSTANCE, CreateAndFollowIndexAction.TransportAction.class)
Expand All @@ -105,7 +105,7 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
Supplier<DiscoveryNodes> nodesInCluster) {
return Arrays.asList(
new RestUnfollowIndexAction(settings, restController),
new RestFollowExistingIndexAction(settings, restController),
new RestFollowIndexAction(settings, restController),
new RestCreateAndFollowIndexAction(settings, restController)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public Response newResponse() {

public static class Request extends AcknowledgedRequest<Request> {

private FollowExistingIndexAction.Request followRequest;
private FollowIndexAction.Request followRequest;

public FollowExistingIndexAction.Request getFollowRequest() {
public FollowIndexAction.Request getFollowRequest() {
return followRequest;
}

public void setFollowRequest(FollowExistingIndexAction.Request followRequest) {
public void setFollowRequest(FollowIndexAction.Request followRequest) {
this.followRequest = followRequest;
}

Expand All @@ -86,7 +86,7 @@ public ActionRequestValidationException validate() {
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
followRequest = new FollowExistingIndexAction.Request();
followRequest = new FollowIndexAction.Request();
followRequest.readFrom(in);
}

Expand Down Expand Up @@ -288,7 +288,7 @@ private void initiateFollowing(Request request, ActionListener<Response> listene
activeShardsObserver.waitForActiveShards(new String[]{request.followRequest.getFollowIndex()},
ActiveShardCount.DEFAULT, request.timeout(), result -> {
if (result) {
client.execute(FollowExistingIndexAction.INSTANCE, request.getFollowRequest(), ActionListener.wrap(
client.execute(FollowIndexAction.INSTANCE, request.getFollowRequest(), ActionListener.wrap(
r -> listener.onResponse(new Response(true, true, r.isAcknowledged())),
listener::onFailure
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReferenceArray;

public class FollowExistingIndexAction extends Action<FollowExistingIndexAction.Request,
FollowExistingIndexAction.Response, FollowExistingIndexAction.RequestBuilder> {
public class FollowIndexAction extends Action<FollowIndexAction.Request,
FollowIndexAction.Response, FollowIndexAction.RequestBuilder> {

public static final FollowExistingIndexAction INSTANCE = new FollowExistingIndexAction();
public static final String NAME = "cluster:admin/xpack/ccr/follow_existing_index";
public static final FollowIndexAction INSTANCE = new FollowIndexAction();
public static final String NAME = "cluster:admin/xpack/ccr/follow_index";

private FollowExistingIndexAction() {
private FollowIndexAction() {
super(NAME);
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public void writeTo(StreamOutput out) throws IOException {
}
}

public static class RequestBuilder extends ActionRequestBuilder<Request, Response, FollowExistingIndexAction.RequestBuilder> {
public static class RequestBuilder extends ActionRequestBuilder<Request, Response, FollowIndexAction.RequestBuilder> {

RequestBuilder(ElasticsearchClient client, Action<Request, Response, RequestBuilder> action) {
super(client, action, new Request());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String getName() {
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
Request request = new Request();
request.setFollowRequest(RestFollowExistingIndexAction.createRequest(restRequest));
request.setFollowRequest(RestFollowIndexAction.createRequest(restRequest));
return channel -> client.execute(INSTANCE, request, new RestToXContentListener<>(channel));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

import java.io.IOException;

import static org.elasticsearch.xpack.ccr.action.FollowExistingIndexAction.INSTANCE;
import static org.elasticsearch.xpack.ccr.action.FollowExistingIndexAction.Request;
import static org.elasticsearch.xpack.ccr.action.FollowIndexAction.INSTANCE;
import static org.elasticsearch.xpack.ccr.action.FollowIndexAction.Request;

// TODO: change to confirm with API design
public class RestFollowExistingIndexAction extends BaseRestHandler {
public class RestFollowIndexAction extends BaseRestHandler {

public RestFollowExistingIndexAction(Settings settings, RestController controller) {
public RestFollowIndexAction(Settings settings, RestController controller) {
super(settings);
// TODO: figure out why: '/{follow_index}/_xpack/ccr/_follow' path clashes with create index api.
controller.registerHandler(RestRequest.Method.POST, "/_xpack/ccr/{follow_index}/_follow", this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.elasticsearch.test.MockHttpTransport;
import org.elasticsearch.test.discovery.TestZenDiscovery;
import org.elasticsearch.xpack.ccr.action.CreateAndFollowIndexAction;
import org.elasticsearch.xpack.ccr.action.FollowExistingIndexAction;
import org.elasticsearch.xpack.ccr.action.FollowIndexAction;
import org.elasticsearch.xpack.ccr.action.ShardChangesAction;
import org.elasticsearch.xpack.ccr.action.ShardFollowNodeTask;
import org.elasticsearch.xpack.ccr.action.ShardFollowTask;
Expand Down Expand Up @@ -147,7 +147,7 @@ public void testFollowIndex() throws Exception {
assertAcked(client().admin().indices().prepareCreate("index1").setSource(leaderIndexSettings, XContentType.JSON));
ensureGreen("index1");

final FollowExistingIndexAction.Request followRequest = new FollowExistingIndexAction.Request();
final FollowIndexAction.Request followRequest = new FollowIndexAction.Request();
followRequest.setLeaderIndex("index1");
followRequest.setFollowIndex("index2");

Expand Down Expand Up @@ -177,7 +177,7 @@ public void testFollowIndex() throws Exception {
}

unFollowIndex("index2");
client().execute(FollowExistingIndexAction.INSTANCE, followRequest).get();
client().execute(FollowIndexAction.INSTANCE, followRequest).get();
final int secondBatchNumDocs = randomIntBetween(2, 64);
for (int i = firstBatchNumDocs; i < firstBatchNumDocs + secondBatchNumDocs; i++) {
final String source = String.format(Locale.ROOT, "{\"f\":%d}", i);
Expand Down Expand Up @@ -212,10 +212,10 @@ public void testFollowIndexWithNestedField() throws Exception {

ensureGreen("index1", "index2");

final FollowExistingIndexAction.Request followRequest = new FollowExistingIndexAction.Request();
final FollowIndexAction.Request followRequest = new FollowIndexAction.Request();
followRequest.setLeaderIndex("index1");
followRequest.setFollowIndex("index2");
client().execute(FollowExistingIndexAction.INSTANCE, followRequest).get();
client().execute(FollowIndexAction.INSTANCE, followRequest).get();

final int numDocs = randomIntBetween(2, 64);
for (int i = 0; i < numDocs; i++) {
Expand Down Expand Up @@ -259,19 +259,19 @@ public void testFollowIndexWithNestedField() throws Exception {
public void testFollowNonExistentIndex() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test-leader").get());
assertAcked(client().admin().indices().prepareCreate("test-follower").get());
final FollowExistingIndexAction.Request followRequest = new FollowExistingIndexAction.Request();
final FollowIndexAction.Request followRequest = new FollowIndexAction.Request();
// Leader index does not exist.
followRequest.setLeaderIndex("non-existent-leader");
followRequest.setFollowIndex("test-follower");
expectThrows(IllegalArgumentException.class, () -> client().execute(FollowExistingIndexAction.INSTANCE, followRequest).actionGet());
expectThrows(IllegalArgumentException.class, () -> client().execute(FollowIndexAction.INSTANCE, followRequest).actionGet());
// Follower index does not exist.
followRequest.setLeaderIndex("test-leader");
followRequest.setFollowIndex("non-existent-follower");
expectThrows(IllegalArgumentException.class, () -> client().execute(FollowExistingIndexAction.INSTANCE, followRequest).actionGet());
expectThrows(IllegalArgumentException.class, () -> client().execute(FollowIndexAction.INSTANCE, followRequest).actionGet());
// Both indices do not exist.
followRequest.setLeaderIndex("non-existent-leader");
followRequest.setFollowIndex("non-existent-follower");
expectThrows(IllegalArgumentException.class, () -> client().execute(FollowExistingIndexAction.INSTANCE, followRequest).actionGet());
expectThrows(IllegalArgumentException.class, () -> client().execute(FollowIndexAction.INSTANCE, followRequest).actionGet());
}

private CheckedRunnable<Exception> assertTask(final int numberOfPrimaryShards, final Map<ShardId, Long> numDocsPerShard) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"xpack.ccr.follow_existing_index": {
"xpack.ccr.follow_index": {
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/current",
"methods": [ "POST" ],
"url": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@
- is_true: acknowledged

- do:
xpack.ccr.create_and_follow:
xpack.ccr.create_and_follow_index:
leader_index: foo
follow_index: bar
- is_true: acknowledged
- is_true: follow_index_created
- is_true: follow_index_shards_acked
- is_true: index_following_started

- do:
xpack.ccr.unfollow_index:
follow_index: bar
- is_true: acknowledged

- do:
xpack.ccr.follow_existing_index:
xpack.ccr.follow_index:
leader_index: foo
follow_index: bar
- is_true: acknowledged
Expand Down

0 comments on commit d79989a

Please sign in to comment.