Skip to content

Commit 0e5d6bd

Browse files
committed
Revert "Remove RestGetAllAliasesAction (#31308)"
This reverts commit 38b1a5f. Relates to #31516
1 parent adbfd1d commit 0e5d6bd

File tree

4 files changed

+106
-3
lines changed

4 files changed

+106
-3
lines changed

server/src/main/java/org/elasticsearch/action/ActionModule.java

+3
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
import org.elasticsearch.rest.action.admin.indices.RestFlushAction;
258258
import org.elasticsearch.rest.action.admin.indices.RestForceMergeAction;
259259
import org.elasticsearch.rest.action.admin.indices.RestGetAliasesAction;
260+
import org.elasticsearch.rest.action.admin.indices.RestGetAllAliasesAction;
260261
import org.elasticsearch.rest.action.admin.indices.RestGetFieldMappingAction;
261262
import org.elasticsearch.rest.action.admin.indices.RestGetIndexTemplateAction;
262263
import org.elasticsearch.rest.action.admin.indices.RestGetIndicesAction;
@@ -557,6 +558,8 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
557558
registerHandler.accept(new RestRestoreSnapshotAction(settings, restController));
558559
registerHandler.accept(new RestDeleteSnapshotAction(settings, restController));
559560
registerHandler.accept(new RestSnapshotsStatusAction(settings, restController));
561+
562+
registerHandler.accept(new RestGetAllAliasesAction(settings, restController));
560563
registerHandler.accept(new RestGetIndicesAction(settings, restController, indexScopedSettings, settingsFilter));
561564
registerHandler.accept(new RestIndicesStatsAction(settings, restController));
562565
registerHandler.accept(new RestIndicesSegmentsAction(settings, restController));

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java

-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ public class RestGetAliasesAction extends BaseRestHandler {
6060

6161
public RestGetAliasesAction(final Settings settings, final RestController controller) {
6262
super(settings);
63-
controller.registerHandler(GET, "/_alias", this);
64-
controller.registerHandler(GET, "/_aliases", this);
6563
controller.registerHandler(GET, "/_alias/{name}", this);
6664
controller.registerHandler(HEAD, "/_alias/{name}", this);
6765
controller.registerHandler(GET, "/{index}/_alias", this);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.admin.indices;
21+
22+
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
23+
import org.elasticsearch.action.admin.indices.get.GetIndexRequest.Feature;
24+
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
25+
import org.elasticsearch.action.support.IndicesOptions;
26+
import org.elasticsearch.client.node.NodeClient;
27+
import org.elasticsearch.cluster.metadata.AliasMetaData;
28+
import org.elasticsearch.common.Strings;
29+
import org.elasticsearch.common.settings.Settings;
30+
import org.elasticsearch.common.xcontent.ToXContent.Params;
31+
import org.elasticsearch.common.xcontent.XContentBuilder;
32+
import org.elasticsearch.rest.BaseRestHandler;
33+
import org.elasticsearch.rest.BytesRestResponse;
34+
import org.elasticsearch.rest.RestController;
35+
import org.elasticsearch.rest.RestRequest;
36+
import org.elasticsearch.rest.RestResponse;
37+
import org.elasticsearch.rest.action.RestBuilderListener;
38+
39+
import java.io.IOException;
40+
import java.util.List;
41+
42+
import static org.elasticsearch.rest.RestRequest.Method.GET;
43+
import static org.elasticsearch.rest.RestStatus.OK;
44+
45+
/**
46+
* The REST handler for retrieving all aliases
47+
*/
48+
public class RestGetAllAliasesAction extends BaseRestHandler {
49+
50+
public RestGetAllAliasesAction(final Settings settings, final RestController controller) {
51+
super(settings);
52+
controller.registerHandler(GET, "/_alias", this);
53+
controller.registerHandler(GET, "/_aliases", this);
54+
}
55+
56+
@Override
57+
public String getName() {
58+
return "get_all_aliases_action";
59+
}
60+
61+
@Override
62+
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
63+
final GetIndexRequest getIndexRequest = new GetIndexRequest();
64+
getIndexRequest.indices(Strings.EMPTY_ARRAY);
65+
getIndexRequest.features(Feature.ALIASES);
66+
getIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, getIndexRequest.indicesOptions()));
67+
getIndexRequest.local(request.paramAsBoolean("local", getIndexRequest.local()));
68+
getIndexRequest.humanReadable(request.paramAsBoolean("human", false));
69+
return channel -> client.admin().indices().getIndex(getIndexRequest, new RestBuilderListener<GetIndexResponse>(channel) {
70+
71+
@Override
72+
public RestResponse buildResponse(final GetIndexResponse response, final XContentBuilder builder) throws Exception {
73+
builder.startObject();
74+
{
75+
for (final String index : response.indices()) {
76+
builder.startObject(index);
77+
{
78+
writeAliases(response.aliases().get(index), builder, request);
79+
}
80+
builder.endObject();
81+
}
82+
}
83+
builder.endObject();
84+
85+
return new BytesRestResponse(OK, builder);
86+
}
87+
88+
private void writeAliases(final List<AliasMetaData> aliases, final XContentBuilder builder,
89+
final Params params) throws IOException {
90+
builder.startObject("aliases");
91+
{
92+
if (aliases != null) {
93+
for (final AliasMetaData alias : aliases) {
94+
AliasMetaData.Builder.toXContent(alias, builder, params);
95+
}
96+
}
97+
}
98+
builder.endObject();
99+
}
100+
});
101+
}
102+
103+
}

x-pack/qa/core-rest-tests-with-security/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ integTestRunner {
1515
['cat.aliases/10_basic/Empty cluster',
1616
'index/10_with_id/Index with ID',
1717
'indices.get_alias/10_basic/Get alias against closed indices',
18-
'indices.get_alias/20_empty/Check empty aliases when getting all aliases via /_alias',
1918
'cat.templates/10_basic/No templates',
2019
'cat.templates/10_basic/Sort templates',
2120
'cat.templates/10_basic/Multiple template',

0 commit comments

Comments
 (0)