Skip to content

Commit

Permalink
[Rest Api Compatibility] Allow copy_settings flag for resize operatio…
Browse files Browse the repository at this point in the history
…ns (#75184)

previously removed in #38514, deprecated in 7.x and defaulted to true.
With rest api compatibility and when value is true it is ignored and warning is emitted
when value is false, an exception is thrown

relates #51816
  • Loading branch information
pgomulka authored Jul 12, 2021
1 parent caa7e16 commit 1855782
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 0 additions & 2 deletions rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ tasks.named("yamlRestCompatTest").configure {
'indices.open/10_basic/?wait_for_active_shards=index-setting',
// not fixing this in #70966
'indices.put_template/11_basic_with_types/Put template with empty mappings',
'indices.shrink/30_copy_settings/Copy settings during shrink index',
'indices.split/30_copy_settings/Copy settings during split index',
'mlt/20_docs/Basic mlt query with docs',
'mlt/30_unlike/Basic mlt query with unlike',
'search.aggregation/200_top_hits_metric/top_hits aggregation with sequence numbers',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -23,6 +26,7 @@
import static org.elasticsearch.rest.RestRequest.Method.PUT;

public abstract class RestResizeHandler extends BaseRestHandler {
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestResizeHandler.class);

RestResizeHandler() {
}
Expand All @@ -34,6 +38,15 @@ public abstract class RestResizeHandler extends BaseRestHandler {

@Override
public final RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
if (request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("copy_settings")) {
deprecationLogger.compatibleApiWarning("copy_settings", "parameter [copy_settings] is deprecated and will be removed in 8.0.0");

final String rawCopySettings = request.param("copy_settings");
final boolean copySettings = Booleans.parseBoolean(rawCopySettings);
if (copySettings == false) {
throw new IllegalArgumentException("parameter [copy_settings] can not be explicitly set to [false]");
}
}
final ResizeRequest resizeRequest = new ResizeRequest(request.param("target"), request.param("index"));
resizeRequest.setResizeType(getResizeType());
request.applyContentParser(resizeRequest::fromXContent);
Expand Down

0 comments on commit 1855782

Please sign in to comment.