Fix IndexMissingException in get template request

Fixes #2873
This commit is contained in:
Igor Motov 2013-04-04 15:53:50 -04:00
parent 3120457bfe
commit 2a588dc1f1
3 changed files with 15 additions and 6 deletions

View File

@ -32,6 +32,8 @@ import java.io.IOException;
*/ */
public class ClusterStateRequest extends MasterNodeOperationRequest<ClusterStateRequest> { public class ClusterStateRequest extends MasterNodeOperationRequest<ClusterStateRequest> {
public final static String NONE = "_na";
private boolean filterRoutingTable = false; private boolean filterRoutingTable = false;
private boolean filterNodes = false; private boolean filterNodes = false;
@ -104,6 +106,11 @@ public class ClusterStateRequest extends MasterNodeOperationRequest<ClusterState
return filteredIndices; return filteredIndices;
} }
public ClusterStateRequest filterOutIndices() {
this.filteredIndices = new String[]{NONE};
return this;
}
public ClusterStateRequest filteredIndices(String... filteredIndices) { public ClusterStateRequest filteredIndices(String... filteredIndices) {
this.filteredIndices = filteredIndices; this.filteredIndices = filteredIndices;
return this; return this;

View File

@ -95,11 +95,13 @@ public class TransportClusterStateAction extends TransportMasterNodeOperationAct
} }
if (request.filteredIndices().length > 0) { if (request.filteredIndices().length > 0) {
String[] indices = currentState.metaData().concreteIndicesIgnoreMissing(request.filteredIndices()); if (!(request.filteredIndices().length == 1 && ClusterStateRequest.NONE.equals(request.filteredIndices()[0]))) {
for (String filteredIndex : indices) { String[] indices = currentState.metaData().concreteIndicesIgnoreMissing(request.filteredIndices());
IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex); for (String filteredIndex : indices) {
if (indexMetaData != null) { IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex);
mdBuilder.put(indexMetaData, false); if (indexMetaData != null) {
mdBuilder.put(indexMetaData, false);
}
} }
} }
} }

View File

@ -64,7 +64,7 @@ public class RestGetIndexTemplateAction extends BaseRestHandler {
.filterRoutingTable(true) .filterRoutingTable(true)
.filterNodes(true) .filterNodes(true)
.filteredIndexTemplates(request.param("name")) .filteredIndexTemplates(request.param("name"))
.filteredIndices("_na"); .filterOutIndices();
clusterStateRequest.listenerThreaded(false); clusterStateRequest.listenerThreaded(false);