From bdd66cbe459eb805bb60c76ba90091cb02edc220 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 21 Jan 2019 20:26:52 +0100 Subject: [PATCH 1/8] Cleaned up duplicate follow config parameter handling Introduced FollowParameters class that put follow, resume follow, put auto follow pattern requests and follow info response classes reuse. The FollowParameters class had the fields, getters etc. for the common parameters that all these APIs have. Also binary and xcontent serialization / parsing is handled by this class. The follow, resume follow, put auto follow pattern request classes originally used optional non primitive fields, so FollowParameters has that too and the follow info api can handle that now too. --- .../ccr/action/AutoFollowCoordinator.java | 30 +- .../ccr/action/TransportFollowInfoAction.java | 25 +- .../TransportPutAutoFollowPatternAction.java | 50 +- .../ccr/action/TransportPutFollowAction.java | 37 +- .../action/TransportResumeFollowAction.java | 62 +-- .../ccr/rest/RestResumeFollowAction.java | 2 +- .../elasticsearch/xpack/CcrIntegTestCase.java | 14 +- .../xpack/CcrSingleNodeTestCase.java | 14 +- .../elasticsearch/xpack/ccr/AutoFollowIT.java | 82 ++-- .../elasticsearch/xpack/ccr/CcrLicenseIT.java | 6 +- .../xpack/ccr/FollowerFailOverIT.java | 30 +- .../xpack/ccr/IndexFollowingIT.java | 20 +- .../xpack/ccr/LocalIndexFollowingIT.java | 16 +- .../action/AutoFollowCoordinatorTests.java | 18 +- .../ccr/action/FollowInfoResponseTests.java | 79 +-- .../PutAutoFollowPatternRequestTests.java | 90 ++-- .../action/PutFollowActionRequestTests.java | 7 +- .../ResumeFollowActionRequestTests.java | 39 +- ...nsportPutAutoFollowPatternActionTests.java | 18 +- .../core/ccr/action/FollowInfoAction.java | 162 +----- .../core/ccr/action/FollowParameters.java | 297 +++++++++++ .../action/PutAutoFollowPatternAction.java | 464 +++++++----------- .../core/ccr/action/PutFollowAction.java | 235 ++++----- .../core/ccr/action/ResumeFollowAction.java | 366 ++++---------- 24 files changed, 972 insertions(+), 1191 deletions(-) create mode 100644 x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java index e3b008efc5657..fad2afc326fd8 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java @@ -40,7 +40,6 @@ import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata.AutoFollowPattern; import org.elasticsearch.xpack.core.ccr.AutoFollowStats; import org.elasticsearch.xpack.core.ccr.action.PutFollowAction; -import org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction; import java.util.ArrayList; import java.util.Collections; @@ -515,23 +514,20 @@ private void followLeaderIndex(String autoFollowPattenName, final String leaderIndexName = indexToFollow.getName(); final String followIndexName = getFollowerIndexName(pattern, leaderIndexName); - ResumeFollowAction.Request followRequest = new ResumeFollowAction.Request(); - followRequest.setFollowerIndex(followIndexName); - followRequest.setMaxReadRequestOperationCount(pattern.getMaxReadRequestOperationCount()); - followRequest.setMaxReadRequestSize(pattern.getMaxReadRequestSize()); - followRequest.setMaxOutstandingReadRequests(pattern.getMaxOutstandingReadRequests()); - followRequest.setMaxWriteRequestOperationCount(pattern.getMaxWriteRequestOperationCount()); - followRequest.setMaxWriteRequestSize(pattern.getMaxWriteRequestSize()); - followRequest.setMaxOutstandingWriteRequests(pattern.getMaxOutstandingWriteRequests()); - followRequest.setMaxWriteBufferCount(pattern.getMaxWriteBufferCount()); - followRequest.setMaxWriteBufferSize(pattern.getMaxWriteBufferSize()); - followRequest.setMaxRetryDelay(pattern.getMaxRetryDelay()); - followRequest.setReadPollTimeout(pattern.getPollTimeout()); - PutFollowAction.Request request = new PutFollowAction.Request(); - request.setRemoteCluster(remoteCluster); - request.setLeaderIndex(indexToFollow.getName()); - request.setFollowRequest(followRequest); + request.getBody().setRemoteCluster(remoteCluster); + request.getBody().setLeaderIndex(indexToFollow.getName()); + request.getBody().setFollowerIndex(followIndexName); + request.getBody().setMaxReadRequestOperationCount(pattern.getMaxReadRequestOperationCount()); + request.getBody().setMaxReadRequestSize(pattern.getMaxReadRequestSize()); + request.getBody().setMaxOutstandingReadRequests(pattern.getMaxOutstandingReadRequests()); + request.getBody().setMaxWriteRequestOperationCount(pattern.getMaxWriteRequestOperationCount()); + request.getBody().setMaxWriteRequestSize(pattern.getMaxWriteRequestSize()); + request.getBody().setMaxOutstandingWriteRequests(pattern.getMaxOutstandingWriteRequests()); + request.getBody().setMaxWriteBufferCount(pattern.getMaxWriteBufferCount()); + request.getBody().setMaxWriteBufferSize(pattern.getMaxWriteBufferSize()); + request.getBody().setMaxRetryDelay(pattern.getMaxRetryDelay()); + request.getBody().setReadPollTimeout(pattern.getPollTimeout()); // Execute if the create and follow api call succeeds: Runnable successHandler = () -> { diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowInfoAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowInfoAction.java index 3e9c0ecbef881..1ecb06ae1845b 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowInfoAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowInfoAction.java @@ -22,7 +22,7 @@ import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.ccr.Ccr; import org.elasticsearch.xpack.core.ccr.action.FollowInfoAction; -import org.elasticsearch.xpack.core.ccr.action.FollowInfoAction.Response.FollowParameters; +import org.elasticsearch.xpack.core.ccr.action.FollowParameters; import org.elasticsearch.xpack.core.ccr.action.FollowInfoAction.Response.FollowerInfo; import org.elasticsearch.xpack.core.ccr.action.FollowInfoAction.Response.Status; @@ -88,18 +88,17 @@ protected void masterOperation(FollowInfoAction.Request request, String leaderIndex = ccrCustomData.get(Ccr.CCR_CUSTOM_METADATA_LEADER_INDEX_NAME_KEY); if (result.isPresent()) { ShardFollowTask params = result.get(); - FollowParameters followParameters = new FollowParameters( - params.getMaxReadRequestOperationCount(), - params.getMaxReadRequestSize(), - params.getMaxOutstandingReadRequests(), - params.getMaxWriteRequestOperationCount(), - params.getMaxWriteRequestSize(), - params.getMaxOutstandingWriteRequests(), - params.getMaxWriteBufferCount(), - params.getMaxWriteBufferSize(), - params.getMaxRetryDelay(), - params.getReadPollTimeout() - ); + FollowParameters followParameters = new FollowParameters(); + followParameters.setMaxOutstandingReadRequests(params.getMaxOutstandingReadRequests()); + followParameters.setMaxOutstandingWriteRequests(params.getMaxOutstandingWriteRequests()); + followParameters.setMaxReadRequestOperationCount(params.getMaxReadRequestOperationCount()); + followParameters.setMaxWriteRequestOperationCount(params.getMaxWriteRequestOperationCount()); + followParameters.setMaxReadRequestSize(params.getMaxReadRequestSize()); + followParameters.setMaxWriteRequestSize(params.getMaxWriteRequestSize()); + followParameters.setMaxWriteBufferCount(params.getMaxWriteBufferCount()); + followParameters.setMaxWriteBufferSize(params.getMaxWriteBufferSize()); + followParameters.setMaxRetryDelay(params.getMaxRetryDelay()); + followParameters.setReadPollTimeout(params.getReadPollTimeout()); followerInfos.add(new FollowerInfo(followerIndex, remoteCluster, leaderIndex, Status.ACTIVE, followParameters)); } else { followerInfos.add(new FollowerInfo(followerIndex, remoteCluster, leaderIndex, Status.PAUSED, null)); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java index 8c722942d19b0..716f9c2d3d4f7 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java @@ -76,16 +76,16 @@ protected void masterOperation(PutAutoFollowPatternAction.Request request, listener.onFailure(LicenseUtils.newComplianceException("ccr")); return; } - final Client remoteClient = client.getRemoteClusterClient(request.getRemoteCluster()); + final Client remoteClient = client.getRemoteClusterClient(request.getBody().getRemoteCluster()); final Map filteredHeaders = threadPool.getThreadContext().getHeaders().entrySet().stream() .filter(e -> ShardFollowTask.HEADER_FILTERS.contains(e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); Consumer consumer = remoteClusterState -> { - String[] indices = request.getLeaderIndexPatterns().toArray(new String[0]); + String[] indices = request.getBody().getLeaderIndexPatterns().toArray(new String[0]); ccrLicenseChecker.hasPrivilegesToFollowIndices(remoteClient, indices, e -> { if (e == null) { - clusterService.submitStateUpdateTask("put-auto-follow-pattern-" + request.getRemoteCluster(), + clusterService.submitStateUpdateTask("put-auto-follow-pattern-" + request.getBody().getRemoteCluster(), new AckedClusterStateUpdateTask(request, listener) { @Override @@ -108,7 +108,7 @@ public ClusterState execute(ClusterState currentState) throws Exception { clusterStateRequest.clear(); clusterStateRequest.metaData(true); - ccrLicenseChecker.checkRemoteClusterLicenseAndFetchClusterState(client, request.getRemoteCluster(), + ccrLicenseChecker.checkRemoteClusterLicenseAndFetchClusterState(client, request.getBody().getRemoteCluster(), clusterStateRequest, listener::onFailure, consumer); } @@ -134,42 +134,42 @@ static ClusterState innerPut(PutAutoFollowPatternAction.Request request, headers = new HashMap<>(); } - AutoFollowPattern previousPattern = patterns.get(request.getName()); + AutoFollowPattern previousPattern = patterns.get(request.getBody().getName()); final List followedIndexUUIDs; - if (followedLeaderIndices.containsKey(request.getName())) { - followedIndexUUIDs = new ArrayList<>(followedLeaderIndices.get(request.getName())); + if (followedLeaderIndices.containsKey(request.getBody().getName())) { + followedIndexUUIDs = new ArrayList<>(followedLeaderIndices.get(request.getBody().getName())); } else { followedIndexUUIDs = new ArrayList<>(); } - followedLeaderIndices.put(request.getName(), followedIndexUUIDs); + followedLeaderIndices.put(request.getBody().getName(), followedIndexUUIDs); // Mark existing leader indices as already auto followed: if (previousPattern != null) { - markExistingIndicesAsAutoFollowedForNewPatterns(request.getLeaderIndexPatterns(), remoteClusterState.metaData(), + markExistingIndicesAsAutoFollowedForNewPatterns(request.getBody().getLeaderIndexPatterns(), remoteClusterState.metaData(), previousPattern, followedIndexUUIDs); } else { - markExistingIndicesAsAutoFollowed(request.getLeaderIndexPatterns(), remoteClusterState.metaData(), + markExistingIndicesAsAutoFollowed(request.getBody().getLeaderIndexPatterns(), remoteClusterState.metaData(), followedIndexUUIDs); } if (filteredHeaders != null) { - headers.put(request.getName(), filteredHeaders); + headers.put(request.getBody().getName(), filteredHeaders); } AutoFollowPattern autoFollowPattern = new AutoFollowPattern( - request.getRemoteCluster(), - request.getLeaderIndexPatterns(), - request.getFollowIndexNamePattern(), - request.getMaxReadRequestOperationCount(), - request.getMaxReadRequestSize(), - request.getMaxConcurrentReadBatches(), - request.getMaxWriteRequestOperationCount(), - request.getMaxWriteRequestSize(), - request.getMaxConcurrentWriteBatches(), - request.getMaxWriteBufferCount(), - request.getMaxWriteBufferSize(), - request.getMaxRetryDelay(), - request.getReadPollTimeout()); - patterns.put(request.getName(), autoFollowPattern); + request.getBody().getRemoteCluster(), + request.getBody().getLeaderIndexPatterns(), + request.getBody().getFollowIndexNamePattern(), + request.getBody().getMaxReadRequestOperationCount(), + request.getBody().getMaxReadRequestSize(), + request.getBody().getMaxOutstandingReadRequests(), + request.getBody().getMaxWriteRequestOperationCount(), + request.getBody().getMaxWriteRequestSize(), + request.getBody().getMaxOutstandingWriteRequests(), + request.getBody().getMaxWriteBufferCount(), + request.getBody().getMaxWriteBufferSize(), + request.getBody().getMaxRetryDelay(), + request.getBody().getReadPollTimeout()); + patterns.put(request.getBody().getName(), autoFollowPattern); ClusterState.Builder newState = ClusterState.builder(localState); newState.metaData(MetaData.builder(localState.getMetaData()) .putCustom(AutoFollowMetadata.TYPE, new AutoFollowMetadata(patterns, followedLeaderIndices, headers)) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java index bca8608904a76..58708aecd5caa 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java @@ -101,11 +101,11 @@ protected void masterOperation( listener.onFailure(LicenseUtils.newComplianceException("ccr")); return; } - String remoteCluster = request.getRemoteCluster(); + String remoteCluster = request.getBody().getRemoteCluster(); // Validates whether the leader cluster has been configured properly: client.getRemoteClusterClient(remoteCluster); - String leaderIndex = request.getLeaderIndex(); + String leaderIndex = request.getBody().getLeaderIndex(); ccrLicenseChecker.checkRemoteClusterLicenseAndFetchLeaderIndexMetadataAndHistoryUUIDs( client, remoteCluster, @@ -120,14 +120,14 @@ private void createFollowerIndex( final PutFollowAction.Request request, final ActionListener listener) { if (leaderIndexMetaData == null) { - listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not exist")); + listener.onFailure(new IllegalArgumentException("leader index [" + request.getBody().getLeaderIndex() + "] does not exist")); return; } // soft deletes are enabled by default on indices created on 7.0.0 or later if (leaderIndexMetaData.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(leaderIndexMetaData.getSettings()).onOrAfter(Version.V_7_0_0)) == false) { - listener.onFailure( - new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not have soft deletes enabled")); + listener.onFailure(new IllegalArgumentException("leader index [" + request.getBody().getLeaderIndex() + + "] does not have soft deletes enabled")); return; } @@ -151,7 +151,7 @@ protected Boolean newResponse(final boolean acknowledged) { @Override public ClusterState execute(final ClusterState currentState) throws Exception { - String followIndex = request.getFollowRequest().getFollowerIndex(); + String followIndex = request.getBody().getFollowerIndex(); IndexMetaData currentIndex = currentState.metaData().index(followIndex); if (currentIndex != null) { throw new ResourceAlreadyExistsException(currentIndex.getIndex()); @@ -165,7 +165,7 @@ public ClusterState execute(final ClusterState currentState) throws Exception { metadata.put(Ccr.CCR_CUSTOM_METADATA_LEADER_INDEX_SHARD_HISTORY_UUIDS, String.join(",", historyUUIDs)); metadata.put(Ccr.CCR_CUSTOM_METADATA_LEADER_INDEX_UUID_KEY, leaderIndexMetaData.getIndexUUID()); metadata.put(Ccr.CCR_CUSTOM_METADATA_LEADER_INDEX_NAME_KEY, leaderIndexMetaData.getIndex().getName()); - metadata.put(Ccr.CCR_CUSTOM_METADATA_REMOTE_CLUSTER_NAME_KEY, request.getRemoteCluster()); + metadata.put(Ccr.CCR_CUSTOM_METADATA_REMOTE_CLUSTER_NAME_KEY, request.getBody().getRemoteCluster()); imdBuilder.putCustom(Ccr.CCR_CUSTOM_METADATA_KEY, metadata); // Copy all settings, but overwrite a few settings. @@ -191,10 +191,10 @@ public ClusterState execute(final ClusterState currentState) throws Exception { ClusterState updatedState = builder.build(); RoutingTable.Builder routingTableBuilder = RoutingTable.builder(updatedState.routingTable()) - .addAsNew(updatedState.metaData().index(request.getFollowRequest().getFollowerIndex())); + .addAsNew(updatedState.metaData().index(request.getBody().getFollowerIndex())); updatedState = allocationService.reroute( ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(), - "follow index [" + request.getFollowRequest().getFollowerIndex() + "] created"); + "follow index [" + request.getBody().getFollowerIndex() + "] created"); logger.info("[{}] creating index, cause [ccr_create_and_follow], shards [{}]/[{}]", followIndex, followIMD.getNumberOfShards(), followIMD.getNumberOfReplicas()); @@ -207,10 +207,23 @@ public ClusterState execute(final ClusterState currentState) throws Exception { private void initiateFollowing( final PutFollowAction.Request request, final ActionListener listener) { - activeShardsObserver.waitForActiveShards(new String[]{request.getFollowRequest().getFollowerIndex()}, + activeShardsObserver.waitForActiveShards(new String[]{request.getBody().getFollowerIndex()}, ActiveShardCount.DEFAULT, request.timeout(), result -> { if (result) { - client.execute(ResumeFollowAction.INSTANCE, request.getFollowRequest(), ActionListener.wrap( + ResumeFollowAction.Request resumeFollowRequest = new ResumeFollowAction.Request(); + resumeFollowRequest.getBody().setFollowerIndex(request.getBody().getFollowerIndex()); + resumeFollowRequest.getBody().setMaxOutstandingReadRequests(request.getBody().getMaxOutstandingReadRequests()); + resumeFollowRequest.getBody().setMaxOutstandingWriteRequests(request.getBody().getMaxOutstandingWriteRequests()); + resumeFollowRequest.getBody().setMaxReadRequestOperationCount(request.getBody().getMaxReadRequestOperationCount()); + resumeFollowRequest.getBody().setMaxWriteRequestOperationCount( + request.getBody().getMaxWriteRequestOperationCount()); + resumeFollowRequest.getBody().setMaxReadRequestSize(request.getBody().getMaxReadRequestSize()); + resumeFollowRequest.getBody().setMaxWriteRequestSize(request.getBody().getMaxWriteRequestSize()); + resumeFollowRequest.getBody().setMaxWriteBufferCount(request.getBody().getMaxWriteBufferCount()); + resumeFollowRequest.getBody().setMaxWriteBufferSize(request.getBody().getMaxWriteBufferSize()); + resumeFollowRequest.getBody().setReadPollTimeout(request.getBody().getReadPollTimeout()); + resumeFollowRequest.getBody().setMaxRetryDelay(request.getBody().getMaxRetryDelay()); + client.execute(ResumeFollowAction.INSTANCE, resumeFollowRequest, ActionListener.wrap( r -> listener.onResponse(new PutFollowAction.Response(true, true, r.isAcknowledged())), listener::onFailure )); @@ -222,7 +235,7 @@ private void initiateFollowing( @Override protected ClusterBlockException checkBlock(final PutFollowAction.Request request, final ClusterState state) { - return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, request.getFollowRequest().getFollowerIndex()); + return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, request.getBody().getFollowerIndex()); } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java index 0a1a22215a04b..e182803c4723a 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java @@ -22,6 +22,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; @@ -121,15 +122,15 @@ protected void masterOperation(final ResumeFollowAction.Request request, return; } - final IndexMetaData followerIndexMetadata = state.getMetaData().index(request.getFollowerIndex()); + final IndexMetaData followerIndexMetadata = state.getMetaData().index(request.getBody().getFollowerIndex()); if (followerIndexMetadata == null) { - listener.onFailure(new IndexNotFoundException(request.getFollowerIndex())); + listener.onFailure(new IndexNotFoundException(request.getBody().getFollowerIndex())); return; } final Map ccrMetadata = followerIndexMetadata.getCustomData(Ccr.CCR_CUSTOM_METADATA_KEY); if (ccrMetadata == null) { - throw new IllegalArgumentException("follow index ["+ request.getFollowerIndex() + "] does not have ccr metadata"); + throw new IllegalArgumentException("follow index ["+ request.getBody().getFollowerIndex() + "] does not have ccr metadata"); } final String leaderCluster = ccrMetadata.get(Ccr.CCR_CUSTOM_METADATA_REMOTE_CLUSTER_NAME_KEY); // Validates whether the leader cluster has been configured properly: @@ -177,8 +178,8 @@ void start( for (int shardId = 0; shardId < numShards; shardId++) { String taskId = followIndexMetadata.getIndexUUID() + "-" + shardId; - - final ShardFollowTask shardFollowTask = createShardFollowTask(shardId, clusterNameAlias, request, + logger.info("README: " + Strings.toString(request.getBody())); + final ShardFollowTask shardFollowTask = createShardFollowTask(shardId, clusterNameAlias, request.getBody(), leaderIndexMetadata, followIndexMetadata, filteredHeaders); persistentTasksService.sendStartRequest(taskId, ShardFollowTask.NAME, shardFollowTask, handler.getActionListener(shardId)); } @@ -190,6 +191,8 @@ static void validate( final IndexMetaData followIndex, final String[] leaderIndexHistoryUUID, final MapperService followerMapperService) { + ResumeFollowAction.Request.Body requestBody = request.getBody(); + Map ccrIndexMetadata = followIndex.getCustomData(Ccr.CCR_CUSTOM_METADATA_KEY); if (ccrIndexMetadata == null) { throw new IllegalArgumentException("follow index ["+ followIndex.getIndex().getName() + "] does not have ccr metadata"); @@ -197,8 +200,8 @@ static void validate( String leaderIndexUUID = leaderIndex.getIndex().getUUID(); String recordedLeaderIndexUUID = ccrIndexMetadata.get(Ccr.CCR_CUSTOM_METADATA_LEADER_INDEX_UUID_KEY); if (leaderIndexUUID.equals(recordedLeaderIndexUUID) == false) { - throw new IllegalArgumentException("follow index [" + request.getFollowerIndex() + "] should reference [" + leaderIndexUUID + - "] as leader index but instead reference [" + recordedLeaderIndexUUID + "] as leader index"); + throw new IllegalArgumentException("follow index [" + requestBody.getFollowerIndex() + "] should reference [" + + leaderIndexUUID + "] as leader index but instead reference [" + recordedLeaderIndexUUID + "] as leader index"); } String[] recordedHistoryUUIDs = extractLeaderShardHistoryUUIDs(ccrIndexMetadata); @@ -207,7 +210,7 @@ static void validate( String recordedLeaderIndexHistoryUUID = recordedHistoryUUIDs[i]; String actualLeaderIndexHistoryUUID = leaderIndexHistoryUUID[i]; if (recordedLeaderIndexHistoryUUID.equals(actualLeaderIndexHistoryUUID) == false) { - throw new IllegalArgumentException("leader shard [" + request.getFollowerIndex() + "][" + i + "] should reference [" + + throw new IllegalArgumentException("leader shard [" + requestBody.getFollowerIndex() + "][" + i + "] should reference [" + recordedLeaderIndexHistoryUUID + "] as history uuid but instead reference [" + actualLeaderIndexHistoryUUID + "] as history uuid"); } @@ -219,7 +222,8 @@ static void validate( "] does not have soft deletes enabled"); } if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(followIndex.getSettings()) == false) { - throw new IllegalArgumentException("follower index [" + request.getFollowerIndex() + "] does not have soft deletes enabled"); + throw new IllegalArgumentException("follower index [" + requestBody.getFollowerIndex() + + "] does not have soft deletes enabled"); } if (leaderIndex.getNumberOfShards() != followIndex.getNumberOfShards()) { throw new IllegalArgumentException("leader index primary shards [" + leaderIndex.getNumberOfShards() + @@ -233,7 +237,7 @@ static void validate( throw new IllegalArgumentException("leader and follow index must be open"); } if (CcrSettings.CCR_FOLLOWING_INDEX_SETTING.get(followIndex.getSettings()) == false) { - throw new IllegalArgumentException("the following index [" + request.getFollowerIndex() + "] is not ready " + + throw new IllegalArgumentException("the following index [" + requestBody.getFollowerIndex() + "] is not ready " + "to follow; the setting [" + CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey() + "] must be enabled."); } // Make a copy, remove settings that are allowed to be different and then compare if the settings are equal. @@ -251,69 +255,69 @@ static void validate( private static ShardFollowTask createShardFollowTask( int shardId, String clusterAliasName, - ResumeFollowAction.Request request, + ResumeFollowAction.Request.Body requestBody, IndexMetaData leaderIndexMetadata, IndexMetaData followIndexMetadata, Map filteredHeaders ) { int maxReadRequestOperationCount; - if (request.getMaxReadRequestOperationCount() != null) { - maxReadRequestOperationCount = request.getMaxReadRequestOperationCount(); + if (requestBody.getMaxReadRequestOperationCount() != null) { + maxReadRequestOperationCount = requestBody.getMaxReadRequestOperationCount(); } else { maxReadRequestOperationCount = DEFAULT_MAX_READ_REQUEST_OPERATION_COUNT; } ByteSizeValue maxReadRequestSize; - if (request.getMaxReadRequestSize() != null) { - maxReadRequestSize = request.getMaxReadRequestSize(); + if (requestBody.getMaxReadRequestSize() != null) { + maxReadRequestSize = requestBody.getMaxReadRequestSize(); } else { maxReadRequestSize = DEFAULT_MAX_READ_REQUEST_SIZE; } int maxOutstandingReadRequests; - if (request.getMaxOutstandingReadRequests() != null){ - maxOutstandingReadRequests = request.getMaxOutstandingReadRequests(); + if (requestBody.getMaxOutstandingReadRequests() != null){ + maxOutstandingReadRequests = requestBody.getMaxOutstandingReadRequests(); } else { maxOutstandingReadRequests = DEFAULT_MAX_OUTSTANDING_READ_REQUESTS; } final int maxWriteRequestOperationCount; - if (request.getMaxWriteRequestOperationCount() != null) { - maxWriteRequestOperationCount = request.getMaxWriteRequestOperationCount(); + if (requestBody.getMaxWriteRequestOperationCount() != null) { + maxWriteRequestOperationCount = requestBody.getMaxWriteRequestOperationCount(); } else { maxWriteRequestOperationCount = DEFAULT_MAX_WRITE_REQUEST_OPERATION_COUNT; } final ByteSizeValue maxWriteRequestSize; - if (request.getMaxWriteRequestSize() != null) { - maxWriteRequestSize = request.getMaxWriteRequestSize(); + if (requestBody.getMaxWriteRequestSize() != null) { + maxWriteRequestSize = requestBody.getMaxWriteRequestSize(); } else { maxWriteRequestSize = DEFAULT_MAX_WRITE_REQUEST_SIZE; } int maxOutstandingWriteRequests; - if (request.getMaxOutstandingWriteRequests() != null) { - maxOutstandingWriteRequests = request.getMaxOutstandingWriteRequests(); + if (requestBody.getMaxOutstandingWriteRequests() != null) { + maxOutstandingWriteRequests = requestBody.getMaxOutstandingWriteRequests(); } else { maxOutstandingWriteRequests = DEFAULT_MAX_OUTSTANDING_WRITE_REQUESTS; } int maxWriteBufferCount; - if (request.getMaxWriteBufferCount() != null) { - maxWriteBufferCount = request.getMaxWriteBufferCount(); + if (requestBody.getMaxWriteBufferCount() != null) { + maxWriteBufferCount = requestBody.getMaxWriteBufferCount(); } else { maxWriteBufferCount = DEFAULT_MAX_WRITE_BUFFER_COUNT; } ByteSizeValue maxWriteBufferSize; - if (request.getMaxWriteBufferSize() != null) { - maxWriteBufferSize = request.getMaxWriteBufferSize(); + if (requestBody.getMaxWriteBufferSize() != null) { + maxWriteBufferSize = requestBody.getMaxWriteBufferSize(); } else { maxWriteBufferSize = DEFAULT_MAX_WRITE_BUFFER_SIZE; } - TimeValue maxRetryDelay = request.getMaxRetryDelay() == null ? DEFAULT_MAX_RETRY_DELAY : request.getMaxRetryDelay(); - TimeValue readPollTimeout = request.getReadPollTimeout() == null ? DEFAULT_READ_POLL_TIMEOUT : request.getReadPollTimeout(); + TimeValue maxRetryDelay = requestBody.getMaxRetryDelay() == null ? DEFAULT_MAX_RETRY_DELAY : requestBody.getMaxRetryDelay(); + TimeValue readPollTimeout = requestBody.getReadPollTimeout() == null ? DEFAULT_READ_POLL_TIMEOUT : requestBody.getReadPollTimeout(); return new ShardFollowTask( clusterAliasName, diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java index ce2eab52e0cab..6682812dee9ed 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java @@ -43,7 +43,7 @@ static Request createRequest(RestRequest restRequest) throws IOException { } } else { Request request = new Request(); - request.setFollowerIndex(restRequest.param("index")); + request.getBody().setFollowerIndex(restRequest.param("index")); return request; } } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java index 7af3d690e3a99..e5d8b50202c0d 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java @@ -412,17 +412,19 @@ protected String getIndexSettings(final int numberOfShards, final int numberOfRe public static PutFollowAction.Request putFollow(String leaderIndex, String followerIndex) { PutFollowAction.Request request = new PutFollowAction.Request(); - request.setRemoteCluster("leader_cluster"); - request.setLeaderIndex(leaderIndex); - request.setFollowRequest(resumeFollow(followerIndex)); + request.getBody().setRemoteCluster("leader_cluster"); + request.getBody().setLeaderIndex(leaderIndex); + request.getBody().setFollowerIndex(followerIndex); + request.getBody().setMaxRetryDelay(TimeValue.timeValueMillis(10)); + request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(10)); return request; } public static ResumeFollowAction.Request resumeFollow(String followerIndex) { ResumeFollowAction.Request request = new ResumeFollowAction.Request(); - request.setFollowerIndex(followerIndex); - request.setMaxRetryDelay(TimeValue.timeValueMillis(10)); - request.setReadPollTimeout(TimeValue.timeValueMillis(10)); + request.getBody().setFollowerIndex(followerIndex); + request.getBody().setMaxRetryDelay(TimeValue.timeValueMillis(10)); + request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(10)); return request; } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java index e77a672f1fddb..0a8120b7fb475 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java @@ -87,17 +87,19 @@ protected AutoFollowStats getAutoFollowStats() { protected ResumeFollowAction.Request getResumeFollowRequest(String followerIndex) { ResumeFollowAction.Request request = new ResumeFollowAction.Request(); - request.setFollowerIndex(followerIndex); - request.setMaxRetryDelay(TimeValue.timeValueMillis(1)); - request.setReadPollTimeout(TimeValue.timeValueMillis(1)); + request.getBody().setFollowerIndex(followerIndex); + request.getBody().setMaxRetryDelay(TimeValue.timeValueMillis(1)); + request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(1)); return request; } protected PutFollowAction.Request getPutFollowRequest(String leaderIndex, String followerIndex) { PutFollowAction.Request request = new PutFollowAction.Request(); - request.setRemoteCluster("local"); - request.setLeaderIndex(leaderIndex); - request.setFollowRequest(getResumeFollowRequest(followerIndex)); + request.getBody().setRemoteCluster("local"); + request.getBody().setLeaderIndex(leaderIndex); + request.getBody().setFollowerIndex(followerIndex); + request.getBody().setMaxRetryDelay(TimeValue.timeValueMillis(1)); + request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(1)); return request; } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java index 4025f647cb2a6..a598349a2c95f 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java @@ -24,7 +24,7 @@ import org.elasticsearch.xpack.core.ccr.action.CcrStatsAction; import org.elasticsearch.xpack.core.ccr.action.DeleteAutoFollowPatternAction; import org.elasticsearch.xpack.core.ccr.action.FollowInfoAction; -import org.elasticsearch.xpack.core.ccr.action.FollowInfoAction.Response.FollowParameters; +import org.elasticsearch.xpack.core.ccr.action.FollowParameters; import org.elasticsearch.xpack.core.ccr.action.FollowInfoAction.Response.FollowerInfo; import org.elasticsearch.xpack.core.ccr.action.PutAutoFollowPatternAction; @@ -185,42 +185,44 @@ public void testAutoFollowParameterAreDelegated() throws Exception { .build(); // Enabling auto following: - PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setName("my-pattern"); - request.setRemoteCluster("leader_cluster"); - request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + PutAutoFollowPatternAction.Request.Body requestBody = new PutAutoFollowPatternAction.Request.Body(); + requestBody.setName("my-pattern"); + requestBody.setRemoteCluster("leader_cluster"); + requestBody.setLeaderIndexPatterns(Collections.singletonList("logs-*")); // Need to set this, because following an index in the same cluster - request.setFollowIndexNamePattern("copy-{{leader_index}}"); + requestBody.setFollowIndexNamePattern("copy-{{leader_index}}"); if (randomBoolean()) { - request.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE)); + requestBody.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { - request.setMaxConcurrentReadBatches(randomIntBetween(0, Integer.MAX_VALUE)); + requestBody.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { - request.setMaxConcurrentWriteBatches(randomIntBetween(0, Integer.MAX_VALUE)); + requestBody.setMaxOutstandingWriteRequests(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { - request.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); + requestBody.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { - request.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); + requestBody.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); } if (randomBoolean()) { - request.setMaxRetryDelay(TimeValue.timeValueMillis(500)); + requestBody.setMaxRetryDelay(TimeValue.timeValueMillis(500)); } if (randomBoolean()) { - request.setReadPollTimeout(TimeValue.timeValueMillis(500)); + requestBody.setReadPollTimeout(TimeValue.timeValueMillis(500)); } if (randomBoolean()) { - request.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); + requestBody.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { - request.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); + requestBody.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); } if (randomBoolean()) { - request.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong())); + requestBody.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong())); } + PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); + request.setBody(requestBody); assertTrue(followerClient().execute(PutAutoFollowPatternAction.INSTANCE, request).actionGet().isAcknowledged()); createLeaderIndex("logs-201901", leaderIndexSettings); @@ -242,35 +244,35 @@ public void testAutoFollowParameterAreDelegated() throws Exception { FollowParameters followParameters = followerInfo.getParameters(); assertThat(followParameters, notNullValue()); - if (request.getMaxWriteBufferCount() != null) { - assertThat(followParameters.getMaxWriteBufferCount(), equalTo(request.getMaxWriteBufferCount())); + if (requestBody.getMaxWriteBufferCount() != null) { + assertThat(followParameters.getMaxWriteBufferCount(), equalTo(requestBody.getMaxWriteBufferCount())); } - if (request.getMaxWriteBufferSize() != null) { - assertThat(followParameters.getMaxWriteBufferSize(), equalTo(request.getMaxWriteBufferSize())); + if (requestBody.getMaxWriteBufferSize() != null) { + assertThat(followParameters.getMaxWriteBufferSize(), equalTo(requestBody.getMaxWriteBufferSize())); } - if (request.getMaxConcurrentReadBatches() != null) { - assertThat(followParameters.getMaxOutstandingReadRequests(), equalTo(request.getMaxConcurrentReadBatches())); + if (requestBody.getMaxOutstandingReadRequests() != null) { + assertThat(followParameters.getMaxOutstandingReadRequests(), equalTo(requestBody.getMaxOutstandingReadRequests())); } - if (request.getMaxConcurrentWriteBatches() != null) { - assertThat(followParameters.getMaxOutstandingWriteRequests(), equalTo(request.getMaxConcurrentWriteBatches())); + if (requestBody.getMaxOutstandingWriteRequests() != null) { + assertThat(followParameters.getMaxOutstandingWriteRequests(), equalTo(requestBody.getMaxOutstandingWriteRequests())); } - if (request.getMaxReadRequestOperationCount() != null) { - assertThat(followParameters.getMaxReadRequestOperationCount(), equalTo(request.getMaxReadRequestOperationCount())); + if (requestBody.getMaxReadRequestOperationCount() != null) { + assertThat(followParameters.getMaxReadRequestOperationCount(), equalTo(requestBody.getMaxReadRequestOperationCount())); } - if (request.getMaxReadRequestSize() != null) { - assertThat(followParameters.getMaxReadRequestSize(), equalTo(request.getMaxReadRequestSize())); + if (requestBody.getMaxReadRequestSize() != null) { + assertThat(followParameters.getMaxReadRequestSize(), equalTo(requestBody.getMaxReadRequestSize())); } - if (request.getMaxRetryDelay() != null) { - assertThat(followParameters.getMaxRetryDelay(), equalTo(request.getMaxRetryDelay())); + if (requestBody.getMaxRetryDelay() != null) { + assertThat(followParameters.getMaxRetryDelay(), equalTo(requestBody.getMaxRetryDelay())); } - if (request.getReadPollTimeout() != null) { - assertThat(followParameters.getReadPollTimeout(), equalTo(request.getReadPollTimeout())); + if (requestBody.getReadPollTimeout() != null) { + assertThat(followParameters.getReadPollTimeout(), equalTo(requestBody.getReadPollTimeout())); } - if (request.getMaxWriteRequestOperationCount() != null) { - assertThat(followParameters.getMaxWriteRequestOperationCount(), equalTo(request.getMaxWriteRequestOperationCount())); + if (requestBody.getMaxWriteRequestOperationCount() != null) { + assertThat(followParameters.getMaxWriteRequestOperationCount(), equalTo(requestBody.getMaxWriteRequestOperationCount())); } - if (request.getMaxWriteRequestSize() != null) { - assertThat(followParameters.getMaxWriteRequestSize(), equalTo(request.getMaxWriteRequestSize())); + if (requestBody.getMaxWriteRequestSize() != null) { + assertThat(followParameters.getMaxWriteRequestSize(), equalTo(requestBody.getMaxWriteRequestSize())); } }); } @@ -358,11 +360,11 @@ public void testAutoFollowSoftDeletesDisabled() throws Exception { private void putAutoFollowPatterns(String name, String[] patterns) { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setName(name); - request.setRemoteCluster("leader_cluster"); - request.setLeaderIndexPatterns(Arrays.asList(patterns)); + request.getBody().setName(name); + request.getBody().setRemoteCluster("leader_cluster"); + request.getBody().setLeaderIndexPatterns(Arrays.asList(patterns)); // Need to set this, because following an index in the same cluster - request.setFollowIndexNamePattern("copy-{{leader_index}}"); + request.getBody().setFollowIndexNamePattern("copy-{{leader_index}}"); assertTrue(followerClient().execute(PutAutoFollowPatternAction.INSTANCE, request).actionGet().isAcknowledged()); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java index f8e7eab1c8647..1947df1791956 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java @@ -117,9 +117,9 @@ public void onFailure(final Exception e) { public void testThatPutAutoFollowPatternsIsUnavailableWithNonCompliantLicense() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setName("name"); - request.setRemoteCluster("leader"); - request.setLeaderIndexPatterns(Collections.singletonList("*")); + request.getBody().setName("name"); + request.getBody().setRemoteCluster("leader"); + request.getBody().setLeaderIndexPatterns(Collections.singletonList("*")); client().execute( PutAutoFollowPatternAction.INSTANCE, request, diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java index d58a2d0a0f18d..b800392651172 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java @@ -77,13 +77,13 @@ public void testFailOverOnFollower() throws Exception { } availableDocs.release(between(100, 200)); PutFollowAction.Request follow = putFollow("leader-index", "follower-index"); - follow.getFollowRequest().setMaxReadRequestOperationCount(randomIntBetween(32, 2048)); - follow.getFollowRequest().setMaxReadRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); - follow.getFollowRequest().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); - follow.getFollowRequest().setMaxWriteRequestOperationCount(randomIntBetween(32, 2048)); - follow.getFollowRequest().setMaxWriteRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); - follow.getFollowRequest().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); - logger.info("--> follow params {}", Strings.toString(follow.getFollowRequest())); + follow.getBody().setMaxReadRequestOperationCount(randomIntBetween(32, 2048)); + follow.getBody().setMaxReadRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); + follow.getBody().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); + follow.getBody().setMaxWriteRequestOperationCount(randomIntBetween(32, 2048)); + follow.getBody().setMaxWriteRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); + follow.getBody().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); + logger.info("--> follow params {}", Strings.toString(follow.getBody())); followerClient().execute(PutFollowAction.INSTANCE, follow).get(); disableDelayedAllocation("follower-index"); ensureFollowerGreen("follower-index"); @@ -137,17 +137,17 @@ public void testFollowIndexAndCloseNode() throws Exception { thread.start(); PutFollowAction.Request followRequest = putFollow("index1", "index2"); - followRequest.getFollowRequest().setMaxReadRequestOperationCount(randomIntBetween(32, 2048)); - followRequest.getFollowRequest().setMaxReadRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); - followRequest.getFollowRequest().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); - followRequest.getFollowRequest().setMaxWriteRequestOperationCount(randomIntBetween(32, 2048)); - followRequest.getFollowRequest().setMaxWriteRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); - followRequest.getFollowRequest().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); + followRequest.getBody().setMaxReadRequestOperationCount(randomIntBetween(32, 2048)); + followRequest.getBody().setMaxReadRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); + followRequest.getBody().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); + followRequest.getBody().setMaxWriteRequestOperationCount(randomIntBetween(32, 2048)); + followRequest.getBody().setMaxWriteRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); + followRequest.getBody().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); disableDelayedAllocation("index2"); - logger.info("--> follow params {}", Strings.toString(followRequest.getFollowRequest())); + logger.info("--> follow params {}", Strings.toString(followRequest.getBody())); - int maxOpsPerRead = followRequest.getFollowRequest().getMaxReadRequestOperationCount(); + int maxOpsPerRead = followRequest.getBody().getMaxReadRequestOperationCount(); int maxNumDocsReplicated = Math.min(between(50, 500), between(maxOpsPerRead, maxOpsPerRead * 10)); availableDocs.release(maxNumDocsReplicated / 2 + 1); atLeastDocsIndexed(followerClient(), "index2", maxNumDocsReplicated / 3); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java index 857445ad88de8..d1c1dc0e64859 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java @@ -120,7 +120,7 @@ public void testFollowIndex() throws Exception { } assertTotalNumberOfOptimizedIndexing(resolveFollowerIndex("index2"), numberOfPrimaryShards, firstBatchNumDocs); pauseFollow("index2"); - followerClient().execute(ResumeFollowAction.INSTANCE, followRequest.getFollowRequest()).get(); + followerClient().execute(ResumeFollowAction.INSTANCE, resumeFollow("index2")).get(); final int secondBatchNumDocs = randomIntBetween(2, 64); logger.info("Indexing [{}] docs as second batch", secondBatchNumDocs); for (int i = firstBatchNumDocs; i < firstBatchNumDocs + secondBatchNumDocs; i++) { @@ -257,10 +257,10 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure) atLeastDocsIndexed(leaderClient(), "index1", numDocsIndexed / 3); PutFollowAction.Request followRequest = putFollow("index1", "index2"); - followRequest.getFollowRequest().setMaxReadRequestOperationCount(maxOpsPerRead); - followRequest.getFollowRequest().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); - followRequest.getFollowRequest().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); - followRequest.getFollowRequest().setMaxWriteBufferCount(randomIntBetween(1024, 10240)); + followRequest.getBody().setMaxReadRequestOperationCount(maxOpsPerRead); + followRequest.getBody().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); + followRequest.getBody().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); + followRequest.getBody().setMaxWriteBufferCount(randomIntBetween(1024, 10240)); followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); availableDocs.release(numDocsIndexed * 2 + bulkSize); atLeastDocsIndexed(leaderClient(), "index1", numDocsIndexed); @@ -358,7 +358,7 @@ public void testFollowIndexMaxOperationSizeInBytes() throws Exception { } PutFollowAction.Request followRequest = putFollow("index1", "index2"); - followRequest.getFollowRequest().setMaxReadRequestSize(new ByteSizeValue(1, ByteSizeUnit.BYTES)); + followRequest.getBody().setMaxReadRequestSize(new ByteSizeValue(1, ByteSizeUnit.BYTES)); followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); final Map firstBatchNumDocsPerShard = new HashMap<>(); @@ -552,14 +552,14 @@ public void testUnknownClusterAlias() throws Exception { assertAcked(leaderClient().admin().indices().prepareCreate("index1").setSource(leaderIndexSettings, XContentType.JSON)); ensureLeaderGreen("index1"); PutFollowAction.Request followRequest = putFollow("index1", "index2"); - followRequest.setRemoteCluster("another_cluster"); + followRequest.getBody().setRemoteCluster("another_cluster"); Exception e = expectThrows(IllegalArgumentException.class, () -> followerClient().execute(PutFollowAction.INSTANCE, followRequest).actionGet()); assertThat(e.getMessage(), equalTo("unknown cluster alias [another_cluster]")); PutAutoFollowPatternAction.Request putAutoFollowRequest = new PutAutoFollowPatternAction.Request(); - putAutoFollowRequest.setName("name"); - putAutoFollowRequest.setRemoteCluster("another_cluster"); - putAutoFollowRequest.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + putAutoFollowRequest.getBody().setName("name"); + putAutoFollowRequest.getBody().setRemoteCluster("another_cluster"); + putAutoFollowRequest.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); e = expectThrows(IllegalArgumentException.class, () -> followerClient().execute(PutAutoFollowPatternAction.INSTANCE, putAutoFollowRequest).actionGet()); assertThat(e.getMessage(), equalTo("unknown cluster alias [another_cluster]")); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java index 2c50411971a1b..0ac85ea7993eb 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java @@ -82,10 +82,10 @@ public void testDoNotCreateFollowerIfLeaderDoesNotHaveSoftDeletes() throws Excep singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "false")); assertAcked(client().admin().indices().prepareCreate("leader-index").setSource(leaderIndexSettings, XContentType.JSON)); ResumeFollowAction.Request followRequest = getResumeFollowRequest("follower"); - followRequest.setFollowerIndex("follower-index"); + followRequest.getBody().setFollowerIndex("follower-index"); PutFollowAction.Request putFollowRequest = getPutFollowRequest("leader", "follower"); - putFollowRequest.setLeaderIndex("leader-index"); - putFollowRequest.setFollowRequest(followRequest); + putFollowRequest.getBody().setLeaderIndex("leader-index"); + putFollowRequest.getBody().setFollowerIndex("follower-index"); IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> client().execute(PutFollowAction.INSTANCE, putFollowRequest).actionGet()); assertThat(error.getMessage(), equalTo("leader index [leader-index] does not have soft deletes enabled")); @@ -94,11 +94,11 @@ public void testDoNotCreateFollowerIfLeaderDoesNotHaveSoftDeletes() throws Excep public void testRemoveRemoteConnection() throws Exception { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setName("my_pattern"); - request.setRemoteCluster("local"); - request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); - request.setFollowIndexNamePattern("copy-{{leader_index}}"); - request.setReadPollTimeout(TimeValue.timeValueMillis(10)); + request.getBody().setName("my_pattern"); + request.getBody().setRemoteCluster("local"); + request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.getBody().setFollowIndexNamePattern("copy-{{leader_index}}"); + request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(10)); assertTrue(client().execute(PutAutoFollowPatternAction.INSTANCE, request).actionGet().isAcknowledged()); long previousNumberOfSuccessfulFollowedIndices = getAutoFollowStats().getNumberOfSuccessfulFollowIndices(); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java index 2ac67a65fc1c6..c720237c1951f 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java @@ -107,9 +107,9 @@ void createAndFollow(Map headers, Runnable successHandler, Consumer failureHandler) { assertThat(headers, equalTo(autoFollowHeaders.get("remote"))); - assertThat(followRequest.getRemoteCluster(), equalTo("remote")); - assertThat(followRequest.getLeaderIndex(), equalTo("logs-20190101")); - assertThat(followRequest.getFollowRequest().getFollowerIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getBody().getRemoteCluster(), equalTo("remote")); + assertThat(followRequest.getBody().getLeaderIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getBody().getFollowerIndex(), equalTo("logs-20190101")); successHandler.run(); } @@ -225,9 +225,9 @@ void createAndFollow(Map headers, PutFollowAction.Request followRequest, Runnable successHandler, Consumer failureHandler) { - assertThat(followRequest.getRemoteCluster(), equalTo("remote")); - assertThat(followRequest.getLeaderIndex(), equalTo("logs-20190101")); - assertThat(followRequest.getFollowRequest().getFollowerIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getBody().getRemoteCluster(), equalTo("remote")); + assertThat(followRequest.getBody().getLeaderIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getBody().getFollowerIndex(), equalTo("logs-20190101")); successHandler.run(); } @@ -282,9 +282,9 @@ void createAndFollow(Map headers, PutFollowAction.Request followRequest, Runnable successHandler, Consumer failureHandler) { - assertThat(followRequest.getRemoteCluster(), equalTo("remote")); - assertThat(followRequest.getLeaderIndex(), equalTo("logs-20190101")); - assertThat(followRequest.getFollowRequest().getFollowerIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getBody().getRemoteCluster(), equalTo("remote")); + assertThat(followRequest.getBody().getLeaderIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getBody().getFollowerIndex(), equalTo("logs-20190101")); failureHandler.accept(failure); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowInfoResponseTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowInfoResponseTests.java index d21098506a121..eceb37819d187 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowInfoResponseTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowInfoResponseTests.java @@ -20,61 +20,13 @@ import java.util.List; import static org.elasticsearch.xpack.core.ccr.action.FollowInfoAction.Response.FOLLOWER_INDICES_FIELD; -import static org.elasticsearch.xpack.core.ccr.action.FollowInfoAction.Response.FollowParameters; + +import org.elasticsearch.xpack.core.ccr.action.FollowParameters; import static org.elasticsearch.xpack.core.ccr.action.FollowInfoAction.Response.Status; public class FollowInfoResponseTests extends AbstractSerializingTestCase { - static final ConstructingObjectParser PARAMETERS_PARSER = new ConstructingObjectParser<>( - "parameters_parser", - args -> { - return new FollowParameters( - (Integer) args[0], - (ByteSizeValue) args[1], - (Integer) args[2], - (Integer) args[3], - (ByteSizeValue) args[4], - (Integer) args[5], - (Integer) args[6], - (ByteSizeValue) args[7], - (TimeValue) args[8], - (TimeValue) args[9] - ); - }); - - static { - PARAMETERS_PARSER.declareInt(ConstructingObjectParser.constructorArg(), ShardFollowTask.MAX_READ_REQUEST_OPERATION_COUNT); - PARAMETERS_PARSER.declareField( - ConstructingObjectParser.constructorArg(), - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), ShardFollowTask.MAX_READ_REQUEST_SIZE.getPreferredName()), - ShardFollowTask.MAX_READ_REQUEST_SIZE, - ObjectParser.ValueType.STRING); - PARAMETERS_PARSER.declareInt(ConstructingObjectParser.constructorArg(), ShardFollowTask.MAX_OUTSTANDING_READ_REQUESTS); - PARAMETERS_PARSER.declareInt(ConstructingObjectParser.constructorArg(), ShardFollowTask.MAX_WRITE_REQUEST_OPERATION_COUNT); - PARAMETERS_PARSER.declareField( - ConstructingObjectParser.constructorArg(), - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), ShardFollowTask.MAX_WRITE_REQUEST_SIZE.getPreferredName()), - ShardFollowTask.MAX_WRITE_REQUEST_SIZE, - ObjectParser.ValueType.STRING); - PARAMETERS_PARSER.declareInt(ConstructingObjectParser.constructorArg(), ShardFollowTask.MAX_OUTSTANDING_WRITE_REQUESTS); - PARAMETERS_PARSER.declareInt(ConstructingObjectParser.constructorArg(), ShardFollowTask.MAX_WRITE_BUFFER_COUNT); - PARAMETERS_PARSER.declareField( - ConstructingObjectParser.constructorArg(), - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), ShardFollowTask.MAX_WRITE_BUFFER_SIZE.getPreferredName()), - ShardFollowTask.MAX_WRITE_BUFFER_SIZE, - ObjectParser.ValueType.STRING); - PARAMETERS_PARSER.declareField( - ConstructingObjectParser.constructorArg(), - (p, c) -> TimeValue.parseTimeValue(p.text(), ShardFollowTask.MAX_RETRY_DELAY.getPreferredName()), - ShardFollowTask.MAX_RETRY_DELAY, - ObjectParser.ValueType.STRING); - PARAMETERS_PARSER.declareField( - ConstructingObjectParser.constructorArg(), - (p, c) -> TimeValue.parseTimeValue(p.text(), ShardFollowTask.READ_POLL_TIMEOUT.getPreferredName()), - ShardFollowTask.READ_POLL_TIMEOUT, - ObjectParser.ValueType.STRING); - } - + static final ObjectParser PARAMETERS_PARSER = new ObjectParser<>("parameters_parser", FollowParameters::new); static final ConstructingObjectParser INFO_PARSER = new ConstructingObjectParser<>( "info_parser", args -> { @@ -88,6 +40,8 @@ public class FollowInfoResponseTests extends AbstractSerializingTestCase instanceReader() @Override protected PutAutoFollowPatternAction.Request createTestInstance() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setName(randomAlphaOfLength(4)); - request.setRemoteCluster(randomAlphaOfLength(4)); - request.setLeaderIndexPatterns(Arrays.asList(generateRandomStringArray(4, 4, false))); + request.getBody().setName(randomAlphaOfLength(4)); + request.getBody().setRemoteCluster(randomAlphaOfLength(4)); + request.getBody().setLeaderIndexPatterns(Arrays.asList(generateRandomStringArray(4, 4, false))); if (randomBoolean()) { - request.setFollowIndexNamePattern(randomAlphaOfLength(4)); - } - if (randomBoolean()) { - request.setReadPollTimeout(TimeValue.timeValueMillis(500)); - } - if (randomBoolean()) { - request.setMaxRetryDelay(TimeValue.timeValueMillis(500)); - } - if (randomBoolean()) { - request.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); - } - if (randomBoolean()) { - request.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong())); - } - if (randomBoolean()) { - request.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong())); - } - if (randomBoolean()) { - request.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); - } - if (randomBoolean()) { - request.setMaxConcurrentReadBatches(randomIntBetween(0, Integer.MAX_VALUE)); - } - if (randomBoolean()) { - request.setMaxConcurrentWriteBatches(randomIntBetween(0, Integer.MAX_VALUE)); - } - if (randomBoolean()) { - request.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); - } - if (randomBoolean()) { - request.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE)); - } - if (randomBoolean()) { - request.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong())); + request.getBody().setFollowIndexNamePattern(randomAlphaOfLength(4)); } + ResumeFollowActionRequestTests.generateFollowParameters(request.getBody()); return request; } @@ -90,56 +56,56 @@ public void testValidate() { assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[name] is missing")); - request.setName("name"); + request.getBody().setName("name"); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[remote_cluster] is missing")); - request.setRemoteCluster("_alias"); + request.getBody().setRemoteCluster("_alias"); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[leader_index_patterns] is missing")); - request.setLeaderIndexPatterns(Collections.emptyList()); + request.getBody().setLeaderIndexPatterns(Collections.emptyList()); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[leader_index_patterns] is missing")); - request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); validationException = request.validate(); assertThat(validationException, nullValue()); - request.setMaxRetryDelay(TimeValue.ZERO); + request.getBody().setMaxRetryDelay(TimeValue.ZERO); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[max_retry_delay] must be positive but was [0ms]")); - request.setMaxRetryDelay(TimeValue.timeValueMinutes(10)); + request.getBody().setMaxRetryDelay(TimeValue.timeValueMinutes(10)); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[max_retry_delay] must be less than [5m] but was [10m]")); - request.setMaxRetryDelay(TimeValue.timeValueMinutes(1)); + request.getBody().setMaxRetryDelay(TimeValue.timeValueMinutes(1)); validationException = request.validate(); assertThat(validationException, nullValue()); } public void testValidateName() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setRemoteCluster("_alias"); - request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.getBody().setRemoteCluster("_alias"); + request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); - request.setName("name"); + request.getBody().setName("name"); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, nullValue()); } public void testValidateNameComma() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setRemoteCluster("_alias"); - request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.getBody().setRemoteCluster("_alias"); + request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); - request.setName("name1,name2"); + request.getBody().setName("name1,name2"); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("name must not contain a ','")); @@ -147,10 +113,10 @@ public void testValidateNameComma() { public void testValidateNameLeadingUnderscore() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setRemoteCluster("_alias"); - request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.getBody().setRemoteCluster("_alias"); + request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); - request.setName("_name"); + request.getBody().setName("_name"); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("name must not start with '_'")); @@ -158,29 +124,29 @@ public void testValidateNameLeadingUnderscore() { public void testValidateNameUnderscores() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setRemoteCluster("_alias"); - request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.getBody().setRemoteCluster("_alias"); + request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); - request.setName("n_a_m_e_"); + request.getBody().setName("n_a_m_e_"); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, nullValue()); } public void testValidateNameTooLong() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setRemoteCluster("_alias"); - request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.getBody().setRemoteCluster("_alias"); + request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < 256; i++) { stringBuilder.append('x'); } - request.setName(stringBuilder.toString()); + request.getBody().setName(stringBuilder.toString()); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("name is too long (256 > 255)")); - request.setName("name"); + request.getBody().setName("name"); validationException = request.validate(); assertThat(validationException, nullValue()); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java index 726a1c9893a50..c3f73b55cb9b0 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java @@ -22,9 +22,10 @@ protected Writeable.Reader instanceReader() { @Override protected PutFollowAction.Request createTestInstance() { PutFollowAction.Request request = new PutFollowAction.Request(); - request.setRemoteCluster(randomAlphaOfLength(4)); - request.setLeaderIndex(randomAlphaOfLength(4)); - request.setFollowRequest(ResumeFollowActionRequestTests.createTestRequest()); + request.getBody().setRemoteCluster(randomAlphaOfLength(4)); + request.getBody().setLeaderIndex(randomAlphaOfLength(4)); + request.getBody().setFollowerIndex(randomAlphaOfLength(4)); + ResumeFollowActionRequestTests.generateFollowParameters(request.getBody()); return request; } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ResumeFollowActionRequestTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ResumeFollowActionRequestTests.java index 3d3e869f53e8a..1c0b5c01064cb 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ResumeFollowActionRequestTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ResumeFollowActionRequestTests.java @@ -12,6 +12,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; +import org.elasticsearch.xpack.core.ccr.action.FollowParameters; import org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction; import java.io.IOException; @@ -29,7 +30,10 @@ protected Writeable.Reader instanceReader() { @Override protected ResumeFollowAction.Request createTestInstance() { - return createTestRequest(); + ResumeFollowAction.Request request = new ResumeFollowAction.Request(); + request.getBody().setFollowerIndex(randomAlphaOfLength(4)); + generateFollowParameters(request.getBody()); + return request; } @Override @@ -42,57 +46,54 @@ protected boolean supportsUnknownFields() { return false; } - static ResumeFollowAction.Request createTestRequest() { - ResumeFollowAction.Request request = new ResumeFollowAction.Request(); - request.setFollowerIndex(randomAlphaOfLength(4)); + static void generateFollowParameters(FollowParameters followParameters) { if (randomBoolean()) { - request.setMaxReadRequestOperationCount(randomIntBetween(1, Integer.MAX_VALUE)); + followParameters.setMaxReadRequestOperationCount(randomIntBetween(1, Integer.MAX_VALUE)); } if (randomBoolean()) { - request.setMaxOutstandingReadRequests(randomIntBetween(1, Integer.MAX_VALUE)); + followParameters.setMaxOutstandingReadRequests(randomIntBetween(1, Integer.MAX_VALUE)); } if (randomBoolean()) { - request.setMaxOutstandingWriteRequests(randomIntBetween(1, Integer.MAX_VALUE)); + followParameters.setMaxOutstandingWriteRequests(randomIntBetween(1, Integer.MAX_VALUE)); } if (randomBoolean()) { - request.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); + followParameters.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); } if (randomBoolean()) { - request.setMaxWriteBufferCount(randomIntBetween(1, Integer.MAX_VALUE)); + followParameters.setMaxWriteBufferCount(randomIntBetween(1, Integer.MAX_VALUE)); } if (randomBoolean()) { - request.setMaxWriteRequestOperationCount(randomIntBetween(1, Integer.MAX_VALUE)); + followParameters.setMaxWriteRequestOperationCount(randomIntBetween(1, Integer.MAX_VALUE)); } if (randomBoolean()) { - request.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong())); + followParameters.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong())); } if (randomBoolean()) { - request.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); + followParameters.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); } if (randomBoolean()) { - request.setMaxRetryDelay(TimeValue.timeValueMillis(500)); + followParameters.setMaxRetryDelay(TimeValue.timeValueMillis(500)); } if (randomBoolean()) { - request.setReadPollTimeout(TimeValue.timeValueMillis(500)); + followParameters.setReadPollTimeout(TimeValue.timeValueMillis(500)); } - return request; } public void testValidate() { ResumeFollowAction.Request request = new ResumeFollowAction.Request(); - request.setFollowerIndex("index2"); - request.setMaxRetryDelay(TimeValue.ZERO); + request.getBody().setFollowerIndex("index2"); + request.getBody().setMaxRetryDelay(TimeValue.ZERO); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[max_retry_delay] must be positive but was [0ms]")); - request.setMaxRetryDelay(TimeValue.timeValueMinutes(10)); + request.getBody().setMaxRetryDelay(TimeValue.timeValueMinutes(10)); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[max_retry_delay] must be less than [5m] but was [10m]")); - request.setMaxRetryDelay(TimeValue.timeValueMinutes(1)); + request.getBody().setMaxRetryDelay(TimeValue.timeValueMinutes(1)); validationException = request.validate(); assertThat(validationException, nullValue()); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java index ac556d47c85dd..16449d466c747 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java @@ -29,9 +29,9 @@ public class TransportPutAutoFollowPatternActionTests extends ESTestCase { public void testInnerPut() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setName("name1"); - request.setRemoteCluster("eu_cluster"); - request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.getBody().setName("name1"); + request.getBody().setRemoteCluster("eu_cluster"); + request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); ClusterState localState = ClusterState.builder(new ClusterName("us_cluster")) .metaData(MetaData.builder()) @@ -54,9 +54,9 @@ public void testInnerPut() { public void testInnerPut_existingLeaderIndices() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setName("name1"); - request.setRemoteCluster("eu_cluster"); - request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.getBody().setName("name1"); + request.getBody().setRemoteCluster("eu_cluster"); + request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); ClusterState localState = ClusterState.builder(new ClusterName("us_cluster")) .metaData(MetaData.builder()) @@ -95,9 +95,9 @@ public void testInnerPut_existingLeaderIndices() { public void testInnerPut_existingLeaderIndicesAndAutoFollowMetadata() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.setName("name1"); - request.setRemoteCluster("eu_cluster"); - request.setLeaderIndexPatterns(Arrays.asList("logs-*", "transactions-*")); + request.getBody().setName("name1"); + request.getBody().setRemoteCluster("eu_cluster"); + request.getBody().setLeaderIndexPatterns(Arrays.asList("logs-*", "transactions-*")); Map existingAutoFollowPatterns = new HashMap<>(); List existingPatterns = new ArrayList<>(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowInfoAction.java index 11d4f22e1b7a8..914277f4fc0ab 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowInfoAction.java @@ -14,8 +14,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -24,17 +22,6 @@ import java.util.List; import java.util.Objects; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_OUTSTANDING_READ_REQUESTS; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_OUTSTANDING_WRITE_REQUESTS; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_READ_REQUEST_OPERATION_COUNT; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_READ_REQUEST_SIZE; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_RETRY_DELAY_FIELD; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_WRITE_BUFFER_COUNT; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_WRITE_BUFFER_SIZE; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_WRITE_REQUEST_OPERATION_COUNT; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_WRITE_REQUEST_SIZE; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.READ_POLL_TIMEOUT; - public class FollowInfoAction extends Action { public static final String NAME = "cluster:monitor/ccr/follow_info"; @@ -202,7 +189,11 @@ public FollowParameters getParameters() { remoteCluster = in.readString(); leaderIndex = in.readString(); status = Status.fromString(in.readString()); - parameters = in.readOptionalWriteable(FollowParameters::new); + parameters = in.readOptionalWriteable(innerIn -> { + FollowParameters parameters = new FollowParameters(); + parameters.fromStreamInput(in); + return parameters; + }); } @Override @@ -224,16 +215,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (parameters != null) { builder.startObject(PARAMETERS_FIELD.getPreferredName()); { - builder.field(MAX_READ_REQUEST_OPERATION_COUNT.getPreferredName(), parameters.maxReadRequestOperationCount); - builder.field(MAX_READ_REQUEST_SIZE.getPreferredName(), parameters.maxReadRequestSize.getStringRep()); - builder.field(MAX_OUTSTANDING_READ_REQUESTS.getPreferredName(), parameters.maxOutstandingReadRequests); - builder.field(MAX_WRITE_REQUEST_OPERATION_COUNT.getPreferredName(), parameters.maxWriteRequestOperationCount); - builder.field(MAX_WRITE_REQUEST_SIZE.getPreferredName(), parameters.maxWriteRequestSize.getStringRep()); - builder.field(MAX_OUTSTANDING_WRITE_REQUESTS.getPreferredName(), parameters.maxOutstandingWriteRequests); - builder.field(MAX_WRITE_BUFFER_COUNT.getPreferredName(), parameters.maxWriteBufferCount); - builder.field(MAX_WRITE_BUFFER_SIZE.getPreferredName(), parameters.maxWriteBufferSize.getStringRep()); - builder.field(MAX_RETRY_DELAY_FIELD.getPreferredName(), parameters.maxRetryDelay.getStringRep()); - builder.field(READ_POLL_TIMEOUT.getPreferredName(), parameters.readPollTimeout.getStringRep()); + parameters.toXContentFragment(builder); } builder.endObject(); } @@ -263,138 +245,6 @@ public String toString() { } } - public static class FollowParameters implements Writeable { - - private final int maxReadRequestOperationCount; - private final ByteSizeValue maxReadRequestSize; - private final int maxOutstandingReadRequests; - private final int maxWriteRequestOperationCount; - private final ByteSizeValue maxWriteRequestSize; - private final int maxOutstandingWriteRequests; - private final int maxWriteBufferCount; - private final ByteSizeValue maxWriteBufferSize; - private final TimeValue maxRetryDelay; - private final TimeValue readPollTimeout; - - public FollowParameters(int maxReadRequestOperationCount, - ByteSizeValue maxReadRequestSize, int maxOutstandingReadRequests, - int maxWriteRequestOperationCount, ByteSizeValue maxWriteRequestSize, - int maxOutstandingWriteRequests, int maxWriteBufferCount, - ByteSizeValue maxWriteBufferSize, TimeValue maxRetryDelay, TimeValue readPollTimeout) { - this.maxReadRequestOperationCount = maxReadRequestOperationCount; - this.maxReadRequestSize = maxReadRequestSize; - this.maxOutstandingReadRequests = maxOutstandingReadRequests; - this.maxWriteRequestOperationCount = maxWriteRequestOperationCount; - this.maxWriteRequestSize = maxWriteRequestSize; - this.maxOutstandingWriteRequests = maxOutstandingWriteRequests; - this.maxWriteBufferCount = maxWriteBufferCount; - this.maxWriteBufferSize = maxWriteBufferSize; - this.maxRetryDelay = maxRetryDelay; - this.readPollTimeout = readPollTimeout; - } - - public int getMaxReadRequestOperationCount() { - return maxReadRequestOperationCount; - } - - public ByteSizeValue getMaxReadRequestSize() { - return maxReadRequestSize; - } - - public int getMaxOutstandingReadRequests() { - return maxOutstandingReadRequests; - } - - public int getMaxWriteRequestOperationCount() { - return maxWriteRequestOperationCount; - } - - public ByteSizeValue getMaxWriteRequestSize() { - return maxWriteRequestSize; - } - - public int getMaxOutstandingWriteRequests() { - return maxOutstandingWriteRequests; - } - - public int getMaxWriteBufferCount() { - return maxWriteBufferCount; - } - - public ByteSizeValue getMaxWriteBufferSize() { - return maxWriteBufferSize; - } - - public TimeValue getMaxRetryDelay() { - return maxRetryDelay; - } - - public TimeValue getReadPollTimeout() { - return readPollTimeout; - } - - FollowParameters(StreamInput in) throws IOException { - this.maxReadRequestOperationCount = in.readVInt(); - this.maxReadRequestSize = new ByteSizeValue(in); - this.maxOutstandingReadRequests = in.readVInt(); - this.maxWriteRequestOperationCount = in.readVInt(); - this.maxWriteRequestSize = new ByteSizeValue(in); - this.maxOutstandingWriteRequests = in.readVInt(); - this.maxWriteBufferCount = in.readVInt(); - this.maxWriteBufferSize = new ByteSizeValue(in); - this.maxRetryDelay = in.readTimeValue(); - this.readPollTimeout = in.readTimeValue(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeVLong(maxReadRequestOperationCount); - maxReadRequestSize.writeTo(out); - out.writeVInt(maxOutstandingReadRequests); - out.writeVLong(maxWriteRequestOperationCount); - maxWriteRequestSize.writeTo(out); - out.writeVInt(maxOutstandingWriteRequests); - out.writeVInt(maxWriteBufferCount); - maxWriteBufferSize.writeTo(out); - out.writeTimeValue(maxRetryDelay); - out.writeTimeValue(readPollTimeout); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - FollowParameters that = (FollowParameters) o; - return maxReadRequestOperationCount == that.maxReadRequestOperationCount && - maxOutstandingReadRequests == that.maxOutstandingReadRequests && - maxWriteRequestOperationCount == that.maxWriteRequestOperationCount && - maxOutstandingWriteRequests == that.maxOutstandingWriteRequests && - maxWriteBufferCount == that.maxWriteBufferCount && - Objects.equals(maxReadRequestSize, that.maxReadRequestSize) && - Objects.equals(maxWriteRequestSize, that.maxWriteRequestSize) && - Objects.equals(maxWriteBufferSize, that.maxWriteBufferSize) && - Objects.equals(maxRetryDelay, that.maxRetryDelay) && - Objects.equals(readPollTimeout, that.readPollTimeout); - } - - @Override - public int hashCode() { - return Objects.hash( - maxReadRequestOperationCount, - maxReadRequestSize, - maxOutstandingReadRequests, - maxWriteRequestOperationCount, - maxWriteRequestSize, - maxOutstandingWriteRequests, - maxWriteBufferCount, - maxWriteBufferSize, - maxRetryDelay, - readPollTimeout - ); - } - - } - public enum Status { ACTIVE("active"), diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java new file mode 100644 index 0000000000000..68f2b780ef1fa --- /dev/null +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java @@ -0,0 +1,297 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.xpack.core.ccr.action; + +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.AbstractObjectParser; +import org.elasticsearch.common.xcontent.ObjectParser; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata; + +import java.io.IOException; +import java.util.Objects; + +import static org.elasticsearch.action.ValidateActions.addValidationError; + +public class FollowParameters implements Writeable { + + static final TimeValue RETRY_DELAY_MAX = TimeValue.timeValueMinutes(5); + + static final ParseField MAX_READ_REQUEST_OPERATION_COUNT = new ParseField("max_read_request_operation_count"); + static final ParseField MAX_WRITE_REQUEST_OPERATION_COUNT = new ParseField("max_write_request_operation_count"); + static final ParseField MAX_OUTSTANDING_READ_REQUESTS = new ParseField("max_outstanding_read_requests"); + static final ParseField MAX_OUTSTANDING_WRITE_REQUESTS = new ParseField("max_outstanding_write_requests"); + static final ParseField MAX_READ_REQUEST_SIZE = new ParseField("max_read_request_size"); + static final ParseField MAX_WRITE_REQUEST_SIZE = new ParseField("max_write_request_size"); + static final ParseField MAX_WRITE_BUFFER_COUNT = new ParseField("max_write_buffer_count"); + static final ParseField MAX_WRITE_BUFFER_SIZE = new ParseField("max_write_buffer_size"); + static final ParseField MAX_RETRY_DELAY = new ParseField("max_retry_delay"); + static final ParseField READ_POLL_TIMEOUT = new ParseField("read_poll_timeout"); + + Integer maxReadRequestOperationCount; + Integer maxWriteRequestOperationCount; + Integer maxOutstandingReadRequests; + Integer maxOutstandingWriteRequests; + ByteSizeValue maxReadRequestSize; + ByteSizeValue maxWriteRequestSize; + Integer maxWriteBufferCount; + ByteSizeValue maxWriteBufferSize; + TimeValue maxRetryDelay; + TimeValue readPollTimeout; + + public FollowParameters() { + } + + public Integer getMaxReadRequestOperationCount() { + return maxReadRequestOperationCount; + } + + public void setMaxReadRequestOperationCount(Integer maxReadRequestOperationCount) { + this.maxReadRequestOperationCount = maxReadRequestOperationCount; + } + + public ByteSizeValue getMaxReadRequestSize() { + return maxReadRequestSize; + } + + public void setMaxReadRequestSize(ByteSizeValue maxReadRequestSize) { + this.maxReadRequestSize = maxReadRequestSize; + } + + public Integer getMaxOutstandingReadRequests() { + return maxOutstandingReadRequests; + } + + public void setMaxOutstandingReadRequests(Integer maxOutstandingReadRequests) { + this.maxOutstandingReadRequests = maxOutstandingReadRequests; + } + + public Integer getMaxWriteRequestOperationCount() { + return maxWriteRequestOperationCount; + } + + public void setMaxWriteRequestOperationCount(Integer maxWriteRequestOperationCount) { + this.maxWriteRequestOperationCount = maxWriteRequestOperationCount; + } + + public ByteSizeValue getMaxWriteRequestSize() { + return maxWriteRequestSize; + } + + public void setMaxWriteRequestSize(ByteSizeValue maxWriteRequestSize) { + this.maxWriteRequestSize = maxWriteRequestSize; + } + + public Integer getMaxOutstandingWriteRequests() { + return maxOutstandingWriteRequests; + } + + public void setMaxOutstandingWriteRequests(Integer maxOutstandingWriteRequests) { + this.maxOutstandingWriteRequests = maxOutstandingWriteRequests; + } + + public Integer getMaxWriteBufferCount() { + return maxWriteBufferCount; + } + + public void setMaxWriteBufferCount(Integer maxWriteBufferCount) { + this.maxWriteBufferCount = maxWriteBufferCount; + } + + public ByteSizeValue getMaxWriteBufferSize() { + return maxWriteBufferSize; + } + + public void setMaxWriteBufferSize(ByteSizeValue maxWriteBufferSize) { + this.maxWriteBufferSize = maxWriteBufferSize; + } + + public TimeValue getMaxRetryDelay() { + return maxRetryDelay; + } + + public void setMaxRetryDelay(TimeValue maxRetryDelay) { + this.maxRetryDelay = maxRetryDelay; + } + + public TimeValue getReadPollTimeout() { + return readPollTimeout; + } + + public void setReadPollTimeout(TimeValue readPollTimeout) { + this.readPollTimeout = readPollTimeout; + } + + public ActionRequestValidationException validate() { + ActionRequestValidationException e = null; + + if (maxReadRequestOperationCount != null && maxReadRequestOperationCount < 1) { + e = addValidationError(MAX_READ_REQUEST_OPERATION_COUNT.getPreferredName() + " must be larger than 0", e); + } + if (maxReadRequestSize != null && maxReadRequestSize.compareTo(ByteSizeValue.ZERO) <= 0) { + e = addValidationError(MAX_READ_REQUEST_SIZE.getPreferredName() + " must be larger than 0", e); + } + if (maxOutstandingReadRequests != null && maxOutstandingReadRequests < 1) { + e = addValidationError(MAX_OUTSTANDING_READ_REQUESTS.getPreferredName() + " must be larger than 0", e); + } + if (maxWriteRequestOperationCount != null && maxWriteRequestOperationCount < 1) { + e = addValidationError(MAX_WRITE_REQUEST_OPERATION_COUNT.getPreferredName() + " must be larger than 0", e); + } + if (maxWriteRequestSize != null && maxWriteRequestSize.compareTo(ByteSizeValue.ZERO) <= 0) { + e = addValidationError(MAX_WRITE_REQUEST_SIZE.getPreferredName() + " must be larger than 0", e); + } + if (maxOutstandingWriteRequests != null && maxOutstandingWriteRequests < 1) { + e = addValidationError(MAX_OUTSTANDING_WRITE_REQUESTS.getPreferredName() + " must be larger than 0", e); + } + if (maxWriteBufferCount != null && maxWriteBufferCount < 1) { + e = addValidationError(MAX_WRITE_BUFFER_COUNT.getPreferredName() + " must be larger than 0", e); + } + if (maxWriteBufferSize != null && maxWriteBufferSize.compareTo(ByteSizeValue.ZERO) <= 0) { + e = addValidationError(MAX_WRITE_BUFFER_SIZE.getPreferredName() + " must be larger than 0", e); + } + if (maxRetryDelay != null && maxRetryDelay.millis() <= 0) { + String message = "[" + MAX_RETRY_DELAY.getPreferredName() + "] must be positive but was [" + + maxRetryDelay.getStringRep() + "]"; + e = addValidationError(message, e); + } + if (maxRetryDelay != null && maxRetryDelay.millis() > RETRY_DELAY_MAX.millis()) { + String message = "[" + MAX_RETRY_DELAY.getPreferredName() + "] must be less than [" + RETRY_DELAY_MAX.getStringRep() + + "] but was [" + maxRetryDelay.getStringRep() + "]"; + e = addValidationError(message, e); + } + + return e; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeOptionalVInt(maxReadRequestOperationCount); + out.writeOptionalVInt(maxOutstandingReadRequests); + out.writeOptionalWriteable(maxReadRequestSize); + out.writeOptionalVInt(maxWriteRequestOperationCount); + out.writeOptionalWriteable(maxWriteRequestSize); + out.writeOptionalVInt(maxOutstandingWriteRequests); + out.writeOptionalVInt(maxWriteBufferCount); + out.writeOptionalWriteable(maxWriteBufferSize); + out.writeOptionalTimeValue(maxRetryDelay); + out.writeOptionalTimeValue(readPollTimeout); + } + + void fromStreamInput(StreamInput in) throws IOException { + maxReadRequestOperationCount = in.readOptionalVInt(); + maxOutstandingReadRequests = in.readOptionalVInt(); + maxReadRequestSize = in.readOptionalWriteable(ByteSizeValue::new); + maxWriteRequestOperationCount = in.readOptionalVInt(); + maxWriteRequestSize = in.readOptionalWriteable(ByteSizeValue::new); + maxOutstandingWriteRequests = in.readOptionalVInt(); + maxWriteBufferCount = in.readOptionalVInt(); + maxWriteBufferSize = in.readOptionalWriteable(ByteSizeValue::new); + maxRetryDelay = in.readOptionalTimeValue(); + readPollTimeout = in.readOptionalTimeValue(); + } + + XContentBuilder toXContentFragment(final XContentBuilder builder) throws IOException { + if (maxReadRequestOperationCount != null) { + builder.field(MAX_READ_REQUEST_OPERATION_COUNT.getPreferredName(), maxReadRequestOperationCount); + } + if (maxWriteRequestOperationCount != null) { + builder.field(MAX_WRITE_REQUEST_OPERATION_COUNT.getPreferredName(), maxWriteRequestOperationCount); + } + if (maxOutstandingReadRequests != null) { + builder.field(MAX_OUTSTANDING_READ_REQUESTS.getPreferredName(), maxOutstandingReadRequests); + } + if (maxOutstandingWriteRequests != null) { + builder.field(MAX_OUTSTANDING_WRITE_REQUESTS.getPreferredName(), maxOutstandingWriteRequests); + } + if (maxReadRequestSize != null) { + builder.field(MAX_READ_REQUEST_SIZE.getPreferredName(), maxReadRequestSize.getStringRep()); + } + if (maxWriteRequestSize != null) { + builder.field(MAX_WRITE_REQUEST_SIZE.getPreferredName(), maxWriteRequestSize.getStringRep()); + } + if (maxWriteBufferCount != null) { + builder.field(MAX_WRITE_BUFFER_COUNT.getPreferredName(), maxWriteBufferCount); + } + if (maxWriteBufferSize != null) { + builder.field(MAX_WRITE_BUFFER_SIZE.getPreferredName(), maxWriteBufferSize.getStringRep()); + } + if (maxRetryDelay != null) { + builder.field(MAX_RETRY_DELAY.getPreferredName(), maxRetryDelay.getStringRep()); + } + if (readPollTimeout != null) { + builder.field(READ_POLL_TIMEOUT.getPreferredName(), readPollTimeout.getStringRep()); + } + return builder; + } + + public static void initParser(AbstractObjectParser parser) { + parser.declareInt(FollowParameters::setMaxReadRequestOperationCount, MAX_READ_REQUEST_OPERATION_COUNT); + parser.declareInt(FollowParameters::setMaxWriteRequestOperationCount, MAX_WRITE_REQUEST_OPERATION_COUNT); + parser.declareInt(FollowParameters::setMaxOutstandingReadRequests, MAX_OUTSTANDING_READ_REQUESTS); + parser.declareInt(FollowParameters::setMaxOutstandingWriteRequests, MAX_OUTSTANDING_WRITE_REQUESTS); + parser.declareField( + FollowParameters::setMaxReadRequestSize, + (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_READ_REQUEST_SIZE.getPreferredName()), + AutoFollowMetadata.AutoFollowPattern.MAX_READ_REQUEST_SIZE, + ObjectParser.ValueType.STRING); + parser.declareField( + FollowParameters::setMaxWriteRequestSize, + (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_WRITE_REQUEST_SIZE.getPreferredName()), + AutoFollowMetadata.AutoFollowPattern.MAX_WRITE_REQUEST_SIZE, + ObjectParser.ValueType.STRING); + parser.declareInt(FollowParameters::setMaxWriteBufferCount, MAX_WRITE_BUFFER_COUNT); + parser.declareField( + FollowParameters::setMaxWriteBufferSize, + (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_WRITE_BUFFER_SIZE.getPreferredName()), + MAX_WRITE_BUFFER_SIZE, + ObjectParser.ValueType.STRING); + parser.declareField(FollowParameters::setMaxRetryDelay, + (p, c) -> TimeValue.parseTimeValue(p.text(), MAX_RETRY_DELAY.getPreferredName()), + MAX_RETRY_DELAY, ObjectParser.ValueType.STRING); + parser.declareField(FollowParameters::setReadPollTimeout, + (p, c) -> TimeValue.parseTimeValue(p.text(), READ_POLL_TIMEOUT.getPreferredName()), + READ_POLL_TIMEOUT, ObjectParser.ValueType.STRING); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FollowParameters that = (FollowParameters) o; + return Objects.equals(maxReadRequestOperationCount, that.maxReadRequestOperationCount) && + Objects.equals(maxWriteRequestOperationCount, that.maxWriteRequestOperationCount) && + Objects.equals(maxOutstandingReadRequests, that.maxOutstandingReadRequests) && + Objects.equals(maxOutstandingWriteRequests, that.maxOutstandingWriteRequests) && + Objects.equals(maxReadRequestSize, that.maxReadRequestSize) && + Objects.equals(maxWriteRequestSize, that.maxWriteRequestSize) && + Objects.equals(maxWriteBufferCount, that.maxWriteBufferCount) && + Objects.equals(maxWriteBufferSize, that.maxWriteBufferSize) && + Objects.equals(maxRetryDelay, that.maxRetryDelay) && + Objects.equals(readPollTimeout, that.readPollTimeout); + } + + @Override + public int hashCode() { + return Objects.hash( + maxReadRequestOperationCount, + maxWriteRequestOperationCount, + maxOutstandingReadRequests, + maxOutstandingWriteRequests, + maxReadRequestSize, + maxWriteRequestSize, + maxWriteBufferCount, + maxWriteBufferSize, + maxRetryDelay, + readPollTimeout + ); + } +} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java index d0969850705f7..14cb001a7e9d9 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.core.ccr.action; +import org.elasticsearch.Version; import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.AcknowledgedRequest; @@ -13,7 +14,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -44,354 +44,232 @@ public AcknowledgedResponse newResponse() { public static class Request extends AcknowledgedRequest implements ToXContentObject { - private static final ObjectParser PARSER = new ObjectParser<>("put_auto_follow_pattern_request", Request::new); - private static final ParseField NAME_FIELD = new ParseField("name"); - private static final int MAX_NAME_BYTES = 255; - - static { - PARSER.declareString(Request::setName, NAME_FIELD); - PARSER.declareString(Request::setRemoteCluster, REMOTE_CLUSTER_FIELD); - PARSER.declareStringArray(Request::setLeaderIndexPatterns, AutoFollowPattern.LEADER_PATTERNS_FIELD); - PARSER.declareString(Request::setFollowIndexNamePattern, AutoFollowPattern.FOLLOW_PATTERN_FIELD); - PARSER.declareInt(Request::setMaxReadRequestOperationCount, AutoFollowPattern.MAX_READ_REQUEST_OPERATION_COUNT); - PARSER.declareField( - Request::setMaxReadRequestSize, - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), AutoFollowPattern.MAX_READ_REQUEST_SIZE.getPreferredName()), - AutoFollowPattern.MAX_READ_REQUEST_SIZE, - ObjectParser.ValueType.STRING); - PARSER.declareInt(Request::setMaxConcurrentReadBatches, AutoFollowPattern.MAX_OUTSTANDING_READ_REQUESTS); - PARSER.declareInt(Request::setMaxWriteRequestOperationCount, AutoFollowPattern.MAX_WRITE_REQUEST_OPERATION_COUNT); - PARSER.declareField( - Request::setMaxWriteRequestSize, - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), AutoFollowPattern.MAX_WRITE_REQUEST_SIZE.getPreferredName()), - AutoFollowPattern.MAX_WRITE_REQUEST_SIZE, - ObjectParser.ValueType.STRING); - PARSER.declareInt(Request::setMaxConcurrentWriteBatches, AutoFollowPattern.MAX_OUTSTANDING_WRITE_REQUESTS); - PARSER.declareInt(Request::setMaxWriteBufferCount, AutoFollowPattern.MAX_WRITE_BUFFER_COUNT); - PARSER.declareField( - Request::setMaxWriteBufferSize, - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), AutoFollowPattern.MAX_WRITE_BUFFER_SIZE.getPreferredName()), - AutoFollowPattern.MAX_WRITE_BUFFER_SIZE, - ObjectParser.ValueType.STRING); - PARSER.declareField(Request::setMaxRetryDelay, - (p, c) -> TimeValue.parseTimeValue(p.text(), AutoFollowPattern.MAX_RETRY_DELAY.getPreferredName()), - AutoFollowPattern.MAX_RETRY_DELAY, ObjectParser.ValueType.STRING); - PARSER.declareField(Request::setReadPollTimeout, - (p, c) -> TimeValue.parseTimeValue(p.text(), AutoFollowPattern.READ_POLL_TIMEOUT.getPreferredName()), - AutoFollowPattern.READ_POLL_TIMEOUT, ObjectParser.ValueType.STRING); - } - public static Request fromXContent(XContentParser parser, String name) throws IOException { - Request request = PARSER.parse(parser, null); + Body body = Body.PARSER.parse(parser, null); if (name != null) { - if (request.name == null) { - request.name = name; + if (body.name == null) { + body.name = name; } else { - if (request.name.equals(name) == false) { + if (body.name.equals(name) == false) { throw new IllegalArgumentException("provided name is not equal"); } } } + Request request = new Request(); + request.setBody(body); return request; } - private String name; - private String remoteCluster; - private List leaderIndexPatterns; - private String followIndexNamePattern; - - private Integer maxReadRequestOperationCount; - private ByteSizeValue maxReadRequestSize; - private Integer maxConcurrentReadBatches; - private Integer maxWriteRequestOperationCount; - private ByteSizeValue maxWriteRequestSize; - private Integer maxConcurrentWriteBatches; - private Integer maxWriteBufferCount; - private ByteSizeValue maxWriteBufferSize; - private TimeValue maxRetryDelay; - private TimeValue readPollTimeout; + private Body body = new Body(); public Request() { } @Override public ActionRequestValidationException validate() { - ActionRequestValidationException validationException = null; - if (name == null) { - validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] is missing", validationException); - } - if (name != null) { - if (name.contains(",")) { - validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] name must not contain a ','", - validationException); - } - if (name.startsWith("_")) { - validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] name must not start with '_'", - validationException); - } - int byteCount = name.getBytes(StandardCharsets.UTF_8).length; - if (byteCount > MAX_NAME_BYTES) { - validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] name is too long (" + - byteCount + " > " + MAX_NAME_BYTES + ")", validationException); - } - } - if (remoteCluster == null) { - validationException = addValidationError("[" + REMOTE_CLUSTER_FIELD.getPreferredName() + - "] is missing", validationException); - } - if (leaderIndexPatterns == null || leaderIndexPatterns.isEmpty()) { - validationException = addValidationError("[" + AutoFollowPattern.LEADER_PATTERNS_FIELD.getPreferredName() + - "] is missing", validationException); - } - if (maxRetryDelay != null) { - if (maxRetryDelay.millis() <= 0) { - String message = "[" + AutoFollowPattern.MAX_RETRY_DELAY.getPreferredName() + "] must be positive but was [" + - maxRetryDelay.getStringRep() + "]"; - validationException = addValidationError(message, validationException); - } - if (maxRetryDelay.millis() > ResumeFollowAction.MAX_RETRY_DELAY.millis()) { - String message = "[" + AutoFollowPattern.MAX_RETRY_DELAY.getPreferredName() + "] must be less than [" + - ResumeFollowAction.MAX_RETRY_DELAY + - "] but was [" + maxRetryDelay.getStringRep() + "]"; - validationException = addValidationError(message, validationException); - } - } - return validationException; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getRemoteCluster() { - return remoteCluster; - } - - public void setRemoteCluster(String remoteCluster) { - this.remoteCluster = remoteCluster; - } - - public List getLeaderIndexPatterns() { - return leaderIndexPatterns; - } - - public void setLeaderIndexPatterns(List leaderIndexPatterns) { - this.leaderIndexPatterns = leaderIndexPatterns; - } - - public String getFollowIndexNamePattern() { - return followIndexNamePattern; + return body.validate(); } - public void setFollowIndexNamePattern(String followIndexNamePattern) { - this.followIndexNamePattern = followIndexNamePattern; + public Body getBody() { + return body; } - public Integer getMaxReadRequestOperationCount() { - return maxReadRequestOperationCount; + public void setBody(Body body) { + this.body = body; } - public void setMaxReadRequestOperationCount(Integer maxReadRequestOperationCount) { - this.maxReadRequestOperationCount = maxReadRequestOperationCount; - } - - public Integer getMaxConcurrentReadBatches() { - return maxConcurrentReadBatches; - } - - public void setMaxConcurrentReadBatches(Integer maxConcurrentReadBatches) { - this.maxConcurrentReadBatches = maxConcurrentReadBatches; - } - - public ByteSizeValue getMaxReadRequestSize() { - return maxReadRequestSize; + public Request(StreamInput in) throws IOException { + super(in); + this.body = new Body(in); } - public void setMaxReadRequestSize(ByteSizeValue maxReadRequestSize) { - this.maxReadRequestSize = maxReadRequestSize; + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + body.writeTo(out); } - public Integer getMaxWriteRequestOperationCount() { - return maxWriteRequestOperationCount; + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + return body.toXContent(builder, params); } - public void setMaxWriteRequestOperationCount(Integer maxWriteRequestOperationCount) { - this.maxWriteRequestOperationCount = maxWriteRequestOperationCount; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Request request = (Request) o; + return Objects.equals(body, request.body); } - public ByteSizeValue getMaxWriteRequestSize() { - return maxWriteRequestSize; + @Override + public int hashCode() { + return Objects.hash(body); } - public void setMaxWriteRequestSize(ByteSizeValue maxWriteRequestSize) { - this.maxWriteRequestSize = maxWriteRequestSize; - } + public static class Body extends FollowParameters implements ToXContentObject { - public Integer getMaxConcurrentWriteBatches() { - return maxConcurrentWriteBatches; - } + private static final ObjectParser PARSER = new ObjectParser<>("put_auto_follow_pattern_request", Body::new); + private static final ParseField NAME_FIELD = new ParseField("name"); + private static final int MAX_NAME_BYTES = 255; - public void setMaxConcurrentWriteBatches(Integer maxConcurrentWriteBatches) { - this.maxConcurrentWriteBatches = maxConcurrentWriteBatches; - } + static { + PARSER.declareString(Body::setName, NAME_FIELD); + PARSER.declareString(Body::setRemoteCluster, REMOTE_CLUSTER_FIELD); + PARSER.declareStringArray(Body::setLeaderIndexPatterns, AutoFollowPattern.LEADER_PATTERNS_FIELD); + PARSER.declareString(Body::setFollowIndexNamePattern, AutoFollowPattern.FOLLOW_PATTERN_FIELD); + initParser(PARSER); + } - public Integer getMaxWriteBufferCount() { - return maxWriteBufferCount; - } + private String name; + private String remoteCluster; + private List leaderIndexPatterns; + private String followIndexNamePattern; - public void setMaxWriteBufferCount(Integer maxWriteBufferCount) { - this.maxWriteBufferCount = maxWriteBufferCount; - } + public Body() { + } - public ByteSizeValue getMaxWriteBufferSize() { - return maxWriteBufferSize; - } + public String getName() { + return name; + } - public void setMaxWriteBufferSize(ByteSizeValue maxWriteBufferSize) { - this.maxWriteBufferSize = maxWriteBufferSize; - } + public void setName(String name) { + this.name = name; + } - public TimeValue getMaxRetryDelay() { - return maxRetryDelay; - } + public String getRemoteCluster() { + return remoteCluster; + } - public void setMaxRetryDelay(TimeValue maxRetryDelay) { - this.maxRetryDelay = maxRetryDelay; - } + public void setRemoteCluster(String remoteCluster) { + this.remoteCluster = remoteCluster; + } - public TimeValue getReadPollTimeout() { - return readPollTimeout; - } + public List getLeaderIndexPatterns() { + return leaderIndexPatterns; + } - public void setReadPollTimeout(TimeValue readPollTimeout) { - this.readPollTimeout = readPollTimeout; - } + public void setLeaderIndexPatterns(List leaderIndexPatterns) { + this.leaderIndexPatterns = leaderIndexPatterns; + } - public Request(StreamInput in) throws IOException { - super(in); - name = in.readString(); - remoteCluster = in.readString(); - leaderIndexPatterns = in.readList(StreamInput::readString); - followIndexNamePattern = in.readOptionalString(); - maxReadRequestOperationCount = in.readOptionalVInt(); - maxReadRequestSize = in.readOptionalWriteable(ByteSizeValue::new); - maxConcurrentReadBatches = in.readOptionalVInt(); - maxWriteRequestOperationCount = in.readOptionalVInt(); - maxWriteRequestSize = in.readOptionalWriteable(ByteSizeValue::new); - maxConcurrentWriteBatches = in.readOptionalVInt(); - maxWriteBufferCount = in.readOptionalVInt(); - maxWriteBufferSize = in.readOptionalWriteable(ByteSizeValue::new); - maxRetryDelay = in.readOptionalTimeValue(); - readPollTimeout = in.readOptionalTimeValue(); - } + public String getFollowIndexNamePattern() { + return followIndexNamePattern; + } - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeString(name); - out.writeString(remoteCluster); - out.writeStringList(leaderIndexPatterns); - out.writeOptionalString(followIndexNamePattern); - out.writeOptionalVInt(maxReadRequestOperationCount); - out.writeOptionalWriteable(maxReadRequestSize); - out.writeOptionalVInt(maxConcurrentReadBatches); - out.writeOptionalVInt(maxWriteRequestOperationCount); - out.writeOptionalWriteable(maxWriteRequestSize); - out.writeOptionalVInt(maxConcurrentWriteBatches); - out.writeOptionalVInt(maxWriteBufferCount); - out.writeOptionalWriteable(maxWriteBufferSize); - out.writeOptionalTimeValue(maxRetryDelay); - out.writeOptionalTimeValue(readPollTimeout); - } + public void setFollowIndexNamePattern(String followIndexNamePattern) { + this.followIndexNamePattern = followIndexNamePattern; + } - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - { - builder.field(NAME_FIELD.getPreferredName(), name); - builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster); - builder.field(AutoFollowPattern.LEADER_PATTERNS_FIELD.getPreferredName(), leaderIndexPatterns); - if (followIndexNamePattern != null) { - builder.field(AutoFollowPattern.FOLLOW_PATTERN_FIELD.getPreferredName(), followIndexNamePattern); - } - if (maxReadRequestOperationCount != null) { - builder.field(AutoFollowPattern.MAX_READ_REQUEST_OPERATION_COUNT.getPreferredName(), maxReadRequestOperationCount); - } - if (maxReadRequestSize != null) { - builder.field(AutoFollowPattern.MAX_READ_REQUEST_SIZE.getPreferredName(), maxReadRequestSize.getStringRep()); + @Override + public ActionRequestValidationException validate() { + ActionRequestValidationException validationException = super.validate(); + if (name == null) { + validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] is missing", validationException); } - if (maxWriteRequestOperationCount != null) { - builder.field(AutoFollowPattern.MAX_WRITE_REQUEST_OPERATION_COUNT.getPreferredName(), maxWriteRequestOperationCount); - } - if (maxWriteRequestSize != null) { - builder.field(AutoFollowPattern.MAX_WRITE_REQUEST_SIZE.getPreferredName(), maxWriteRequestSize.getStringRep()); - } - if (maxWriteBufferCount != null) { - builder.field(AutoFollowPattern.MAX_WRITE_BUFFER_COUNT.getPreferredName(), maxWriteBufferCount); + if (name != null) { + if (name.contains(",")) { + validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] name must not contain a ','", + validationException); + } + if (name.startsWith("_")) { + validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] name must not start with '_'", + validationException); + } + int byteCount = name.getBytes(StandardCharsets.UTF_8).length; + if (byteCount > MAX_NAME_BYTES) { + validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] name is too long (" + + byteCount + " > " + MAX_NAME_BYTES + ")", validationException); + } } - if (maxWriteBufferSize != null) { - builder.field(AutoFollowPattern.MAX_WRITE_BUFFER_SIZE.getPreferredName(), maxWriteBufferSize.getStringRep()); + if (remoteCluster == null) { + validationException = addValidationError("[" + REMOTE_CLUSTER_FIELD.getPreferredName() + + "] is missing", validationException); } - if (maxConcurrentReadBatches != null) { - builder.field(AutoFollowPattern.MAX_OUTSTANDING_READ_REQUESTS.getPreferredName(), maxConcurrentReadBatches); + if (leaderIndexPatterns == null || leaderIndexPatterns.isEmpty()) { + validationException = addValidationError("[" + AutoFollowPattern.LEADER_PATTERNS_FIELD.getPreferredName() + + "] is missing", validationException); } - if (maxConcurrentWriteBatches != null) { - builder.field(AutoFollowPattern.MAX_OUTSTANDING_WRITE_REQUESTS.getPreferredName(), maxConcurrentWriteBatches); + return validationException; + } + + Body(StreamInput in) throws IOException { + name = in.readString(); + remoteCluster = in.readString(); + leaderIndexPatterns = in.readList(StreamInput::readString); + followIndexNamePattern = in.readOptionalString(); + if (in.getVersion().onOrAfter(Version.V_7_0_0)) { + fromStreamInput(in); + } else { + maxReadRequestOperationCount = in.readOptionalVInt(); + maxReadRequestSize = in.readOptionalWriteable(ByteSizeValue::new); + maxOutstandingReadRequests = in.readOptionalVInt(); + maxWriteRequestOperationCount = in.readOptionalVInt(); + maxWriteRequestSize = in.readOptionalWriteable(ByteSizeValue::new); + maxOutstandingWriteRequests = in.readOptionalVInt(); + maxWriteBufferCount = in.readOptionalVInt(); + maxWriteBufferSize = in.readOptionalWriteable(ByteSizeValue::new); + maxRetryDelay = in.readOptionalTimeValue(); + readPollTimeout = in.readOptionalTimeValue(); } - if (maxRetryDelay != null) { - builder.field(AutoFollowPattern.MAX_RETRY_DELAY.getPreferredName(), maxRetryDelay.getStringRep()); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(name); + out.writeString(remoteCluster); + out.writeStringList(leaderIndexPatterns); + out.writeOptionalString(followIndexNamePattern); + if (out.getVersion().onOrAfter(Version.V_7_0_0)) { + super.writeTo(out); + } else { + out.writeOptionalVInt(maxReadRequestOperationCount); + out.writeOptionalWriteable(maxReadRequestSize); + out.writeOptionalVInt(maxOutstandingReadRequests); + out.writeOptionalVInt(maxWriteRequestOperationCount); + out.writeOptionalWriteable(maxWriteRequestSize); + out.writeOptionalVInt(maxOutstandingWriteRequests); + out.writeOptionalVInt(maxWriteBufferCount); + out.writeOptionalWriteable(maxWriteBufferSize); + out.writeOptionalTimeValue(maxRetryDelay); + out.writeOptionalTimeValue(readPollTimeout); } - if (readPollTimeout != null) { - builder.field(AutoFollowPattern.READ_POLL_TIMEOUT.getPreferredName(), readPollTimeout.getStringRep()); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + { + builder.field(NAME_FIELD.getPreferredName(), name); + builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster); + builder.field(AutoFollowPattern.LEADER_PATTERNS_FIELD.getPreferredName(), leaderIndexPatterns); + if (followIndexNamePattern != null) { + builder.field(AutoFollowPattern.FOLLOW_PATTERN_FIELD.getPreferredName(), followIndexNamePattern); + } + toXContentFragment(builder); } + builder.endObject(); + return builder; } - builder.endObject(); - return builder; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Request request = (Request) o; - return Objects.equals(name, request.name) && - Objects.equals(remoteCluster, request.remoteCluster) && - Objects.equals(leaderIndexPatterns, request.leaderIndexPatterns) && - Objects.equals(followIndexNamePattern, request.followIndexNamePattern) && - Objects.equals(maxReadRequestOperationCount, request.maxReadRequestOperationCount) && - Objects.equals(maxReadRequestSize, request.maxReadRequestSize) && - Objects.equals(maxConcurrentReadBatches, request.maxConcurrentReadBatches) && - Objects.equals(maxWriteRequestOperationCount, request.maxWriteRequestOperationCount) && - Objects.equals(maxWriteRequestSize, request.maxWriteRequestSize) && - Objects.equals(maxConcurrentWriteBatches, request.maxConcurrentWriteBatches) && - Objects.equals(maxWriteBufferCount, request.maxWriteBufferCount) && - Objects.equals(maxWriteBufferSize, request.maxWriteBufferSize) && - Objects.equals(maxRetryDelay, request.maxRetryDelay) && - Objects.equals(readPollTimeout, request.readPollTimeout); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + Body body = (Body) o; + return Objects.equals(name, body.name) && + Objects.equals(remoteCluster, body.remoteCluster) && + Objects.equals(leaderIndexPatterns, body.leaderIndexPatterns) && + Objects.equals(followIndexNamePattern, body.followIndexNamePattern); + } - @Override - public int hashCode() { - return Objects.hash( - name, - remoteCluster, - leaderIndexPatterns, - followIndexNamePattern, - maxReadRequestOperationCount, - maxReadRequestSize, - maxConcurrentReadBatches, - maxWriteRequestOperationCount, - maxWriteRequestSize, - maxConcurrentWriteBatches, - maxWriteBufferCount, - maxWriteBufferSize, - maxRetryDelay, - readPollTimeout); + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), name, remoteCluster, leaderIndexPatterns, followIndexNamePattern); + } } + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java index 47240a6a1da10..9909ec49bc8e5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java @@ -16,8 +16,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -28,16 +26,6 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.FOLLOWER_INDEX_FIELD; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_READ_REQUEST_OPERATION_COUNT; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_READ_REQUEST_SIZE; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_OUTSTANDING_READ_REQUESTS; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_OUTSTANDING_WRITE_REQUESTS; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_RETRY_DELAY_FIELD; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_WRITE_BUFFER_COUNT; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_WRITE_BUFFER_SIZE; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_WRITE_REQUEST_OPERATION_COUNT; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.MAX_WRITE_REQUEST_SIZE; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.READ_POLL_TIMEOUT; public final class PutFollowAction extends Action { @@ -60,111 +48,43 @@ public Writeable.Reader getResponseReader() { public static class Request extends AcknowledgedRequest implements IndicesRequest, ToXContentObject { - private static final ParseField REMOTE_CLUSTER_FIELD = new ParseField("remote_cluster"); - private static final ParseField LEADER_INDEX_FIELD = new ParseField("leader_index"); - - private static final ObjectParser PARSER = new ObjectParser<>(NAME, () -> { - Request request = new Request(); - request.setFollowRequest(new ResumeFollowAction.Request()); - return request; - }); - - static { - PARSER.declareString(Request::setRemoteCluster, REMOTE_CLUSTER_FIELD); - PARSER.declareString(Request::setLeaderIndex, LEADER_INDEX_FIELD); - PARSER.declareString((req, val) -> req.followRequest.setFollowerIndex(val), FOLLOWER_INDEX_FIELD); - PARSER.declareInt((req, val) -> req.followRequest.setMaxReadRequestOperationCount(val), MAX_READ_REQUEST_OPERATION_COUNT); - PARSER.declareField( - (req, val) -> req.followRequest.setMaxReadRequestSize(val), - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_READ_REQUEST_SIZE.getPreferredName()), - MAX_READ_REQUEST_SIZE, - ObjectParser.ValueType.STRING); - PARSER.declareInt((req, val) -> req.followRequest.setMaxOutstandingReadRequests(val), MAX_OUTSTANDING_READ_REQUESTS); - PARSER.declareInt((req, val) -> req.followRequest.setMaxWriteRequestOperationCount(val), MAX_WRITE_REQUEST_OPERATION_COUNT); - PARSER.declareField( - (req, val) -> req.followRequest.setMaxWriteRequestSize(val), - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_WRITE_REQUEST_SIZE.getPreferredName()), - MAX_WRITE_REQUEST_SIZE, - ObjectParser.ValueType.STRING); - PARSER.declareInt((req, val) -> req.followRequest.setMaxOutstandingWriteRequests(val), MAX_OUTSTANDING_WRITE_REQUESTS); - PARSER.declareInt((req, val) -> req.followRequest.setMaxWriteBufferCount(val), MAX_WRITE_BUFFER_COUNT); - PARSER.declareField( - (req, val) -> req.followRequest.setMaxWriteBufferSize(val), - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_WRITE_BUFFER_SIZE.getPreferredName()), - MAX_WRITE_BUFFER_SIZE, - ObjectParser.ValueType.STRING); - PARSER.declareField( - (req, val) -> req.followRequest.setMaxRetryDelay(val), - (p, c) -> TimeValue.parseTimeValue(p.text(), MAX_RETRY_DELAY_FIELD.getPreferredName()), - MAX_RETRY_DELAY_FIELD, - ObjectParser.ValueType.STRING); - PARSER.declareField( - (req, val) -> req.followRequest.setReadPollTimeout(val), - (p, c) -> TimeValue.parseTimeValue(p.text(), READ_POLL_TIMEOUT.getPreferredName()), - READ_POLL_TIMEOUT, - ObjectParser.ValueType.STRING); - } - public static Request fromXContent(final XContentParser parser, final String followerIndex) throws IOException { - Request request = PARSER.parse(parser, followerIndex); + Body body = Body.PARSER.parse(parser, null); if (followerIndex != null) { - if (request.getFollowRequest().getFollowerIndex() == null) { - request.getFollowRequest().setFollowerIndex(followerIndex); + if (body.getFollowerIndex() == null) { + body.setFollowerIndex(followerIndex); } else { - if (request.getFollowRequest().getFollowerIndex().equals(followerIndex) == false) { + if (body.getFollowerIndex().equals(followerIndex) == false) { throw new IllegalArgumentException("provided follower_index is not equal"); } } } + Request request = new Request(); + request.setBody(body); return request; } - private String remoteCluster; - private String leaderIndex; - private ResumeFollowAction.Request followRequest; + private Body body = new Body(); public Request() { } - public String getRemoteCluster() { - return remoteCluster; - } - - public void setRemoteCluster(String remoteCluster) { - this.remoteCluster = remoteCluster; + public Body getBody() { + return body; } - public String getLeaderIndex() { - return leaderIndex; - } - - public void setLeaderIndex(String leaderIndex) { - this.leaderIndex = leaderIndex; - } - - public ResumeFollowAction.Request getFollowRequest() { - return followRequest; - } - - public void setFollowRequest(ResumeFollowAction.Request followRequest) { - this.followRequest = followRequest; + public void setBody(Body body) { + this.body = body; } @Override public ActionRequestValidationException validate() { - ActionRequestValidationException e = followRequest.validate(); - if (remoteCluster == null) { - e = addValidationError(REMOTE_CLUSTER_FIELD.getPreferredName() + " is missing", e); - } - if (leaderIndex == null) { - e = addValidationError(LEADER_INDEX_FIELD.getPreferredName() + " is missing", e); - } - return e; + return body.validate(); } @Override public String[] indices() { - return new String[]{followRequest.getFollowerIndex()}; + return new String[]{body.getFollowerIndex()}; } @Override @@ -174,29 +94,18 @@ public IndicesOptions indicesOptions() { public Request(StreamInput in) throws IOException { super(in); - remoteCluster = in.readString(); - leaderIndex = in.readString(); - followRequest = new ResumeFollowAction.Request(in); + body = new Body(in); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeString(remoteCluster); - out.writeString(leaderIndex); - followRequest.writeTo(out); + body.writeTo(out); } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - { - builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster); - builder.field(LEADER_INDEX_FIELD.getPreferredName(), leaderIndex); - followRequest.toXContentFragment(builder, params); - } - builder.endObject(); - return builder; + return body.toXContent(builder, params); } @Override @@ -204,15 +113,119 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Request request = (Request) o; - return Objects.equals(remoteCluster, request.remoteCluster) && - Objects.equals(leaderIndex, request.leaderIndex) && - Objects.equals(followRequest, request.followRequest); + return Objects.equals(body, request.body); } @Override public int hashCode() { - return Objects.hash(remoteCluster, leaderIndex, followRequest); + return Objects.hash(body); } + + public static class Body extends FollowParameters implements ToXContentObject { + + private static final ParseField REMOTE_CLUSTER_FIELD = new ParseField("remote_cluster"); + private static final ParseField LEADER_INDEX_FIELD = new ParseField("leader_index"); + + private static final ObjectParser PARSER = new ObjectParser<>(NAME, Body::new); + + static { + PARSER.declareString(Body::setRemoteCluster, REMOTE_CLUSTER_FIELD); + PARSER.declareString(Body::setLeaderIndex, LEADER_INDEX_FIELD); + PARSER.declareString(Body::setFollowerIndex, FOLLOWER_INDEX_FIELD); + initParser(PARSER); + } + + private String remoteCluster; + private String leaderIndex; + private String followerIndex; + + public Body() { + } + + public String getRemoteCluster() { + return remoteCluster; + } + + public void setRemoteCluster(String remoteCluster) { + this.remoteCluster = remoteCluster; + } + + public String getLeaderIndex() { + return leaderIndex; + } + + public void setLeaderIndex(String leaderIndex) { + this.leaderIndex = leaderIndex; + } + + public String getFollowerIndex() { + return followerIndex; + } + + public void setFollowerIndex(String followerIndex) { + this.followerIndex = followerIndex; + } + + @Override + public ActionRequestValidationException validate() { + ActionRequestValidationException e = super.validate(); + if (remoteCluster == null) { + e = addValidationError(REMOTE_CLUSTER_FIELD.getPreferredName() + " is missing", e); + } + if (leaderIndex == null) { + e = addValidationError(LEADER_INDEX_FIELD.getPreferredName() + " is missing", e); + } + if (followerIndex == null) { + e = addValidationError(FOLLOWER_INDEX_FIELD.getPreferredName() + " is missing", e); + } + return e; + } + + public Body(StreamInput in) throws IOException { + this.remoteCluster = in.readString(); + this.leaderIndex = in.readString(); + this.followerIndex = in.readString(); + fromStreamInput(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(remoteCluster); + out.writeString(leaderIndex); + out.writeString(followerIndex); + super.writeTo(out); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + { + builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster); + builder.field(LEADER_INDEX_FIELD.getPreferredName(), leaderIndex); + builder.field(FOLLOWER_INDEX_FIELD.getPreferredName(), followerIndex); + toXContentFragment(builder); + } + builder.endObject(); + return builder; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + Body body = (Body) o; + return Objects.equals(remoteCluster, body.remoteCluster) && + Objects.equals(leaderIndex, body.leaderIndex) && + Objects.equals(followerIndex, body.followerIndex); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), remoteCluster, leaderIndex, followerIndex); + } + } + } public static class Response extends ActionResponse implements ToXContentObject { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java index 41728928e098f..a54e8785b4208 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java @@ -13,8 +13,6 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -30,8 +28,6 @@ public final class ResumeFollowAction extends Action { public static final ResumeFollowAction INSTANCE = new ResumeFollowAction(); public static final String NAME = "cluster:admin/xpack/ccr/resume_follow"; - public static final TimeValue MAX_RETRY_DELAY = TimeValue.timeValueMinutes(5); - private ResumeFollowAction() { super(NAME); } @@ -44,328 +40,136 @@ public AcknowledgedResponse newResponse() { public static class Request extends MasterNodeRequest implements ToXContentObject { static final ParseField FOLLOWER_INDEX_FIELD = new ParseField("follower_index"); - static final ParseField MAX_READ_REQUEST_OPERATION_COUNT = new ParseField("max_read_request_operation_count"); - static final ParseField MAX_READ_REQUEST_SIZE = new ParseField("max_read_request_size"); - static final ParseField MAX_OUTSTANDING_READ_REQUESTS = new ParseField("max_outstanding_read_requests"); - static final ParseField MAX_WRITE_REQUEST_OPERATION_COUNT = new ParseField("max_write_request_operation_count"); - static final ParseField MAX_WRITE_REQUEST_SIZE = new ParseField("max_write_request_size"); - static final ParseField MAX_OUTSTANDING_WRITE_REQUESTS = new ParseField("max_outstanding_write_requests"); - static final ParseField MAX_WRITE_BUFFER_COUNT = new ParseField("max_write_buffer_count"); - static final ParseField MAX_WRITE_BUFFER_SIZE = new ParseField("max_write_buffer_size"); - static final ParseField MAX_RETRY_DELAY_FIELD = new ParseField("max_retry_delay"); - static final ParseField READ_POLL_TIMEOUT = new ParseField("read_poll_timeout"); - static final ObjectParser PARSER = new ObjectParser<>(NAME, Request::new); - - static { - PARSER.declareString(Request::setFollowerIndex, FOLLOWER_INDEX_FIELD); - PARSER.declareInt(Request::setMaxReadRequestOperationCount, MAX_READ_REQUEST_OPERATION_COUNT); - PARSER.declareField( - Request::setMaxReadRequestSize, - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_READ_REQUEST_SIZE.getPreferredName()), MAX_READ_REQUEST_SIZE, - ObjectParser.ValueType.STRING); - PARSER.declareInt(Request::setMaxOutstandingReadRequests, MAX_OUTSTANDING_READ_REQUESTS); - PARSER.declareInt(Request::setMaxWriteRequestOperationCount, MAX_WRITE_REQUEST_OPERATION_COUNT); - PARSER.declareField(Request::setMaxWriteRequestSize, - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_WRITE_REQUEST_SIZE.getPreferredName()), MAX_WRITE_REQUEST_SIZE, - ObjectParser.ValueType.STRING); - PARSER.declareInt(Request::setMaxOutstandingWriteRequests, MAX_OUTSTANDING_WRITE_REQUESTS); - PARSER.declareInt(Request::setMaxWriteBufferCount, MAX_WRITE_BUFFER_COUNT); - PARSER.declareField( - Request::setMaxWriteBufferSize, - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_WRITE_BUFFER_SIZE.getPreferredName()), - MAX_WRITE_BUFFER_SIZE, - ObjectParser.ValueType.STRING); - PARSER.declareField( - Request::setMaxRetryDelay, - (p, c) -> TimeValue.parseTimeValue(p.text(), MAX_RETRY_DELAY_FIELD.getPreferredName()), - MAX_RETRY_DELAY_FIELD, - ObjectParser.ValueType.STRING); - PARSER.declareField( - Request::setReadPollTimeout, - (p, c) -> TimeValue.parseTimeValue(p.text(), READ_POLL_TIMEOUT.getPreferredName()), - READ_POLL_TIMEOUT, - ObjectParser.ValueType.STRING); - } public static Request fromXContent(final XContentParser parser, final String followerIndex) throws IOException { - Request request = PARSER.parse(parser, followerIndex); + Body body = Body.PARSER.parse(parser, null); if (followerIndex != null) { - if (request.followerIndex == null) { - request.followerIndex = followerIndex; + if (body.followerIndex == null) { + body.followerIndex = followerIndex; } else { - if (request.followerIndex.equals(followerIndex) == false) { + if (body.followerIndex.equals(followerIndex) == false) { throw new IllegalArgumentException("provided follower_index is not equal"); } } } + Request request = new Request(); + request.setBody(body); return request; } - private String followerIndex; - - public String getFollowerIndex() { - return followerIndex; - } - - public void setFollowerIndex(String followerIndex) { - this.followerIndex = followerIndex; - } - - private Integer maxReadRequestOperationCount; - - public Integer getMaxReadRequestOperationCount() { - return maxReadRequestOperationCount; - } - - public void setMaxReadRequestOperationCount(Integer maxReadRequestOperationCount) { - this.maxReadRequestOperationCount = maxReadRequestOperationCount; - } - - private Integer maxOutstandingReadRequests; - - public Integer getMaxOutstandingReadRequests() { - return maxOutstandingReadRequests; - } - - public void setMaxOutstandingReadRequests(Integer maxOutstandingReadRequests) { - this.maxOutstandingReadRequests = maxOutstandingReadRequests; - } - - private ByteSizeValue maxReadRequestSize; - - public ByteSizeValue getMaxReadRequestSize() { - return maxReadRequestSize; - } - - public void setMaxReadRequestSize(ByteSizeValue maxReadRequestSize) { - this.maxReadRequestSize = maxReadRequestSize; - } - - private Integer maxWriteRequestOperationCount; - - public Integer getMaxWriteRequestOperationCount() { - return maxWriteRequestOperationCount; - } - - public void setMaxWriteRequestOperationCount(Integer maxWriteRequestOperationCount) { - this.maxWriteRequestOperationCount = maxWriteRequestOperationCount; - } - - private ByteSizeValue maxWriteRequestSize; - - public ByteSizeValue getMaxWriteRequestSize() { - return maxWriteRequestSize; - } - - public void setMaxWriteRequestSize(ByteSizeValue maxWriteRequestSize) { - this.maxWriteRequestSize = maxWriteRequestSize; - } - - private Integer maxOutstandingWriteRequests; - - public Integer getMaxOutstandingWriteRequests() { - return maxOutstandingWriteRequests; - } - - public void setMaxOutstandingWriteRequests(Integer maxOutstandingWriteRequests) { - this.maxOutstandingWriteRequests = maxOutstandingWriteRequests; - } - - private Integer maxWriteBufferCount; - - public Integer getMaxWriteBufferCount() { - return maxWriteBufferCount; - } - - public void setMaxWriteBufferCount(Integer maxWriteBufferCount) { - this.maxWriteBufferCount = maxWriteBufferCount; - } - - private ByteSizeValue maxWriteBufferSize; - - public ByteSizeValue getMaxWriteBufferSize() { - return maxWriteBufferSize; - } - - public void setMaxWriteBufferSize(ByteSizeValue maxWriteBufferSize) { - this.maxWriteBufferSize = maxWriteBufferSize; - } - - private TimeValue maxRetryDelay; - - public void setMaxRetryDelay(TimeValue maxRetryDelay) { - this.maxRetryDelay = maxRetryDelay; - } - - public TimeValue getMaxRetryDelay() { - return maxRetryDelay; - } - - private TimeValue readPollTimeout; + private Body body = new Body(); - public TimeValue getReadPollTimeout() { - return readPollTimeout; + public Request() { } - public void setReadPollTimeout(TimeValue readPollTimeout) { - this.readPollTimeout = readPollTimeout; + public Body getBody() { + return body; } - public Request() { + public void setBody(Body body) { + this.body = body; } @Override public ActionRequestValidationException validate() { - ActionRequestValidationException e = null; - - if (followerIndex == null) { - e = addValidationError(FOLLOWER_INDEX_FIELD.getPreferredName() + " is missing", e); - } - if (maxReadRequestOperationCount != null && maxReadRequestOperationCount < 1) { - e = addValidationError(MAX_READ_REQUEST_OPERATION_COUNT.getPreferredName() + " must be larger than 0", e); - } - if (maxReadRequestSize != null && maxReadRequestSize.compareTo(ByteSizeValue.ZERO) <= 0) { - e = addValidationError(MAX_READ_REQUEST_SIZE.getPreferredName() + " must be larger than 0", e); - } - if (maxOutstandingReadRequests != null && maxOutstandingReadRequests < 1) { - e = addValidationError(MAX_OUTSTANDING_READ_REQUESTS.getPreferredName() + " must be larger than 0", e); - } - if (maxWriteRequestOperationCount != null && maxWriteRequestOperationCount < 1) { - e = addValidationError(MAX_WRITE_REQUEST_OPERATION_COUNT.getPreferredName() + " must be larger than 0", e); - } - if (maxWriteRequestSize != null && maxWriteRequestSize.compareTo(ByteSizeValue.ZERO) <= 0) { - e = addValidationError(MAX_WRITE_REQUEST_SIZE.getPreferredName() + " must be larger than 0", e); - } - if (maxOutstandingWriteRequests != null && maxOutstandingWriteRequests < 1) { - e = addValidationError(MAX_OUTSTANDING_WRITE_REQUESTS.getPreferredName() + " must be larger than 0", e); - } - if (maxWriteBufferCount != null && maxWriteBufferCount < 1) { - e = addValidationError(MAX_WRITE_BUFFER_COUNT.getPreferredName() + " must be larger than 0", e); - } - if (maxWriteBufferSize != null && maxWriteBufferSize.compareTo(ByteSizeValue.ZERO) <= 0) { - e = addValidationError(MAX_WRITE_BUFFER_SIZE.getPreferredName() + " must be larger than 0", e); - } - if (maxRetryDelay != null && maxRetryDelay.millis() <= 0) { - String message = "[" + MAX_RETRY_DELAY_FIELD.getPreferredName() + "] must be positive but was [" + - maxRetryDelay.getStringRep() + "]"; - e = addValidationError(message, e); - } - if (maxRetryDelay != null && maxRetryDelay.millis() > ResumeFollowAction.MAX_RETRY_DELAY.millis()) { - String message = "[" + MAX_RETRY_DELAY_FIELD.getPreferredName() + "] must be less than [" + MAX_RETRY_DELAY + - "] but was [" + maxRetryDelay.getStringRep() + "]"; - e = addValidationError(message, e); - } - - return e; + return body.validate(); } public Request(StreamInput in) throws IOException { super(in); - followerIndex = in.readString(); - maxReadRequestOperationCount = in.readOptionalVInt(); - maxOutstandingReadRequests = in.readOptionalVInt(); - maxReadRequestSize = in.readOptionalWriteable(ByteSizeValue::new); - maxWriteRequestOperationCount = in.readOptionalVInt(); - maxWriteRequestSize = in.readOptionalWriteable(ByteSizeValue::new); - maxOutstandingWriteRequests = in.readOptionalVInt(); - maxWriteBufferCount = in.readOptionalVInt(); - maxWriteBufferSize = in.readOptionalWriteable(ByteSizeValue::new); - maxRetryDelay = in.readOptionalTimeValue(); - readPollTimeout = in.readOptionalTimeValue(); + body = new Body(in); } @Override public void writeTo(final StreamOutput out) throws IOException { super.writeTo(out); - out.writeString(followerIndex); - out.writeOptionalVInt(maxReadRequestOperationCount); - out.writeOptionalVInt(maxOutstandingReadRequests); - out.writeOptionalWriteable(maxReadRequestSize); - out.writeOptionalVInt(maxWriteRequestOperationCount); - out.writeOptionalWriteable(maxWriteRequestSize); - out.writeOptionalVInt(maxOutstandingWriteRequests); - out.writeOptionalVInt(maxWriteBufferCount); - out.writeOptionalWriteable(maxWriteBufferSize); - out.writeOptionalTimeValue(maxRetryDelay); - out.writeOptionalTimeValue(readPollTimeout); + body.writeTo(out); } @Override public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { - builder.startObject(); - { - toXContentFragment(builder, params); - } - builder.endObject(); - return builder; + return body.toXContent(builder, params); } - void toXContentFragment(final XContentBuilder builder, final Params params) throws IOException { - builder.field(FOLLOWER_INDEX_FIELD.getPreferredName(), followerIndex); - if (maxReadRequestOperationCount != null) { - builder.field(MAX_READ_REQUEST_OPERATION_COUNT.getPreferredName(), maxReadRequestOperationCount); - } - if (maxReadRequestSize != null) { - builder.field(MAX_READ_REQUEST_SIZE.getPreferredName(), maxReadRequestSize.getStringRep()); - } - if (maxWriteRequestOperationCount != null) { - builder.field(MAX_WRITE_REQUEST_OPERATION_COUNT.getPreferredName(), maxWriteRequestOperationCount); + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Request request = (Request) o; + return Objects.equals(body, request.body); + } + + @Override + public int hashCode() { + return Objects.hash(body); + } + + public static class Body extends FollowParameters implements ToXContentObject { + + static final ObjectParser PARSER = new ObjectParser<>(NAME, Body::new); + + static { + PARSER.declareString(Body::setFollowerIndex, FOLLOWER_INDEX_FIELD); + initParser(PARSER); } - if (maxWriteRequestSize != null) { - builder.field(MAX_WRITE_REQUEST_SIZE.getPreferredName(), maxWriteRequestSize.getStringRep()); + + private String followerIndex; + + public Body() { } - if (maxWriteBufferCount != null) { - builder.field(MAX_WRITE_BUFFER_COUNT.getPreferredName(), maxWriteBufferCount); + + public String getFollowerIndex() { + return followerIndex; } - if (maxWriteBufferSize != null) { - builder.field(MAX_WRITE_BUFFER_SIZE.getPreferredName(), maxWriteBufferSize.getStringRep()); + + public void setFollowerIndex(String followerIndex) { + this.followerIndex = followerIndex; } - if (maxOutstandingReadRequests != null) { - builder.field(MAX_OUTSTANDING_READ_REQUESTS.getPreferredName(), maxOutstandingReadRequests); + + @Override + public ActionRequestValidationException validate() { + ActionRequestValidationException e = super.validate(); + if (followerIndex == null) { + e = addValidationError(FOLLOWER_INDEX_FIELD.getPreferredName() + " is missing", e); + } + return e; } - if (maxOutstandingWriteRequests != null) { - builder.field(MAX_OUTSTANDING_WRITE_REQUESTS.getPreferredName(), maxOutstandingWriteRequests); + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + { + builder.field(FOLLOWER_INDEX_FIELD.getPreferredName(), followerIndex); + super.toXContentFragment(builder); + } + builder.endObject(); + return builder; } - if (maxRetryDelay != null) { - builder.field(MAX_RETRY_DELAY_FIELD.getPreferredName(), maxRetryDelay.getStringRep()); + + Body(StreamInput in) throws IOException { + followerIndex = in.readString(); + fromStreamInput(in); } - if (readPollTimeout != null) { - builder.field(READ_POLL_TIMEOUT.getPreferredName(), readPollTimeout.getStringRep()); + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(followerIndex); + super.writeTo(out); } - } - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Request request = (Request) o; - return Objects.equals(maxReadRequestOperationCount, request.maxReadRequestOperationCount) && - Objects.equals(maxReadRequestSize, request.maxReadRequestSize) && - Objects.equals(maxOutstandingReadRequests, request.maxOutstandingReadRequests) && - Objects.equals(maxWriteRequestOperationCount, request.maxWriteRequestOperationCount) && - Objects.equals(maxWriteRequestSize, request.maxWriteRequestSize) && - Objects.equals(maxOutstandingWriteRequests, request.maxOutstandingWriteRequests) && - Objects.equals(maxWriteBufferCount, request.maxWriteBufferCount) && - Objects.equals(maxWriteBufferSize, request.maxWriteBufferSize) && - Objects.equals(maxRetryDelay, request.maxRetryDelay) && - Objects.equals(readPollTimeout, request.readPollTimeout) && - Objects.equals(followerIndex, request.followerIndex); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + Body body = (Body) o; + return Objects.equals(followerIndex, body.followerIndex); + } - @Override - public int hashCode() { - return Objects.hash( - followerIndex, - maxReadRequestOperationCount, - maxReadRequestSize, - maxOutstandingReadRequests, - maxWriteRequestOperationCount, - maxWriteRequestSize, - maxOutstandingWriteRequests, - maxWriteBufferCount, - maxWriteBufferSize, - maxRetryDelay, - readPollTimeout); + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), followerIndex); + } } } From 0ea6547e3ca9708806641197069322041ee5a873 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 4 Feb 2019 11:19:56 +0100 Subject: [PATCH 2/8] Removed Body class from ResumeFollowAction.Request class. The followerIndex field can in production only be specified via the url path. If it is also specified via the request body then it must have the same value as is specified in the url path. This option only existed to xcontent testing. However the AbstractSerializingTestCase base class now also supports createXContextTestInstance() to provide a different test instance when testing xcontent, so allowing followerIndex to be specified via the request body is no longer needed. By moving the followerIndex field from Body to ResumeFollowAction.Request class and not allowing the followerIndex field to be specified via the request body the Body class is redundant and can be removed. The ResumeFollowAction.Request class can then directly use the FollowParameters class. For consistency I also removed the ability to specified followerIndex in the put follow api and the name in put auto follow pattern api via the request body. --- .../ccr/action/AutoFollowCoordinator.java | 2 +- .../TransportPutAutoFollowPatternAction.java | 12 +- .../ccr/action/TransportPutFollowAction.java | 34 ++--- .../action/TransportResumeFollowAction.java | 61 ++++---- .../ccr/rest/RestResumeFollowAction.java | 2 +- .../elasticsearch/xpack/CcrIntegTestCase.java | 8 +- .../xpack/CcrSingleNodeTestCase.java | 8 +- .../elasticsearch/xpack/ccr/AutoFollowIT.java | 4 +- .../elasticsearch/xpack/ccr/CcrLicenseIT.java | 2 +- .../xpack/ccr/IndexFollowingIT.java | 2 +- .../xpack/ccr/LocalIndexFollowingIT.java | 6 +- .../action/AutoFollowCoordinatorTests.java | 6 +- .../PutAutoFollowPatternRequestTests.java | 32 +++-- .../action/PutFollowActionRequestTests.java | 17 ++- .../ResumeFollowActionRequestTests.java | 23 ++- ...nsportPutAutoFollowPatternActionTests.java | 6 +- .../core/ccr/action/FollowInfoAction.java | 6 +- .../core/ccr/action/FollowParameters.java | 6 +- .../action/PutAutoFollowPatternAction.java | 84 +++++------ .../core/ccr/action/PutFollowAction.java | 84 ++++++----- .../core/ccr/action/ResumeFollowAction.java | 132 ++++++------------ 21 files changed, 266 insertions(+), 271 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java index 4a4bda8322cd0..da1b532a582fb 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java @@ -516,7 +516,7 @@ private void followLeaderIndex(String autoFollowPattenName, PutFollowAction.Request request = new PutFollowAction.Request(); request.getBody().setRemoteCluster(remoteCluster); request.getBody().setLeaderIndex(indexToFollow.getName()); - request.getBody().setFollowerIndex(followIndexName); + request.setFollowerIndex(followIndexName); request.getBody().setMaxReadRequestOperationCount(pattern.getMaxReadRequestOperationCount()); request.getBody().setMaxReadRequestSize(pattern.getMaxReadRequestSize()); request.getBody().setMaxOutstandingReadRequests(pattern.getMaxOutstandingReadRequests()); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java index 716f9c2d3d4f7..353914d8d9424 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java @@ -134,14 +134,14 @@ static ClusterState innerPut(PutAutoFollowPatternAction.Request request, headers = new HashMap<>(); } - AutoFollowPattern previousPattern = patterns.get(request.getBody().getName()); + AutoFollowPattern previousPattern = patterns.get(request.getName()); final List followedIndexUUIDs; - if (followedLeaderIndices.containsKey(request.getBody().getName())) { - followedIndexUUIDs = new ArrayList<>(followedLeaderIndices.get(request.getBody().getName())); + if (followedLeaderIndices.containsKey(request.getName())) { + followedIndexUUIDs = new ArrayList<>(followedLeaderIndices.get(request.getName())); } else { followedIndexUUIDs = new ArrayList<>(); } - followedLeaderIndices.put(request.getBody().getName(), followedIndexUUIDs); + followedLeaderIndices.put(request.getName(), followedIndexUUIDs); // Mark existing leader indices as already auto followed: if (previousPattern != null) { markExistingIndicesAsAutoFollowedForNewPatterns(request.getBody().getLeaderIndexPatterns(), remoteClusterState.metaData(), @@ -152,7 +152,7 @@ static ClusterState innerPut(PutAutoFollowPatternAction.Request request, } if (filteredHeaders != null) { - headers.put(request.getBody().getName(), filteredHeaders); + headers.put(request.getName(), filteredHeaders); } AutoFollowPattern autoFollowPattern = new AutoFollowPattern( @@ -169,7 +169,7 @@ static ClusterState innerPut(PutAutoFollowPatternAction.Request request, request.getBody().getMaxWriteBufferSize(), request.getBody().getMaxRetryDelay(), request.getBody().getReadPollTimeout()); - patterns.put(request.getBody().getName(), autoFollowPattern); + patterns.put(request.getName(), autoFollowPattern); ClusterState.Builder newState = ClusterState.builder(localState); newState.metaData(MetaData.builder(localState.getMetaData()) .putCustom(AutoFollowMetadata.TYPE, new AutoFollowMetadata(patterns, followedLeaderIndices, headers)) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java index 6050368930c9c..426eb5cfd95e5 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java @@ -38,6 +38,7 @@ import org.elasticsearch.xpack.ccr.CcrLicenseChecker; import org.elasticsearch.xpack.ccr.CcrSettings; import org.elasticsearch.xpack.ccr.repository.CcrRepository; +import org.elasticsearch.xpack.core.ccr.action.FollowParameters; import org.elasticsearch.xpack.core.ccr.action.PutFollowAction; import org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction; @@ -132,12 +133,12 @@ private void createFollowerIndex( } final Settings.Builder settingsBuilder = Settings.builder() - .put(IndexMetaData.SETTING_INDEX_PROVIDED_NAME, request.getBody().getFollowerIndex()) + .put(IndexMetaData.SETTING_INDEX_PROVIDED_NAME, request.getFollowerIndex()) .put(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey(), true); final String leaderClusterRepoName = CcrRepository.NAME_PREFIX + request.getBody().getRemoteCluster(); final RestoreSnapshotRequest restoreRequest = new RestoreSnapshotRequest(leaderClusterRepoName, CcrRepository.LATEST) .indices(request.getBody().getLeaderIndex()).indicesOptions(request.indicesOptions()).renamePattern("^(.*)$") - .renameReplacement(request.getBody().getFollowerIndex()).masterNodeTimeout(request.masterNodeTimeout()) + .renameReplacement(request.getFollowerIndex()).masterNodeTimeout(request.masterNodeTimeout()) .indexSettings(settingsBuilder); final Client clientWithHeaders = CcrLicenseChecker.wrapClient(this.client, threadPool.getThreadContext().getHeaders()); @@ -217,22 +218,23 @@ private void initiateFollowing( final PutFollowAction.Request request, final ActionListener listener) { assert request.waitForActiveShards() != ActiveShardCount.DEFAULT : "PutFollowAction does not support DEFAULT."; - activeShardsObserver.waitForActiveShards(new String[]{request.getBody().getFollowerIndex()}, + activeShardsObserver.waitForActiveShards(new String[]{request.getFollowerIndex()}, request.waitForActiveShards(), request.timeout(), result -> { if (result) { + FollowParameters parameters = request.getBody(); ResumeFollowAction.Request resumeFollowRequest = new ResumeFollowAction.Request(); - resumeFollowRequest.getBody().setFollowerIndex(request.getBody().getFollowerIndex()); - resumeFollowRequest.getBody().setMaxOutstandingReadRequests(request.getBody().getMaxOutstandingReadRequests()); - resumeFollowRequest.getBody().setMaxOutstandingWriteRequests(request.getBody().getMaxOutstandingWriteRequests()); - resumeFollowRequest.getBody().setMaxReadRequestOperationCount(request.getBody().getMaxReadRequestOperationCount()); - resumeFollowRequest.getBody().setMaxWriteRequestOperationCount( - request.getBody().getMaxWriteRequestOperationCount()); - resumeFollowRequest.getBody().setMaxReadRequestSize(request.getBody().getMaxReadRequestSize()); - resumeFollowRequest.getBody().setMaxWriteRequestSize(request.getBody().getMaxWriteRequestSize()); - resumeFollowRequest.getBody().setMaxWriteBufferCount(request.getBody().getMaxWriteBufferCount()); - resumeFollowRequest.getBody().setMaxWriteBufferSize(request.getBody().getMaxWriteBufferSize()); - resumeFollowRequest.getBody().setReadPollTimeout(request.getBody().getReadPollTimeout()); - resumeFollowRequest.getBody().setMaxRetryDelay(request.getBody().getMaxRetryDelay()); + resumeFollowRequest.setFollowerIndex(request.getFollowerIndex()); + resumeFollowRequest.getParameters().setMaxOutstandingReadRequests(parameters.getMaxOutstandingReadRequests()); + resumeFollowRequest.getParameters().setMaxOutstandingWriteRequests(parameters.getMaxOutstandingWriteRequests()); + resumeFollowRequest.getParameters().setMaxReadRequestOperationCount(parameters.getMaxReadRequestOperationCount()); + resumeFollowRequest.getParameters().setMaxWriteRequestOperationCount( + parameters.getMaxWriteRequestOperationCount()); + resumeFollowRequest.getParameters().setMaxReadRequestSize(parameters.getMaxReadRequestSize()); + resumeFollowRequest.getParameters().setMaxWriteRequestSize(parameters.getMaxWriteRequestSize()); + resumeFollowRequest.getParameters().setMaxWriteBufferCount(parameters.getMaxWriteBufferCount()); + resumeFollowRequest.getParameters().setMaxWriteBufferSize(parameters.getMaxWriteBufferSize()); + resumeFollowRequest.getParameters().setReadPollTimeout(parameters.getReadPollTimeout()); + resumeFollowRequest.getParameters().setMaxRetryDelay(parameters.getMaxRetryDelay()); client.execute(ResumeFollowAction.INSTANCE, resumeFollowRequest, ActionListener.wrap( r -> listener.onResponse(new PutFollowAction.Response(true, true, r.isAcknowledged())), listener::onFailure @@ -245,6 +247,6 @@ private void initiateFollowing( @Override protected ClusterBlockException checkBlock(final PutFollowAction.Request request, final ClusterState state) { - return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, request.getBody().getFollowerIndex()); + return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, request.getFollowerIndex()); } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java index e182803c4723a..150e1df7a3bae 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java @@ -16,13 +16,12 @@ import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; @@ -48,6 +47,7 @@ import org.elasticsearch.xpack.ccr.Ccr; import org.elasticsearch.xpack.ccr.CcrLicenseChecker; import org.elasticsearch.xpack.ccr.CcrSettings; +import org.elasticsearch.xpack.core.ccr.action.FollowParameters; import org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction; import java.io.IOException; @@ -122,15 +122,15 @@ protected void masterOperation(final ResumeFollowAction.Request request, return; } - final IndexMetaData followerIndexMetadata = state.getMetaData().index(request.getBody().getFollowerIndex()); + final IndexMetaData followerIndexMetadata = state.getMetaData().index(request.getFollowerIndex()); if (followerIndexMetadata == null) { - listener.onFailure(new IndexNotFoundException(request.getBody().getFollowerIndex())); + listener.onFailure(new IndexNotFoundException(request.getFollowerIndex())); return; } final Map ccrMetadata = followerIndexMetadata.getCustomData(Ccr.CCR_CUSTOM_METADATA_KEY); if (ccrMetadata == null) { - throw new IllegalArgumentException("follow index ["+ request.getBody().getFollowerIndex() + "] does not have ccr metadata"); + throw new IllegalArgumentException("follow index ["+ request.getFollowerIndex() + "] does not have ccr metadata"); } final String leaderCluster = ccrMetadata.get(Ccr.CCR_CUSTOM_METADATA_REMOTE_CLUSTER_NAME_KEY); // Validates whether the leader cluster has been configured properly: @@ -178,8 +178,7 @@ void start( for (int shardId = 0; shardId < numShards; shardId++) { String taskId = followIndexMetadata.getIndexUUID() + "-" + shardId; - logger.info("README: " + Strings.toString(request.getBody())); - final ShardFollowTask shardFollowTask = createShardFollowTask(shardId, clusterNameAlias, request.getBody(), + final ShardFollowTask shardFollowTask = createShardFollowTask(shardId, clusterNameAlias, request.getParameters(), leaderIndexMetadata, followIndexMetadata, filteredHeaders); persistentTasksService.sendStartRequest(taskId, ShardFollowTask.NAME, shardFollowTask, handler.getActionListener(shardId)); } @@ -191,7 +190,7 @@ static void validate( final IndexMetaData followIndex, final String[] leaderIndexHistoryUUID, final MapperService followerMapperService) { - ResumeFollowAction.Request.Body requestBody = request.getBody(); + FollowParameters parameters = request.getParameters(); Map ccrIndexMetadata = followIndex.getCustomData(Ccr.CCR_CUSTOM_METADATA_KEY); if (ccrIndexMetadata == null) { @@ -200,7 +199,7 @@ static void validate( String leaderIndexUUID = leaderIndex.getIndex().getUUID(); String recordedLeaderIndexUUID = ccrIndexMetadata.get(Ccr.CCR_CUSTOM_METADATA_LEADER_INDEX_UUID_KEY); if (leaderIndexUUID.equals(recordedLeaderIndexUUID) == false) { - throw new IllegalArgumentException("follow index [" + requestBody.getFollowerIndex() + "] should reference [" + + throw new IllegalArgumentException("follow index [" + request.getFollowerIndex() + "] should reference [" + leaderIndexUUID + "] as leader index but instead reference [" + recordedLeaderIndexUUID + "] as leader index"); } @@ -210,7 +209,7 @@ static void validate( String recordedLeaderIndexHistoryUUID = recordedHistoryUUIDs[i]; String actualLeaderIndexHistoryUUID = leaderIndexHistoryUUID[i]; if (recordedLeaderIndexHistoryUUID.equals(actualLeaderIndexHistoryUUID) == false) { - throw new IllegalArgumentException("leader shard [" + requestBody.getFollowerIndex() + "][" + i + "] should reference [" + + throw new IllegalArgumentException("leader shard [" + request.getFollowerIndex() + "][" + i + "] should reference [" + recordedLeaderIndexHistoryUUID + "] as history uuid but instead reference [" + actualLeaderIndexHistoryUUID + "] as history uuid"); } @@ -222,7 +221,7 @@ static void validate( "] does not have soft deletes enabled"); } if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(followIndex.getSettings()) == false) { - throw new IllegalArgumentException("follower index [" + requestBody.getFollowerIndex() + + throw new IllegalArgumentException("follower index [" + request.getFollowerIndex() + "] does not have soft deletes enabled"); } if (leaderIndex.getNumberOfShards() != followIndex.getNumberOfShards()) { @@ -237,7 +236,7 @@ static void validate( throw new IllegalArgumentException("leader and follow index must be open"); } if (CcrSettings.CCR_FOLLOWING_INDEX_SETTING.get(followIndex.getSettings()) == false) { - throw new IllegalArgumentException("the following index [" + requestBody.getFollowerIndex() + "] is not ready " + + throw new IllegalArgumentException("the following index [" + request.getFollowerIndex() + "] is not ready " + "to follow; the setting [" + CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey() + "] must be enabled."); } // Make a copy, remove settings that are allowed to be different and then compare if the settings are equal. @@ -255,69 +254,69 @@ static void validate( private static ShardFollowTask createShardFollowTask( int shardId, String clusterAliasName, - ResumeFollowAction.Request.Body requestBody, + FollowParameters parameters, IndexMetaData leaderIndexMetadata, IndexMetaData followIndexMetadata, Map filteredHeaders ) { int maxReadRequestOperationCount; - if (requestBody.getMaxReadRequestOperationCount() != null) { - maxReadRequestOperationCount = requestBody.getMaxReadRequestOperationCount(); + if (parameters.getMaxReadRequestOperationCount() != null) { + maxReadRequestOperationCount = parameters.getMaxReadRequestOperationCount(); } else { maxReadRequestOperationCount = DEFAULT_MAX_READ_REQUEST_OPERATION_COUNT; } ByteSizeValue maxReadRequestSize; - if (requestBody.getMaxReadRequestSize() != null) { - maxReadRequestSize = requestBody.getMaxReadRequestSize(); + if (parameters.getMaxReadRequestSize() != null) { + maxReadRequestSize = parameters.getMaxReadRequestSize(); } else { maxReadRequestSize = DEFAULT_MAX_READ_REQUEST_SIZE; } int maxOutstandingReadRequests; - if (requestBody.getMaxOutstandingReadRequests() != null){ - maxOutstandingReadRequests = requestBody.getMaxOutstandingReadRequests(); + if (parameters.getMaxOutstandingReadRequests() != null){ + maxOutstandingReadRequests = parameters.getMaxOutstandingReadRequests(); } else { maxOutstandingReadRequests = DEFAULT_MAX_OUTSTANDING_READ_REQUESTS; } final int maxWriteRequestOperationCount; - if (requestBody.getMaxWriteRequestOperationCount() != null) { - maxWriteRequestOperationCount = requestBody.getMaxWriteRequestOperationCount(); + if (parameters.getMaxWriteRequestOperationCount() != null) { + maxWriteRequestOperationCount = parameters.getMaxWriteRequestOperationCount(); } else { maxWriteRequestOperationCount = DEFAULT_MAX_WRITE_REQUEST_OPERATION_COUNT; } final ByteSizeValue maxWriteRequestSize; - if (requestBody.getMaxWriteRequestSize() != null) { - maxWriteRequestSize = requestBody.getMaxWriteRequestSize(); + if (parameters.getMaxWriteRequestSize() != null) { + maxWriteRequestSize = parameters.getMaxWriteRequestSize(); } else { maxWriteRequestSize = DEFAULT_MAX_WRITE_REQUEST_SIZE; } int maxOutstandingWriteRequests; - if (requestBody.getMaxOutstandingWriteRequests() != null) { - maxOutstandingWriteRequests = requestBody.getMaxOutstandingWriteRequests(); + if (parameters.getMaxOutstandingWriteRequests() != null) { + maxOutstandingWriteRequests = parameters.getMaxOutstandingWriteRequests(); } else { maxOutstandingWriteRequests = DEFAULT_MAX_OUTSTANDING_WRITE_REQUESTS; } int maxWriteBufferCount; - if (requestBody.getMaxWriteBufferCount() != null) { - maxWriteBufferCount = requestBody.getMaxWriteBufferCount(); + if (parameters.getMaxWriteBufferCount() != null) { + maxWriteBufferCount = parameters.getMaxWriteBufferCount(); } else { maxWriteBufferCount = DEFAULT_MAX_WRITE_BUFFER_COUNT; } ByteSizeValue maxWriteBufferSize; - if (requestBody.getMaxWriteBufferSize() != null) { - maxWriteBufferSize = requestBody.getMaxWriteBufferSize(); + if (parameters.getMaxWriteBufferSize() != null) { + maxWriteBufferSize = parameters.getMaxWriteBufferSize(); } else { maxWriteBufferSize = DEFAULT_MAX_WRITE_BUFFER_SIZE; } - TimeValue maxRetryDelay = requestBody.getMaxRetryDelay() == null ? DEFAULT_MAX_RETRY_DELAY : requestBody.getMaxRetryDelay(); - TimeValue readPollTimeout = requestBody.getReadPollTimeout() == null ? DEFAULT_READ_POLL_TIMEOUT : requestBody.getReadPollTimeout(); + TimeValue maxRetryDelay = parameters.getMaxRetryDelay() == null ? DEFAULT_MAX_RETRY_DELAY : parameters.getMaxRetryDelay(); + TimeValue readPollTimeout = parameters.getReadPollTimeout() == null ? DEFAULT_READ_POLL_TIMEOUT : parameters.getReadPollTimeout(); return new ShardFollowTask( clusterAliasName, diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java index 6682812dee9ed..ce2eab52e0cab 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java @@ -43,7 +43,7 @@ static Request createRequest(RestRequest restRequest) throws IOException { } } else { Request request = new Request(); - request.getBody().setFollowerIndex(restRequest.param("index")); + request.setFollowerIndex(restRequest.param("index")); return request; } } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java index 69798033cf4b6..1e71ed41a3cc4 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java @@ -426,7 +426,7 @@ public static PutFollowAction.Request putFollow(String leaderIndex, String follo PutFollowAction.Request request = new PutFollowAction.Request(); request.getBody().setRemoteCluster("leader_cluster"); request.getBody().setLeaderIndex(leaderIndex); - request.getBody().setFollowerIndex(followerIndex); + request.setFollowerIndex(followerIndex); request.getBody().setMaxRetryDelay(TimeValue.timeValueMillis(10)); request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(10)); request.waitForActiveShards(waitForActiveShards); @@ -435,9 +435,9 @@ public static PutFollowAction.Request putFollow(String leaderIndex, String follo public static ResumeFollowAction.Request resumeFollow(String followerIndex) { ResumeFollowAction.Request request = new ResumeFollowAction.Request(); - request.getBody().setFollowerIndex(followerIndex); - request.getBody().setMaxRetryDelay(TimeValue.timeValueMillis(10)); - request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(10)); + request.setFollowerIndex(followerIndex); + request.getParameters().setMaxRetryDelay(TimeValue.timeValueMillis(10)); + request.getParameters().setReadPollTimeout(TimeValue.timeValueMillis(10)); return request; } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java index 7c2d1b62557c0..44e6ba0af279e 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java @@ -88,9 +88,9 @@ protected AutoFollowStats getAutoFollowStats() { protected ResumeFollowAction.Request getResumeFollowRequest(String followerIndex) { ResumeFollowAction.Request request = new ResumeFollowAction.Request(); - request.getBody().setFollowerIndex(followerIndex); - request.getBody().setMaxRetryDelay(TimeValue.timeValueMillis(1)); - request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(1)); + request.setFollowerIndex(followerIndex); + request.getParameters().setMaxRetryDelay(TimeValue.timeValueMillis(1)); + request.getParameters().setReadPollTimeout(TimeValue.timeValueMillis(1)); return request; } @@ -98,7 +98,7 @@ protected PutFollowAction.Request getPutFollowRequest(String leaderIndex, String PutFollowAction.Request request = new PutFollowAction.Request(); request.getBody().setRemoteCluster("local"); request.getBody().setLeaderIndex(leaderIndex); - request.getBody().setFollowerIndex(followerIndex); + request.setFollowerIndex(followerIndex); request.getBody().setMaxRetryDelay(TimeValue.timeValueMillis(1)); request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(1)); request.waitForActiveShards(ActiveShardCount.ONE); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java index a598349a2c95f..f9a1c85fa9d21 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java @@ -186,7 +186,6 @@ public void testAutoFollowParameterAreDelegated() throws Exception { // Enabling auto following: PutAutoFollowPatternAction.Request.Body requestBody = new PutAutoFollowPatternAction.Request.Body(); - requestBody.setName("my-pattern"); requestBody.setRemoteCluster("leader_cluster"); requestBody.setLeaderIndexPatterns(Collections.singletonList("logs-*")); // Need to set this, because following an index in the same cluster @@ -222,6 +221,7 @@ public void testAutoFollowParameterAreDelegated() throws Exception { requestBody.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong())); } PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); + request.setName("my-pattern"); request.setBody(requestBody); assertTrue(followerClient().execute(PutAutoFollowPatternAction.INSTANCE, request).actionGet().isAcknowledged()); @@ -360,7 +360,7 @@ public void testAutoFollowSoftDeletesDisabled() throws Exception { private void putAutoFollowPatterns(String name, String[] patterns) { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setName(name); + request.setName(name); request.getBody().setRemoteCluster("leader_cluster"); request.getBody().setLeaderIndexPatterns(Arrays.asList(patterns)); // Need to set this, because following an index in the same cluster diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java index 1947df1791956..dc8dbd69052ae 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java @@ -117,7 +117,7 @@ public void onFailure(final Exception e) { public void testThatPutAutoFollowPatternsIsUnavailableWithNonCompliantLicense() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setName("name"); + request.setName("name"); request.getBody().setRemoteCluster("leader"); request.getBody().setLeaderIndexPatterns(Collections.singletonList("*")); client().execute( diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java index 133ed2f7015fb..c16d1ba60b1cf 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java @@ -733,7 +733,7 @@ public void testUnknownClusterAlias() throws Exception { () -> followerClient().execute(PutFollowAction.INSTANCE, followRequest).actionGet()); assertThat(e.getMessage(), equalTo("no such remote cluster: [another_cluster]")); PutAutoFollowPatternAction.Request putAutoFollowRequest = new PutAutoFollowPatternAction.Request(); - putAutoFollowRequest.getBody().setName("name"); + putAutoFollowRequest.setName("name"); putAutoFollowRequest.getBody().setRemoteCluster("another_cluster"); putAutoFollowRequest.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); e = expectThrows(NoSuchRemoteClusterException.class, diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java index 800dbf5302927..cd782726048ce 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java @@ -82,10 +82,10 @@ public void testDoNotCreateFollowerIfLeaderDoesNotHaveSoftDeletes() throws Excep singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "false")); assertAcked(client().admin().indices().prepareCreate("leader-index").setSource(leaderIndexSettings, XContentType.JSON)); ResumeFollowAction.Request followRequest = getResumeFollowRequest("follower"); - followRequest.getBody().setFollowerIndex("follower-index"); + followRequest.setFollowerIndex("follower-index"); PutFollowAction.Request putFollowRequest = getPutFollowRequest("leader", "follower"); putFollowRequest.getBody().setLeaderIndex("leader-index"); - putFollowRequest.getBody().setFollowerIndex("follower-index"); + putFollowRequest.setFollowerIndex("follower-index"); IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> client().execute(PutFollowAction.INSTANCE, putFollowRequest).actionGet()); assertThat(error.getMessage(), equalTo("leader index [leader-index] does not have soft deletes enabled")); @@ -94,7 +94,7 @@ public void testDoNotCreateFollowerIfLeaderDoesNotHaveSoftDeletes() throws Excep public void testRemoveRemoteConnection() throws Exception { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setName("my_pattern"); + request.setName("my_pattern"); request.getBody().setRemoteCluster("local"); request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); request.getBody().setFollowIndexNamePattern("copy-{{leader_index}}"); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java index 25a3d823bdcf2..01cf243dc8958 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java @@ -109,7 +109,7 @@ void createAndFollow(Map headers, assertThat(headers, equalTo(autoFollowHeaders.get("remote"))); assertThat(followRequest.getBody().getRemoteCluster(), equalTo("remote")); assertThat(followRequest.getBody().getLeaderIndex(), equalTo("logs-20190101")); - assertThat(followRequest.getBody().getFollowerIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getFollowerIndex(), equalTo("logs-20190101")); successHandler.run(); } @@ -227,7 +227,7 @@ void createAndFollow(Map headers, Consumer failureHandler) { assertThat(followRequest.getBody().getRemoteCluster(), equalTo("remote")); assertThat(followRequest.getBody().getLeaderIndex(), equalTo("logs-20190101")); - assertThat(followRequest.getBody().getFollowerIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getFollowerIndex(), equalTo("logs-20190101")); successHandler.run(); } @@ -284,7 +284,7 @@ void createAndFollow(Map headers, Consumer failureHandler) { assertThat(followRequest.getBody().getRemoteCluster(), equalTo("remote")); assertThat(followRequest.getBody().getLeaderIndex(), equalTo("logs-20190101")); - assertThat(followRequest.getBody().getFollowerIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getFollowerIndex(), equalTo("logs-20190101")); failureHandler.accept(failure); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutAutoFollowPatternRequestTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutAutoFollowPatternRequestTests.java index 0df0115bafa23..3e73a4e4dbaac 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutAutoFollowPatternRequestTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutAutoFollowPatternRequestTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.xpack.core.ccr.action.PutAutoFollowPatternAction; @@ -40,7 +41,22 @@ protected Writeable.Reader instanceReader() @Override protected PutAutoFollowPatternAction.Request createTestInstance() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setName(randomAlphaOfLength(4)); + request.setName(randomAlphaOfLength(4)); + + request.getBody().setRemoteCluster(randomAlphaOfLength(4)); + request.getBody().setLeaderIndexPatterns(Arrays.asList(generateRandomStringArray(4, 4, false))); + if (randomBoolean()) { + request.getBody().setFollowIndexNamePattern(randomAlphaOfLength(4)); + } + ResumeFollowActionRequestTests.generateFollowParameters(request.getBody()); + return request; + } + + @Override + protected PutAutoFollowPatternAction.Request createXContextTestInstance(XContentType xContentType) { + // follower index parameter is not part of the request body and is provided in the url path. + // So this field cannot be used for creating a test instance for xcontent testing. + PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); request.getBody().setRemoteCluster(randomAlphaOfLength(4)); request.getBody().setLeaderIndexPatterns(Arrays.asList(generateRandomStringArray(4, 4, false))); if (randomBoolean()) { @@ -56,7 +72,7 @@ public void testValidate() { assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[name] is missing")); - request.getBody().setName("name"); + request.setName("name"); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[remote_cluster] is missing")); @@ -95,7 +111,7 @@ public void testValidateName() { request.getBody().setRemoteCluster("_alias"); request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); - request.getBody().setName("name"); + request.setName("name"); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, nullValue()); } @@ -105,7 +121,7 @@ public void testValidateNameComma() { request.getBody().setRemoteCluster("_alias"); request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); - request.getBody().setName("name1,name2"); + request.setName("name1,name2"); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("name must not contain a ','")); @@ -116,7 +132,7 @@ public void testValidateNameLeadingUnderscore() { request.getBody().setRemoteCluster("_alias"); request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); - request.getBody().setName("_name"); + request.setName("_name"); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("name must not start with '_'")); @@ -127,7 +143,7 @@ public void testValidateNameUnderscores() { request.getBody().setRemoteCluster("_alias"); request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); - request.getBody().setName("n_a_m_e_"); + request.setName("n_a_m_e_"); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, nullValue()); } @@ -141,12 +157,12 @@ public void testValidateNameTooLong() { for (int i = 0; i < 256; i++) { stringBuilder.append('x'); } - request.getBody().setName(stringBuilder.toString()); + request.setName(stringBuilder.toString()); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("name is too long (256 > 255)")); - request.getBody().setName("name"); + request.setName("name"); validationException = request.validate(); assertThat(validationException, nullValue()); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java index 7651a7c7eec65..efdcae2f3e67e 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java @@ -8,6 +8,7 @@ import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.xpack.core.ccr.action.PutFollowAction; @@ -22,10 +23,24 @@ protected Writeable.Reader instanceReader() { @Override protected PutFollowAction.Request createTestInstance() { + PutFollowAction.Request request = new PutFollowAction.Request(); + request.setFollowerIndex(randomAlphaOfLength(4)); + request.waitForActiveShards(randomFrom(ActiveShardCount.DEFAULT, ActiveShardCount.NONE, ActiveShardCount.ONE, + ActiveShardCount.ALL)); + + request.getBody().setRemoteCluster(randomAlphaOfLength(4)); + request.getBody().setLeaderIndex(randomAlphaOfLength(4)); + ResumeFollowActionRequestTests.generateFollowParameters(request.getBody()); + return request; + } + + @Override + protected PutFollowAction.Request createXContextTestInstance(XContentType xContentType) { + // follower index parameter and wait for active shards params are not part of the request body and + // are provided in the url path. So these fields cannot be used for creating a test instance for xcontent testing. PutFollowAction.Request request = new PutFollowAction.Request(); request.getBody().setRemoteCluster(randomAlphaOfLength(4)); request.getBody().setLeaderIndex(randomAlphaOfLength(4)); - request.getBody().setFollowerIndex(randomAlphaOfLength(4)); ResumeFollowActionRequestTests.generateFollowParameters(request.getBody()); return request; } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ResumeFollowActionRequestTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ResumeFollowActionRequestTests.java index 1c0b5c01064cb..53efac70a7dc0 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ResumeFollowActionRequestTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ResumeFollowActionRequestTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.xpack.core.ccr.action.FollowParameters; import org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction; @@ -31,8 +32,18 @@ protected Writeable.Reader instanceReader() { @Override protected ResumeFollowAction.Request createTestInstance() { ResumeFollowAction.Request request = new ResumeFollowAction.Request(); - request.getBody().setFollowerIndex(randomAlphaOfLength(4)); - generateFollowParameters(request.getBody()); + request.setFollowerIndex(randomAlphaOfLength(4)); + + generateFollowParameters(request.getParameters()); + return request; + } + + @Override + protected ResumeFollowAction.Request createXContextTestInstance(XContentType type) { + // follower index parameter is not part of the request body and is provided in the url path. + // So this field cannot be used for creating a test instance for xcontent testing. + ResumeFollowAction.Request request = new ResumeFollowAction.Request(); + generateFollowParameters(request.getParameters()); return request; } @@ -81,19 +92,19 @@ static void generateFollowParameters(FollowParameters followParameters) { public void testValidate() { ResumeFollowAction.Request request = new ResumeFollowAction.Request(); - request.getBody().setFollowerIndex("index2"); - request.getBody().setMaxRetryDelay(TimeValue.ZERO); + request.setFollowerIndex("index2"); + request.getParameters().setMaxRetryDelay(TimeValue.ZERO); ActionRequestValidationException validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[max_retry_delay] must be positive but was [0ms]")); - request.getBody().setMaxRetryDelay(TimeValue.timeValueMinutes(10)); + request.getParameters().setMaxRetryDelay(TimeValue.timeValueMinutes(10)); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[max_retry_delay] must be less than [5m] but was [10m]")); - request.getBody().setMaxRetryDelay(TimeValue.timeValueMinutes(1)); + request.getParameters().setMaxRetryDelay(TimeValue.timeValueMinutes(1)); validationException = request.validate(); assertThat(validationException, nullValue()); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java index 16449d466c747..7950af31abc41 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java @@ -29,7 +29,7 @@ public class TransportPutAutoFollowPatternActionTests extends ESTestCase { public void testInnerPut() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setName("name1"); + request.setName("name1"); request.getBody().setRemoteCluster("eu_cluster"); request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); @@ -54,7 +54,7 @@ public void testInnerPut() { public void testInnerPut_existingLeaderIndices() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setName("name1"); + request.setName("name1"); request.getBody().setRemoteCluster("eu_cluster"); request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); @@ -95,7 +95,7 @@ public void testInnerPut_existingLeaderIndices() { public void testInnerPut_existingLeaderIndicesAndAutoFollowMetadata() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setName("name1"); + request.setName("name1"); request.getBody().setRemoteCluster("eu_cluster"); request.getBody().setLeaderIndexPatterns(Arrays.asList("logs-*", "transactions-*")); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowInfoAction.java index 914277f4fc0ab..4cbd575c67b30 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowInfoAction.java @@ -189,11 +189,7 @@ public FollowParameters getParameters() { remoteCluster = in.readString(); leaderIndex = in.readString(); status = Status.fromString(in.readString()); - parameters = in.readOptionalWriteable(innerIn -> { - FollowParameters parameters = new FollowParameters(); - parameters.fromStreamInput(in); - return parameters; - }); + parameters = in.readOptionalWriteable(innerIn -> new FollowParameters(in)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java index 68f2b780ef1fa..2c6a8fe7328c9 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java @@ -172,6 +172,10 @@ public ActionRequestValidationException validate() { return e; } + FollowParameters(StreamInput in) throws IOException { + fromStreamInput(in); + } + @Override public void writeTo(StreamOutput out) throws IOException { out.writeOptionalVInt(maxReadRequestOperationCount); @@ -233,7 +237,7 @@ XContentBuilder toXContentFragment(final XContentBuilder builder) throws IOExcep return builder; } - public static void initParser(AbstractObjectParser parser) { + public static void initParser(AbstractObjectParser parser) { parser.declareInt(FollowParameters::setMaxReadRequestOperationCount, MAX_READ_REQUEST_OPERATION_COUNT); parser.declareInt(FollowParameters::setMaxWriteRequestOperationCount, MAX_WRITE_REQUEST_OPERATION_COUNT); parser.declareInt(FollowParameters::setMaxOutstandingReadRequests, MAX_OUTSTANDING_READ_REQUESTS); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java index 8791c0b396290..988a30baafd0d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java @@ -32,6 +32,7 @@ public class PutAutoFollowPatternAction extends Action { public static final String NAME = "cluster:admin/xpack/ccr/auto_follow_pattern/put"; public static final PutAutoFollowPatternAction INSTANCE = new PutAutoFollowPatternAction(); + private static final int MAX_NAME_BYTES = 255; private PutAutoFollowPatternAction() { super(NAME); @@ -46,20 +47,13 @@ public static class Request extends AcknowledgedRequest implements ToXC public static Request fromXContent(XContentParser parser, String name) throws IOException { Body body = Body.PARSER.parse(parser, null); - if (name != null) { - if (body.name == null) { - body.name = name; - } else { - if (body.name.equals(name) == false) { - throw new IllegalArgumentException("provided name is not equal"); - } - } - } Request request = new Request(); + request.setName(name); request.setBody(body); return request; } + private String name; private Body body = new Body(); public Request() { @@ -67,7 +61,32 @@ public Request() { @Override public ActionRequestValidationException validate() { - return body.validate(); + ActionRequestValidationException validationException = body.validate(); + if (name == null) { + validationException = addValidationError("[name] is missing", validationException); + } + if (name != null) { + if (name.contains(",")) { + validationException = addValidationError("[name] name must not contain a ','", validationException); + } + if (name.startsWith("_")) { + validationException = addValidationError("[name] name must not start with '_'", validationException); + } + int byteCount = name.getBytes(StandardCharsets.UTF_8).length; + if (byteCount > MAX_NAME_BYTES) { + validationException = addValidationError("[name] name is too long (" + byteCount + " > " + MAX_NAME_BYTES + ")", + validationException); + } + } + return validationException; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; } public Body getBody() { @@ -80,12 +99,14 @@ public void setBody(Body body) { public Request(StreamInput in) throws IOException { super(in); + name = in.readString(); this.body = new Body(in); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); + out.writeString(name); body.writeTo(out); } @@ -99,29 +120,26 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Request request = (Request) o; - return Objects.equals(body, request.body); + return Objects.equals(name, request.name) && + Objects.equals(body, request.body); } @Override public int hashCode() { - return Objects.hash(body); + return Objects.hash(name, body); } public static class Body extends FollowParameters implements ToXContentObject { private static final ObjectParser PARSER = new ObjectParser<>("put_auto_follow_pattern_request", Body::new); - private static final ParseField NAME_FIELD = new ParseField("name"); - private static final int MAX_NAME_BYTES = 255; static { - PARSER.declareString(Body::setName, NAME_FIELD); PARSER.declareString(Body::setRemoteCluster, REMOTE_CLUSTER_FIELD); PARSER.declareStringArray(Body::setLeaderIndexPatterns, AutoFollowPattern.LEADER_PATTERNS_FIELD); PARSER.declareString(Body::setFollowIndexNamePattern, AutoFollowPattern.FOLLOW_PATTERN_FIELD); initParser(PARSER); } - private String name; private String remoteCluster; private List leaderIndexPatterns; private String followIndexNamePattern; @@ -129,14 +147,6 @@ public static class Body extends FollowParameters implements ToXContentObject { public Body() { } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - public String getRemoteCluster() { return remoteCluster; } @@ -164,24 +174,6 @@ public void setFollowIndexNamePattern(String followIndexNamePattern) { @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = super.validate(); - if (name == null) { - validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] is missing", validationException); - } - if (name != null) { - if (name.contains(",")) { - validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] name must not contain a ','", - validationException); - } - if (name.startsWith("_")) { - validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] name must not start with '_'", - validationException); - } - int byteCount = name.getBytes(StandardCharsets.UTF_8).length; - if (byteCount > MAX_NAME_BYTES) { - validationException = addValidationError("[" + NAME_FIELD.getPreferredName() + "] name is too long (" + - byteCount + " > " + MAX_NAME_BYTES + ")", validationException); - } - } if (remoteCluster == null) { validationException = addValidationError("[" + REMOTE_CLUSTER_FIELD.getPreferredName() + "] is missing", validationException); @@ -194,7 +186,6 @@ public ActionRequestValidationException validate() { } Body(StreamInput in) throws IOException { - name = in.readString(); remoteCluster = in.readString(); leaderIndexPatterns = in.readStringList(); followIndexNamePattern = in.readOptionalString(); @@ -216,7 +207,6 @@ public ActionRequestValidationException validate() { @Override public void writeTo(StreamOutput out) throws IOException { - out.writeString(name); out.writeString(remoteCluster); out.writeStringCollection(leaderIndexPatterns); out.writeOptionalString(followIndexNamePattern); @@ -240,7 +230,6 @@ public void writeTo(StreamOutput out) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); { - builder.field(NAME_FIELD.getPreferredName(), name); builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster); builder.field(AutoFollowPattern.LEADER_PATTERNS_FIELD.getPreferredName(), leaderIndexPatterns); if (followIndexNamePattern != null) { @@ -258,15 +247,14 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; Body body = (Body) o; - return Objects.equals(name, body.name) && - Objects.equals(remoteCluster, body.remoteCluster) && + return Objects.equals(remoteCluster, body.remoteCluster) && Objects.equals(leaderIndexPatterns, body.leaderIndexPatterns) && Objects.equals(followIndexNamePattern, body.followIndexNamePattern); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), name, remoteCluster, leaderIndexPatterns, followIndexNamePattern); + return Objects.hash(super.hashCode(), remoteCluster, leaderIndexPatterns, followIndexNamePattern); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java index f7031f23e6446..1b5a3d4116dd2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java @@ -27,7 +27,6 @@ import java.util.Objects; import static org.elasticsearch.action.ValidateActions.addValidationError; -import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request.FOLLOWER_INDEX_FIELD; public final class PutFollowAction extends Action { @@ -53,27 +52,29 @@ public static class Request extends AcknowledgedRequest implements Indi public static Request fromXContent(final XContentParser parser, final String followerIndex, ActiveShardCount waitForActiveShards) throws IOException { Body body = Body.PARSER.parse(parser, null); - if (followerIndex != null) { - if (body.getFollowerIndex() == null) { - body.setFollowerIndex(followerIndex); - } else { - if (body.getFollowerIndex().equals(followerIndex) == false) { - throw new IllegalArgumentException("provided follower_index is not equal"); - } - } - } + Request request = new Request(); + request.setFollowerIndex(followerIndex); request.setBody(body); request.waitForActiveShards(waitForActiveShards); return request; } + private String followerIndex; private Body body = new Body(); private ActiveShardCount waitForActiveShards = ActiveShardCount.NONE; public Request() { } + public String getFollowerIndex() { + return followerIndex; + } + + public void setFollowerIndex(String followerIndex) { + this.followerIndex = followerIndex; + } + public Body getBody() { return body; } @@ -105,12 +106,16 @@ public void waitForActiveShards(ActiveShardCount waitForActiveShards) { @Override public ActionRequestValidationException validate() { - return body.validate(); + ActionRequestValidationException e = body.validate(); + if (followerIndex == null) { + e = addValidationError("follower_index is missing", e); + } + return e; } @Override public String[] indices() { - return new String[]{body.getFollowerIndex()}; + return new String[]{followerIndex}; } @Override @@ -120,7 +125,15 @@ public IndicesOptions indicesOptions() { public Request(StreamInput in) throws IOException { super(in); - body = new Body(in); + if (in.getVersion().onOrAfter(Version.V_7_0_0)) { + this.followerIndex = in.readString(); + body = new Body(in); + } else { + String remoteCluster = in.readString(); + String leaderIndex = in.readString(); + this.followerIndex = in.readString(); + body = new Body(in, remoteCluster, leaderIndex); + } if (in.getVersion().onOrAfter(Version.V_6_7_0)) { waitForActiveShards(ActiveShardCount.readFrom(in)); } @@ -129,7 +142,12 @@ public Request(StreamInput in) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - body.writeTo(out); + if (out.getVersion().onOrAfter(Version.V_7_0_0)) { + out.writeString(followerIndex); + body.writeTo(out); + } else { + body.writeTo(out, followerIndex); + } if (out.getVersion().onOrAfter(Version.V_6_7_0)) { waitForActiveShards.writeTo(out); } @@ -145,12 +163,14 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Request request = (Request) o; - return Objects.equals(body, request.body); + return Objects.equals(followerIndex, request.followerIndex) && + Objects.equals(body, request.body) && + Objects.equals(waitForActiveShards, request.waitForActiveShards); } @Override public int hashCode() { - return Objects.hash(body); + return Objects.hash(followerIndex, body, waitForActiveShards); } public static class Body extends FollowParameters implements ToXContentObject { @@ -163,13 +183,11 @@ public static class Body extends FollowParameters implements ToXContentObject { static { PARSER.declareString(Body::setRemoteCluster, REMOTE_CLUSTER_FIELD); PARSER.declareString(Body::setLeaderIndex, LEADER_INDEX_FIELD); - PARSER.declareString(Body::setFollowerIndex, FOLLOWER_INDEX_FIELD); initParser(PARSER); } private String remoteCluster; private String leaderIndex; - private String followerIndex; public Body() { } @@ -190,14 +208,6 @@ public void setLeaderIndex(String leaderIndex) { this.leaderIndex = leaderIndex; } - public String getFollowerIndex() { - return followerIndex; - } - - public void setFollowerIndex(String followerIndex) { - this.followerIndex = followerIndex; - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException e = super.validate(); @@ -207,21 +217,29 @@ public ActionRequestValidationException validate() { if (leaderIndex == null) { e = addValidationError(LEADER_INDEX_FIELD.getPreferredName() + " is missing", e); } - if (followerIndex == null) { - e = addValidationError(FOLLOWER_INDEX_FIELD.getPreferredName() + " is missing", e); - } return e; } public Body(StreamInput in) throws IOException { this.remoteCluster = in.readString(); this.leaderIndex = in.readString(); - this.followerIndex = in.readString(); fromStreamInput(in); } @Override public void writeTo(StreamOutput out) throws IOException { + out.writeString(remoteCluster); + out.writeString(leaderIndex); + super.writeTo(out); + } + + private Body(StreamInput in, String remoteCluster, String leaderIndex) throws IOException { + this.remoteCluster = remoteCluster; + this.leaderIndex = leaderIndex; + fromStreamInput(in); + } + + private void writeTo(StreamOutput out, String followerIndex) throws IOException { out.writeString(remoteCluster); out.writeString(leaderIndex); out.writeString(followerIndex); @@ -234,7 +252,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws { builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster); builder.field(LEADER_INDEX_FIELD.getPreferredName(), leaderIndex); - builder.field(FOLLOWER_INDEX_FIELD.getPreferredName(), followerIndex); toXContentFragment(builder); } builder.endObject(); @@ -248,13 +265,12 @@ public boolean equals(Object o) { if (!super.equals(o)) return false; Body body = (Body) o; return Objects.equals(remoteCluster, body.remoteCluster) && - Objects.equals(leaderIndex, body.leaderIndex) && - Objects.equals(followerIndex, body.followerIndex); + Objects.equals(leaderIndex, body.leaderIndex); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), remoteCluster, leaderIndex, followerIndex); + return Objects.hash(super.hashCode(), remoteCluster, leaderIndex); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java index a54e8785b4208..e34c70c157344 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.action.support.master.MasterNodeRequest; -import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; @@ -39,56 +38,72 @@ public AcknowledgedResponse newResponse() { public static class Request extends MasterNodeRequest implements ToXContentObject { - static final ParseField FOLLOWER_INDEX_FIELD = new ParseField("follower_index"); + static final ObjectParser PARSER = new ObjectParser<>(NAME, FollowParameters::new); + + static { + FollowParameters.initParser(PARSER); + } public static Request fromXContent(final XContentParser parser, final String followerIndex) throws IOException { - Body body = Body.PARSER.parse(parser, null); - if (followerIndex != null) { - if (body.followerIndex == null) { - body.followerIndex = followerIndex; - } else { - if (body.followerIndex.equals(followerIndex) == false) { - throw new IllegalArgumentException("provided follower_index is not equal"); - } - } - } + FollowParameters parameters = PARSER.parse(parser, null); Request request = new Request(); - request.setBody(body); + request.setFollowerIndex(followerIndex); + request.setParameters(parameters); return request; } - private Body body = new Body(); + private String followerIndex; + private FollowParameters parameters = new FollowParameters(); public Request() { } - public Body getBody() { - return body; + public String getFollowerIndex() { + return followerIndex; + } + + public void setFollowerIndex(String followerIndex) { + this.followerIndex = followerIndex; } - public void setBody(Body body) { - this.body = body; + public FollowParameters getParameters() { + return parameters; + } + + public void setParameters(FollowParameters parameters) { + this.parameters = parameters; } @Override public ActionRequestValidationException validate() { - return body.validate(); + ActionRequestValidationException e = parameters.validate(); + if (followerIndex == null) { + e = addValidationError("follower_index is missing", e); + } + return e; } public Request(StreamInput in) throws IOException { super(in); - body = new Body(in); + followerIndex = in.readString(); + parameters = new FollowParameters(in); } @Override public void writeTo(final StreamOutput out) throws IOException { super.writeTo(out); - body.writeTo(out); + out.writeString(followerIndex); + parameters.writeTo(out); } @Override public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { - return body.toXContent(builder, params); + builder.startObject(); + { + parameters.toXContentFragment(builder); + } + builder.endObject(); + return builder; } @Override @@ -96,80 +111,13 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Request request = (Request) o; - return Objects.equals(body, request.body); + return Objects.equals(followerIndex, request.followerIndex) && + Objects.equals(parameters, request.parameters); } @Override public int hashCode() { - return Objects.hash(body); - } - - public static class Body extends FollowParameters implements ToXContentObject { - - static final ObjectParser PARSER = new ObjectParser<>(NAME, Body::new); - - static { - PARSER.declareString(Body::setFollowerIndex, FOLLOWER_INDEX_FIELD); - initParser(PARSER); - } - - private String followerIndex; - - public Body() { - } - - public String getFollowerIndex() { - return followerIndex; - } - - public void setFollowerIndex(String followerIndex) { - this.followerIndex = followerIndex; - } - - @Override - public ActionRequestValidationException validate() { - ActionRequestValidationException e = super.validate(); - if (followerIndex == null) { - e = addValidationError(FOLLOWER_INDEX_FIELD.getPreferredName() + " is missing", e); - } - return e; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - { - builder.field(FOLLOWER_INDEX_FIELD.getPreferredName(), followerIndex); - super.toXContentFragment(builder); - } - builder.endObject(); - return builder; - } - - Body(StreamInput in) throws IOException { - followerIndex = in.readString(); - fromStreamInput(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(followerIndex); - super.writeTo(out); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - Body body = (Body) o; - return Objects.equals(followerIndex, body.followerIndex); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), followerIndex); - } + return Objects.hash(followerIndex, parameters); } } From e365768a3b0e7e645ccb16f3042d9d914caf0e72 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 4 Feb 2019 11:33:53 +0100 Subject: [PATCH 3/8] fixed checkstyle --- .../xpack/core/ccr/action/PutAutoFollowPatternAction.java | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java index 988a30baafd0d..5175f55e8ef7a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.AcknowledgedRequest; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.ByteSizeValue; From 8f6eb1bc9e62d0ec6ec45993c09e91b5b9bd0258 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 4 Feb 2019 12:35:26 +0100 Subject: [PATCH 4/8] fixed hlrc to not send followIndex in request body --- .../org/elasticsearch/client/ccr/PutFollowRequest.java | 2 -- .../org/elasticsearch/client/ccr/ResumeFollowRequest.java | 3 --- .../elasticsearch/client/ccr/PutFollowRequestTests.java | 5 ++--- .../client/ccr/ResumeFollowRequestTests.java | 8 +++----- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PutFollowRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PutFollowRequest.java index 8307b04bd7087..9c9e3f92b8173 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PutFollowRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PutFollowRequest.java @@ -32,7 +32,6 @@ public final class PutFollowRequest extends FollowConfig implements Validatable, static final ParseField REMOTE_CLUSTER_FIELD = new ParseField("remote_cluster"); static final ParseField LEADER_INDEX_FIELD = new ParseField("leader_index"); - static final ParseField FOLLOWER_INDEX_FIELD = new ParseField("follower_index"); private final String remoteCluster; private final String leaderIndex; @@ -55,7 +54,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.startObject(); builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster); builder.field(LEADER_INDEX_FIELD.getPreferredName(), leaderIndex); - builder.field(FOLLOWER_INDEX_FIELD.getPreferredName(), followerIndex); toXContentFragment(builder, params); builder.endObject(); return builder; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/ResumeFollowRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/ResumeFollowRequest.java index d9ceb666afd2f..972f327134749 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/ResumeFollowRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/ResumeFollowRequest.java @@ -26,8 +26,6 @@ import java.io.IOException; import java.util.Objects; -import static org.elasticsearch.client.ccr.PutFollowRequest.FOLLOWER_INDEX_FIELD; - public final class ResumeFollowRequest extends FollowConfig implements Validatable, ToXContentObject { private final String followerIndex; @@ -39,7 +37,6 @@ public ResumeFollowRequest(String followerIndex) { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.field(FOLLOWER_INDEX_FIELD.getPreferredName(), followerIndex); toXContentFragment(builder, params); builder.endObject(); return builder; diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/PutFollowRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/PutFollowRequestTests.java index 35353ce4a96f9..1f6a3d9f0ac28 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/PutFollowRequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/PutFollowRequestTests.java @@ -31,12 +31,11 @@ public class PutFollowRequestTests extends AbstractXContentTestCase { private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("test_parser", - true, (args) -> new PutFollowRequest((String) args[0], (String) args[1], (String) args[2])); + true, (args) -> new PutFollowRequest((String) args[0], (String) args[1], "followerIndex")); static { PARSER.declareString(ConstructingObjectParser.constructorArg(), PutFollowRequest.REMOTE_CLUSTER_FIELD); PARSER.declareString(ConstructingObjectParser.constructorArg(), PutFollowRequest.LEADER_INDEX_FIELD); - PARSER.declareString(ConstructingObjectParser.constructorArg(), PutFollowRequest.FOLLOWER_INDEX_FIELD); PARSER.declareInt(PutFollowRequest::setMaxReadRequestOperationCount, PutFollowRequest.MAX_READ_REQUEST_OPERATION_COUNT); PARSER.declareField( PutFollowRequest::setMaxReadRequestSize, @@ -82,7 +81,7 @@ protected boolean supportsUnknownFields() { @Override protected PutFollowRequest createTestInstance() { PutFollowRequest putFollowRequest = - new PutFollowRequest(randomAlphaOfLength(4), randomAlphaOfLength(4), randomAlphaOfLength(4)); + new PutFollowRequest(randomAlphaOfLength(4), randomAlphaOfLength(4), "followerIndex"); if (randomBoolean()) { putFollowRequest.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE)); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/ResumeFollowRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/ResumeFollowRequestTests.java index 3f00891331839..d5d2b7e25539f 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/ResumeFollowRequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/ResumeFollowRequestTests.java @@ -21,7 +21,6 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractXContentTestCase; @@ -30,11 +29,10 @@ public class ResumeFollowRequestTests extends AbstractXContentTestCase { - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("test_parser", - true, (args) -> new ResumeFollowRequest((String) args[0])); + private static final ObjectParser PARSER = new ObjectParser<>("test_parser", + true, () -> new ResumeFollowRequest("followerIndex")); static { - PARSER.declareString(ConstructingObjectParser.constructorArg(), PutFollowRequest.FOLLOWER_INDEX_FIELD); PARSER.declareInt(ResumeFollowRequest::setMaxReadRequestOperationCount, FollowConfig.MAX_READ_REQUEST_OPERATION_COUNT); PARSER.declareField( ResumeFollowRequest::setMaxReadRequestSize, @@ -79,7 +77,7 @@ protected boolean supportsUnknownFields() { @Override protected ResumeFollowRequest createTestInstance() { - ResumeFollowRequest resumeFollowRequest = new ResumeFollowRequest(randomAlphaOfLength(4)); + ResumeFollowRequest resumeFollowRequest = new ResumeFollowRequest("followerIndex"); if (randomBoolean()) { resumeFollowRequest.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE)); } From 58e1f369a42de5238479dd853c5fbb908e147138 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 4 Feb 2019 15:36:01 +0100 Subject: [PATCH 5/8] hide body classes --- .../ccr/action/AutoFollowCoordinator.java | 24 +- .../TransportPutAutoFollowPatternAction.java | 39 ++- .../ccr/action/TransportPutFollowAction.java | 14 +- .../elasticsearch/xpack/CcrIntegTestCase.java | 8 +- .../xpack/CcrSingleNodeTestCase.java | 8 +- .../elasticsearch/xpack/ccr/AutoFollowIT.java | 81 +++--- .../elasticsearch/xpack/ccr/CcrLicenseIT.java | 4 +- .../xpack/ccr/FollowerFailOverIT.java | 30 +-- .../xpack/ccr/IndexFollowingIT.java | 16 +- .../xpack/ccr/LocalIndexFollowingIT.java | 10 +- .../action/AutoFollowCoordinatorTests.java | 12 +- .../PutAutoFollowPatternRequestTests.java | 48 ++-- .../action/PutFollowActionRequestTests.java | 15 +- ...nsportPutAutoFollowPatternActionTests.java | 12 +- .../core/ccr/action/FollowParameters.java | 2 +- .../action/PutAutoFollowPatternAction.java | 243 ++++++++---------- .../core/ccr/action/PutFollowAction.java | 191 +++++--------- 17 files changed, 337 insertions(+), 420 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java index da1b532a582fb..03e936ca8c2ea 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java @@ -514,19 +514,19 @@ private void followLeaderIndex(String autoFollowPattenName, final String followIndexName = getFollowerIndexName(pattern, leaderIndexName); PutFollowAction.Request request = new PutFollowAction.Request(); - request.getBody().setRemoteCluster(remoteCluster); - request.getBody().setLeaderIndex(indexToFollow.getName()); + request.setRemoteCluster(remoteCluster); + request.setLeaderIndex(indexToFollow.getName()); request.setFollowerIndex(followIndexName); - request.getBody().setMaxReadRequestOperationCount(pattern.getMaxReadRequestOperationCount()); - request.getBody().setMaxReadRequestSize(pattern.getMaxReadRequestSize()); - request.getBody().setMaxOutstandingReadRequests(pattern.getMaxOutstandingReadRequests()); - request.getBody().setMaxWriteRequestOperationCount(pattern.getMaxWriteRequestOperationCount()); - request.getBody().setMaxWriteRequestSize(pattern.getMaxWriteRequestSize()); - request.getBody().setMaxOutstandingWriteRequests(pattern.getMaxOutstandingWriteRequests()); - request.getBody().setMaxWriteBufferCount(pattern.getMaxWriteBufferCount()); - request.getBody().setMaxWriteBufferSize(pattern.getMaxWriteBufferSize()); - request.getBody().setMaxRetryDelay(pattern.getMaxRetryDelay()); - request.getBody().setReadPollTimeout(pattern.getPollTimeout()); + request.getParameters().setMaxReadRequestOperationCount(pattern.getMaxReadRequestOperationCount()); + request.getParameters().setMaxReadRequestSize(pattern.getMaxReadRequestSize()); + request.getParameters().setMaxOutstandingReadRequests(pattern.getMaxOutstandingReadRequests()); + request.getParameters().setMaxWriteRequestOperationCount(pattern.getMaxWriteRequestOperationCount()); + request.getParameters().setMaxWriteRequestSize(pattern.getMaxWriteRequestSize()); + request.getParameters().setMaxOutstandingWriteRequests(pattern.getMaxOutstandingWriteRequests()); + request.getParameters().setMaxWriteBufferCount(pattern.getMaxWriteBufferCount()); + request.getParameters().setMaxWriteBufferSize(pattern.getMaxWriteBufferSize()); + request.getParameters().setMaxRetryDelay(pattern.getMaxRetryDelay()); + request.getParameters().setReadPollTimeout(pattern.getPollTimeout()); // Execute if the create and follow api call succeeds: Runnable successHandler = () -> { diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java index 353914d8d9424..d5127cbb74d4b 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternAction.java @@ -76,16 +76,16 @@ protected void masterOperation(PutAutoFollowPatternAction.Request request, listener.onFailure(LicenseUtils.newComplianceException("ccr")); return; } - final Client remoteClient = client.getRemoteClusterClient(request.getBody().getRemoteCluster()); + final Client remoteClient = client.getRemoteClusterClient(request.getRemoteCluster()); final Map filteredHeaders = threadPool.getThreadContext().getHeaders().entrySet().stream() .filter(e -> ShardFollowTask.HEADER_FILTERS.contains(e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); Consumer consumer = remoteClusterState -> { - String[] indices = request.getBody().getLeaderIndexPatterns().toArray(new String[0]); + String[] indices = request.getLeaderIndexPatterns().toArray(new String[0]); ccrLicenseChecker.hasPrivilegesToFollowIndices(remoteClient, indices, e -> { if (e == null) { - clusterService.submitStateUpdateTask("put-auto-follow-pattern-" + request.getBody().getRemoteCluster(), + clusterService.submitStateUpdateTask("put-auto-follow-pattern-" + request.getRemoteCluster(), new AckedClusterStateUpdateTask(request, listener) { @Override @@ -108,7 +108,7 @@ public ClusterState execute(ClusterState currentState) throws Exception { clusterStateRequest.clear(); clusterStateRequest.metaData(true); - ccrLicenseChecker.checkRemoteClusterLicenseAndFetchClusterState(client, request.getBody().getRemoteCluster(), + ccrLicenseChecker.checkRemoteClusterLicenseAndFetchClusterState(client, request.getRemoteCluster(), clusterStateRequest, listener::onFailure, consumer); } @@ -144,11 +144,10 @@ static ClusterState innerPut(PutAutoFollowPatternAction.Request request, followedLeaderIndices.put(request.getName(), followedIndexUUIDs); // Mark existing leader indices as already auto followed: if (previousPattern != null) { - markExistingIndicesAsAutoFollowedForNewPatterns(request.getBody().getLeaderIndexPatterns(), remoteClusterState.metaData(), + markExistingIndicesAsAutoFollowedForNewPatterns(request.getLeaderIndexPatterns(), remoteClusterState.metaData(), previousPattern, followedIndexUUIDs); } else { - markExistingIndicesAsAutoFollowed(request.getBody().getLeaderIndexPatterns(), remoteClusterState.metaData(), - followedIndexUUIDs); + markExistingIndicesAsAutoFollowed(request.getLeaderIndexPatterns(), remoteClusterState.metaData(), followedIndexUUIDs); } if (filteredHeaders != null) { @@ -156,19 +155,19 @@ static ClusterState innerPut(PutAutoFollowPatternAction.Request request, } AutoFollowPattern autoFollowPattern = new AutoFollowPattern( - request.getBody().getRemoteCluster(), - request.getBody().getLeaderIndexPatterns(), - request.getBody().getFollowIndexNamePattern(), - request.getBody().getMaxReadRequestOperationCount(), - request.getBody().getMaxReadRequestSize(), - request.getBody().getMaxOutstandingReadRequests(), - request.getBody().getMaxWriteRequestOperationCount(), - request.getBody().getMaxWriteRequestSize(), - request.getBody().getMaxOutstandingWriteRequests(), - request.getBody().getMaxWriteBufferCount(), - request.getBody().getMaxWriteBufferSize(), - request.getBody().getMaxRetryDelay(), - request.getBody().getReadPollTimeout()); + request.getRemoteCluster(), + request.getLeaderIndexPatterns(), + request.getFollowIndexNamePattern(), + request.getParameters().getMaxReadRequestOperationCount(), + request.getParameters().getMaxReadRequestSize(), + request.getParameters().getMaxOutstandingReadRequests(), + request.getParameters().getMaxWriteRequestOperationCount(), + request.getParameters().getMaxWriteRequestSize(), + request.getParameters().getMaxOutstandingWriteRequests(), + request.getParameters().getMaxWriteBufferCount(), + request.getParameters().getMaxWriteBufferSize(), + request.getParameters().getMaxRetryDelay(), + request.getParameters().getReadPollTimeout()); patterns.put(request.getName(), autoFollowPattern); ClusterState.Builder newState = ClusterState.builder(localState); newState.metaData(MetaData.builder(localState.getMetaData()) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java index 426eb5cfd95e5..a4a25f91b4583 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java @@ -103,11 +103,11 @@ protected void masterOperation( listener.onFailure(LicenseUtils.newComplianceException("ccr")); return; } - String remoteCluster = request.getBody().getRemoteCluster(); + String remoteCluster = request.getRemoteCluster(); // Validates whether the leader cluster has been configured properly: client.getRemoteClusterClient(remoteCluster); - String leaderIndex = request.getBody().getLeaderIndex(); + String leaderIndex = request.getLeaderIndex(); ccrLicenseChecker.checkRemoteClusterLicenseAndFetchLeaderIndexMetadataAndHistoryUUIDs( client, remoteCluster, @@ -121,13 +121,13 @@ private void createFollowerIndex( final PutFollowAction.Request request, final ActionListener listener) { if (leaderIndexMetaData == null) { - listener.onFailure(new IllegalArgumentException("leader index [" + request.getBody().getLeaderIndex() + "] does not exist")); + listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not exist")); return; } // soft deletes are enabled by default on indices created on 7.0.0 or later if (leaderIndexMetaData.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(leaderIndexMetaData.getSettings()).onOrAfter(Version.V_7_0_0)) == false) { - listener.onFailure(new IllegalArgumentException("leader index [" + request.getBody().getLeaderIndex() + + listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not have soft deletes enabled")); return; } @@ -135,9 +135,9 @@ private void createFollowerIndex( final Settings.Builder settingsBuilder = Settings.builder() .put(IndexMetaData.SETTING_INDEX_PROVIDED_NAME, request.getFollowerIndex()) .put(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey(), true); - final String leaderClusterRepoName = CcrRepository.NAME_PREFIX + request.getBody().getRemoteCluster(); + final String leaderClusterRepoName = CcrRepository.NAME_PREFIX + request.getRemoteCluster(); final RestoreSnapshotRequest restoreRequest = new RestoreSnapshotRequest(leaderClusterRepoName, CcrRepository.LATEST) - .indices(request.getBody().getLeaderIndex()).indicesOptions(request.indicesOptions()).renamePattern("^(.*)$") + .indices(request.getLeaderIndex()).indicesOptions(request.indicesOptions()).renamePattern("^(.*)$") .renameReplacement(request.getFollowerIndex()).masterNodeTimeout(request.masterNodeTimeout()) .indexSettings(settingsBuilder); @@ -221,7 +221,7 @@ private void initiateFollowing( activeShardsObserver.waitForActiveShards(new String[]{request.getFollowerIndex()}, request.waitForActiveShards(), request.timeout(), result -> { if (result) { - FollowParameters parameters = request.getBody(); + FollowParameters parameters = request.getParameters(); ResumeFollowAction.Request resumeFollowRequest = new ResumeFollowAction.Request(); resumeFollowRequest.setFollowerIndex(request.getFollowerIndex()); resumeFollowRequest.getParameters().setMaxOutstandingReadRequests(parameters.getMaxOutstandingReadRequests()); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java index 1e71ed41a3cc4..d76774fd27c4d 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java @@ -424,11 +424,11 @@ public static PutFollowAction.Request putFollow(String leaderIndex, String follo public static PutFollowAction.Request putFollow(String leaderIndex, String followerIndex, ActiveShardCount waitForActiveShards) { PutFollowAction.Request request = new PutFollowAction.Request(); - request.getBody().setRemoteCluster("leader_cluster"); - request.getBody().setLeaderIndex(leaderIndex); + request.setRemoteCluster("leader_cluster"); + request.setLeaderIndex(leaderIndex); request.setFollowerIndex(followerIndex); - request.getBody().setMaxRetryDelay(TimeValue.timeValueMillis(10)); - request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(10)); + request.getParameters().setMaxRetryDelay(TimeValue.timeValueMillis(10)); + request.getParameters().setReadPollTimeout(TimeValue.timeValueMillis(10)); request.waitForActiveShards(waitForActiveShards); return request; } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java index 44e6ba0af279e..c2760aa5efd6b 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java @@ -96,11 +96,11 @@ protected ResumeFollowAction.Request getResumeFollowRequest(String followerIndex protected PutFollowAction.Request getPutFollowRequest(String leaderIndex, String followerIndex) { PutFollowAction.Request request = new PutFollowAction.Request(); - request.getBody().setRemoteCluster("local"); - request.getBody().setLeaderIndex(leaderIndex); + request.setRemoteCluster("local"); + request.setLeaderIndex(leaderIndex); request.setFollowerIndex(followerIndex); - request.getBody().setMaxRetryDelay(TimeValue.timeValueMillis(1)); - request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(1)); + request.getParameters().setMaxRetryDelay(TimeValue.timeValueMillis(1)); + request.getParameters().setReadPollTimeout(TimeValue.timeValueMillis(1)); request.waitForActiveShards(ActiveShardCount.ONE); return request; } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java index f9a1c85fa9d21..f12dcea4af9b5 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java @@ -185,44 +185,43 @@ public void testAutoFollowParameterAreDelegated() throws Exception { .build(); // Enabling auto following: - PutAutoFollowPatternAction.Request.Body requestBody = new PutAutoFollowPatternAction.Request.Body(); - requestBody.setRemoteCluster("leader_cluster"); - requestBody.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); + request.setRemoteCluster("leader_cluster"); + request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); // Need to set this, because following an index in the same cluster - requestBody.setFollowIndexNamePattern("copy-{{leader_index}}"); + request.setFollowIndexNamePattern("copy-{{leader_index}}"); if (randomBoolean()) { - requestBody.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE)); + request.getParameters().setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { - requestBody.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE)); + request.getParameters().setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { - requestBody.setMaxOutstandingWriteRequests(randomIntBetween(0, Integer.MAX_VALUE)); + request.getParameters().setMaxOutstandingWriteRequests(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { - requestBody.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); + request.getParameters().setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { - requestBody.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); + request.getParameters().setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); } if (randomBoolean()) { - requestBody.setMaxRetryDelay(TimeValue.timeValueMillis(500)); + request.getParameters().setMaxRetryDelay(TimeValue.timeValueMillis(500)); } if (randomBoolean()) { - requestBody.setReadPollTimeout(TimeValue.timeValueMillis(500)); + request.getParameters().setReadPollTimeout(TimeValue.timeValueMillis(500)); } if (randomBoolean()) { - requestBody.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); + request.getParameters().setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { - requestBody.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); + request.getParameters().setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong(), ByteSizeUnit.BYTES)); } if (randomBoolean()) { - requestBody.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong())); + request.getParameters().setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong())); } - PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); + request.setName("my-pattern"); - request.setBody(requestBody); assertTrue(followerClient().execute(PutAutoFollowPatternAction.INSTANCE, request).actionGet().isAcknowledged()); createLeaderIndex("logs-201901", leaderIndexSettings); @@ -244,35 +243,39 @@ public void testAutoFollowParameterAreDelegated() throws Exception { FollowParameters followParameters = followerInfo.getParameters(); assertThat(followParameters, notNullValue()); - if (requestBody.getMaxWriteBufferCount() != null) { - assertThat(followParameters.getMaxWriteBufferCount(), equalTo(requestBody.getMaxWriteBufferCount())); + if (request.getParameters().getMaxWriteBufferCount() != null) { + assertThat(followParameters.getMaxWriteBufferCount(), equalTo(request.getParameters().getMaxWriteBufferCount())); } - if (requestBody.getMaxWriteBufferSize() != null) { - assertThat(followParameters.getMaxWriteBufferSize(), equalTo(requestBody.getMaxWriteBufferSize())); + if (request.getParameters().getMaxWriteBufferSize() != null) { + assertThat(followParameters.getMaxWriteBufferSize(), equalTo(request.getParameters().getMaxWriteBufferSize())); } - if (requestBody.getMaxOutstandingReadRequests() != null) { - assertThat(followParameters.getMaxOutstandingReadRequests(), equalTo(requestBody.getMaxOutstandingReadRequests())); + if (request.getParameters().getMaxOutstandingReadRequests() != null) { + assertThat(followParameters.getMaxOutstandingReadRequests(), + equalTo(request.getParameters().getMaxOutstandingReadRequests())); } - if (requestBody.getMaxOutstandingWriteRequests() != null) { - assertThat(followParameters.getMaxOutstandingWriteRequests(), equalTo(requestBody.getMaxOutstandingWriteRequests())); + if (request.getParameters().getMaxOutstandingWriteRequests() != null) { + assertThat(followParameters.getMaxOutstandingWriteRequests(), + equalTo(request.getParameters().getMaxOutstandingWriteRequests())); } - if (requestBody.getMaxReadRequestOperationCount() != null) { - assertThat(followParameters.getMaxReadRequestOperationCount(), equalTo(requestBody.getMaxReadRequestOperationCount())); + if (request.getParameters().getMaxReadRequestOperationCount() != null) { + assertThat(followParameters.getMaxReadRequestOperationCount(), + equalTo(request.getParameters().getMaxReadRequestOperationCount())); } - if (requestBody.getMaxReadRequestSize() != null) { - assertThat(followParameters.getMaxReadRequestSize(), equalTo(requestBody.getMaxReadRequestSize())); + if (request.getParameters().getMaxReadRequestSize() != null) { + assertThat(followParameters.getMaxReadRequestSize(), equalTo(request.getParameters().getMaxReadRequestSize())); } - if (requestBody.getMaxRetryDelay() != null) { - assertThat(followParameters.getMaxRetryDelay(), equalTo(requestBody.getMaxRetryDelay())); + if (request.getParameters().getMaxRetryDelay() != null) { + assertThat(followParameters.getMaxRetryDelay(), equalTo(request.getParameters().getMaxRetryDelay())); } - if (requestBody.getReadPollTimeout() != null) { - assertThat(followParameters.getReadPollTimeout(), equalTo(requestBody.getReadPollTimeout())); + if (request.getParameters().getReadPollTimeout() != null) { + assertThat(followParameters.getReadPollTimeout(), equalTo(request.getParameters().getReadPollTimeout())); } - if (requestBody.getMaxWriteRequestOperationCount() != null) { - assertThat(followParameters.getMaxWriteRequestOperationCount(), equalTo(requestBody.getMaxWriteRequestOperationCount())); + if (request.getParameters().getMaxWriteRequestOperationCount() != null) { + assertThat(followParameters.getMaxWriteRequestOperationCount(), + equalTo(request.getParameters().getMaxWriteRequestOperationCount())); } - if (requestBody.getMaxWriteRequestSize() != null) { - assertThat(followParameters.getMaxWriteRequestSize(), equalTo(requestBody.getMaxWriteRequestSize())); + if (request.getParameters().getMaxWriteRequestSize() != null) { + assertThat(followParameters.getMaxWriteRequestSize(), equalTo(request.getParameters().getMaxWriteRequestSize())); } }); } @@ -361,10 +364,10 @@ public void testAutoFollowSoftDeletesDisabled() throws Exception { private void putAutoFollowPatterns(String name, String[] patterns) { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); request.setName(name); - request.getBody().setRemoteCluster("leader_cluster"); - request.getBody().setLeaderIndexPatterns(Arrays.asList(patterns)); + request.setRemoteCluster("leader_cluster"); + request.setLeaderIndexPatterns(Arrays.asList(patterns)); // Need to set this, because following an index in the same cluster - request.getBody().setFollowIndexNamePattern("copy-{{leader_index}}"); + request.setFollowIndexNamePattern("copy-{{leader_index}}"); assertTrue(followerClient().execute(PutAutoFollowPatternAction.INSTANCE, request).actionGet().isAcknowledged()); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java index dc8dbd69052ae..f8e7eab1c8647 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java @@ -118,8 +118,8 @@ public void testThatPutAutoFollowPatternsIsUnavailableWithNonCompliantLicense() final CountDownLatch latch = new CountDownLatch(1); final PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); request.setName("name"); - request.getBody().setRemoteCluster("leader"); - request.getBody().setLeaderIndexPatterns(Collections.singletonList("*")); + request.setRemoteCluster("leader"); + request.setLeaderIndexPatterns(Collections.singletonList("*")); client().execute( PutAutoFollowPatternAction.INSTANCE, request, diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java index 11901eb5559f1..8f0cf54d94d54 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java @@ -90,13 +90,13 @@ public void testFailOverOnFollower() throws Exception { } availableDocs.release(between(100, 200)); PutFollowAction.Request follow = putFollow("leader-index", "follower-index"); - follow.getBody().setMaxReadRequestOperationCount(randomIntBetween(32, 2048)); - follow.getBody().setMaxReadRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); - follow.getBody().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); - follow.getBody().setMaxWriteRequestOperationCount(randomIntBetween(32, 2048)); - follow.getBody().setMaxWriteRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); - follow.getBody().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); - logger.info("--> follow params {}", Strings.toString(follow.getBody())); + follow.getParameters().setMaxReadRequestOperationCount(randomIntBetween(32, 2048)); + follow.getParameters().setMaxReadRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); + follow.getParameters().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); + follow.getParameters().setMaxWriteRequestOperationCount(randomIntBetween(32, 2048)); + follow.getParameters().setMaxWriteRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); + follow.getParameters().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); + logger.info("--> follow request {}", Strings.toString(follow)); followerClient().execute(PutFollowAction.INSTANCE, follow).get(); disableDelayedAllocation("follower-index"); ensureFollowerGreen("follower-index"); @@ -150,17 +150,17 @@ public void testFollowIndexAndCloseNode() throws Exception { thread.start(); PutFollowAction.Request followRequest = putFollow("index1", "index2"); - followRequest.getBody().setMaxReadRequestOperationCount(randomIntBetween(32, 2048)); - followRequest.getBody().setMaxReadRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); - followRequest.getBody().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); - followRequest.getBody().setMaxWriteRequestOperationCount(randomIntBetween(32, 2048)); - followRequest.getBody().setMaxWriteRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); - followRequest.getBody().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); + followRequest.getParameters().setMaxReadRequestOperationCount(randomIntBetween(32, 2048)); + followRequest.getParameters().setMaxReadRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); + followRequest.getParameters().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); + followRequest.getParameters().setMaxWriteRequestOperationCount(randomIntBetween(32, 2048)); + followRequest.getParameters().setMaxWriteRequestSize(new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB)); + followRequest.getParameters().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); disableDelayedAllocation("index2"); - logger.info("--> follow params {}", Strings.toString(followRequest.getBody())); + logger.info("--> follow request {}", Strings.toString(followRequest)); - int maxOpsPerRead = followRequest.getBody().getMaxReadRequestOperationCount(); + int maxOpsPerRead = followRequest.getParameters().getMaxReadRequestOperationCount(); int maxNumDocsReplicated = Math.min(between(50, 500), between(maxOpsPerRead, maxOpsPerRead * 10)); availableDocs.release(maxNumDocsReplicated / 2 + 1); atLeastDocsIndexed(followerClient(), "index2", maxNumDocsReplicated / 3); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java index c16d1ba60b1cf..8513bf12e62f6 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java @@ -437,10 +437,10 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure) atLeastDocsIndexed(leaderClient(), "index1", numDocsIndexed / 3); PutFollowAction.Request followRequest = putFollow("index1", "index2"); - followRequest.getBody().setMaxReadRequestOperationCount(maxOpsPerRead); - followRequest.getBody().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); - followRequest.getBody().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); - followRequest.getBody().setMaxWriteBufferCount(randomIntBetween(1024, 10240)); + followRequest.getParameters().setMaxReadRequestOperationCount(maxOpsPerRead); + followRequest.getParameters().setMaxOutstandingReadRequests(randomIntBetween(1, 10)); + followRequest.getParameters().setMaxOutstandingWriteRequests(randomIntBetween(1, 10)); + followRequest.getParameters().setMaxWriteBufferCount(randomIntBetween(1024, 10240)); followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); availableDocs.release(numDocsIndexed * 2 + bulkSize); atLeastDocsIndexed(leaderClient(), "index1", numDocsIndexed); @@ -535,7 +535,7 @@ public void testFollowIndexMaxOperationSizeInBytes() throws Exception { } PutFollowAction.Request followRequest = putFollow("index1", "index2"); - followRequest.getBody().setMaxReadRequestSize(new ByteSizeValue(1, ByteSizeUnit.BYTES)); + followRequest.getParameters().setMaxReadRequestSize(new ByteSizeValue(1, ByteSizeUnit.BYTES)); followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); final Map firstBatchNumDocsPerShard = new HashMap<>(); @@ -728,14 +728,14 @@ public void testUnknownClusterAlias() throws Exception { assertAcked(leaderClient().admin().indices().prepareCreate("index1").setSource(leaderIndexSettings, XContentType.JSON)); ensureLeaderGreen("index1"); PutFollowAction.Request followRequest = putFollow("index1", "index2"); - followRequest.getBody().setRemoteCluster("another_cluster"); + followRequest.setRemoteCluster("another_cluster"); Exception e = expectThrows(NoSuchRemoteClusterException.class, () -> followerClient().execute(PutFollowAction.INSTANCE, followRequest).actionGet()); assertThat(e.getMessage(), equalTo("no such remote cluster: [another_cluster]")); PutAutoFollowPatternAction.Request putAutoFollowRequest = new PutAutoFollowPatternAction.Request(); putAutoFollowRequest.setName("name"); - putAutoFollowRequest.getBody().setRemoteCluster("another_cluster"); - putAutoFollowRequest.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); + putAutoFollowRequest.setRemoteCluster("another_cluster"); + putAutoFollowRequest.setLeaderIndexPatterns(Collections.singletonList("logs-*")); e = expectThrows(NoSuchRemoteClusterException.class, () -> followerClient().execute(PutAutoFollowPatternAction.INSTANCE, putAutoFollowRequest).actionGet()); assertThat(e.getMessage(), equalTo("no such remote cluster: [another_cluster]")); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java index cd782726048ce..0df3f4ea47f43 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java @@ -84,7 +84,7 @@ public void testDoNotCreateFollowerIfLeaderDoesNotHaveSoftDeletes() throws Excep ResumeFollowAction.Request followRequest = getResumeFollowRequest("follower"); followRequest.setFollowerIndex("follower-index"); PutFollowAction.Request putFollowRequest = getPutFollowRequest("leader", "follower"); - putFollowRequest.getBody().setLeaderIndex("leader-index"); + putFollowRequest.setLeaderIndex("leader-index"); putFollowRequest.setFollowerIndex("follower-index"); IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> client().execute(PutFollowAction.INSTANCE, putFollowRequest).actionGet()); @@ -95,10 +95,10 @@ public void testDoNotCreateFollowerIfLeaderDoesNotHaveSoftDeletes() throws Excep public void testRemoveRemoteConnection() throws Exception { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); request.setName("my_pattern"); - request.getBody().setRemoteCluster("local"); - request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); - request.getBody().setFollowIndexNamePattern("copy-{{leader_index}}"); - request.getBody().setReadPollTimeout(TimeValue.timeValueMillis(10)); + request.setRemoteCluster("local"); + request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.setFollowIndexNamePattern("copy-{{leader_index}}"); + request.getParameters().setReadPollTimeout(TimeValue.timeValueMillis(10)); assertTrue(client().execute(PutAutoFollowPatternAction.INSTANCE, request).actionGet().isAcknowledged()); long previousNumberOfSuccessfulFollowedIndices = getAutoFollowStats().getNumberOfSuccessfulFollowIndices(); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java index 01cf243dc8958..2037c7faaa7b4 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java @@ -107,8 +107,8 @@ void createAndFollow(Map headers, Runnable successHandler, Consumer failureHandler) { assertThat(headers, equalTo(autoFollowHeaders.get("remote"))); - assertThat(followRequest.getBody().getRemoteCluster(), equalTo("remote")); - assertThat(followRequest.getBody().getLeaderIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getRemoteCluster(), equalTo("remote")); + assertThat(followRequest.getLeaderIndex(), equalTo("logs-20190101")); assertThat(followRequest.getFollowerIndex(), equalTo("logs-20190101")); successHandler.run(); } @@ -225,8 +225,8 @@ void createAndFollow(Map headers, PutFollowAction.Request followRequest, Runnable successHandler, Consumer failureHandler) { - assertThat(followRequest.getBody().getRemoteCluster(), equalTo("remote")); - assertThat(followRequest.getBody().getLeaderIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getRemoteCluster(), equalTo("remote")); + assertThat(followRequest.getLeaderIndex(), equalTo("logs-20190101")); assertThat(followRequest.getFollowerIndex(), equalTo("logs-20190101")); successHandler.run(); } @@ -282,8 +282,8 @@ void createAndFollow(Map headers, PutFollowAction.Request followRequest, Runnable successHandler, Consumer failureHandler) { - assertThat(followRequest.getBody().getRemoteCluster(), equalTo("remote")); - assertThat(followRequest.getBody().getLeaderIndex(), equalTo("logs-20190101")); + assertThat(followRequest.getRemoteCluster(), equalTo("remote")); + assertThat(followRequest.getLeaderIndex(), equalTo("logs-20190101")); assertThat(followRequest.getFollowerIndex(), equalTo("logs-20190101")); failureHandler.accept(failure); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutAutoFollowPatternRequestTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutAutoFollowPatternRequestTests.java index 3e73a4e4dbaac..601265d146779 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutAutoFollowPatternRequestTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutAutoFollowPatternRequestTests.java @@ -43,12 +43,12 @@ protected PutAutoFollowPatternAction.Request createTestInstance() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); request.setName(randomAlphaOfLength(4)); - request.getBody().setRemoteCluster(randomAlphaOfLength(4)); - request.getBody().setLeaderIndexPatterns(Arrays.asList(generateRandomStringArray(4, 4, false))); + request.setRemoteCluster(randomAlphaOfLength(4)); + request.setLeaderIndexPatterns(Arrays.asList(generateRandomStringArray(4, 4, false))); if (randomBoolean()) { - request.getBody().setFollowIndexNamePattern(randomAlphaOfLength(4)); + request.setFollowIndexNamePattern(randomAlphaOfLength(4)); } - ResumeFollowActionRequestTests.generateFollowParameters(request.getBody()); + ResumeFollowActionRequestTests.generateFollowParameters(request.getParameters()); return request; } @@ -57,12 +57,12 @@ protected PutAutoFollowPatternAction.Request createXContextTestInstance(XContent // follower index parameter is not part of the request body and is provided in the url path. // So this field cannot be used for creating a test instance for xcontent testing. PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setRemoteCluster(randomAlphaOfLength(4)); - request.getBody().setLeaderIndexPatterns(Arrays.asList(generateRandomStringArray(4, 4, false))); + request.setRemoteCluster(randomAlphaOfLength(4)); + request.setLeaderIndexPatterns(Arrays.asList(generateRandomStringArray(4, 4, false))); if (randomBoolean()) { - request.getBody().setFollowIndexNamePattern(randomAlphaOfLength(4)); + request.setFollowIndexNamePattern(randomAlphaOfLength(4)); } - ResumeFollowActionRequestTests.generateFollowParameters(request.getBody()); + ResumeFollowActionRequestTests.generateFollowParameters(request.getParameters()); return request; } @@ -77,39 +77,39 @@ public void testValidate() { assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[remote_cluster] is missing")); - request.getBody().setRemoteCluster("_alias"); + request.setRemoteCluster("_alias"); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[leader_index_patterns] is missing")); - request.getBody().setLeaderIndexPatterns(Collections.emptyList()); + request.setLeaderIndexPatterns(Collections.emptyList()); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[leader_index_patterns] is missing")); - request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); validationException = request.validate(); assertThat(validationException, nullValue()); - request.getBody().setMaxRetryDelay(TimeValue.ZERO); + request.getParameters().setMaxRetryDelay(TimeValue.ZERO); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[max_retry_delay] must be positive but was [0ms]")); - request.getBody().setMaxRetryDelay(TimeValue.timeValueMinutes(10)); + request.getParameters().setMaxRetryDelay(TimeValue.timeValueMinutes(10)); validationException = request.validate(); assertThat(validationException, notNullValue()); assertThat(validationException.getMessage(), containsString("[max_retry_delay] must be less than [5m] but was [10m]")); - request.getBody().setMaxRetryDelay(TimeValue.timeValueMinutes(1)); + request.getParameters().setMaxRetryDelay(TimeValue.timeValueMinutes(1)); validationException = request.validate(); assertThat(validationException, nullValue()); } public void testValidateName() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setRemoteCluster("_alias"); - request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.setRemoteCluster("_alias"); + request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); request.setName("name"); ActionRequestValidationException validationException = request.validate(); @@ -118,8 +118,8 @@ public void testValidateName() { public void testValidateNameComma() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setRemoteCluster("_alias"); - request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.setRemoteCluster("_alias"); + request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); request.setName("name1,name2"); ActionRequestValidationException validationException = request.validate(); @@ -129,8 +129,8 @@ public void testValidateNameComma() { public void testValidateNameLeadingUnderscore() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setRemoteCluster("_alias"); - request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.setRemoteCluster("_alias"); + request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); request.setName("_name"); ActionRequestValidationException validationException = request.validate(); @@ -140,8 +140,8 @@ public void testValidateNameLeadingUnderscore() { public void testValidateNameUnderscores() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setRemoteCluster("_alias"); - request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.setRemoteCluster("_alias"); + request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); request.setName("n_a_m_e_"); ActionRequestValidationException validationException = request.validate(); @@ -150,8 +150,8 @@ public void testValidateNameUnderscores() { public void testValidateNameTooLong() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); - request.getBody().setRemoteCluster("_alias"); - request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.setRemoteCluster("_alias"); + request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < 256; i++) { diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java index efdcae2f3e67e..02b5eca08fa4a 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java @@ -28,9 +28,9 @@ protected PutFollowAction.Request createTestInstance() { request.waitForActiveShards(randomFrom(ActiveShardCount.DEFAULT, ActiveShardCount.NONE, ActiveShardCount.ONE, ActiveShardCount.ALL)); - request.getBody().setRemoteCluster(randomAlphaOfLength(4)); - request.getBody().setLeaderIndex(randomAlphaOfLength(4)); - ResumeFollowActionRequestTests.generateFollowParameters(request.getBody()); + request.setRemoteCluster(randomAlphaOfLength(4)); + request.setLeaderIndex(randomAlphaOfLength(4)); + ResumeFollowActionRequestTests.generateFollowParameters(request.getParameters()); return request; } @@ -39,15 +39,16 @@ protected PutFollowAction.Request createXContextTestInstance(XContentType xConte // follower index parameter and wait for active shards params are not part of the request body and // are provided in the url path. So these fields cannot be used for creating a test instance for xcontent testing. PutFollowAction.Request request = new PutFollowAction.Request(); - request.getBody().setRemoteCluster(randomAlphaOfLength(4)); - request.getBody().setLeaderIndex(randomAlphaOfLength(4)); - ResumeFollowActionRequestTests.generateFollowParameters(request.getBody()); + request.setRemoteCluster(randomAlphaOfLength(4)); + request.setLeaderIndex(randomAlphaOfLength(4)); + request.setFollowerIndex("followerIndex"); + ResumeFollowActionRequestTests.generateFollowParameters(request.getParameters()); return request; } @Override protected PutFollowAction.Request doParseInstance(XContentParser parser) throws IOException { - return PutFollowAction.Request.fromXContent(parser, null, ActiveShardCount.DEFAULT); + return PutFollowAction.Request.fromXContent(parser, "followerIndex", ActiveShardCount.DEFAULT); } @Override diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java index 7950af31abc41..ac556d47c85dd 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutAutoFollowPatternActionTests.java @@ -30,8 +30,8 @@ public class TransportPutAutoFollowPatternActionTests extends ESTestCase { public void testInnerPut() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); request.setName("name1"); - request.getBody().setRemoteCluster("eu_cluster"); - request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.setRemoteCluster("eu_cluster"); + request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); ClusterState localState = ClusterState.builder(new ClusterName("us_cluster")) .metaData(MetaData.builder()) @@ -55,8 +55,8 @@ public void testInnerPut() { public void testInnerPut_existingLeaderIndices() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); request.setName("name1"); - request.getBody().setRemoteCluster("eu_cluster"); - request.getBody().setLeaderIndexPatterns(Collections.singletonList("logs-*")); + request.setRemoteCluster("eu_cluster"); + request.setLeaderIndexPatterns(Collections.singletonList("logs-*")); ClusterState localState = ClusterState.builder(new ClusterName("us_cluster")) .metaData(MetaData.builder()) @@ -96,8 +96,8 @@ public void testInnerPut_existingLeaderIndices() { public void testInnerPut_existingLeaderIndicesAndAutoFollowMetadata() { PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request(); request.setName("name1"); - request.getBody().setRemoteCluster("eu_cluster"); - request.getBody().setLeaderIndexPatterns(Arrays.asList("logs-*", "transactions-*")); + request.setRemoteCluster("eu_cluster"); + request.setLeaderIndexPatterns(Arrays.asList("logs-*", "transactions-*")); Map existingAutoFollowPatterns = new HashMap<>(); List existingPatterns = new ArrayList<>(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java index 2c6a8fe7328c9..6a4f824e09842 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java @@ -269,7 +269,7 @@ public static void initParser(AbstractObjectPars @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (o == null || (o instanceof FollowParameters == false)) return false; FollowParameters that = (FollowParameters) o; return Objects.equals(maxReadRequestOperationCount, that.maxReadRequestOperationCount) && Objects.equals(maxWriteRequestOperationCount, that.maxWriteRequestOperationCount) && diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java index 5175f55e8ef7a..a4ad1213ef419 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java @@ -44,23 +44,38 @@ public AcknowledgedResponse newResponse() { public static class Request extends AcknowledgedRequest implements ToXContentObject { + private static final ObjectParser PARSER = new ObjectParser<>("put_auto_follow_pattern_request", Body::new); + + static { + PARSER.declareString((params, value) -> params.remoteCluster = value, REMOTE_CLUSTER_FIELD); + PARSER.declareStringArray((params, value) -> params.leaderIndexPatterns = value, AutoFollowPattern.LEADER_PATTERNS_FIELD); + PARSER.declareString((params, value) -> params.followIndexNamePattern = value, AutoFollowPattern.FOLLOW_PATTERN_FIELD); + FollowParameters.initParser(PARSER); + } + public static Request fromXContent(XContentParser parser, String name) throws IOException { - Body body = Body.PARSER.parse(parser, null); + Body body = PARSER.parse(parser, null); Request request = new Request(); request.setName(name); - request.setBody(body); + request.setRemoteCluster(body.remoteCluster); + request.setLeaderIndexPatterns(body.leaderIndexPatterns); + request.setFollowIndexNamePattern(body.followIndexNamePattern); + request.setParameters(body); return request; } private String name; - private Body body = new Body(); + private String remoteCluster; + private List leaderIndexPatterns; + private String followIndexNamePattern; + private FollowParameters parameters = new FollowParameters(); public Request() { } @Override public ActionRequestValidationException validate() { - ActionRequestValidationException validationException = body.validate(); + ActionRequestValidationException validationException = parameters.validate(); if (name == null) { validationException = addValidationError("[name] is missing", validationException); } @@ -77,6 +92,14 @@ public ActionRequestValidationException validate() { validationException); } } + if (remoteCluster == null) { + validationException = addValidationError("[" + REMOTE_CLUSTER_FIELD.getPreferredName() + + "] is missing", validationException); + } + if (leaderIndexPatterns == null || leaderIndexPatterns.isEmpty()) { + validationException = addValidationError("[" + AutoFollowPattern.LEADER_PATTERNS_FIELD.getPreferredName() + + "] is missing", validationException); + } return validationException; } @@ -88,30 +111,97 @@ public void setName(String name) { this.name = name; } - public Body getBody() { - return body; + public String getRemoteCluster() { + return remoteCluster; + } + + public void setRemoteCluster(String remoteCluster) { + this.remoteCluster = remoteCluster; + } + + public List getLeaderIndexPatterns() { + return leaderIndexPatterns; + } + + public void setLeaderIndexPatterns(List leaderIndexPatterns) { + this.leaderIndexPatterns = leaderIndexPatterns; + } + + public String getFollowIndexNamePattern() { + return followIndexNamePattern; + } + + public void setFollowIndexNamePattern(String followIndexNamePattern) { + this.followIndexNamePattern = followIndexNamePattern; + } + + public FollowParameters getParameters() { + return parameters; } - public void setBody(Body body) { - this.body = body; + public void setParameters(FollowParameters parameters) { + this.parameters = parameters; } public Request(StreamInput in) throws IOException { super(in); name = in.readString(); - this.body = new Body(in); + remoteCluster = in.readString(); + leaderIndexPatterns = in.readStringList(); + followIndexNamePattern = in.readOptionalString(); + if (in.getVersion().onOrAfter(Version.V_7_0_0)) { + parameters = new FollowParameters(in); + } else { + parameters = new FollowParameters(); + parameters.maxReadRequestOperationCount = in.readOptionalVInt(); + parameters.maxReadRequestSize = in.readOptionalWriteable(ByteSizeValue::new); + parameters.maxOutstandingReadRequests = in.readOptionalVInt(); + parameters.maxWriteRequestOperationCount = in.readOptionalVInt(); + parameters.maxWriteRequestSize = in.readOptionalWriteable(ByteSizeValue::new); + parameters.maxOutstandingWriteRequests = in.readOptionalVInt(); + parameters.maxWriteBufferCount = in.readOptionalVInt(); + parameters.maxWriteBufferSize = in.readOptionalWriteable(ByteSizeValue::new); + parameters.maxRetryDelay = in.readOptionalTimeValue(); + parameters.readPollTimeout = in.readOptionalTimeValue(); + } } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(name); - body.writeTo(out); + out.writeString(remoteCluster); + out.writeStringCollection(leaderIndexPatterns); + out.writeOptionalString(followIndexNamePattern); + if (out.getVersion().onOrAfter(Version.V_7_0_0)) { + parameters.writeTo(out); + } else { + out.writeOptionalVInt(parameters.maxReadRequestOperationCount); + out.writeOptionalWriteable(parameters.maxReadRequestSize); + out.writeOptionalVInt(parameters.maxOutstandingReadRequests); + out.writeOptionalVInt(parameters.maxWriteRequestOperationCount); + out.writeOptionalWriteable(parameters.maxWriteRequestSize); + out.writeOptionalVInt(parameters.maxOutstandingWriteRequests); + out.writeOptionalVInt(parameters.maxWriteBufferCount); + out.writeOptionalWriteable(parameters.maxWriteBufferSize); + out.writeOptionalTimeValue(parameters.maxRetryDelay); + out.writeOptionalTimeValue(parameters.readPollTimeout); + } } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - return body.toXContent(builder, params); + builder.startObject(); + { + builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster); + builder.field(AutoFollowPattern.LEADER_PATTERNS_FIELD.getPreferredName(), leaderIndexPatterns); + if (followIndexNamePattern != null) { + builder.field(AutoFollowPattern.FOLLOW_PATTERN_FIELD.getPreferredName(), followIndexNamePattern); + } + parameters.toXContentFragment(builder); + } + builder.endObject(); + return builder; } @Override @@ -120,141 +210,22 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; Request request = (Request) o; return Objects.equals(name, request.name) && - Objects.equals(body, request.body); + Objects.equals(remoteCluster, request.remoteCluster) && + Objects.equals(leaderIndexPatterns, request.leaderIndexPatterns) && + Objects.equals(followIndexNamePattern, request.followIndexNamePattern) && + Objects.equals(parameters, request.parameters); } @Override public int hashCode() { - return Objects.hash(name, body); + return Objects.hash(name, remoteCluster, leaderIndexPatterns, followIndexNamePattern, parameters); } - public static class Body extends FollowParameters implements ToXContentObject { - - private static final ObjectParser PARSER = new ObjectParser<>("put_auto_follow_pattern_request", Body::new); - - static { - PARSER.declareString(Body::setRemoteCluster, REMOTE_CLUSTER_FIELD); - PARSER.declareStringArray(Body::setLeaderIndexPatterns, AutoFollowPattern.LEADER_PATTERNS_FIELD); - PARSER.declareString(Body::setFollowIndexNamePattern, AutoFollowPattern.FOLLOW_PATTERN_FIELD); - initParser(PARSER); - } + private static class Body extends FollowParameters { private String remoteCluster; private List leaderIndexPatterns; private String followIndexNamePattern; - - public Body() { - } - - public String getRemoteCluster() { - return remoteCluster; - } - - public void setRemoteCluster(String remoteCluster) { - this.remoteCluster = remoteCluster; - } - - public List getLeaderIndexPatterns() { - return leaderIndexPatterns; - } - - public void setLeaderIndexPatterns(List leaderIndexPatterns) { - this.leaderIndexPatterns = leaderIndexPatterns; - } - - public String getFollowIndexNamePattern() { - return followIndexNamePattern; - } - - public void setFollowIndexNamePattern(String followIndexNamePattern) { - this.followIndexNamePattern = followIndexNamePattern; - } - - @Override - public ActionRequestValidationException validate() { - ActionRequestValidationException validationException = super.validate(); - if (remoteCluster == null) { - validationException = addValidationError("[" + REMOTE_CLUSTER_FIELD.getPreferredName() + - "] is missing", validationException); - } - if (leaderIndexPatterns == null || leaderIndexPatterns.isEmpty()) { - validationException = addValidationError("[" + AutoFollowPattern.LEADER_PATTERNS_FIELD.getPreferredName() + - "] is missing", validationException); - } - return validationException; - } - - Body(StreamInput in) throws IOException { - remoteCluster = in.readString(); - leaderIndexPatterns = in.readStringList(); - followIndexNamePattern = in.readOptionalString(); - if (in.getVersion().onOrAfter(Version.V_7_0_0)) { - fromStreamInput(in); - } else { - maxReadRequestOperationCount = in.readOptionalVInt(); - maxReadRequestSize = in.readOptionalWriteable(ByteSizeValue::new); - maxOutstandingReadRequests = in.readOptionalVInt(); - maxWriteRequestOperationCount = in.readOptionalVInt(); - maxWriteRequestSize = in.readOptionalWriteable(ByteSizeValue::new); - maxOutstandingWriteRequests = in.readOptionalVInt(); - maxWriteBufferCount = in.readOptionalVInt(); - maxWriteBufferSize = in.readOptionalWriteable(ByteSizeValue::new); - maxRetryDelay = in.readOptionalTimeValue(); - readPollTimeout = in.readOptionalTimeValue(); - } - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(remoteCluster); - out.writeStringCollection(leaderIndexPatterns); - out.writeOptionalString(followIndexNamePattern); - if (out.getVersion().onOrAfter(Version.V_7_0_0)) { - super.writeTo(out); - } else { - out.writeOptionalVInt(maxReadRequestOperationCount); - out.writeOptionalWriteable(maxReadRequestSize); - out.writeOptionalVInt(maxOutstandingReadRequests); - out.writeOptionalVInt(maxWriteRequestOperationCount); - out.writeOptionalWriteable(maxWriteRequestSize); - out.writeOptionalVInt(maxOutstandingWriteRequests); - out.writeOptionalVInt(maxWriteBufferCount); - out.writeOptionalWriteable(maxWriteBufferSize); - out.writeOptionalTimeValue(maxRetryDelay); - out.writeOptionalTimeValue(readPollTimeout); - } - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - { - builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster); - builder.field(AutoFollowPattern.LEADER_PATTERNS_FIELD.getPreferredName(), leaderIndexPatterns); - if (followIndexNamePattern != null) { - builder.field(AutoFollowPattern.FOLLOW_PATTERN_FIELD.getPreferredName(), followIndexNamePattern); - } - toXContentFragment(builder); - } - builder.endObject(); - return builder; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - Body body = (Body) o; - return Objects.equals(remoteCluster, body.remoteCluster) && - Objects.equals(leaderIndexPatterns, body.leaderIndexPatterns) && - Objects.equals(followIndexNamePattern, body.followIndexNamePattern); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), remoteCluster, leaderIndexPatterns, followIndexNamePattern); - } } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java index 1b5a3d4116dd2..d6f00c3922fb9 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java @@ -49,19 +49,33 @@ public Writeable.Reader getResponseReader() { public static class Request extends AcknowledgedRequest implements IndicesRequest, ToXContentObject { + private static final ParseField REMOTE_CLUSTER_FIELD = new ParseField("remote_cluster"); + private static final ParseField LEADER_INDEX_FIELD = new ParseField("leader_index"); + private static final ObjectParser PARSER = new ObjectParser<>(NAME, PutFollowParameters::new); + + static { + PARSER.declareString((putFollowParameters, value) -> putFollowParameters.remoteCluster = value, REMOTE_CLUSTER_FIELD); + PARSER.declareString((putFollowParameters, value) -> putFollowParameters.leaderIndex = value, LEADER_INDEX_FIELD); + FollowParameters.initParser(PARSER); + } + public static Request fromXContent(final XContentParser parser, final String followerIndex, ActiveShardCount waitForActiveShards) throws IOException { - Body body = Body.PARSER.parse(parser, null); + PutFollowParameters parameters = PARSER.parse(parser, null); Request request = new Request(); - request.setFollowerIndex(followerIndex); - request.setBody(body); request.waitForActiveShards(waitForActiveShards); + request.setFollowerIndex(followerIndex); + request.setRemoteCluster(parameters.remoteCluster); + request.setLeaderIndex(parameters.leaderIndex); + request.setParameters(parameters); return request; } + private String remoteCluster; + private String leaderIndex; private String followerIndex; - private Body body = new Body(); + private FollowParameters parameters = new FollowParameters(); private ActiveShardCount waitForActiveShards = ActiveShardCount.NONE; public Request() { @@ -75,12 +89,28 @@ public void setFollowerIndex(String followerIndex) { this.followerIndex = followerIndex; } - public Body getBody() { - return body; + public String getRemoteCluster() { + return remoteCluster; + } + + public void setRemoteCluster(String remoteCluster) { + this.remoteCluster = remoteCluster; + } + + public String getLeaderIndex() { + return leaderIndex; + } + + public void setLeaderIndex(String leaderIndex) { + this.leaderIndex = leaderIndex; } - public void setBody(Body body) { - this.body = body; + public FollowParameters getParameters() { + return parameters; + } + + public void setParameters(FollowParameters parameters) { + this.parameters = parameters; } public ActiveShardCount waitForActiveShards() { @@ -106,7 +136,13 @@ public void waitForActiveShards(ActiveShardCount waitForActiveShards) { @Override public ActionRequestValidationException validate() { - ActionRequestValidationException e = body.validate(); + ActionRequestValidationException e = parameters.validate(); + if (remoteCluster == null) { + e = addValidationError(REMOTE_CLUSTER_FIELD.getPreferredName() + " is missing", e); + } + if (leaderIndex == null) { + e = addValidationError(LEADER_INDEX_FIELD.getPreferredName() + " is missing", e); + } if (followerIndex == null) { e = addValidationError("follower_index is missing", e); } @@ -125,15 +161,10 @@ public IndicesOptions indicesOptions() { public Request(StreamInput in) throws IOException { super(in); - if (in.getVersion().onOrAfter(Version.V_7_0_0)) { - this.followerIndex = in.readString(); - body = new Body(in); - } else { - String remoteCluster = in.readString(); - String leaderIndex = in.readString(); - this.followerIndex = in.readString(); - body = new Body(in, remoteCluster, leaderIndex); - } + this.remoteCluster = in.readString(); + this.leaderIndex = in.readString(); + this.followerIndex = in.readString(); + this.parameters = new FollowParameters(in); if (in.getVersion().onOrAfter(Version.V_6_7_0)) { waitForActiveShards(ActiveShardCount.readFrom(in)); } @@ -142,12 +173,10 @@ public Request(StreamInput in) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - if (out.getVersion().onOrAfter(Version.V_7_0_0)) { - out.writeString(followerIndex); - body.writeTo(out); - } else { - body.writeTo(out, followerIndex); - } + out.writeString(remoteCluster); + out.writeString(leaderIndex); + out.writeString(followerIndex); + parameters.writeTo(out); if (out.getVersion().onOrAfter(Version.V_6_7_0)) { waitForActiveShards.writeTo(out); } @@ -155,7 +184,14 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - return body.toXContent(builder, params); + builder.startObject(); + { + builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster); + builder.field(LEADER_INDEX_FIELD.getPreferredName(), leaderIndex); + parameters.toXContentFragment(builder); + } + builder.endObject(); + return builder; } @Override @@ -163,115 +199,22 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Request request = (Request) o; - return Objects.equals(followerIndex, request.followerIndex) && - Objects.equals(body, request.body) && + return Objects.equals(remoteCluster, request.remoteCluster) && + Objects.equals(leaderIndex, request.leaderIndex) && + Objects.equals(followerIndex, request.followerIndex) && + Objects.equals(parameters, request.parameters) && Objects.equals(waitForActiveShards, request.waitForActiveShards); } @Override public int hashCode() { - return Objects.hash(followerIndex, body, waitForActiveShards); + return Objects.hash(remoteCluster, leaderIndex, followerIndex, parameters, waitForActiveShards); } - public static class Body extends FollowParameters implements ToXContentObject { - - private static final ParseField REMOTE_CLUSTER_FIELD = new ParseField("remote_cluster"); - private static final ParseField LEADER_INDEX_FIELD = new ParseField("leader_index"); - - private static final ObjectParser PARSER = new ObjectParser<>(NAME, Body::new); - - static { - PARSER.declareString(Body::setRemoteCluster, REMOTE_CLUSTER_FIELD); - PARSER.declareString(Body::setLeaderIndex, LEADER_INDEX_FIELD); - initParser(PARSER); - } + private static class PutFollowParameters extends FollowParameters { private String remoteCluster; private String leaderIndex; - - public Body() { - } - - public String getRemoteCluster() { - return remoteCluster; - } - - public void setRemoteCluster(String remoteCluster) { - this.remoteCluster = remoteCluster; - } - - public String getLeaderIndex() { - return leaderIndex; - } - - public void setLeaderIndex(String leaderIndex) { - this.leaderIndex = leaderIndex; - } - - @Override - public ActionRequestValidationException validate() { - ActionRequestValidationException e = super.validate(); - if (remoteCluster == null) { - e = addValidationError(REMOTE_CLUSTER_FIELD.getPreferredName() + " is missing", e); - } - if (leaderIndex == null) { - e = addValidationError(LEADER_INDEX_FIELD.getPreferredName() + " is missing", e); - } - return e; - } - - public Body(StreamInput in) throws IOException { - this.remoteCluster = in.readString(); - this.leaderIndex = in.readString(); - fromStreamInput(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(remoteCluster); - out.writeString(leaderIndex); - super.writeTo(out); - } - - private Body(StreamInput in, String remoteCluster, String leaderIndex) throws IOException { - this.remoteCluster = remoteCluster; - this.leaderIndex = leaderIndex; - fromStreamInput(in); - } - - private void writeTo(StreamOutput out, String followerIndex) throws IOException { - out.writeString(remoteCluster); - out.writeString(leaderIndex); - out.writeString(followerIndex); - super.writeTo(out); - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - { - builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster); - builder.field(LEADER_INDEX_FIELD.getPreferredName(), leaderIndex); - toXContentFragment(builder); - } - builder.endObject(); - return builder; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - Body body = (Body) o; - return Objects.equals(remoteCluster, body.remoteCluster) && - Objects.equals(leaderIndex, body.leaderIndex); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), remoteCluster, leaderIndex); - } } } From f0ed61e8654afaba3962a6b54d0c5c8b111d0b94 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 4 Feb 2019 15:42:17 +0100 Subject: [PATCH 6/8] rename --- .../ccr/action/PutAutoFollowPatternAction.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java index a4ad1213ef419..bd2b1bc87cdaa 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java @@ -44,7 +44,8 @@ public AcknowledgedResponse newResponse() { public static class Request extends AcknowledgedRequest implements ToXContentObject { - private static final ObjectParser PARSER = new ObjectParser<>("put_auto_follow_pattern_request", Body::new); + private static final ObjectParser PARSER = + new ObjectParser<>("put_auto_follow_pattern_request", PutAutoFollowPatternParameters::new); static { PARSER.declareString((params, value) -> params.remoteCluster = value, REMOTE_CLUSTER_FIELD); @@ -54,13 +55,13 @@ public static class Request extends AcknowledgedRequest implements ToXC } public static Request fromXContent(XContentParser parser, String name) throws IOException { - Body body = PARSER.parse(parser, null); + PutAutoFollowPatternParameters parameters = PARSER.parse(parser, null); Request request = new Request(); request.setName(name); - request.setRemoteCluster(body.remoteCluster); - request.setLeaderIndexPatterns(body.leaderIndexPatterns); - request.setFollowIndexNamePattern(body.followIndexNamePattern); - request.setParameters(body); + request.setRemoteCluster(parameters.remoteCluster); + request.setLeaderIndexPatterns(parameters.leaderIndexPatterns); + request.setFollowIndexNamePattern(parameters.followIndexNamePattern); + request.setParameters(parameters); return request; } @@ -221,7 +222,7 @@ public int hashCode() { return Objects.hash(name, remoteCluster, leaderIndexPatterns, followIndexNamePattern, parameters); } - private static class Body extends FollowParameters { + private static class PutAutoFollowPatternParameters extends FollowParameters { private String remoteCluster; private List leaderIndexPatterns; From 93538d2eff11cd3c24c700ea9d2b6e6928330db3 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 5 Feb 2019 09:39:14 +0100 Subject: [PATCH 7/8] iter --- .../ccr/action/TransportPutFollowAction.java | 12 +----------- .../xpack/ccr/IndexFollowingIT.java | 2 +- .../xpack/core/ccr/action/FollowParameters.java | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java index a4a25f91b4583..84250baaeaa21 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java @@ -224,17 +224,7 @@ private void initiateFollowing( FollowParameters parameters = request.getParameters(); ResumeFollowAction.Request resumeFollowRequest = new ResumeFollowAction.Request(); resumeFollowRequest.setFollowerIndex(request.getFollowerIndex()); - resumeFollowRequest.getParameters().setMaxOutstandingReadRequests(parameters.getMaxOutstandingReadRequests()); - resumeFollowRequest.getParameters().setMaxOutstandingWriteRequests(parameters.getMaxOutstandingWriteRequests()); - resumeFollowRequest.getParameters().setMaxReadRequestOperationCount(parameters.getMaxReadRequestOperationCount()); - resumeFollowRequest.getParameters().setMaxWriteRequestOperationCount( - parameters.getMaxWriteRequestOperationCount()); - resumeFollowRequest.getParameters().setMaxReadRequestSize(parameters.getMaxReadRequestSize()); - resumeFollowRequest.getParameters().setMaxWriteRequestSize(parameters.getMaxWriteRequestSize()); - resumeFollowRequest.getParameters().setMaxWriteBufferCount(parameters.getMaxWriteBufferCount()); - resumeFollowRequest.getParameters().setMaxWriteBufferSize(parameters.getMaxWriteBufferSize()); - resumeFollowRequest.getParameters().setReadPollTimeout(parameters.getReadPollTimeout()); - resumeFollowRequest.getParameters().setMaxRetryDelay(parameters.getMaxRetryDelay()); + resumeFollowRequest.setParameters(new FollowParameters(parameters)); client.execute(ResumeFollowAction.INSTANCE, resumeFollowRequest, ActionListener.wrap( r -> listener.onResponse(new PutFollowAction.Response(true, true, r.isAcknowledged())), listener::onFailure diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java index d55ae3d67f2b0..28f845fe7d463 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java @@ -1016,7 +1016,7 @@ public void testIndexFallBehind() throws Exception { forceMergeRequest.maxNumSegments(1); leaderClient().admin().indices().forceMerge(forceMergeRequest).actionGet(); - followerClient().execute(ResumeFollowAction.INSTANCE, followRequest.getFollowRequest()).get(); + followerClient().execute(ResumeFollowAction.INSTANCE, resumeFollow("index2")).get(); assertBusy(() -> { List statuses = getFollowTaskStatuses("index2"); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java index 6a4f824e09842..001a79323ab38 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowParameters.java @@ -51,6 +51,19 @@ public class FollowParameters implements Writeable { public FollowParameters() { } + public FollowParameters(FollowParameters source) { + this.maxReadRequestOperationCount = source.maxReadRequestOperationCount; + this.maxWriteRequestOperationCount = source.maxWriteRequestOperationCount; + this.maxOutstandingReadRequests = source.maxOutstandingReadRequests; + this.maxOutstandingWriteRequests = source.maxOutstandingWriteRequests; + this.maxReadRequestSize = source.maxReadRequestSize; + this.maxWriteRequestSize = source.maxWriteRequestSize; + this.maxWriteBufferCount = source.maxWriteBufferCount; + this.maxWriteBufferSize = source.maxWriteBufferSize; + this.maxRetryDelay = source.maxRetryDelay; + this.readPollTimeout = source.readPollTimeout; + } + public Integer getMaxReadRequestOperationCount() { return maxReadRequestOperationCount; } @@ -237,7 +250,7 @@ XContentBuilder toXContentFragment(final XContentBuilder builder) throws IOExcep return builder; } - public static void initParser(AbstractObjectParser parser) { + public static

void initParser(AbstractObjectParser parser) { parser.declareInt(FollowParameters::setMaxReadRequestOperationCount, MAX_READ_REQUEST_OPERATION_COUNT); parser.declareInt(FollowParameters::setMaxWriteRequestOperationCount, MAX_WRITE_REQUEST_OPERATION_COUNT); parser.declareInt(FollowParameters::setMaxOutstandingReadRequests, MAX_OUTSTANDING_READ_REQUESTS); @@ -269,7 +282,7 @@ public static void initParser(AbstractObjectPars @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || (o instanceof FollowParameters == false)) return false; + if (o instanceof FollowParameters == false) return false; FollowParameters that = (FollowParameters) o; return Objects.equals(maxReadRequestOperationCount, that.maxReadRequestOperationCount) && Objects.equals(maxWriteRequestOperationCount, that.maxWriteRequestOperationCount) && From e85791462f44b7d6be9a2da2544b9fda0b7aa7f1 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 5 Feb 2019 09:57:13 +0100 Subject: [PATCH 8/8] added comments --- .../xpack/core/ccr/action/PutAutoFollowPatternAction.java | 4 ++++ .../elasticsearch/xpack/core/ccr/action/PutFollowAction.java | 5 +++++ .../xpack/core/ccr/action/ResumeFollowAction.java | 3 +++ 3 files changed, 12 insertions(+) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java index bd2b1bc87cdaa..1ae9801916bce 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java @@ -44,6 +44,9 @@ public AcknowledgedResponse newResponse() { public static class Request extends AcknowledgedRequest implements ToXContentObject { + // Note that Request should be the Value class here for this parser with a 'parameters' field that maps to + // PutAutoFollowPatternParameters class. But since two minor version are already released with duplicate + // follow parameters in several APIs, PutAutoFollowPatternParameters is now the Value class here. private static final ObjectParser PARSER = new ObjectParser<>("put_auto_follow_pattern_request", PutAutoFollowPatternParameters::new); @@ -222,6 +225,7 @@ public int hashCode() { return Objects.hash(name, remoteCluster, leaderIndexPatterns, followIndexNamePattern, parameters); } + // This class only exists for reuse of the FollowParameters class, see comment above the parser field. private static class PutAutoFollowPatternParameters extends FollowParameters { private String remoteCluster; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java index d6f00c3922fb9..89c18a9824ab4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java @@ -51,6 +51,10 @@ public static class Request extends AcknowledgedRequest implements Indi private static final ParseField REMOTE_CLUSTER_FIELD = new ParseField("remote_cluster"); private static final ParseField LEADER_INDEX_FIELD = new ParseField("leader_index"); + + // Note that Request should be the Value class here for this parser with a 'parameters' field that maps to + // PutFollowParameters class. But since two minor version are already released with duplicate follow parameters + // in several APIs, PutFollowParameters is now the Value class here. private static final ObjectParser PARSER = new ObjectParser<>(NAME, PutFollowParameters::new); static { @@ -211,6 +215,7 @@ public int hashCode() { return Objects.hash(remoteCluster, leaderIndex, followerIndex, parameters, waitForActiveShards); } + // This class only exists for reuse of the FollowParameters class, see comment above the parser field. private static class PutFollowParameters extends FollowParameters { private String remoteCluster; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java index e34c70c157344..547f04889a669 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ResumeFollowAction.java @@ -38,6 +38,9 @@ public AcknowledgedResponse newResponse() { public static class Request extends MasterNodeRequest implements ToXContentObject { + // Note that Request should be the Value class here for this parser with a 'parameters' field that maps to FollowParameters class + // But since two minor version are already released with duplicate follow parameters in several APIs, FollowParameters + // is now the Value class here. static final ObjectParser PARSER = new ObjectParser<>(NAME, FollowParameters::new); static {