Brought back the deprecated _aliases api.
This commit is contained in:
parent
9763d079b8
commit
e3327f5271
|
@ -46,6 +46,7 @@ import org.elasticsearch.rest.action.admin.cluster.tasks.RestPendingClusterTasks
|
|||
import org.elasticsearch.rest.action.admin.indices.alias.RestIndicesAliasesAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.delete.RestIndexDeleteAliasesAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.get.RestGetAliasesAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.get.RestGetIndicesAliasesAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.head.RestAliasesExistAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.put.RestIndexPutAliasAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.analyze.RestAnalyzeAction;
|
||||
|
@ -151,6 +152,7 @@ public class RestActionModule extends AbstractModule {
|
|||
bind(RestIndexDeleteAliasesAction.class).asEagerSingleton();
|
||||
bind(RestIndexPutAliasAction.class).asEagerSingleton();
|
||||
bind(RestIndicesAliasesAction.class).asEagerSingleton();
|
||||
bind(RestGetIndicesAliasesAction.class).asEagerSingleton();
|
||||
bind(RestCreateIndexAction.class).asEagerSingleton();
|
||||
bind(RestDeleteIndexAction.class).asEagerSingleton();
|
||||
bind(RestCloseIndexAction.class).asEagerSingleton();
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package org.elasticsearch.rest.action.admin.indices.alias.get;
|
||||
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Deprecated
|
||||
public class RestGetIndicesAliasesAction extends BaseRestHandler {
|
||||
|
||||
@Inject
|
||||
public RestGetIndicesAliasesAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
controller.registerHandler(GET, "/_aliases", this);
|
||||
controller.registerHandler(GET, "/{index}/_aliases", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
|
||||
ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest()
|
||||
.filterRoutingTable(true)
|
||||
.filterNodes(true)
|
||||
.filteredIndices(indices);
|
||||
|
||||
clusterStateRequest.listenerThreaded(false);
|
||||
|
||||
client.admin().cluster().state(clusterStateRequest, new ActionListener<ClusterStateResponse>() {
|
||||
@Override
|
||||
public void onResponse(ClusterStateResponse response) {
|
||||
try {
|
||||
MetaData metaData = response.getState().metaData();
|
||||
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
|
||||
builder.startObject();
|
||||
|
||||
for (IndexMetaData indexMetaData : metaData) {
|
||||
builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
|
||||
|
||||
builder.startObject("aliases");
|
||||
for (ObjectCursor<AliasMetaData> cursor : indexMetaData.aliases().values()) {
|
||||
AliasMetaData.Builder.toXContent(cursor.value, builder, ToXContent.EMPTY_PARAMS);
|
||||
}
|
||||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
builder.endObject();
|
||||
|
||||
channel.sendResponse(new XContentRestResponse(request, OK, builder));
|
||||
} catch (Throwable e) {
|
||||
onFailure(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new XContentThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue