Skip to content

Commit e457a92

Browse files
authored
Compatible Delete and Update rest actions (#58246)
based on compat/search branch fixed tests from delete and update directories. Delete test is still not fixed CompatRestIT. test {yaml=delete/70_mix_typeless_typeful/DELETE with typeless API on an index that has types} current state 1306tests | 174failures previously 1306tests | 197failures relates #54160
1 parent cacef33 commit e457a92

File tree

6 files changed

+230
-2
lines changed

6 files changed

+230
-2
lines changed

modules/rest-compatibility/src/main/java/org/elasticsearch/compat/RestCompatPlugin.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
99
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
10+
* http://www.apache.org/licenses/LICENSE-2.0
1111
*
1212
* Unless required by applicable law or agreed to in writing,
1313
* software distributed under the License is distributed on an
@@ -33,10 +33,12 @@
3333
import org.elasticsearch.rest.RestController;
3434
import org.elasticsearch.rest.RestHandler;
3535
import org.elasticsearch.rest.action.admin.indices.RestCreateIndexActionV7;
36+
import org.elasticsearch.rest.action.document.RestDeleteActionV7;
3637
import org.elasticsearch.rest.action.document.RestGetActionV7;
3738
import org.elasticsearch.rest.action.document.RestIndexActionV7;
3839
import org.elasticsearch.rest.action.document.RestMultiTermVectorsActionV7;
3940
import org.elasticsearch.rest.action.document.RestTermVectorsActionV7;
41+
import org.elasticsearch.rest.action.document.RestUpdateActionV7;
4042
import org.elasticsearch.rest.action.search.RestMultiSearchActionV7;
4143
import org.elasticsearch.rest.action.search.RestSearchActionV7;
4244
import org.elasticsearch.script.mustache.RestMultiSearchTemplateActionV7;
@@ -74,7 +76,9 @@ public List<RestHandler> getRestHandlers(
7476
new RestSearchActionV7(),
7577
new RestMultiSearchActionV7(settings),
7678
new RestSearchTemplateActionV7(),
77-
new RestMultiSearchTemplateActionV7(settings)
79+
new RestMultiSearchTemplateActionV7(settings),
80+
new RestDeleteActionV7(),
81+
new RestUpdateActionV7()
7882
);
7983
}
8084
return Collections.emptyList();
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.rest.action.document;
21+
22+
import org.elasticsearch.Version;
23+
import org.elasticsearch.client.node.NodeClient;
24+
import org.elasticsearch.common.logging.DeprecationLogger;
25+
import org.elasticsearch.rest.RestRequest;
26+
27+
import java.io.IOException;
28+
import java.util.List;
29+
30+
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
31+
32+
public class RestDeleteActionV7 extends RestDeleteAction {
33+
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestDeleteActionV7.class);
34+
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in "
35+
+ "document index requests is deprecated, use the /{index}/_doc/{id} endpoint instead.";
36+
37+
@Override
38+
public List<Route> routes() {
39+
return List.of(new Route(DELETE, "/{index}/{type}/{id}"));
40+
}
41+
42+
@Override
43+
public String getName() {
44+
return "document_delete_action_v7";
45+
}
46+
47+
@Override
48+
public Version compatibleWithVersion() {
49+
return Version.V_7_0_0;
50+
}
51+
52+
@Override
53+
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
54+
if (request.hasParam("type")) {
55+
request.param("type");
56+
deprecationLogger.deprecate("delete_with_types", TYPES_DEPRECATION_MESSAGE);
57+
// todo compatible log
58+
}
59+
60+
return super.prepareRequest(request, client);
61+
}
62+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.rest.action.document;
21+
22+
import org.elasticsearch.Version;
23+
import org.elasticsearch.client.node.NodeClient;
24+
import org.elasticsearch.common.logging.DeprecationLogger;
25+
import org.elasticsearch.rest.RestRequest;
26+
27+
import java.io.IOException;
28+
import java.util.List;
29+
30+
import static org.elasticsearch.rest.RestRequest.Method.POST;
31+
32+
public class RestUpdateActionV7 extends RestUpdateAction {
33+
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestGetActionV7.class);
34+
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in "
35+
+ "document update requests is deprecated, use the endpoint /{index}/_update/{id} instead.";
36+
37+
@Override
38+
public List<Route> routes() {
39+
return List.of(new Route(POST, "/{index}/{type}/{id}/_update"));
40+
}
41+
42+
@Override
43+
public String getName() {
44+
return "document_update_action_v7";
45+
}
46+
47+
@Override
48+
public Version compatibleWithVersion() {
49+
return Version.V_7_0_0;
50+
}
51+
52+
@Override
53+
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
54+
if (request.hasParam("type")) {
55+
request.param("type");
56+
deprecationLogger.deprecate("update_with_types", TYPES_DEPRECATION_MESSAGE);
57+
// todo compatible log
58+
}
59+
60+
return super.prepareRequest(request, client);
61+
}
62+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.rest.action.document;
21+
22+
import org.elasticsearch.compat.FakeCompatRestRequestBuilder;
23+
import org.elasticsearch.rest.RestRequest;
24+
import org.elasticsearch.test.rest.RestActionTestCase;
25+
import org.junit.Before;
26+
27+
public class RestDeleteActionV7Tests extends RestActionTestCase {
28+
@Before
29+
public void setUpAction() {
30+
controller().registerHandler(new RestDeleteActionV7());
31+
controller().registerHandler(new RestDeleteAction());
32+
}
33+
34+
public void testTypeInPath() {
35+
RestRequest deprecatedRequest = new FakeCompatRestRequestBuilder(xContentRegistry()).withMethod(RestRequest.Method.DELETE)
36+
.withPath("/some_index/some_type/some_id")
37+
.build();
38+
dispatchRequest(deprecatedRequest);
39+
assertWarnings(RestDeleteActionV7.TYPES_DEPRECATION_MESSAGE);
40+
41+
RestRequest validRequest = new FakeCompatRestRequestBuilder(xContentRegistry()).withMethod(RestRequest.Method.DELETE)
42+
.withPath("/some_index/_doc/some_id")
43+
.build();
44+
dispatchRequest(validRequest);
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.rest.action.document;
21+
22+
import org.elasticsearch.compat.FakeCompatRestRequestBuilder;
23+
import org.elasticsearch.rest.RestRequest;
24+
import org.elasticsearch.test.rest.RestActionTestCase;
25+
import org.junit.Before;
26+
27+
public class RestUpdateActionV7Tests extends RestActionTestCase {
28+
@Before
29+
public void setUpAction() {
30+
controller().registerHandler(new RestUpdateActionV7());
31+
controller().registerHandler(new RestUpdateAction());
32+
}
33+
34+
public void testTypeInPath() {
35+
RestRequest deprecatedRequest = new FakeCompatRestRequestBuilder(xContentRegistry()).withMethod(RestRequest.Method.POST)
36+
.withPath("/some_index/some_type/some_id/_update")
37+
.build();
38+
dispatchRequest(deprecatedRequest);
39+
assertWarnings(RestUpdateActionV7.TYPES_DEPRECATION_MESSAGE);
40+
41+
RestRequest validRequest = new FakeCompatRestRequestBuilder(xContentRegistry()).withMethod(RestRequest.Method.POST)
42+
.withPath("/some_index/_update/some_id")
43+
.build();
44+
dispatchRequest(validRequest);
45+
}
46+
}

server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ protected final String unrecognized(
148148
return message.toString();
149149
}
150150

151+
@Override
152+
public String toString() {
153+
return this.getClass()+"{" +
154+
"name=" + this.getName() + ", " +
155+
"compatibleWithVersion=" + this.compatibleWithVersion() +
156+
'}';
157+
}
158+
151159
/**
152160
* REST requests are handled by preparing a channel consumer that represents the execution of
153161
* the request against a channel.

0 commit comments

Comments
 (0)