diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java index c5a6857bfb8..f2c74f0ca2f 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.cluster.health; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.TransportMasterNodeReadOperationAction; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; @@ -139,7 +140,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadOperati } if (request.indices().length > 0) { try { - clusterState.metaData().concreteIndices(request.indices()); + clusterState.metaData().concreteIndices(request.indices(), IndicesOptions.ERROR_UNAVAILABLE_EXPAND_OPEN_CLOSE); waitForCounter++; } catch (IndexMissingException e) { response.status = ClusterHealthStatus.RED; // no indices, make sure its RED @@ -220,7 +221,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadOperati } String[] concreteIndices; try { - concreteIndices = clusterState.metaData().concreteIndicesIgnoreMissing(request.indices()); + concreteIndices = clusterState.metaData().concreteIndices(request.indices(), IndicesOptions.IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY); } catch (IndexMissingException e) { // one of the specified indices is not there - treat it as RED. ClusterHealthResponse response = new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState); diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java index c8da29c0a36..a87335dc932 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java @@ -19,15 +19,14 @@ package org.elasticsearch.action.admin.cluster.state; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.TransportMasterNodeReadOperationAction; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.common.inject.Inject; @@ -104,7 +103,7 @@ public class TransportClusterStateAction extends TransportMasterNodeReadOperatio } if (request.indices().length > 0) { - String[] indices = currentState.metaData().concreteIndicesIgnoreMissing(request.indices()); + String[] indices = currentState.metaData().concreteIndices(request.indices(), IndicesOptions.IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY); for (String filteredIndex : indices) { IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex); if (indexMetaData != null) { diff --git a/src/main/java/org/elasticsearch/action/support/IndicesOptions.java b/src/main/java/org/elasticsearch/action/support/IndicesOptions.java index b05f7746083..9820e43f10a 100644 --- a/src/main/java/org/elasticsearch/action/support/IndicesOptions.java +++ b/src/main/java/org/elasticsearch/action/support/IndicesOptions.java @@ -42,6 +42,16 @@ public class IndicesOptions { } } + /** + * Indices option that ignores unavailable indices, allows no indices and expand wildcards to open only indices + */ + public static IndicesOptions IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY = fromOptions(true, true, true, false); + /** + * Indices option that doesn't ignore unavailable indices, allows no indices and expand wildcards to both open and closed indices + */ + public static IndicesOptions ERROR_UNAVAILABLE_EXPAND_OPEN_CLOSE = fromOptions(false, true, true, true); + + private final byte id; private IndicesOptions(byte id) { diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index e0497104592..0d3c544a81e 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -623,20 +623,6 @@ public class MetaData implements Iterable { return null; } - /** - * Translates the provided indices (possibly aliased) into actual indices. - */ - public String[] concreteIndices(String[] indices) throws IndexMissingException { - return concreteIndices(indices, IndicesOptions.fromOptions(false, true, true, true)); - } - - /** - * Translates the provided indices (possibly aliased) into actual indices. - */ - public String[] concreteIndicesIgnoreMissing(String[] indices) { - return concreteIndices(indices, IndicesOptions.fromOptions(true, true, true, false)); - } - /** * Translates the provided indices (possibly aliased) into actual indices. */ diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java index df74a514ba8..caf94358119 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java @@ -22,6 +22,7 @@ package org.elasticsearch.cluster.metadata; import com.google.common.collect.Sets; import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsClusterStateUpdateRequest; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.*; import org.elasticsearch.cluster.ack.ClusterStateUpdateListener; import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse; @@ -228,7 +229,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements @Override public ClusterState execute(ClusterState currentState) { - String[] actualIndices = currentState.metaData().concreteIndices(request.indices()); + String[] actualIndices = currentState.metaData().concreteIndices(request.indices(), IndicesOptions.ERROR_UNAVAILABLE_EXPAND_OPEN_CLOSE); RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable()); MetaData.Builder metaDataBuilder = MetaData.builder(currentState.metaData()); diff --git a/src/main/java/org/elasticsearch/index/query/IndicesFilterParser.java b/src/main/java/org/elasticsearch/index/query/IndicesFilterParser.java index e8d8e77f116..753469a7d65 100644 --- a/src/main/java/org/elasticsearch/index/query/IndicesFilterParser.java +++ b/src/main/java/org/elasticsearch/index/query/IndicesFilterParser.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.query; import org.apache.lucene.search.Filter; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.Inject; @@ -145,7 +146,7 @@ public class IndicesFilterParser implements FilterParser { } protected boolean matchesIndices(String currentIndex, String... indices) { - final String[] concreteIndices = clusterService.state().metaData().concreteIndicesIgnoreMissing(indices); + final String[] concreteIndices = clusterService.state().metaData().concreteIndices(indices, IndicesOptions.IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY); for (String index : concreteIndices) { if (Regex.simpleMatch(index, currentIndex)) { return true; diff --git a/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java b/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java index 34fba493dbf..1e019a7f2a8 100644 --- a/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.query; import org.apache.lucene.search.Query; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.Inject; @@ -146,7 +147,7 @@ public class IndicesQueryParser implements QueryParser { } protected boolean matchesIndices(String currentIndex, String... indices) { - final String[] concreteIndices = clusterService.state().metaData().concreteIndicesIgnoreMissing(indices); + final String[] concreteIndices = clusterService.state().metaData().concreteIndices(indices, IndicesOptions.IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY); for (String index : concreteIndices) { if (Regex.simpleMatch(index, currentIndex)) { return true; diff --git a/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java index 2ef578f3f63..76908843e23 100644 --- a/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java +++ b/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -27,6 +27,7 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.action.admin.indices.stats.IndexStats; import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; import org.elasticsearch.common.Strings; @@ -71,7 +72,7 @@ public class RestIndicesAction extends AbstractCatAction { client.admin().cluster().state(clusterStateRequest, new RestActionListener(channel) { @Override public void processResponse(final ClusterStateResponse clusterStateResponse) { - final String[] concreteIndices = clusterStateResponse.getState().metaData().concreteIndicesIgnoreMissing(indices); + final String[] concreteIndices = clusterStateResponse.getState().metaData().concreteIndices(indices, IndicesOptions.IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY); ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(concreteIndices); clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local())); client.admin().cluster().health(clusterHealthRequest, new RestActionListener(channel) { diff --git a/src/test/java/org/elasticsearch/cluster/ClusterHealthResponsesTests.java b/src/test/java/org/elasticsearch/cluster/ClusterHealthResponsesTests.java index e3894e648f0..9fc47121142 100644 --- a/src/test/java/org/elasticsearch/cluster/ClusterHealthResponsesTests.java +++ b/src/test/java/org/elasticsearch/cluster/ClusterHealthResponsesTests.java @@ -24,6 +24,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.action.admin.cluster.health.ClusterIndexHealth; import org.elasticsearch.action.admin.cluster.health.ClusterShardHealth; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.*; @@ -188,7 +189,7 @@ public class ClusterHealthResponsesTests extends ElasticsearchTestCase { routingTable.add(indexRoutingTable); } ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); - ClusterHealthResponse clusterHealth = new ClusterHealthResponse("bla", clusterState.metaData().concreteIndices(null), clusterState); + ClusterHealthResponse clusterHealth = new ClusterHealthResponse("bla", clusterState.metaData().concreteIndices(null, IndicesOptions.ERROR_UNAVAILABLE_EXPAND_OPEN_CLOSE), clusterState); logger.info("cluster status: {}, expected {}", clusterHealth.getStatus(), counter.status()); assertClusterHealth(clusterHealth, counter); @@ -209,7 +210,7 @@ public class ClusterHealthResponsesTests extends ElasticsearchTestCase { metaData.put(indexMetaData, true); routingTable.add(indexRoutingTable); ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); - ClusterHealthResponse clusterHealth = new ClusterHealthResponse("bla", clusterState.metaData().concreteIndices(null), clusterState); + ClusterHealthResponse clusterHealth = new ClusterHealthResponse("bla", clusterState.metaData().concreteIndices(null, IndicesOptions.ERROR_UNAVAILABLE_EXPAND_OPEN_CLOSE), clusterState); // currently we have no cluster level validation failures as index validation issues are reported per index. assertThat(clusterHealth.getValidationFailures(), Matchers.hasSize(0)); }