Indices exists API, closes #1022.

This commit is contained in:
kimchy 2011-06-12 12:01:29 +03:00
parent 5ee6bbfae9
commit 2dbe890022
16 changed files with 479 additions and 3 deletions

View File

@ -36,6 +36,7 @@ import org.elasticsearch.action.admin.indices.cache.clear.TransportClearIndicesC
import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction; import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction;
import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction; import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction; import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction;
import org.elasticsearch.action.admin.indices.exists.TransportIndicesExistsAction;
import org.elasticsearch.action.admin.indices.flush.TransportFlushAction; import org.elasticsearch.action.admin.indices.flush.TransportFlushAction;
import org.elasticsearch.action.admin.indices.gateway.snapshot.TransportGatewaySnapshotAction; import org.elasticsearch.action.admin.indices.gateway.snapshot.TransportGatewaySnapshotAction;
import org.elasticsearch.action.admin.indices.mapping.delete.TransportDeleteMappingAction; import org.elasticsearch.action.admin.indices.mapping.delete.TransportDeleteMappingAction;
@ -62,7 +63,15 @@ import org.elasticsearch.action.mlt.TransportMoreLikeThisAction;
import org.elasticsearch.action.percolate.TransportPercolateAction; import org.elasticsearch.action.percolate.TransportPercolateAction;
import org.elasticsearch.action.search.TransportSearchAction; import org.elasticsearch.action.search.TransportSearchAction;
import org.elasticsearch.action.search.TransportSearchScrollAction; import org.elasticsearch.action.search.TransportSearchScrollAction;
import org.elasticsearch.action.search.type.*; import org.elasticsearch.action.search.type.TransportSearchCache;
import org.elasticsearch.action.search.type.TransportSearchDfsQueryAndFetchAction;
import org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction;
import org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction;
import org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction;
import org.elasticsearch.action.search.type.TransportSearchScanAction;
import org.elasticsearch.action.search.type.TransportSearchScrollQueryAndFetchAction;
import org.elasticsearch.action.search.type.TransportSearchScrollQueryThenFetchAction;
import org.elasticsearch.action.search.type.TransportSearchScrollScanAction;
import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.AbstractModule;
/** /**
@ -90,6 +99,7 @@ public class TransportActionModule extends AbstractModule {
bind(TransportDeleteIndexAction.class).asEagerSingleton(); bind(TransportDeleteIndexAction.class).asEagerSingleton();
bind(TransportOpenIndexAction.class).asEagerSingleton(); bind(TransportOpenIndexAction.class).asEagerSingleton();
bind(TransportCloseIndexAction.class).asEagerSingleton(); bind(TransportCloseIndexAction.class).asEagerSingleton();
bind(TransportIndicesExistsAction.class).asEagerSingleton();
bind(TransportPutMappingAction.class).asEagerSingleton(); bind(TransportPutMappingAction.class).asEagerSingleton();
bind(TransportDeleteMappingAction.class).asEagerSingleton(); bind(TransportDeleteMappingAction.class).asEagerSingleton();
bind(TransportIndicesAliasesAction.class).asEagerSingleton(); bind(TransportIndicesAliasesAction.class).asEagerSingleton();

View File

@ -57,6 +57,7 @@ public class TransportActions {
public static final String REFRESH = "indices/refresh"; public static final String REFRESH = "indices/refresh";
public static final String OPTIMIZE = "indices/optimize"; public static final String OPTIMIZE = "indices/optimize";
public static final String STATUS = "indices/status"; public static final String STATUS = "indices/status";
public static final String EXISTS = "indices/exists";
public static final String ALIASES = "indices/aliases"; public static final String ALIASES = "indices/aliases";
public static final String UPDATE_SETTINGS = "indices/updateSettings"; public static final String UPDATE_SETTINGS = "indices/updateSettings";
public static final String ANALYZE = "indices/analyze"; public static final String ANALYZE = "indices/analyze";

View File

@ -0,0 +1,70 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.indices.exists;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
import static org.elasticsearch.action.Actions.*;
public class IndicesExistsRequest extends MasterNodeOperationRequest {
private String[] indices;
public IndicesExistsRequest(String... indices) {
this.indices = indices;
}
public String[] indices() {
return indices;
}
public void indices(String[] indices) {
this.indices = indices;
}
@Override public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (indices == null || indices.length == 0) {
validationException = addValidationError("index/indices is missing", validationException);
}
return validationException;
}
@Override public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
indices = new String[in.readVInt()];
for (int i = 0; i < indices.length; i++) {
indices[i] = in.readUTF();
}
}
@Override public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(indices.length);
for (String index : indices) {
out.writeUTF(index);
}
}
}

View File

@ -0,0 +1,55 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.indices.exists;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import java.io.IOException;
public class IndicesExistsResponse implements ActionResponse, Streamable {
private boolean exists;
IndicesExistsResponse() {
}
public IndicesExistsResponse(boolean exists) {
this.exists = exists;
}
public boolean exists() {
return this.exists;
}
public boolean isExists() {
return exists();
}
@Override public void readFrom(StreamInput in) throws IOException {
exists = in.readBoolean();
}
@Override public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(exists);
}
}

View File

@ -0,0 +1,81 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.indices.exists;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
/**
* Indices exists action.
*
* @author kimchy (shay.banon)
*/
public class TransportIndicesExistsAction extends TransportMasterNodeOperationAction<IndicesExistsRequest, IndicesExistsResponse> {
@Inject public TransportIndicesExistsAction(Settings settings, TransportService transportService, ClusterService clusterService,
ThreadPool threadPool) {
super(settings, transportService, clusterService, threadPool);
}
@Override protected String executor() {
return ThreadPool.Names.CACHED;
}
@Override protected String transportAction() {
return TransportActions.Admin.Indices.CLOSE;
}
@Override protected IndicesExistsRequest newRequest() {
return new IndicesExistsRequest();
}
@Override protected IndicesExistsResponse newResponse() {
return new IndicesExistsResponse();
}
@Override protected void doExecute(IndicesExistsRequest request, ActionListener<IndicesExistsResponse> listener) {
request.indices(clusterService.state().metaData().concreteIndices(request.indices()));
super.doExecute(request, listener);
}
@Override protected ClusterBlockException checkBlock(IndicesExistsRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, request.indices());
}
@Override protected IndicesExistsResponse masterOperation(IndicesExistsRequest request, ClusterState state) throws ElasticSearchException {
boolean exists = true;
for (String index : request.indices()) {
if (!state.metaData().hasConcreteIndex(index)) {
exists = false;
}
}
return new IndicesExistsResponse(exists);
}
}

View File

@ -33,6 +33,8 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.flush.FlushRequest; import org.elasticsearch.action.admin.indices.flush.FlushRequest;
import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.action.admin.indices.flush.FlushResponse;
import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest; import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest;
@ -61,6 +63,7 @@ import org.elasticsearch.client.action.admin.indices.cache.clear.ClearIndicesCac
import org.elasticsearch.client.action.admin.indices.close.CloseIndexRequestBuilder; import org.elasticsearch.client.action.admin.indices.close.CloseIndexRequestBuilder;
import org.elasticsearch.client.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.client.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.client.action.admin.indices.delete.DeleteIndexRequestBuilder; import org.elasticsearch.client.action.admin.indices.delete.DeleteIndexRequestBuilder;
import org.elasticsearch.client.action.admin.indices.exists.IndicesExistsRequestBuilder;
import org.elasticsearch.client.action.admin.indices.flush.FlushRequestBuilder; import org.elasticsearch.client.action.admin.indices.flush.FlushRequestBuilder;
import org.elasticsearch.client.action.admin.indices.gateway.snapshot.GatewaySnapshotRequestBuilder; import org.elasticsearch.client.action.admin.indices.gateway.snapshot.GatewaySnapshotRequestBuilder;
import org.elasticsearch.client.action.admin.indices.mapping.delete.DeleteMappingRequestBuilder; import org.elasticsearch.client.action.admin.indices.mapping.delete.DeleteMappingRequestBuilder;
@ -81,6 +84,29 @@ import org.elasticsearch.client.action.admin.indices.template.put.PutIndexTempla
*/ */
public interface IndicesAdminClient { public interface IndicesAdminClient {
/**
* Indices Exists.
*
* @param request The indices exists request
* @return The result future
* @see Requests#indicesExistsRequest(String...)
*/
ActionFuture<IndicesExistsResponse> exists(IndicesExistsRequest request);
/**
* The status of one or more indices.
*
* @param request The indices status request
* @param listener A listener to be notified with a result
* @see Requests#indicesExistsRequest(String...)
*/
void exists(IndicesExistsRequest request, ActionListener<IndicesExistsResponse> listener);
/**
* Indices exists.
*/
IndicesExistsRequestBuilder prepareExists(String... indices);
/** /**
* The status of one or more indices. * The status of one or more indices.
* *

View File

@ -33,6 +33,7 @@ import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheReque
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.flush.FlushRequest; import org.elasticsearch.action.admin.indices.flush.FlushRequest;
import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest; import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest;
import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest; import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest;
@ -187,6 +188,17 @@ public class Requests {
return new IndicesStatusRequest(indices); return new IndicesStatusRequest(indices);
} }
/**
* Creates an indices exists request.
*
* @param indices The indices to check if they exists or not.
* @return The indices exists request
* @see org.elasticsearch.client.IndicesAdminClient#exists(org.elasticsearch.action.admin.indices.exists.IndicesExistsRequest)
*/
public static IndicesExistsRequest indicesExistsRequest(String... indices) {
return new IndicesExistsRequest(indices);
}
/** /**
* Creates a create index request. * Creates a create index request.
* *

View File

@ -0,0 +1,45 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.action.admin.indices.exists;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsResponse;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.action.admin.indices.support.BaseIndicesRequestBuilder;
/**
* @author kimchy (shay.banon)
*/
public class IndicesExistsRequestBuilder extends BaseIndicesRequestBuilder<IndicesExistsRequest, IndicesExistsResponse> {
public IndicesExistsRequestBuilder(IndicesAdminClient indicesClient, String... indices) {
super(indicesClient, new IndicesExistsRequest(indices));
}
public IndicesExistsRequestBuilder setIndices(String... indices) {
request.indices(indices);
return this;
}
@Override protected void doExecute(ActionListener<IndicesExistsResponse> listener) {
client.exists(request, listener);
}
}

View File

@ -39,6 +39,9 @@ import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction; import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.exists.TransportIndicesExistsAction;
import org.elasticsearch.action.admin.indices.flush.FlushRequest; import org.elasticsearch.action.admin.indices.flush.FlushRequest;
import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.action.admin.indices.flush.FlushResponse;
import org.elasticsearch.action.admin.indices.flush.TransportFlushAction; import org.elasticsearch.action.admin.indices.flush.TransportFlushAction;
@ -85,6 +88,8 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
private final ThreadPool threadPool; private final ThreadPool threadPool;
private final TransportIndicesExistsAction indicesExistsAction;
private final TransportIndicesStatusAction indicesStatusAction; private final TransportIndicesStatusAction indicesStatusAction;
private final TransportCreateIndexAction createIndexAction; private final TransportCreateIndexAction createIndexAction;
@ -119,7 +124,7 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
private final TransportDeleteIndexTemplateAction deleteIndexTemplateAction; private final TransportDeleteIndexTemplateAction deleteIndexTemplateAction;
@Inject public NodeIndicesAdminClient(Settings settings, ThreadPool threadPool, TransportIndicesStatusAction indicesStatusAction, @Inject public NodeIndicesAdminClient(Settings settings, ThreadPool threadPool, TransportIndicesExistsAction indicesExistsAction, TransportIndicesStatusAction indicesStatusAction,
TransportCreateIndexAction createIndexAction, TransportDeleteIndexAction deleteIndexAction, TransportCreateIndexAction createIndexAction, TransportDeleteIndexAction deleteIndexAction,
TransportCloseIndexAction closeIndexAction, TransportOpenIndexAction openIndexAction, TransportCloseIndexAction closeIndexAction, TransportOpenIndexAction openIndexAction,
TransportRefreshAction refreshAction, TransportFlushAction flushAction, TransportOptimizeAction optimizeAction, TransportRefreshAction refreshAction, TransportFlushAction flushAction, TransportOptimizeAction optimizeAction,
@ -128,6 +133,7 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
TransportUpdateSettingsAction updateSettingsAction, TransportAnalyzeAction analyzeAction, TransportUpdateSettingsAction updateSettingsAction, TransportAnalyzeAction analyzeAction,
TransportPutIndexTemplateAction putIndexTemplateAction, TransportDeleteIndexTemplateAction deleteIndexTemplateAction) { TransportPutIndexTemplateAction putIndexTemplateAction, TransportDeleteIndexTemplateAction deleteIndexTemplateAction) {
this.threadPool = threadPool; this.threadPool = threadPool;
this.indicesExistsAction = indicesExistsAction;
this.indicesStatusAction = indicesStatusAction; this.indicesStatusAction = indicesStatusAction;
this.createIndexAction = createIndexAction; this.createIndexAction = createIndexAction;
this.deleteIndexAction = deleteIndexAction; this.deleteIndexAction = deleteIndexAction;
@ -151,6 +157,14 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
return this.threadPool; return this.threadPool;
} }
@Override public ActionFuture<IndicesExistsResponse> exists(IndicesExistsRequest request) {
return indicesExistsAction.execute(request);
}
@Override public void exists(IndicesExistsRequest request, ActionListener<IndicesExistsResponse> listener) {
indicesExistsAction.execute(request, listener);
}
@Override public ActionFuture<IndicesStatusResponse> status(IndicesStatusRequest request) { @Override public ActionFuture<IndicesStatusResponse> status(IndicesStatusRequest request) {
return indicesStatusAction.execute(request); return indicesStatusAction.execute(request);
} }

View File

@ -25,6 +25,7 @@ import org.elasticsearch.client.action.admin.indices.cache.clear.ClearIndicesCac
import org.elasticsearch.client.action.admin.indices.close.CloseIndexRequestBuilder; import org.elasticsearch.client.action.admin.indices.close.CloseIndexRequestBuilder;
import org.elasticsearch.client.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.client.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.client.action.admin.indices.delete.DeleteIndexRequestBuilder; import org.elasticsearch.client.action.admin.indices.delete.DeleteIndexRequestBuilder;
import org.elasticsearch.client.action.admin.indices.exists.IndicesExistsRequestBuilder;
import org.elasticsearch.client.action.admin.indices.flush.FlushRequestBuilder; import org.elasticsearch.client.action.admin.indices.flush.FlushRequestBuilder;
import org.elasticsearch.client.action.admin.indices.gateway.snapshot.GatewaySnapshotRequestBuilder; import org.elasticsearch.client.action.admin.indices.gateway.snapshot.GatewaySnapshotRequestBuilder;
import org.elasticsearch.client.action.admin.indices.mapping.delete.DeleteMappingRequestBuilder; import org.elasticsearch.client.action.admin.indices.mapping.delete.DeleteMappingRequestBuilder;
@ -43,6 +44,10 @@ import org.elasticsearch.client.internal.InternalIndicesAdminClient;
*/ */
public abstract class AbstractIndicesAdminClient implements InternalIndicesAdminClient { public abstract class AbstractIndicesAdminClient implements InternalIndicesAdminClient {
@Override public IndicesExistsRequestBuilder prepareExists(String... indices) {
return new IndicesExistsRequestBuilder(this, indices);
}
@Override public IndicesAliasesRequestBuilder prepareAliases() { @Override public IndicesAliasesRequestBuilder prepareAliases() {
return new IndicesAliasesRequestBuilder(this); return new IndicesAliasesRequestBuilder(this);
} }

View File

@ -34,6 +34,7 @@ import org.elasticsearch.client.transport.action.admin.indices.cache.clear.Clien
import org.elasticsearch.client.transport.action.admin.indices.close.ClientTransportCloseIndexAction; import org.elasticsearch.client.transport.action.admin.indices.close.ClientTransportCloseIndexAction;
import org.elasticsearch.client.transport.action.admin.indices.create.ClientTransportCreateIndexAction; import org.elasticsearch.client.transport.action.admin.indices.create.ClientTransportCreateIndexAction;
import org.elasticsearch.client.transport.action.admin.indices.delete.ClientTransportDeleteIndexAction; import org.elasticsearch.client.transport.action.admin.indices.delete.ClientTransportDeleteIndexAction;
import org.elasticsearch.client.transport.action.admin.indices.exists.ClientTransportIndicesExistsAction;
import org.elasticsearch.client.transport.action.admin.indices.flush.ClientTransportFlushAction; import org.elasticsearch.client.transport.action.admin.indices.flush.ClientTransportFlushAction;
import org.elasticsearch.client.transport.action.admin.indices.gateway.snapshot.ClientTransportGatewaySnapshotAction; import org.elasticsearch.client.transport.action.admin.indices.gateway.snapshot.ClientTransportGatewaySnapshotAction;
import org.elasticsearch.client.transport.action.admin.indices.mapping.delete.ClientTransportDeleteMappingAction; import org.elasticsearch.client.transport.action.admin.indices.mapping.delete.ClientTransportDeleteMappingAction;
@ -72,6 +73,7 @@ public class ClientTransportActionModule extends AbstractModule {
bind(ClientTransportBulkAction.class).asEagerSingleton(); bind(ClientTransportBulkAction.class).asEagerSingleton();
bind(ClientTransportPercolateAction.class).asEagerSingleton(); bind(ClientTransportPercolateAction.class).asEagerSingleton();
bind(ClientTransportIndicesExistsAction.class).asEagerSingleton();
bind(ClientTransportIndicesStatusAction.class).asEagerSingleton(); bind(ClientTransportIndicesStatusAction.class).asEagerSingleton();
bind(ClientTransportRefreshAction.class).asEagerSingleton(); bind(ClientTransportRefreshAction.class).asEagerSingleton();
bind(ClientTransportFlushAction.class).asEagerSingleton(); bind(ClientTransportFlushAction.class).asEagerSingleton();

View File

@ -0,0 +1,42 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.transport.action.admin.indices.exists;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsResponse;
import org.elasticsearch.client.transport.action.support.BaseClientTransportAction;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.transport.TransportService;
/**
* @author kimchy (Shay Banon)
*/
public class ClientTransportIndicesExistsAction extends BaseClientTransportAction<IndicesExistsRequest, IndicesExistsResponse> {
@Inject public ClientTransportIndicesExistsAction(Settings settings, TransportService transportService) {
super(settings, transportService, IndicesExistsResponse.class);
}
@Override protected String action() {
return TransportActions.Admin.Indices.EXISTS;
}
}

View File

@ -34,6 +34,8 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.flush.FlushRequest; import org.elasticsearch.action.admin.indices.flush.FlushRequest;
import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.action.admin.indices.flush.FlushResponse;
import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest; import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest;
@ -65,6 +67,7 @@ import org.elasticsearch.client.transport.action.admin.indices.cache.clear.Clien
import org.elasticsearch.client.transport.action.admin.indices.close.ClientTransportCloseIndexAction; import org.elasticsearch.client.transport.action.admin.indices.close.ClientTransportCloseIndexAction;
import org.elasticsearch.client.transport.action.admin.indices.create.ClientTransportCreateIndexAction; import org.elasticsearch.client.transport.action.admin.indices.create.ClientTransportCreateIndexAction;
import org.elasticsearch.client.transport.action.admin.indices.delete.ClientTransportDeleteIndexAction; import org.elasticsearch.client.transport.action.admin.indices.delete.ClientTransportDeleteIndexAction;
import org.elasticsearch.client.transport.action.admin.indices.exists.ClientTransportIndicesExistsAction;
import org.elasticsearch.client.transport.action.admin.indices.flush.ClientTransportFlushAction; import org.elasticsearch.client.transport.action.admin.indices.flush.ClientTransportFlushAction;
import org.elasticsearch.client.transport.action.admin.indices.gateway.snapshot.ClientTransportGatewaySnapshotAction; import org.elasticsearch.client.transport.action.admin.indices.gateway.snapshot.ClientTransportGatewaySnapshotAction;
import org.elasticsearch.client.transport.action.admin.indices.mapping.delete.ClientTransportDeleteMappingAction; import org.elasticsearch.client.transport.action.admin.indices.mapping.delete.ClientTransportDeleteMappingAction;
@ -90,6 +93,8 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli
private final ThreadPool threadPool; private final ThreadPool threadPool;
private final ClientTransportIndicesExistsAction indicesExistsAction;
private final ClientTransportIndicesStatusAction indicesStatusAction; private final ClientTransportIndicesStatusAction indicesStatusAction;
private final ClientTransportCreateIndexAction createIndexAction; private final ClientTransportCreateIndexAction createIndexAction;
@ -125,7 +130,7 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli
private final ClientTransportDeleteIndexTemplateAction deleteIndexTemplateAction; private final ClientTransportDeleteIndexTemplateAction deleteIndexTemplateAction;
@Inject public InternalTransportIndicesAdminClient(Settings settings, TransportClientNodesService nodesService, ThreadPool threadPool, @Inject public InternalTransportIndicesAdminClient(Settings settings, TransportClientNodesService nodesService, ThreadPool threadPool,
ClientTransportIndicesStatusAction indicesStatusAction, ClientTransportIndicesExistsAction indicesExistsAction, ClientTransportIndicesStatusAction indicesStatusAction,
ClientTransportCreateIndexAction createIndexAction, ClientTransportDeleteIndexAction deleteIndexAction, ClientTransportCreateIndexAction createIndexAction, ClientTransportDeleteIndexAction deleteIndexAction,
ClientTransportCloseIndexAction closeIndexAction, ClientTransportOpenIndexAction openIndexAction, ClientTransportCloseIndexAction closeIndexAction, ClientTransportOpenIndexAction openIndexAction,
ClientTransportRefreshAction refreshAction, ClientTransportFlushAction flushAction, ClientTransportOptimizeAction optimizeAction, ClientTransportRefreshAction refreshAction, ClientTransportFlushAction flushAction, ClientTransportOptimizeAction optimizeAction,
@ -135,6 +140,7 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli
ClientTransportPutIndexTemplateAction putIndexTemplateAction, ClientTransportDeleteIndexTemplateAction deleteIndexTemplateAction) { ClientTransportPutIndexTemplateAction putIndexTemplateAction, ClientTransportDeleteIndexTemplateAction deleteIndexTemplateAction) {
this.nodesService = nodesService; this.nodesService = nodesService;
this.threadPool = threadPool; this.threadPool = threadPool;
this.indicesExistsAction = indicesExistsAction;
this.indicesStatusAction = indicesStatusAction; this.indicesStatusAction = indicesStatusAction;
this.createIndexAction = createIndexAction; this.createIndexAction = createIndexAction;
this.deleteIndexAction = deleteIndexAction; this.deleteIndexAction = deleteIndexAction;
@ -158,6 +164,23 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli
return this.threadPool; return this.threadPool;
} }
@Override public ActionFuture<IndicesExistsResponse> exists(final IndicesExistsRequest request) {
return nodesService.execute(new TransportClientNodesService.NodeCallback<ActionFuture<IndicesExistsResponse>>() {
@Override public ActionFuture<IndicesExistsResponse> doWithNode(DiscoveryNode node) throws ElasticSearchException {
return indicesExistsAction.execute(node, request);
}
});
}
@Override public void exists(final IndicesExistsRequest request, final ActionListener<IndicesExistsResponse> listener) {
nodesService.execute(new TransportClientNodesService.NodeCallback<Void>() {
@Override public Void doWithNode(DiscoveryNode node) throws ElasticSearchException {
indicesExistsAction.execute(node, request, listener);
return null;
}
});
}
@Override public ActionFuture<IndicesStatusResponse> status(final IndicesStatusRequest request) { @Override public ActionFuture<IndicesStatusResponse> status(final IndicesStatusRequest request) {
return nodesService.execute(new TransportClientNodesService.NodeCallback<ActionFuture<IndicesStatusResponse>>() { return nodesService.execute(new TransportClientNodesService.NodeCallback<ActionFuture<IndicesStatusResponse>>() {
@Override public ActionFuture<IndicesStatusResponse> doWithNode(DiscoveryNode node) throws ElasticSearchException { @Override public ActionFuture<IndicesStatusResponse> doWithNode(DiscoveryNode node) throws ElasticSearchException {

View File

@ -38,6 +38,7 @@ import org.elasticsearch.rest.action.admin.indices.cache.clear.RestClearIndicesC
import org.elasticsearch.rest.action.admin.indices.close.RestCloseIndexAction; import org.elasticsearch.rest.action.admin.indices.close.RestCloseIndexAction;
import org.elasticsearch.rest.action.admin.indices.create.RestCreateIndexAction; import org.elasticsearch.rest.action.admin.indices.create.RestCreateIndexAction;
import org.elasticsearch.rest.action.admin.indices.delete.RestDeleteIndexAction; import org.elasticsearch.rest.action.admin.indices.delete.RestDeleteIndexAction;
import org.elasticsearch.rest.action.admin.indices.exists.RestIndicesExistsAction;
import org.elasticsearch.rest.action.admin.indices.flush.RestFlushAction; import org.elasticsearch.rest.action.admin.indices.flush.RestFlushAction;
import org.elasticsearch.rest.action.admin.indices.gateway.snapshot.RestGatewaySnapshotAction; import org.elasticsearch.rest.action.admin.indices.gateway.snapshot.RestGatewaySnapshotAction;
import org.elasticsearch.rest.action.admin.indices.mapping.delete.RestDeleteMappingAction; import org.elasticsearch.rest.action.admin.indices.mapping.delete.RestDeleteMappingAction;
@ -94,6 +95,7 @@ public class RestActionModule extends AbstractModule {
bind(RestBroadcastPingAction.class).asEagerSingleton(); bind(RestBroadcastPingAction.class).asEagerSingleton();
bind(RestReplicationPingAction.class).asEagerSingleton(); bind(RestReplicationPingAction.class).asEagerSingleton();
bind(RestIndicesExistsAction.class).asEagerSingleton();
bind(RestIndicesStatusAction.class).asEagerSingleton(); bind(RestIndicesStatusAction.class).asEagerSingleton();
bind(RestGetIndicesAliasesAction.class).asEagerSingleton(); bind(RestGetIndicesAliasesAction.class).asEagerSingleton();
bind(RestIndicesAliasesAction.class).asEagerSingleton(); bind(RestIndicesAliasesAction.class).asEagerSingleton();

View File

@ -0,0 +1,83 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.rest.action.admin.indices.exists;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.StringRestResponse;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.*;
import static org.elasticsearch.rest.RestStatus.*;
import static org.elasticsearch.rest.action.support.RestActions.*;
/**
* @author kimchy (Shay Banon)
*/
public class RestIndicesExistsAction extends BaseRestHandler {
private final SettingsFilter settingsFilter;
@Inject public RestIndicesExistsAction(Settings settings, Client client, RestController controller,
SettingsFilter settingsFilter) {
super(settings, client);
controller.registerHandler(HEAD, "/{index}", this);
this.settingsFilter = settingsFilter;
}
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(splitIndices(request.param("index")));
// we just send back a response, no need to fork a listener
indicesExistsRequest.listenerThreaded(false);
client.admin().indices().exists(indicesExistsRequest, new ActionListener<IndicesExistsResponse>() {
@Override public void onResponse(IndicesExistsResponse response) {
try {
if (response.exists()) {
channel.sendResponse(new StringRestResponse(OK));
} else {
channel.sendResponse(new StringRestResponse(NOT_FOUND));
}
} catch (Exception 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);
}
}
});
}
}

View File

@ -22,6 +22,7 @@ package org.elasticsearch.test.integration.document;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.action.admin.indices.flush.FlushResponse;
import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
@ -120,6 +121,10 @@ public class DocumentActionsTests extends AbstractNodesTests {
assertThat(refreshResponse.successfulShards(), equalTo(10)); assertThat(refreshResponse.successfulShards(), equalTo(10));
assertThat(refreshResponse.failedShards(), equalTo(0)); assertThat(refreshResponse.failedShards(), equalTo(0));
logger.info("--> index exists?");
IndicesExistsResponse indicesExistsResponse = client1.admin().indices().prepareExists(getConcreteIndexName()).execute().actionGet();
assertThat(indicesExistsResponse.exists(), equalTo(true));
logger.info("Clearing cache"); logger.info("Clearing cache");
ClearIndicesCacheResponse clearIndicesCacheResponse = client1.admin().indices().clearCache(clearIndicesCacheRequest("test")).actionGet(); ClearIndicesCacheResponse clearIndicesCacheResponse = client1.admin().indices().clearCache(clearIndicesCacheRequest("test")).actionGet();
assertThat(clearIndicesCacheResponse.successfulShards(), equalTo(10)); assertThat(clearIndicesCacheResponse.successfulShards(), equalTo(10));