diff options
88 files changed, 564 insertions, 663 deletions
diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 789589f3f6..57d82c14d7 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -26,7 +26,12 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.logging.support.LoggerMessageFormat; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexNotFoundException; +import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.index.shard.ShardNotFoundException; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesNotFoundException; import java.io.IOException; import java.lang.reflect.Constructor; @@ -39,6 +44,11 @@ import java.util.*; public class ElasticsearchException extends RuntimeException implements ToXContent { public static final String REST_EXCEPTION_SKIP_CAUSE = "rest.exception.skip_cause"; + private static final String INDEX_HEADER_KEY = "es.index"; + private static final String SHARD_HEADER_KEY = "es.shard"; + private static final String RESOURCE_HEADER_TYPE_KEY = "es.resource.type"; + private static final String RESOURCE_HEADER_ID_KEY = "es.resource.id"; + private static final Map<String, Constructor<? extends ElasticsearchException>> MAPPING; private final Map<String, List<String>> headers = new HashMap<>(); @@ -252,7 +262,14 @@ public class ElasticsearchException extends RuntimeException implements ToXConte } else { builder.field("type", getExceptionName()); builder.field("reason", getMessage()); + for (String key : headers.keySet()) { + if (key.startsWith("es.")) { + List<String> values = headers.get(key); + xContentHeader(builder, key.substring("es.".length()), values); + } + } innerToXContent(builder, params); + renderHeader(builder, params); } return builder; } @@ -277,6 +294,38 @@ public class ElasticsearchException extends RuntimeException implements ToXConte } } + protected final void renderHeader(XContentBuilder builder, Params params) throws IOException { + boolean hasHeader = false; + for (String key : headers.keySet()) { + if (key.startsWith("es.")) { + continue; + } + if (hasHeader == false) { + builder.startObject("header"); + hasHeader = true; + } + List<String> values = headers.get(key); + xContentHeader(builder, key, values); + } + if (hasHeader) { + builder.endObject(); + } + } + + private void xContentHeader(XContentBuilder builder, String key, List<String> values) throws IOException { + if (values != null && values.isEmpty() == false) { + if(values.size() == 1) { + builder.field(key, values.get(0)); + } else { + builder.startArray(key); + for (String value : values) { + builder.value(value); + } + builder.endArray(); + } + } + } + /** * Statis toXContent helper method that also renders non {@link org.elasticsearch.ElasticsearchException} instances as XContent. */ @@ -342,7 +391,15 @@ public class ElasticsearchException extends RuntimeException implements ToXConte @Override public String toString() { - return ExceptionsHelper.detailedMessage(this).trim(); + StringBuilder builder = new StringBuilder(); + if (headers.containsKey(INDEX_HEADER_KEY)) { + builder.append('[').append(getIndex()).append(']'); + if (headers.containsKey(SHARD_HEADER_KEY)) { + builder.append('[').append(getShardId()).append(']'); + } + builder.append(' '); + } + return builder.append(ExceptionsHelper.detailedMessage(this).trim()).toString(); } /** @@ -396,7 +453,6 @@ public class ElasticsearchException extends RuntimeException implements ToXConte org.elasticsearch.indices.recovery.RecoverFilesRecoveryException.class, org.elasticsearch.index.translog.TruncatedTranslogException.class, org.elasticsearch.repositories.RepositoryException.class, - org.elasticsearch.index.shard.IndexShardException.class, org.elasticsearch.index.engine.DocumentSourceMissingException.class, org.elasticsearch.index.engine.DocumentMissingException.class, org.elasticsearch.common.util.concurrent.EsRejectedExecutionException.class, @@ -421,12 +477,10 @@ public class ElasticsearchException extends RuntimeException implements ToXConte org.elasticsearch.index.snapshots.IndexShardSnapshotException.class, org.elasticsearch.search.query.QueryPhaseExecutionException.class, org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException.class, - org.elasticsearch.index.shard.IndexShardCreationException.class, org.elasticsearch.index.percolator.PercolatorException.class, org.elasticsearch.snapshots.ConcurrentSnapshotExecutionException.class, org.elasticsearch.indices.IndexTemplateAlreadyExistsException.class, org.elasticsearch.indices.InvalidIndexNameException.class, - org.elasticsearch.index.IndexException.class, org.elasticsearch.indices.recovery.DelayRecoveryException.class, org.elasticsearch.indices.AliasFilterParsingException.class, org.elasticsearch.indices.InvalidIndexTemplateException.class, @@ -443,7 +497,6 @@ public class ElasticsearchException extends RuntimeException implements ToXConte org.elasticsearch.cluster.block.ClusterBlockException.class, org.elasticsearch.action.FailedNodeException.class, org.elasticsearch.indices.TypeMissingException.class, - org.elasticsearch.index.IndexShardMissingException.class, org.elasticsearch.indices.InvalidTypeNameException.class, org.elasticsearch.transport.netty.SizeHeaderFrameDecoder.HttpOnTransportException.class, org.elasticsearch.common.util.CancellableThreads.ExecutionCancelledException.class, @@ -493,7 +546,6 @@ public class ElasticsearchException extends RuntimeException implements ToXConte org.elasticsearch.ElasticsearchTimeoutException.class, org.elasticsearch.search.SearchContextMissingException.class, org.elasticsearch.transport.SendRequestTransportException.class, - org.elasticsearch.indices.IndexMissingException.class, org.elasticsearch.index.IndexShardAlreadyExistsException.class, org.elasticsearch.indices.IndexAlreadyExistsException.class, org.elasticsearch.index.engine.DocumentAlreadyExistsException.class, @@ -504,7 +556,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte org.elasticsearch.index.shard.IndexShardNotStartedException.class, org.elasticsearch.index.mapper.StrictDynamicMappingException.class, org.elasticsearch.index.engine.EngineClosedException.class, - org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException.class, + AliasesNotFoundException.class, org.elasticsearch.transport.ResponseHandlerFailureTransportException.class, org.elasticsearch.search.SearchParseException.class, org.elasticsearch.search.fetch.FetchPhaseExecutionException.class, @@ -520,7 +572,6 @@ public class ElasticsearchException extends RuntimeException implements ToXConte org.elasticsearch.index.engine.RecoveryEngineException.class, org.elasticsearch.common.blobstore.BlobStoreException.class, org.elasticsearch.index.snapshots.IndexShardRestoreException.class, - org.elasticsearch.index.store.StoreException.class, org.elasticsearch.index.query.QueryParsingException.class, org.elasticsearch.action.support.replication.TransportReplicationAction.RetryOnPrimaryException.class, org.elasticsearch.index.engine.DeleteByQueryFailedEngineException.class, @@ -534,6 +585,9 @@ public class ElasticsearchException extends RuntimeException implements ToXConte org.elasticsearch.index.engine.CreateFailedEngineException.class, org.elasticsearch.index.shard.IllegalIndexShardStateException.class, ElasticsearchSecurityException.class, + ResourceNotFoundException.class, + IndexNotFoundException.class, + ShardNotFoundException.class, NotSerializableExceptionWrapper.class }; Map<String, Constructor<? extends ElasticsearchException>> mapping = new HashMap<>(exceptions.length); @@ -553,4 +607,58 @@ public class ElasticsearchException extends RuntimeException implements ToXConte MAPPING = Collections.unmodifiableMap(mapping); } + public String getIndex() { + List<String> index = getHeader(INDEX_HEADER_KEY); + if (index != null && index.isEmpty() == false) { + return index.get(0); + } + + return null; + } + + public ShardId getShardId() { + List<String> shard = getHeader(SHARD_HEADER_KEY); + if (shard != null && shard.isEmpty() == false) { + return new ShardId(getIndex(), Integer.parseInt(shard.get(0))); + } + return null; + } + + public void setIndex(Index index) { + if (index != null) { + addHeader(INDEX_HEADER_KEY, index.getName()); + } + } + + public void setIndex(String index) { + if (index != null) { + addHeader(INDEX_HEADER_KEY, index); + } + } + + public void setShard(ShardId shardId) { + if (shardId != null) { + addHeader(INDEX_HEADER_KEY, shardId.getIndex()); + addHeader(SHARD_HEADER_KEY, Integer.toString(shardId.id())); + } + } + + public void setResources(String type, String... id) { + assert type != null; + addHeader(RESOURCE_HEADER_ID_KEY, id); + addHeader(RESOURCE_HEADER_TYPE_KEY, type); + } + + public List<String> getResourceId() { + return getHeader(RESOURCE_HEADER_ID_KEY); + } + + public String getResourceType() { + List<String> header = getHeader(RESOURCE_HEADER_TYPE_KEY); + if (header != null && header.isEmpty() == false) { + assert header.size() == 1; + return header.get(0); + } + return null; + } } diff --git a/core/src/main/java/org/elasticsearch/ExceptionsHelper.java b/core/src/main/java/org/elasticsearch/ExceptionsHelper.java index c9f51cb5d5..df7be834eb 100644 --- a/core/src/main/java/org/elasticsearch/ExceptionsHelper.java +++ b/core/src/main/java/org/elasticsearch/ExceptionsHelper.java @@ -26,8 +26,6 @@ import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -240,12 +238,12 @@ public final class ExceptionsHelper { static class GroupBy { final String reason; - final Index index; + final String index; final Class<? extends Throwable> causeType; public GroupBy(Throwable t) { - if (t instanceof IndexException) { - index = ((IndexException) t).index(); + if (t instanceof ElasticsearchException) { + index = ((ElasticsearchException) t).getIndex(); } else { index = null; } diff --git a/core/src/main/java/org/elasticsearch/index/IndexShardMissingException.java b/core/src/main/java/org/elasticsearch/ResourceNotFoundException.java index 6b356ee685..d38de2e3bc 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexShardMissingException.java +++ b/core/src/main/java/org/elasticsearch/ResourceNotFoundException.java @@ -16,31 +16,32 @@ * specific language governing permissions and limitations * under the License. */ - -package org.elasticsearch.index; +package org.elasticsearch; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.index.shard.IndexShardException; -import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; import java.io.IOException; /** - * + * Generic ResourceNotFoundException corresponding to the {@link RestStatus#NOT_FOUND} status code */ -public class IndexShardMissingException extends IndexShardException { +public class ResourceNotFoundException extends ElasticsearchException { + + public ResourceNotFoundException(String msg, Object... args) { + super(msg, args); + } - public IndexShardMissingException(ShardId shardId) { - super(shardId, "missing"); + protected ResourceNotFoundException(String msg, Throwable cause, Object... args) { + super(msg, cause, args); } - public IndexShardMissingException(StreamInput in) throws IOException{ + public ResourceNotFoundException(StreamInput in) throws IOException { super(in); } @Override - public RestStatus status() { + public final RestStatus status() { return RestStatus.NOT_FOUND; } -}
\ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java b/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java index 3ab5869045..00562af99c 100644 --- a/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java +++ b/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java @@ -19,8 +19,8 @@ package org.elasticsearch.action; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; @@ -29,18 +29,19 @@ import java.io.IOException; /** * */ -public class NoShardAvailableActionException extends IndexShardException { +public class NoShardAvailableActionException extends ElasticsearchException { public NoShardAvailableActionException(ShardId shardId) { - super(shardId, null); + this(shardId, null); } public NoShardAvailableActionException(ShardId shardId, String msg) { - super(shardId, msg); + this(shardId, msg, null); } public NoShardAvailableActionException(ShardId shardId, String msg, Throwable cause) { - super(shardId, msg, cause); + super(msg, cause); + setShard(shardId); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java b/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java index 920d48b952..86bca96d74 100644 --- a/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java +++ b/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java @@ -32,8 +32,6 @@ import java.util.Objects; */ public class RoutingMissingException extends ElasticsearchException { - private final String index; - private final String type; private final String id; @@ -43,20 +41,16 @@ public class RoutingMissingException extends ElasticsearchException { Objects.requireNonNull(index, "index must not be null"); Objects.requireNonNull(type, "type must not be null"); Objects.requireNonNull(id, "id must not be null"); - this.index = index; + setIndex(index); this.type = type; this.id = id; } - public String index() { - return index; - } - - public String type() { + public String getType() { return type; } - public String id() { + public String getId() { return id; } @@ -67,7 +61,6 @@ public class RoutingMissingException extends ElasticsearchException { public RoutingMissingException(StreamInput in) throws IOException{ super(in); - index = in.readString(); type = in.readString(); id = in.readString(); } @@ -75,7 +68,6 @@ public class RoutingMissingException extends ElasticsearchException { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeString(index); out.writeString(type); out.writeString(id); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java index 39d533c79a..06d8d6361b 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java @@ -32,7 +32,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.gateway.GatewayAllocator; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -203,7 +203,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadAction< try { indexNameExpressionResolver.concreteIndices(clusterState, IndicesOptions.strictExpand(), request.indices()); waitForCounter++; - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { response.status = ClusterHealthStatus.RED; // no indices, make sure its RED // missing indices, wait a bit more... } @@ -269,7 +269,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadAction< String[] concreteIndices; try { concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { // one of the specified indices is not there - treat it as RED. ClusterHealthResponse response = new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState, numberOfPendingTasks, numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(settings, clusterState), diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java index d8f3f7f662..5cabb7f533 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java @@ -34,7 +34,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaDataIndexAliasesService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException; +import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesNotFoundException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -102,7 +102,7 @@ public class TransportIndicesAliasesAction extends TransportMasterNodeAction<Ind } } if (hasOnlyDeletesButNoneCanBeDone && actions.size() != 0) { - throw new AliasesMissingException(aliases.toArray(new String[aliases.size()])); + throw new AliasesNotFoundException(aliases.toArray(new String[aliases.size()])); } request.aliasActions().clear(); IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest() diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java index 324ba4431c..254b5fa0c6 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java @@ -30,7 +30,7 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -70,7 +70,7 @@ public class TransportIndicesExistsAction extends TransportMasterNodeReadAction< // Similar as the previous behaviour, but now also aliases and wildcards are supported. indexNameExpressionResolver.concreteIndices(state, request); exists = true; - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { exists = false; } listener.onResponse(new IndicesExistsResponse(exists)); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java index ec9ae1c6ea..b298cdff75 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java @@ -38,9 +38,9 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexService; -import org.elasticsearch.index.IndexShardMissingException; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.index.shard.ShardNotFoundException; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -125,7 +125,7 @@ public class TransportIndicesStatsAction extends TransportBroadcastAction<Indice IndexShard indexShard = indexService.shardSafe(request.shardId().id()); // if we don't have the routing entry yet, we need it stats wise, we treat it as if the shard is not ready yet if (indexShard.routingEntry() == null) { - throw new IndexShardMissingException(indexShard.shardId()); + throw new ShardNotFoundException(indexShard.shardId()); } CommonStatsFlags flags = new CommonStatsFlags().clear(); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/TransportDeleteWarmerAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/TransportDeleteWarmerAction.java index 20bd7c99f4..54a0c4d427 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/TransportDeleteWarmerAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/TransportDeleteWarmerAction.java @@ -33,8 +33,7 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.search.warmer.IndexWarmerMissingException; import org.elasticsearch.search.warmer.IndexWarmersMetaData; import org.elasticsearch.threadpool.ThreadPool; @@ -96,7 +95,7 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeAction<Delet for (String index : concreteIndices) { IndexMetaData indexMetaData = currentState.metaData().index(index); if (indexMetaData == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE); if (warmers != null) { @@ -132,7 +131,7 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeAction<Delet for (String index : concreteIndices) { IndexMetaData indexMetaData = currentState.metaData().index(index); if (indexMetaData == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE); if (warmers != null) { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/TransportPutWarmerAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/TransportPutWarmerAction.java index fdcbc418a6..9b0a5e273d 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/TransportPutWarmerAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/TransportPutWarmerAction.java @@ -37,8 +37,7 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.search.warmer.IndexWarmersMetaData; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -128,7 +127,7 @@ public class TransportPutWarmerAction extends TransportMasterNodeAction<PutWarme for (String index : concreteIndices) { IndexMetaData indexMetaData = metaData.index(index); if (indexMetaData == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE); if (warmers == null) { diff --git a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index 8e8097f880..67b31a3fac 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -50,10 +50,10 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.indices.IndexClosedException; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -363,12 +363,10 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul if (concreteIndex == null) { try { concreteIndex = concreteIndices.resolveIfAbsent(request); - } catch (IndexClosedException ice) { - unavailableException = ice; - } catch (IndexMissingException ime) { + } catch (IndexClosedException | IndexNotFoundException ex) { // Fix for issue where bulk request references an index that // cannot be auto-created see issue #8125 - unavailableException = ime; + unavailableException = ex; } } if (unavailableException == null) { diff --git a/core/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java b/core/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java index 43ec69d175..c485c747aa 100644 --- a/core/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java +++ b/core/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java @@ -36,9 +36,9 @@ import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.AtomicArray; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.engine.DocumentMissingException; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.percolator.PercolatorService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -166,7 +166,7 @@ public class TransportMultiPercolateAction extends HandledTransportAction<MultiP String[] concreteIndices; try { concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, percolateRequest); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { reducedResponses.set(slot, e); responsesByItemAndShard.set(slot, new AtomicReferenceArray(0)); expectedOperationsPerItem.set(slot, new AtomicInteger(0)); diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java index a8d27c49d8..180bf69d1c 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java @@ -25,8 +25,6 @@ import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; import java.io.IOException; diff --git a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java index 420bc61991..fda34657f1 100644 --- a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -28,8 +28,8 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.IndexClosedException; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -86,7 +86,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest, // if we only have one group, then we always want Q_A_F, no need for DFS, and no need to do THEN since we hit one shard searchRequest.searchType(QUERY_AND_FETCH); } - } catch (IndexMissingException|IndexClosedException e) { + } catch (IndexNotFoundException | IndexClosedException e) { // ignore these failures, we will notify the search response if its really the case from the actual action } catch (Exception e) { logger.debug("failed to optimize search type, continue as normal", e); diff --git a/core/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java b/core/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java index 313692d75b..7482cfdfdc 100644 --- a/core/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java +++ b/core/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java @@ -24,9 +24,7 @@ import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -49,9 +47,9 @@ public class DefaultShardOperationFailedException implements ShardOperationFaile private DefaultShardOperationFailedException() { } - public DefaultShardOperationFailedException(IndexShardException e) { - this.index = e.shardId().index().name(); - this.shardId = e.shardId().id(); + public DefaultShardOperationFailedException(ElasticsearchException e) { + this.index = e.getIndex(); + this.shardId = e.getShardId().id(); this.reason = e; this.status = e.status(); } diff --git a/core/src/main/java/org/elasticsearch/action/support/TransportActions.java b/core/src/main/java/org/elasticsearch/action/support/TransportActions.java index 0b4b72befb..1de3ef1aea 100644 --- a/core/src/main/java/org/elasticsearch/action/support/TransportActions.java +++ b/core/src/main/java/org/elasticsearch/action/support/TransportActions.java @@ -21,9 +21,9 @@ package org.elasticsearch.action.support; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.NoShardAvailableActionException; -import org.elasticsearch.index.IndexShardMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.shard.IllegalIndexShardStateException; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.shard.ShardNotFoundException; /** */ @@ -31,16 +31,10 @@ public class TransportActions { public static boolean isShardNotAvailableException(Throwable t) { Throwable actual = ExceptionsHelper.unwrapCause(t); - if (actual instanceof IllegalIndexShardStateException) { - return true; - } - if (actual instanceof IndexMissingException) { - return true; - } - if (actual instanceof IndexShardMissingException) { - return true; - } - if (actual instanceof NoShardAvailableActionException) { + if (actual instanceof ShardNotFoundException || + actual instanceof IndexNotFoundException || + actual instanceof IllegalIndexShardStateException || + actual instanceof NoShardAvailableActionException) { return true; } return false; diff --git a/core/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationFailedException.java b/core/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationFailedException.java index ca761470e2..fb42c7a6e4 100644 --- a/core/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationFailedException.java +++ b/core/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationFailedException.java @@ -19,9 +19,9 @@ package org.elasticsearch.action.support.broadcast; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchWrapperException; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; @@ -31,18 +31,19 @@ import java.io.IOException; * * */ -public class BroadcastShardOperationFailedException extends IndexShardException implements ElasticsearchWrapperException { +public class BroadcastShardOperationFailedException extends ElasticsearchException implements ElasticsearchWrapperException { public BroadcastShardOperationFailedException(ShardId shardId, String msg) { - super(shardId, msg, null); + this(shardId, msg, null); } public BroadcastShardOperationFailedException(ShardId shardId, Throwable cause) { - super(shardId, "", cause); + this(shardId, "", cause); } public BroadcastShardOperationFailedException(ShardId shardId, String msg, Throwable cause) { - super(shardId, msg, cause); + super(msg, cause); + setShard(shardId); } public BroadcastShardOperationFailedException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java index 545ce55bda..51155b538d 100644 --- a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.support.replication; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionWriteResponse; @@ -58,7 +59,6 @@ import org.elasticsearch.index.engine.VersionConflictEngineException; import org.elasticsearch.index.mapper.Mapping; import org.elasticsearch.index.mapper.SourceToParse; import org.elasticsearch.index.shard.IndexShard; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.translog.Translog; import org.elasticsearch.indices.IndicesService; @@ -242,10 +242,11 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ } } - public static class RetryOnReplicaException extends IndexShardException { + public static class RetryOnReplicaException extends ElasticsearchException { public RetryOnReplicaException(ShardId shardId, String msg) { - super(shardId, msg); + super(msg); + setShard(shardId); } public RetryOnReplicaException(StreamInput in) throws IOException{ @@ -325,9 +326,10 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ } } - public static class RetryOnPrimaryException extends IndexShardException { + public static class RetryOnPrimaryException extends ElasticsearchException { public RetryOnPrimaryException(ShardId shardId, String msg) { - super(shardId, msg); + super(msg); + setShard(shardId); } public RetryOnPrimaryException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java index ea658912c6..77c35fdcf5 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -23,7 +23,6 @@ import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import org.apache.commons.lang3.StringUtils; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.ClusterState; @@ -33,8 +32,8 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.IndexClosedException; -import org.elasticsearch.indices.IndexMissingException; import java.util.*; @@ -54,7 +53,7 @@ public class IndexNameExpressionResolver { * Same as {@link #concreteIndices(ClusterState, IndicesOptions, String...)}, but the index expressions and options * are encapsulated in the specified request. */ - public String[] concreteIndices(ClusterState state, IndicesRequest request) throws IndexMissingException, IllegalArgumentException { + public String[] concreteIndices(ClusterState state, IndicesRequest request) { Context context = new Context(state, request.indicesOptions()); return concreteIndices(context, request.indices()); } @@ -66,18 +65,18 @@ public class IndexNameExpressionResolver { * @param options defines how the aliases or indices need to be resolved to concrete indices * @param indexExpressions expressions that can be resolved to alias or index names. * @return the resolved concrete indices based on the cluster state, indices options and index expressions - * @throws IndexMissingException if one of the index expressions is pointing to a missing index or alias and the + * @throws IndexNotFoundException if one of the index expressions is pointing to a missing index or alias and the * provided indices options in the context don't allow such a case, or if the final result of the indices resolution * contains no indices and the indices options in the context don't allow such a case. * @throws IllegalArgumentException if one of the aliases resolve to multiple indices and the provided * indices options in the context don't allow such a case. */ - public String[] concreteIndices(ClusterState state, IndicesOptions options, String... indexExpressions) throws IndexMissingException, IllegalArgumentException { + public String[] concreteIndices(ClusterState state, IndicesOptions options, String... indexExpressions) { Context context = new Context(state, options); return concreteIndices(context, indexExpressions); } - String[] concreteIndices(Context context, String... indexExpressions) throws IndexMissingException, IllegalArgumentException { + String[] concreteIndices(Context context, String... indexExpressions) { if (indexExpressions == null || indexExpressions.length == 0) { indexExpressions = new String[]{MetaData.ALL}; } @@ -99,7 +98,9 @@ public class IndexNameExpressionResolver { if (expressions.isEmpty()) { if (!options.allowNoIndices()) { - throw new IndexMissingException(new Index(Arrays.toString(indexExpressions))); + IndexNotFoundException infe = new IndexNotFoundException((String)null); + infe.setResources("index_expression", indexExpressions); + throw infe; } else { return Strings.EMPTY_ARRAY; } @@ -113,7 +114,10 @@ public class IndexNameExpressionResolver { ImmutableOpenMap<String, AliasMetaData> indexAliasMap = metaData.aliases().get(expression); if (indexAliasMap == null) { if (failNoIndices) { - throw new IndexMissingException(new Index(expression)); + IndexNotFoundException infe = new IndexNotFoundException(expression); + infe.setResources("index_expression", expression); + throw infe; + } else { continue; } @@ -147,7 +151,9 @@ public class IndexNameExpressionResolver { } if (options.allowNoIndices() == false && concreteIndices.isEmpty()) { - throw new IndexMissingException(new Index(Arrays.toString(indexExpressions))); + IndexNotFoundException infe = new IndexNotFoundException((String)null); + infe.setResources("index_expression", indexExpressions); + throw infe; } return concreteIndices.toArray(new String[concreteIndices.size()]); } @@ -160,11 +166,11 @@ public class IndexNameExpressionResolver { * * @param request request containing the index or alias to be resolved to concrete index and * the indices options to be used for the index resolution - * @throws IndexMissingException if the resolved index or alias provided doesn't exist + * @throws IndexNotFoundException if the resolved index or alias provided doesn't exist * @throws IllegalArgumentException if the index resolution lead to more than one index * @return the concrete index obtained as a result of the index resolution */ - public String concreteSingleIndex(ClusterState state, IndicesRequest request) throws IndexMissingException, IllegalArgumentException { + public String concreteSingleIndex(ClusterState state, IndicesRequest request) { String indexOrAlias = request.indices() != null && request.indices().length > 0 ? request.indices()[0] : null; String[] indices = concreteIndices(state, request.indicesOptions(), indexOrAlias); if (indices.length != 1) { @@ -197,7 +203,7 @@ public class IndexNameExpressionResolver { IndexMetaData indexMetaData = state.metaData().getIndices().get(index); if (indexMetaData == null) { // Shouldn't happen - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } AliasMetaData aliasMetaData = indexMetaData.aliases().get(alias); boolean filteringRequired = aliasMetaData != null && aliasMetaData.filteringRequired(); @@ -215,7 +221,7 @@ public class IndexNameExpressionResolver { IndexMetaData indexMetaData = state.metaData().getIndices().get(index); if (indexMetaData == null) { // Shouldn't happen - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } AliasMetaData aliasMetaData = indexMetaData.aliases().get(alias); @@ -538,7 +544,9 @@ public class IndexNameExpressionResolver { } if (!Regex.isSimpleMatchPattern(aliasOrIndex)) { if (!options.ignoreUnavailable() && !metaData.getAliasAndIndexMap().containsKey(aliasOrIndex)) { - throw new IndexMissingException(new Index(aliasOrIndex)); + IndexNotFoundException infe = new IndexNotFoundException(aliasOrIndex); + infe.setResources("index_or_alias", aliasOrIndex); + throw infe; } if (result != null) { if (add) { @@ -590,14 +598,18 @@ public class IndexNameExpressionResolver { } } if (!found && !options.allowNoIndices()) { - throw new IndexMissingException(new Index(aliasOrIndex)); + IndexNotFoundException infe = new IndexNotFoundException(aliasOrIndex); + infe.setResources("index_or_alias", aliasOrIndex); + throw infe; } } if (result == null) { return expressions; } if (result.isEmpty() && !options.allowNoIndices()) { - throw new IndexMissingException(new Index(StringUtils.join(expressions.iterator(), ','))); + IndexNotFoundException infe = new IndexNotFoundException((String)null); + infe.setResources("index_or_alias", expressions.toArray(new String[0])); + throw infe; } return new ArrayList<>(result); } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index b9b5ab346e..a3d839f0d3 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -48,7 +48,7 @@ import org.elasticsearch.common.settings.loader.SettingsLoader; import org.elasticsearch.common.xcontent.*; import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.index.Index; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.recovery.RecoverySettings; import org.elasticsearch.indices.store.IndicesStore; import org.elasticsearch.indices.ttl.IndicesTTLService; @@ -943,7 +943,7 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData> { for (String index : indices) { IndexMetaData indexMetaData = this.indices.get(index); if (indexMetaData == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } put(IndexMetaData.builder(indexMetaData) .settings(settingsBuilder().put(indexMetaData.settings()).put(settings))); @@ -958,7 +958,7 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData> { for (String index : indices) { IndexMetaData indexMetaData = this.indices.get(index); if (indexMetaData == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } put(IndexMetaData.builder(indexMetaData).numberOfReplicas(numberOfReplicas)); } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java index 3d5d938bde..10bc32190a 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java @@ -34,8 +34,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.FutureUtils; -import org.elasticsearch.index.Index; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.threadpool.ThreadPool; import java.util.concurrent.ScheduledFuture; @@ -116,7 +115,7 @@ public class MetaDataDeleteIndexService extends AbstractComponent { @Override public ClusterState execute(final ClusterState currentState) { if (!currentState.metaData().hasConcreteIndex(request.index)) { - throw new IndexMissingException(new Index(request.index)); + throw new IndexNotFoundException(request.index); } logger.info("[{}] deleting index", request.index); diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java index 7ab2c08f56..fb2e933dcf 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java @@ -33,10 +33,9 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.IndexService; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.indices.IndicesService; import java.util.List; @@ -76,7 +75,7 @@ public class MetaDataIndexAliasesService extends AbstractComponent { for (AliasAction aliasAction : request.actions()) { aliasValidator.validateAliasAction(aliasAction, currentState.metaData()); if (!currentState.metaData().hasIndex(aliasAction.index())) { - throw new IndexMissingException(new Index(aliasAction.index())); + throw new IndexNotFoundException(aliasAction.index()); } } @@ -85,7 +84,7 @@ public class MetaDataIndexAliasesService extends AbstractComponent { for (AliasAction aliasAction : request.actions()) { IndexMetaData indexMetaData = builder.get(aliasAction.index()); if (indexMetaData == null) { - throw new IndexMissingException(new Index(aliasAction.index())); + throw new IndexNotFoundException(aliasAction.index()); } // TODO: not copy (putAll) IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(indexMetaData); diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java index c1113f8e68..f680ac1d5e 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java @@ -39,8 +39,7 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException; import org.elasticsearch.rest.RestStatus; @@ -87,7 +86,7 @@ public class MetaDataIndexStateService extends AbstractComponent { for (String index : request.indices()) { IndexMetaData indexMetaData = currentState.metaData().index(index); if (indexMetaData == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } if (indexMetaData.state() != IndexMetaData.State.CLOSE) { @@ -147,7 +146,7 @@ public class MetaDataIndexStateService extends AbstractComponent { for (String index : request.indices()) { IndexMetaData indexMetaData = currentState.metaData().index(index); if (indexMetaData == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } if (indexMetaData.state() != IndexMetaData.State.OPEN) { indicesToOpen.add(index); @@ -167,11 +166,7 @@ public class MetaDataIndexStateService extends AbstractComponent { IndexMetaData indexMetaData = IndexMetaData.builder(currentState.metaData().index(index)).state(IndexMetaData.State.OPEN).build(); // The index might be closed because we couldn't import it due to old incompatible version // We need to check that this index can be upgraded to the current version - try { - indexMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData); - } catch (Exception ex) { - throw new IndexException(new Index(index), "cannot open the index due to upgrade failure", ex); - } + indexMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData); mdBuilder.put(indexMetaData, true); blocksBuilder.removeIndexBlock(index, INDEX_CLOSED_BLOCK); } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java index b19f168760..f3af952e8b 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java @@ -81,7 +81,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { * If the index does not need upgrade it returns the index metadata unchanged, otherwise it returns a modified index metadata. If index * cannot be updated the method throws an exception. */ - public IndexMetaData upgradeIndexMetaData(IndexMetaData indexMetaData) throws Exception { + public IndexMetaData upgradeIndexMetaData(IndexMetaData indexMetaData) { // Throws an exception if there are too-old segments: checkSupportedVersion(indexMetaData); IndexMetaData newMetaData = upgradeLegacyRoutingSettings(indexMetaData); @@ -94,7 +94,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { * that were created before Elasticsearch v0.90.0 should be upgraded using upgrade plugin before they can * be open by this version of elasticsearch. */ - private void checkSupportedVersion(IndexMetaData indexMetaData) throws Exception { + private void checkSupportedVersion(IndexMetaData indexMetaData) { if (indexMetaData.getState() == IndexMetaData.State.OPEN && isSupportedVersion(indexMetaData) == false) { throw new IllegalStateException("The index [" + indexMetaData.getIndex() + "] was created before v0.90.0 and wasn't upgraded." + " This index should be open using a version before " + Version.CURRENT.minimumCompatibilityVersion() @@ -122,7 +122,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { * Elasticsearch 2.0 deprecated custom routing hash functions. So what we do here is that for old indices, we * move this old and deprecated node setting to an index setting so that we can keep things backward compatible. */ - private IndexMetaData upgradeLegacyRoutingSettings(IndexMetaData indexMetaData) throws Exception { + private IndexMetaData upgradeLegacyRoutingSettings(IndexMetaData indexMetaData) { if (indexMetaData.settings().get(IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION) == null && indexMetaData.getCreationVersion().before(Version.V_2_0_0_beta1)) { // these settings need an upgrade diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index 772c8d491c..04d52b0ea5 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -37,13 +37,12 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.index.mapper.MergeResult; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.InvalidTypeNameException; import org.elasticsearch.percolator.PercolatorService; @@ -347,7 +346,7 @@ public class MetaDataMappingService extends AbstractComponent { try { for (String index : request.indices()) { if (!currentState.metaData().hasIndex(index)) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } } @@ -472,7 +471,7 @@ public class MetaDataMappingService extends AbstractComponent { for (String indexName : request.indices()) { IndexMetaData indexMetaData = currentState.metaData().index(indexName); if (indexMetaData == null) { - throw new IndexMissingException(new Index(indexName)); + throw new IndexNotFoundException(indexName); } MappingMetaData mappingMd = mappings.get(indexName); if (mappingMd != null) { diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java index 57156f5763..ae12a387b7 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java @@ -32,10 +32,9 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.math.MathUtils; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexShardMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.shard.ShardNotFoundException; import java.util.Collections; import java.util.HashSet; @@ -57,32 +56,32 @@ public class OperationRouting extends AbstractComponent { this.awarenessAllocationDecider = awarenessAllocationDecider; } - public ShardIterator indexShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing) throws IndexMissingException, IndexShardMissingException { + public ShardIterator indexShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing) { return shards(clusterState, index, type, id, routing).shardsIt(); } - public ShardIterator deleteShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing) throws IndexMissingException, IndexShardMissingException { + public ShardIterator deleteShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing) { return shards(clusterState, index, type, id, routing).shardsIt(); } - public ShardIterator getShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing, @Nullable String preference) throws IndexMissingException, IndexShardMissingException { + public ShardIterator getShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing, @Nullable String preference) { return preferenceActiveShardIterator(shards(clusterState, index, type, id, routing), clusterState.nodes().localNodeId(), clusterState.nodes(), preference); } - public ShardIterator getShards(ClusterState clusterState, String index, int shardId, @Nullable String preference) throws IndexMissingException, IndexShardMissingException { + public ShardIterator getShards(ClusterState clusterState, String index, int shardId, @Nullable String preference) { return preferenceActiveShardIterator(shards(clusterState, index, shardId), clusterState.nodes().localNodeId(), clusterState.nodes(), preference); } - public GroupShardsIterator broadcastDeleteShards(ClusterState clusterState, String index) throws IndexMissingException { + public GroupShardsIterator broadcastDeleteShards(ClusterState clusterState, String index) { return indexRoutingTable(clusterState, index).groupByShardsIt(); } - public int searchShardsCount(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing) throws IndexMissingException { + public int searchShardsCount(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing) { final Set<IndexShardRoutingTable> shards = computeTargetedShards(clusterState, concreteIndices, routing); return shards.size(); } - public GroupShardsIterator searchShards(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException { + public GroupShardsIterator searchShards(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing, @Nullable String preference) { final Set<IndexShardRoutingTable> shards = computeTargetedShards(clusterState, concreteIndices, routing); final Set<ShardIterator> set = new HashSet<>(shards.size()); for (IndexShardRoutingTable shard : shards) { @@ -96,7 +95,7 @@ public class OperationRouting extends AbstractComponent { private static final Map<String, Set<String>> EMPTY_ROUTING = Collections.emptyMap(); - private Set<IndexShardRoutingTable> computeTargetedShards(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing) throws IndexMissingException { + private Set<IndexShardRoutingTable> computeTargetedShards(ClusterState clusterState, String[] concreteIndices, @Nullable Map<String, Set<String>> routing) { routing = routing == null ? EMPTY_ROUTING : routing; // just use an empty map final Set<IndexShardRoutingTable> set = new HashSet<>(); // we use set here and not list since we might get duplicates @@ -108,7 +107,7 @@ public class OperationRouting extends AbstractComponent { int shardId = shardId(clusterState, index, null, null, r); IndexShardRoutingTable indexShard = indexRouting.shard(shardId); if (indexShard == null) { - throw new IndexShardMissingException(new ShardId(index, shardId)); + throw new ShardNotFoundException(new ShardId(index, shardId)); } // we might get duplicates, but that's ok, they will override one another set.add(indexShard); @@ -202,7 +201,7 @@ public class OperationRouting extends AbstractComponent { public IndexMetaData indexMetaData(ClusterState clusterState, String index) { IndexMetaData indexMetaData = clusterState.metaData().index(index); if (indexMetaData == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } return indexMetaData; } @@ -210,7 +209,7 @@ public class OperationRouting extends AbstractComponent { protected IndexRoutingTable indexRoutingTable(ClusterState clusterState, String index) { IndexRoutingTable indexRouting = clusterState.routingTable().index(index); if (indexRouting == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } return indexRouting; } @@ -226,7 +225,7 @@ public class OperationRouting extends AbstractComponent { protected IndexShardRoutingTable shards(ClusterState clusterState, String index, int shardId) { IndexShardRoutingTable indexShard = indexRoutingTable(clusterState, index).shard(shardId); if (indexShard == null) { - throw new IndexShardMissingException(new ShardId(index, shardId)); + throw new ShardNotFoundException(new ShardId(index, shardId)); } return indexShard; } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java index 1327b55620..0359849a6f 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java @@ -26,9 +26,8 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.indices.IndexMissingException; import java.io.IOException; import java.util.ArrayList; @@ -124,7 +123,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi * * @return All the shards */ - public List<ShardRouting> allShards() throws IndexMissingException { + public List<ShardRouting> allShards() { List<ShardRouting> shards = Lists.newArrayList(); String[] indices = indicesRouting.keySet().toArray(new String[indicesRouting.keySet().size()]); for (String index : indices) { @@ -139,13 +138,13 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi * * @param index The index to return all the shards (replicas). * @return All the shards matching the specific index - * @throws IndexMissingException If the index passed does not exists + * @throws IndexNotFoundException If the index passed does not exists */ - public List<ShardRouting> allShards(String index) throws IndexMissingException { + public List<ShardRouting> allShards(String index) { List<ShardRouting> shards = Lists.newArrayList(); IndexRoutingTable indexRoutingTable = index(index); if (indexRoutingTable == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) { for (ShardRouting shardRouting : indexShardRoutingTable) { @@ -155,7 +154,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi return shards; } - public GroupShardsIterator allActiveShardsGrouped(String[] indices, boolean includeEmpty) throws IndexMissingException { + public GroupShardsIterator allActiveShardsGrouped(String[] indices, boolean includeEmpty) { return allActiveShardsGrouped(indices, includeEmpty, false); } @@ -166,7 +165,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi * @param includeRelocationTargets if true, an <b>extra</b> shard iterator will be added for relocating shards. The extra * iterator contains a single ShardRouting pointing at the relocating target */ - public GroupShardsIterator allActiveShardsGrouped(String[] indices, boolean includeEmpty, boolean includeRelocationTargets) throws IndexMissingException { + public GroupShardsIterator allActiveShardsGrouped(String[] indices, boolean includeEmpty, boolean includeRelocationTargets) { // use list here since we need to maintain identity across shards ArrayList<ShardIterator> set = new ArrayList<>(); for (String index : indices) { @@ -191,7 +190,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi return new GroupShardsIterator(set); } - public GroupShardsIterator allAssignedShardsGrouped(String[] indices, boolean includeEmpty) throws IndexMissingException { + public GroupShardsIterator allAssignedShardsGrouped(String[] indices, boolean includeEmpty) { return allAssignedShardsGrouped(indices, includeEmpty, false); } @@ -202,7 +201,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi * @param includeRelocationTargets if true, an <b>extra</b> shard iterator will be added for relocating shards. The extra * iterator contains a single ShardRouting pointing at the relocating target */ - public GroupShardsIterator allAssignedShardsGrouped(String[] indices, boolean includeEmpty, boolean includeRelocationTargets) throws IndexMissingException { + public GroupShardsIterator allAssignedShardsGrouped(String[] indices, boolean includeEmpty, boolean includeRelocationTargets) { // use list here since we need to maintain identity across shards ArrayList<ShardIterator> set = new ArrayList<>(); for (String index : indices) { @@ -234,16 +233,16 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi * * @param indices The indices to return all the shards (replicas) * @return All the primary shards grouped into a single shard element group each - * @throws IndexMissingException If an index passed does not exists + * @throws IndexNotFoundException If an index passed does not exists * @see IndexRoutingTable#groupByAllIt() */ - public GroupShardsIterator activePrimaryShardsGrouped(String[] indices, boolean includeEmpty) throws IndexMissingException { + public GroupShardsIterator activePrimaryShardsGrouped(String[] indices, boolean includeEmpty) { // use list here since we need to maintain identity across shards ArrayList<ShardIterator> set = new ArrayList<>(); for (String index : indices) { IndexRoutingTable indexRoutingTable = index(index); if (indexRoutingTable == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) { ShardRouting primary = indexShardRoutingTable.primaryShard(); @@ -387,7 +386,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi return this; } - public Builder updateNumberOfReplicas(int numberOfReplicas, String... indices) throws IndexMissingException { + public Builder updateNumberOfReplicas(int numberOfReplicas, String... indices) { if (indices == null || indices.length == 0) { indices = indicesRouting.keySet().toArray(new String[indicesRouting.keySet().size()]); } diff --git a/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java b/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java index 705f9a40a3..24e910b905 100644 --- a/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java +++ b/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java @@ -36,7 +36,7 @@ public class AlreadyExpiredException extends ElasticsearchException implements I public AlreadyExpiredException(String index, String type, String id, long timestamp, long ttl, long now) { super("already expired [" + index + "]/[" + type + "]/[" + id + "] due to expire at [" + (timestamp + ttl) + "] and was processed at [" + now + "]"); - this.index = index; + this.setIndex(index); this.type = type; this.id = id; this.timestamp = timestamp; diff --git a/core/src/main/java/org/elasticsearch/index/IndexException.java b/core/src/main/java/org/elasticsearch/index/IndexException.java deleted file mode 100644 index c309ebcb7f..0000000000 --- a/core/src/main/java/org/elasticsearch/index/IndexException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch 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.index; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; - -import java.io.IOException; - -/** - * - */ -public class IndexException extends ElasticsearchException { - - private final Index index; - - public IndexException(Index index, String msg, Object... args) { - this(index, msg, null, args); - } - - public IndexException(Index index, String msg, Throwable cause, Object... args) { - super(msg, cause); - this.index = index; - } - - public Index index() { - return index; - } - - @Override - protected void innerToXContent(XContentBuilder builder, Params params) throws IOException { - if (index != null) { - builder.field("index", index.getName()); - } - super.innerToXContent(builder, params); - } - - @Override - public String toString() { - return "[" + (index == null ? "_na" : index.name()) + "] " + getMessage(); - } - - - public IndexException(StreamInput in) throws IOException{ - super(in); - index = in.readBoolean() ? Index.readIndexName(in) : null; - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeOptionalStreamable(index); - } -} diff --git a/core/src/main/java/org/elasticsearch/index/store/StoreException.java b/core/src/main/java/org/elasticsearch/index/IndexNotFoundException.java index d221583e0d..bc7e55d5a0 100644 --- a/core/src/main/java/org/elasticsearch/index/store/StoreException.java +++ b/core/src/main/java/org/elasticsearch/index/IndexNotFoundException.java @@ -16,25 +16,25 @@ * specific language governing permissions and limitations * under the License. */ +package org.elasticsearch.index; -package org.elasticsearch.index.store; - +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.index.shard.IndexShardException; -import org.elasticsearch.index.shard.ShardId; import java.io.IOException; -/** - * - */ -public class StoreException extends IndexShardException { +public final class IndexNotFoundException extends ResourceNotFoundException { + + public IndexNotFoundException(String index) { + this(index, null); + } - public StoreException(ShardId shardId, String msg, Throwable cause) { - super(shardId, msg, cause); + public IndexNotFoundException(String index, Throwable cause) { + super("no such index", cause); + setIndex(index); } - public StoreException(StreamInput in) throws IOException{ + public IndexNotFoundException(StreamInput in) throws IOException { super(in); } -}
\ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java index 25942e6b35..46f6e90246 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexService.java +++ b/core/src/main/java/org/elasticsearch/index/IndexService.java @@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterators; import org.apache.lucene.util.IOUtils; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; @@ -173,10 +174,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone /** * Return the shard with the provided id, or throw an exception if it doesn't exist. */ - public IndexShard shardSafe(int shardId) throws IndexShardMissingException { + public IndexShard shardSafe(int shardId) { IndexShard indexShard = shard(shardId); if (indexShard == null) { - throw new IndexShardMissingException(new ShardId(index, shardId)); + throw new ShardNotFoundException(new ShardId(index, shardId)); } return indexShard; } @@ -242,10 +243,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone /** * Return the shard injector for the provided id, or throw an exception if there is no such shard. */ - public Injector shardInjectorSafe(int shardId) throws IndexShardMissingException { + public Injector shardInjectorSafe(int shardId) { Tuple<IndexShard, Injector> tuple = shards.get(shardId); if (tuple == null) { - throw new IndexShardMissingException(new ShardId(index, shardId)); + throw new ShardNotFoundException(new ShardId(index, shardId)); } return tuple.v2(); } @@ -316,9 +317,13 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone try { shardInjector = modules.createChildInjector(injector); } catch (CreationException e) { - throw new IndexShardCreationException(shardId, Injectors.getFirstErrorFailure(e)); + ElasticsearchException ex = new ElasticsearchException("failed to create shard", Injectors.getFirstErrorFailure(e)); + ex.setShard(shardId); + throw ex; } catch (Throwable e) { - throw new IndexShardCreationException(shardId, e); + ElasticsearchException ex = new ElasticsearchException("failed to create shard", e); + ex.setShard(shardId); + throw ex; } IndexShard indexShard = shardInjector.getInstance(IndexShard.class); @@ -328,8 +333,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone shards = newMapBuilder(shards).put(shardId.id(), new Tuple<>(indexShard, shardInjector)).immutableMap(); success = true; return indexShard; - } catch (IOException ex) { - throw new IndexShardCreationException(shardId, ex); + } catch (IOException e) { + ElasticsearchException ex = new ElasticsearchException("failed to create shard", e); + ex.setShard(shardId); + throw ex; } finally { if (success == false) { IOUtils.closeWhileHandlingException(lock); diff --git a/core/src/main/java/org/elasticsearch/index/engine/EngineException.java b/core/src/main/java/org/elasticsearch/index/engine/EngineException.java index a856ed190a..d7487ef66f 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/EngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/EngineException.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; @@ -28,14 +28,15 @@ import java.io.IOException; /** * */ -public class EngineException extends IndexShardException { +public class EngineException extends ElasticsearchException { public EngineException(ShardId shardId, String msg) { - super(shardId, msg); + this(shardId, msg, null); } public EngineException(ShardId shardId, String msg, Throwable cause) { - super(shardId, msg, cause); + super(msg, cause); + setShard(shardId); } public EngineException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/index/engine/ShadowEngine.java b/core/src/main/java/org/elasticsearch/index/engine/ShadowEngine.java index 73921e216b..f89b9ce471 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/ShadowEngine.java +++ b/core/src/main/java/org/elasticsearch/index/engine/ShadowEngine.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.ReleasableLock; import org.elasticsearch.index.deletionpolicy.SnapshotIndexCommit; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.translog.Translog; import java.io.IOException; @@ -82,7 +81,7 @@ public class ShadowEngine extends Engine { this.lastCommittedSegmentInfos = readLastCommittedSegmentInfos(searcherManager, store); success = true; } else { - throw new IndexShardException(shardId, "failed to open a shadow engine after" + + throw new IllegalStateException("failed to open a shadow engine after" + nonexistentRetryTime + "ms, " + "directory is not an index"); } diff --git a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java index 65019be247..3813679d81 100644 --- a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java +++ b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java @@ -18,19 +18,20 @@ */ package org.elasticsearch.index.percolator; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import java.io.IOException; /** * Exception during indexing a percolator query. */ -public class PercolatorException extends IndexException { +public class PercolatorException extends ElasticsearchException { public PercolatorException(Index index, String msg, Throwable cause) { - super(index, msg, cause); + super(msg, cause); + setIndex(index); } public PercolatorException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java b/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java index f904b74094..c606953bca 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java @@ -19,13 +19,13 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentLocation; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -33,7 +33,7 @@ import java.io.IOException; /** * */ -public class QueryParsingException extends IndexException { +public class QueryParsingException extends ElasticsearchException { static final int UNKNOWN_POSITION = -1; private final int lineNumber; @@ -44,7 +44,8 @@ public class QueryParsingException extends IndexException { } public QueryParsingException(QueryParseContext parseContext, String msg, Throwable cause, Object... args) { - super(parseContext.index(), msg, cause, args); + super(msg, cause, args); + setIndex(parseContext.index()); int lineNumber = UNKNOWN_POSITION; int columnNumber = UNKNOWN_POSITION; XContentParser parser = parseContext.parser(); @@ -64,7 +65,8 @@ public class QueryParsingException extends IndexException { * {@link QueryParseContext} may not be available */ public QueryParsingException(Index index, int line, int col, String msg, Throwable cause) { - super(index, msg, cause); + super(msg, cause); + setIndex(index); this.lineNumber = line; this.columnNumber = col; } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java b/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java index 0cde08f43c..31c235e09e 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java @@ -19,6 +19,8 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; @@ -28,17 +30,17 @@ import java.io.IOException; /** * */ -public class IllegalIndexShardStateException extends IndexShardException { +public class IllegalIndexShardStateException extends ElasticsearchException { private final IndexShardState currentState; public IllegalIndexShardStateException(ShardId shardId, IndexShardState currentState, String msg) { - super(shardId, "CurrentState[" + currentState + "] " + msg); - this.currentState = currentState; + this(shardId, currentState, msg, null); } public IllegalIndexShardStateException(ShardId shardId, IndexShardState currentState, String msg, Throwable ex) { - super(shardId, "CurrentState[" + currentState + "] ", ex); + super("CurrentState[" + currentState + "] " + msg, ex); + setShard(shardId); this.currentState = currentState; } @@ -46,11 +48,6 @@ public class IllegalIndexShardStateException extends IndexShardException { return currentState; } - @Override - public RestStatus status() { - return RestStatus.NOT_FOUND; - } - public IllegalIndexShardStateException(StreamInput in) throws IOException{ super(in); currentState = IndexShardState.fromId(in.readByte()); @@ -61,4 +58,9 @@ public class IllegalIndexShardStateException extends IndexShardException { super.writeTo(out); out.writeByte(currentState.id()); } + + @Override + public RestStatus status() { + return RestStatus.NOT_FOUND; + } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 13b34a48d8..dd4b6bc7dc 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -24,11 +24,13 @@ import com.google.common.base.Preconditions; import org.apache.lucene.codecs.PostingsFormat; import org.apache.lucene.index.CheckIndex; +import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.search.QueryCachingPolicy; import org.apache.lucene.search.UsageTrackingQueryCachingPolicy; import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.ThreadInterruptedException; +import org.elasticsearch.ElasticsearchCorruptionException; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.flush.FlushRequest; @@ -104,6 +106,7 @@ import org.elasticsearch.indices.IndicesLifecycle; import org.elasticsearch.indices.IndicesWarmer; import org.elasticsearch.indices.InternalIndicesLifecycle; import org.elasticsearch.indices.cache.query.IndicesQueryCache; +import org.elasticsearch.indices.recovery.RecoveryFailedException; import org.elasticsearch.indices.recovery.RecoveryState; import org.elasticsearch.search.suggest.completion.Completion090PostingsFormat; import org.elasticsearch.search.suggest.completion.CompletionStats; @@ -839,7 +842,11 @@ public class IndexShard extends AbstractIndexShardComponent { recoveryState.setStage(RecoveryState.Stage.VERIFY_INDEX); // also check here, before we apply the translog if (Booleans.parseBoolean(checkIndexOnStartup, false)) { - checkIndex(); + try { + checkIndex(); + } catch (IOException ex) { + throw new RecoveryFailedException(recoveryState, "check index failed", ex); + } } recoveryState.setStage(RecoveryState.Stage.TRANSLOG); // we disable deletes since we allow for operations to be executed against the shard while recovering @@ -1182,19 +1189,17 @@ public class IndexShard extends AbstractIndexShardComponent { } } - private void checkIndex() throws IndexShardException { + private void checkIndex() throws IOException { if (store.tryIncRef()) { try { doCheckIndex(); - } catch (IOException e) { - throw new IndexShardException(shardId, "exception during checkindex", e); } finally { store.decRef(); } } } - private void doCheckIndex() throws IndexShardException, IOException { + private void doCheckIndex() throws IOException { long timeNS = System.nanoTime(); if (!Lucene.indexExists(store.directory())) { return; @@ -1204,7 +1209,7 @@ public class IndexShard extends AbstractIndexShardComponent { if ("checksum".equalsIgnoreCase(checkIndexOnStartup)) { // physical verification only: verify all checksums for the latest commit - boolean corrupt = false; + IOException corrupt = null; MetadataSnapshot metadata = store.getMetadata(); for (Map.Entry<String, StoreFileMetaData> entry : metadata.asMap().entrySet()) { try { @@ -1213,13 +1218,13 @@ public class IndexShard extends AbstractIndexShardComponent { } catch (IOException exc) { out.println("checksum failed: " + entry.getKey()); exc.printStackTrace(out); - corrupt = true; + corrupt = exc; } } out.flush(); - if (corrupt) { + if (corrupt != null) { logger.warn("check index [failure]\n{}", new String(os.bytes().toBytes(), Charsets.UTF_8)); - throw new IndexShardException(shardId, "index check failure"); + throw corrupt; } } else { // full checkindex @@ -1244,7 +1249,7 @@ public class IndexShard extends AbstractIndexShardComponent { } } else { // only throw a failure if we are not going to fix the index - throw new IndexShardException(shardId, "index check failure"); + throw new IllegalStateException("index check failure but can't fix it"); } } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardException.java deleted file mode 100644 index 23fde2abc1..0000000000 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardException.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch 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.index.shard; - -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.IndexException; - -import java.io.IOException; - -/** - * - */ -public class IndexShardException extends IndexException { - - private final ShardId shardId; - - public IndexShardException(ShardId shardId, String msg) { - this(shardId, msg, null); - } - - public IndexShardException(ShardId shardId, String msg, Throwable cause) { - super(shardId == null ? null : shardId.index(), msg, cause); - this.shardId = shardId; - } - - public ShardId shardId() { - return shardId; - } - - @Override - public String toString() { - return (shardId == null ? "_na" : shardId) + " " + getMessage(); - } - - @Override - protected void innerToXContent(XContentBuilder builder, Params params) throws IOException { - if (shardId != null) { - builder.field("shard", shardId.getId()); - } - super.innerToXContent(builder, params); - } - - public IndexShardException(StreamInput in) throws IOException{ - super(in); - if (in.readBoolean()) { - shardId = ShardId.readShardId(in); - } else { - shardId = null; - } - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeOptionalStreamable(shardId); - } -} diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java index d53d1eaa6a..8ed3c95f92 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java @@ -19,18 +19,18 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.index.shard.IndexShardException; -import org.elasticsearch.index.shard.ShardId; import java.io.IOException; /** * */ -public class IndexShardRecoveryException extends IndexShardException { +public class IndexShardRecoveryException extends ElasticsearchException { public IndexShardRecoveryException(ShardId shardId, String msg, Throwable cause) { - super(shardId, msg, cause); + super(msg, cause); + setShard(shardId); } public IndexShardRecoveryException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardCreationException.java b/core/src/main/java/org/elasticsearch/index/shard/ShardNotFoundException.java index a6d879e5b0..fa2c8ce710 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardCreationException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/ShardNotFoundException.java @@ -19,19 +19,25 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.common.io.stream.StreamInput; import java.io.IOException; /** + * */ -public class IndexShardCreationException extends IndexShardException { - - public IndexShardCreationException(ShardId shardId, Throwable cause) { - super(shardId, "failed to create shard", cause); +public class ShardNotFoundException extends ResourceNotFoundException { + public ShardNotFoundException(ShardId shardId) { + this(shardId, null); } - public IndexShardCreationException(StreamInput in) throws IOException{ + public ShardNotFoundException(ShardId shardId, Throwable ex) { + super("no such shard", ex); + setShard(shardId); + + } + public ShardNotFoundException(StreamInput in) throws IOException{ super(in); } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java b/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java index 91da224ec3..1a54c748c3 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java +++ b/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java @@ -90,12 +90,13 @@ public class TranslogRecoveryPerformer { return numOps; } - public static class BatchOperationException extends IndexShardException { + public static class BatchOperationException extends ElasticsearchException { private final int completedOperations; public BatchOperationException(ShardId shardId, String msg, int completedOperations, Throwable cause) { - super(shardId, msg, cause); + super(msg, cause); + setShard(shardId); this.completedOperations = completedOperations; } diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java index 92a2ed4ab9..55410b8cb9 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.snapshots; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; @@ -28,13 +28,14 @@ import java.io.IOException; /** * Generic shard restore exception */ -public class IndexShardRestoreException extends IndexShardException { +public class IndexShardRestoreException extends ElasticsearchException { public IndexShardRestoreException(ShardId shardId, String msg) { - super(shardId, msg); + this(shardId, msg, null); } public IndexShardRestoreException(ShardId shardId, String msg, Throwable cause) { - super(shardId, msg, cause); + super(msg, cause); + setShard(shardId); } public IndexShardRestoreException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java index e915d22753..741350966a 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.snapshots; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; @@ -28,13 +28,14 @@ import java.io.IOException; /** * Generic shard snapshot exception */ -public class IndexShardSnapshotException extends IndexShardException { +public class IndexShardSnapshotException extends ElasticsearchException { public IndexShardSnapshotException(ShardId shardId, String msg) { - super(shardId, msg); + this(shardId, msg, null); } public IndexShardSnapshotException(ShardId shardId, String msg, Throwable cause) { - super(shardId, msg, cause); + super(msg, cause); + setShard(shardId); } public IndexShardSnapshotException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java b/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java index afc2dac335..d40297b8d9 100644 --- a/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java +++ b/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.store; import com.google.common.collect.Sets; import org.apache.lucene.store.*; import org.apache.lucene.util.Constants; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.metrics.CounterMetric; import org.elasticsearch.common.settings.Settings; @@ -74,11 +75,7 @@ public class FsDirectoryService extends DirectoryService implements StoreRateLim } protected final LockFactory buildLockFactory() throws IOException { - try { - return buildLockFactory(indexSettings); - } catch (IllegalArgumentException e) { - throw new StoreException(shardId, "unable to build lock factory", e); - } + return buildLockFactory(indexSettings); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java b/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java index 2e80cb6f78..2ebf279588 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java +++ b/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.translog; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; @@ -28,14 +28,15 @@ import java.io.IOException; /** * */ -public class TranslogException extends IndexShardException { +public class TranslogException extends ElasticsearchException { public TranslogException(ShardId shardId, String msg) { - super(shardId, msg); + this(shardId, msg, null); } public TranslogException(ShardId shardId, String msg, Throwable cause) { - super(shardId, msg, cause); + super(msg, cause); + setShard(shardId); } public TranslogException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java b/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java index 54baafe0a0..52e801a4cb 100644 --- a/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java +++ b/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java @@ -19,22 +19,22 @@ package org.elasticsearch.indices; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import java.io.IOException; /** * */ -public class AliasFilterParsingException extends IndexException { +public class AliasFilterParsingException extends ElasticsearchException { public AliasFilterParsingException(Index index, String name, String desc, Throwable ex) { - super(index, "[" + name + "], " + desc, ex); + super("[" + name + "], " + desc, ex); + setIndex(index); } - public AliasFilterParsingException(StreamInput in) throws IOException{ super(in); } diff --git a/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java b/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java index 5bd12bc3aa..9d6616e4e2 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java @@ -19,9 +19,9 @@ package org.elasticsearch.indices; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -29,14 +29,15 @@ import java.io.IOException; /** * */ -public class IndexAlreadyExistsException extends IndexException { +public class IndexAlreadyExistsException extends ElasticsearchException { public IndexAlreadyExistsException(Index index) { this(index, "already exists"); } public IndexAlreadyExistsException(Index index, String message) { - super(index, message); + super(message); + setIndex(index); } public IndexAlreadyExistsException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java b/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java index d522bf2c57..22425ddc46 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java @@ -19,9 +19,9 @@ package org.elasticsearch.indices; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -29,10 +29,11 @@ import java.io.IOException; /** * Exception indicating that one or more requested indices are closed. */ -public class IndexClosedException extends IndexException { +public class IndexClosedException extends ElasticsearchException { public IndexClosedException(Index index) { - super(index, "closed"); + super("closed"); + setIndex(index); } public IndexClosedException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java b/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java index e681376af0..09b6696e11 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java @@ -19,19 +19,20 @@ package org.elasticsearch.indices; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchWrapperException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import java.io.IOException; /** */ -public class IndexCreationException extends IndexException implements ElasticsearchWrapperException { +public class IndexCreationException extends ElasticsearchException implements ElasticsearchWrapperException { public IndexCreationException(Index index, Throwable cause) { - super(index, "failed to create index", cause); + super("failed to create index", cause); + setIndex(index); } public IndexCreationException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java b/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java index 0dda08fe7f..b7dd3e68ce 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java @@ -19,9 +19,9 @@ package org.elasticsearch.indices; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -30,13 +30,14 @@ import java.io.IOException; * Thrown when some action cannot be performed because the primary shard of * some shard group in an index has not been allocated post api action. */ -public class IndexPrimaryShardNotAllocatedException extends IndexException { +public class IndexPrimaryShardNotAllocatedException extends ElasticsearchException { public IndexPrimaryShardNotAllocatedException(StreamInput in) throws IOException{ super(in); } public IndexPrimaryShardNotAllocatedException(Index index) { - super(index, "primary not allocated post api"); + super("primary not allocated post api"); + setIndex(index); } @Override diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 505b12aa40..912a1ded50 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -270,12 +270,12 @@ public class IndicesService extends AbstractLifecycleComponent<IndicesService> i } /** - * Returns an IndexService for the specified index if exists otherwise a {@link IndexMissingException} is thrown. + * Returns an IndexService for the specified index if exists otherwise a {@link IndexNotFoundException} is thrown. */ - public IndexService indexServiceSafe(String index) throws IndexMissingException { + public IndexService indexServiceSafe(String index) { IndexService indexService = indexService(index); if (indexService == null) { - throw new IndexMissingException(new Index(index)); + throw new IndexNotFoundException(index); } return indexService; } diff --git a/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java b/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java index 179f6ca851..4e2c443ff4 100644 --- a/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java +++ b/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java @@ -19,9 +19,9 @@ package org.elasticsearch.indices; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -29,10 +29,11 @@ import java.io.IOException; /** * */ -public class InvalidAliasNameException extends IndexException { +public class InvalidAliasNameException extends ElasticsearchException { public InvalidAliasNameException(Index index, String name, String desc) { - super(index, "Invalid alias name [" + name + "], " + desc); + super("Invalid alias name [{}], {}", name, desc); + setIndex(index); } public InvalidAliasNameException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java b/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java index 468d158f38..163f4df26a 100644 --- a/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java +++ b/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java @@ -19,9 +19,9 @@ package org.elasticsearch.indices; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -29,10 +29,11 @@ import java.io.IOException; /** * */ -public class InvalidIndexNameException extends IndexException { +public class InvalidIndexNameException extends ElasticsearchException { public InvalidIndexNameException(Index index, String name, String desc) { - super(index, "Invalid index name [" + name + "], " + desc); + super("Invalid index name [" + name + "], " + desc); + setIndex(index); } public InvalidIndexNameException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java b/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java index ef4a1d6d8d..0a332dbaf1 100644 --- a/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java +++ b/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java @@ -19,9 +19,9 @@ package org.elasticsearch.indices; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -30,10 +30,11 @@ import java.util.Arrays; /** * */ -public class TypeMissingException extends IndexException { +public class TypeMissingException extends ElasticsearchException { public TypeMissingException(Index index, String... types) { - super(index, "type[" + Arrays.toString(types) + "] missing"); + super("type[" + Arrays.toString(types) + "] missing"); + setIndex(index); } public TypeMissingException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java index 0cc3c1d357..a1011e583d 100644 --- a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -45,7 +45,6 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexShardAlreadyExistsException; -import org.elasticsearch.index.IndexShardMissingException; import org.elasticsearch.index.aliases.IndexAliasesService; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.mapper.DocumentMapper; @@ -803,7 +802,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic if (indexService.hasShard(shardRouting.getId())) { try { indexService.removeShard(shardRouting.getId(), message); - } catch (IndexShardMissingException e) { + } catch (ShardNotFoundException e) { // the node got closed on us, ignore it } catch (Throwable e1) { logger.warn("[{}][{}] failed to remove shard after failure ([{}])", e1, shardRouting.getIndex(), shardRouting.getId(), message); diff --git a/core/src/main/java/org/elasticsearch/indices/flush/SyncedFlushService.java b/core/src/main/java/org/elasticsearch/indices/flush/SyncedFlushService.java index 054d9d5299..5cd034a153 100644 --- a/core/src/main/java/org/elasticsearch/indices/flush/SyncedFlushService.java +++ b/core/src/main/java/org/elasticsearch/indices/flush/SyncedFlushService.java @@ -38,14 +38,13 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.common.util.concurrent.CountDown; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexService; -import org.elasticsearch.index.IndexShardMissingException; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.IndexShard; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.index.shard.ShardNotFoundException; import org.elasticsearch.indices.IndexClosedException; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.indices.IndicesLifecycle; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; @@ -239,11 +238,11 @@ public class SyncedFlushService extends AbstractComponent { if (index != null && index.state() == IndexMetaData.State.CLOSE) { throw new IndexClosedException(shardId.index()); } - throw new IndexMissingException(shardId.index()); + throw new IndexNotFoundException(shardId.index().getName()); } final IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId.id()); if (shardRoutingTable == null) { - throw new IndexShardMissingException(shardId); + throw new ShardNotFoundException(shardId); } return shardRoutingTable; } @@ -429,7 +428,7 @@ public class SyncedFlushService extends AbstractComponent { IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex()); IndexShard indexShard = indexService.shardSafe(request.shardId().id()); if (indexShard.routingEntry().primary() == false) { - throw new IndexShardException(request.shardId(), "expected a primary shard"); + throw new IllegalStateException("[" + request.shardId() +"] expected a primary shard"); } int opCount = indexShard.getOperationsCount(); logger.trace("{} in flight operations sampled at [{}]", request.shardId(), opCount); diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java index 508e52f359..69a55e03c9 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java @@ -19,11 +19,11 @@ package org.elasticsearch.indices.recovery; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchWrapperException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; @@ -32,15 +32,16 @@ import java.util.Objects; /** * */ -public class RecoverFilesRecoveryException extends IndexShardException implements ElasticsearchWrapperException { +public class RecoverFilesRecoveryException extends ElasticsearchException implements ElasticsearchWrapperException { private final int numberOfFiles; private final ByteSizeValue totalFilesSize; public RecoverFilesRecoveryException(ShardId shardId, int numberOfFiles, ByteSizeValue totalFilesSize, Throwable cause) { - super(shardId, "Failed to transfer [" + numberOfFiles + "] files with total size of [" + totalFilesSize + "]", cause); + super("Failed to transfer [{}] files with total size of [{}]", cause, numberOfFiles, totalFilesSize); Objects.requireNonNull(totalFilesSize, "totalFilesSize must not be null"); + setShard(shardId); this.numberOfFiles = numberOfFiles; this.totalFilesSize = totalFilesSize; } diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java index 22bd433697..0388265e64 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java @@ -43,13 +43,12 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.CancellableThreads; import org.elasticsearch.common.util.concurrent.AbstractRunnable; -import org.elasticsearch.index.IndexShardMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.engine.RecoveryEngineException; import org.elasticsearch.index.mapper.MapperException; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.*; import org.elasticsearch.index.store.Store; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.indices.IndicesLifecycle; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; @@ -231,7 +230,7 @@ public class RecoveryTarget extends AbstractComponent { // here, we would add checks against exception that need to be retried (and not removeAndClean in this case) - if (cause instanceof IllegalIndexShardStateException || cause instanceof IndexMissingException || cause instanceof IndexShardMissingException) { + if (cause instanceof IllegalIndexShardStateException || cause instanceof IndexNotFoundException || cause instanceof ShardNotFoundException) { // if the target is not ready yet, retry retryRecovery(recoveryStatus, "remote shard not ready", recoverySettings.retryDelayStateSync(), request); return; diff --git a/core/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java b/core/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java index 6c4f1a2c28..7785337122 100644 --- a/core/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java +++ b/core/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java @@ -53,7 +53,6 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; @@ -336,7 +335,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent<Rep ShardId shardId = new ShardId(index, i); try { indexShardRepository.delete(snapshotId, shardId); - } catch (IndexShardException | SnapshotException ex) { + } catch (SnapshotException ex) { logger.warn("[{}] failed to delete shard data for shard [{}]", ex, snapshotId, shardId); } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java deleted file mode 100644 index d6ac3042d2..0000000000 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch 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.alias.delete; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.rest.RestStatus; - -import java.io.IOException; -import java.util.Arrays; - -/** - * - */ -public class AliasesMissingException extends ElasticsearchException { - - private final String[] names; - - public AliasesMissingException(String... names) { - super("aliases " + Arrays.toString(names) + " missing"); - this.names = names; - } - - public String[] names() { - return this.names; - } - - @Override - public RestStatus status() { - return RestStatus.NOT_FOUND; - } - - public AliasesMissingException(StreamInput in) throws IOException{ - super(in); - names = in.readStringArray(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeStringArray(names); - } -} diff --git a/core/src/main/java/org/elasticsearch/indices/IndexMissingException.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesNotFoundException.java index 8b6d7735c9..6e183786df 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexMissingException.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesNotFoundException.java @@ -16,31 +16,25 @@ * specific language governing permissions and limitations * under the License. */ +package org.elasticsearch.rest.action.admin.indices.alias.delete; -package org.elasticsearch.indices; - +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; -import org.elasticsearch.rest.RestStatus; import java.io.IOException; +import java.util.Arrays; /** * */ -public class IndexMissingException extends IndexException { +public class AliasesNotFoundException extends ResourceNotFoundException { - public IndexMissingException(Index index) { - super(index, "no such index"); + public AliasesNotFoundException(String... names) { + super("aliases " + Arrays.toString(names) + " missing"); + this.setResources("aliases", names); } - public IndexMissingException(StreamInput in) throws IOException{ + public AliasesNotFoundException(StreamInput in) throws IOException{ super(in); } - - @Override - public RestStatus status() { - return RestStatus.NOT_FOUND; - } -}
\ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java index 3e9b40027f..3cfb6f6da6 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java @@ -32,7 +32,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.index.Index; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.TypeMissingException; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestBuilderListener; @@ -71,7 +71,7 @@ public class RestGetMappingAction extends BaseRestHandler { if (indices.length != 0 && types.length != 0) { return new BytesRestResponse(OK, builder.endObject()); } else if (indices.length != 0) { - return new BytesRestResponse(channel, new IndexMissingException(new Index(indices[0]))); + return new BytesRestResponse(channel, new IndexNotFoundException(indices[0])); } else if (types.length != 0) { return new BytesRestResponse(channel, new TypeMissingException(new Index("_all"), types[0])); } else { diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotUtils.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotUtils.java index d65225ba0d..84e29063dd 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotUtils.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotUtils.java @@ -21,8 +21,7 @@ package org.elasticsearch.snapshots; import com.google.common.collect.ImmutableList; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.index.Index; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import java.util.HashSet; import java.util.List; @@ -75,7 +74,7 @@ public class SnapshotUtils { if (indexOrPattern.isEmpty() || !Regex.isSimpleMatchPattern(indexOrPattern)) { if (!availableIndices.contains(indexOrPattern)) { if (!indicesOptions.ignoreUnavailable()) { - throw new IndexMissingException(new Index(indexOrPattern)); + throw new IndexNotFoundException(indexOrPattern); } else { if (result == null) { // add all the previous ones... @@ -111,7 +110,7 @@ public class SnapshotUtils { } } if (!found && !indicesOptions.allowNoIndices()) { - throw new IndexMissingException(new Index(indexOrPattern)); + throw new IndexNotFoundException(indexOrPattern); } } if (result == null) { diff --git a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java index 581868ff39..30b1d8c1da 100644 --- a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java +++ b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java @@ -34,10 +34,9 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentLocation; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.query.QueryParsingException; import org.elasticsearch.index.query.TestQueryParsingException; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.SearchParseException; import org.elasticsearch.search.SearchShardTarget; @@ -65,10 +64,10 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { exception = new ElasticsearchException("test", new RuntimeException()); assertThat(exception.status(), equalTo(RestStatus.INTERNAL_SERVER_ERROR)); - exception = new ElasticsearchException("test", new IndexMissingException(new Index("test"))); + exception = new ElasticsearchException("test", new ResourceNotFoundException("test")); assertThat(exception.status(), equalTo(RestStatus.INTERNAL_SERVER_ERROR)); - exception = new RemoteTransportException("test", new IndexMissingException(new Index("test"))); + exception = new RemoteTransportException("test", new ResourceNotFoundException("test")); assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND)); exception = new RemoteTransportException("test", new IllegalArgumentException("foobar")); @@ -80,11 +79,11 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { public void testGuessRootCause() { { - ElasticsearchException exception = new ElasticsearchException("foo", new ElasticsearchException("bar", new IndexException(new Index("foo"), "index is closed", new RuntimeException("foobar")))); + ElasticsearchException exception = new ElasticsearchException("foo", new ElasticsearchException("bar", new IndexNotFoundException("foo", new RuntimeException("foobar")))); ElasticsearchException[] rootCauses = exception.guessRootCauses(); assertEquals(rootCauses.length, 1); - assertEquals(ElasticsearchException.getExceptionName(rootCauses[0]), "index_exception"); - assertEquals(rootCauses[0].getMessage(), "index is closed"); + assertEquals(ElasticsearchException.getExceptionName(rootCauses[0]), "index_not_found_exception"); + assertEquals(rootCauses[0].getMessage(), "no such index"); ShardSearchFailure failure = new ShardSearchFailure(new TestQueryParsingException(new Index("foo"), "foobar", null), new SearchShardTarget("node_1", "foo", 1)); ShardSearchFailure failure1 = new ShardSearchFailure(new TestQueryParsingException(new Index("foo"), "foobar", null), @@ -116,7 +115,7 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { assertEquals(rootCauses.length, 2); assertEquals(ElasticsearchException.getExceptionName(rootCauses[0]), "test_query_parsing_exception"); assertEquals(rootCauses[0].getMessage(), "foobar"); - assertEquals(((QueryParsingException)rootCauses[0]).index().name(), "foo"); + assertEquals(((QueryParsingException)rootCauses[0]).getIndex(), "foo"); assertEquals(ElasticsearchException.getExceptionName(rootCauses[1]), "test_query_parsing_exception"); assertEquals(rootCauses[1].getMessage(), "foobar"); assertEquals(((QueryParsingException) rootCauses[1]).getLineNumber(), 1); @@ -222,7 +221,7 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { builder.startObject(); ElasticsearchException.toXContent(builder, ToXContent.EMPTY_PARAMS, ex); builder.endObject(); - String expected = "{\"type\":\"test_query_parsing_exception\",\"reason\":\"foobar\",\"line\":1,\"col\":2,\"index\":\"foo\"}"; + String expected = "{\"type\":\"test_query_parsing_exception\",\"reason\":\"foobar\",\"index\":\"foo\",\"line\":1,\"col\":2}"; assertEquals(expected, builder.string()); } @@ -241,6 +240,18 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { assertEquals(otherBuilder.string(), builder.string()); assertEquals("{\"type\":\"file_not_found_exception\",\"reason\":\"foo not found\"}", builder.string()); } + + { // render header + QueryParsingException ex = new TestQueryParsingException(new Index("foo"), 1, 2, "foobar", null); + ex.addHeader("test", "some value"); + ex.addHeader("test_multi", "some value", "another value"); + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder.startObject(); + ElasticsearchException.toXContent(builder, ToXContent.EMPTY_PARAMS, ex); + builder.endObject(); + String expected = "{\"type\":\"test_query_parsing_exception\",\"reason\":\"foobar\",\"index\":\"foo\",\"line\":1,\"col\":2,\"header\":{\"test_multi\":[\"some value\",\"another value\"],\"test\":\"some value\"}}"; + assertEquals(expected, builder.string()); + } } public void testSerializeElasticsearchException() throws IOException { @@ -250,7 +261,7 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { StreamInput in = StreamInput.wrap(out.bytes()); QueryParsingException e = in.readThrowable(); - assertEquals(ex.index(), e.index()); + assertEquals(ex.getIndex(), e.getIndex()); assertEquals(ex.getMessage(), e.getMessage()); assertEquals(ex.getLineNumber(), e.getLineNumber()); assertEquals(ex.getColumnNumber(), e.getColumnNumber()); @@ -267,7 +278,7 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { assertEquals("wtf", throwable.getMessage()); assertTrue(throwable instanceof ElasticsearchException); QueryParsingException e = (QueryParsingException)throwable.getCause(); - assertEquals(queryParsingException.index(), e.index()); + assertEquals(queryParsingException.getIndex(), e.getIndex()); assertEquals(queryParsingException.getMessage(), e.getMessage()); assertEquals(queryParsingException.getLineNumber(), e.getLineNumber()); assertEquals(queryParsingException.getColumnNumber(), e.getColumnNumber()); diff --git a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index f1040699e0..6381532c99 100644 --- a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -41,7 +41,6 @@ import org.elasticsearch.common.xcontent.*; import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.index.AlreadyExpiredException; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.index.engine.CreateFailedEngineException; import org.elasticsearch.index.engine.IndexFailedEngineException; import org.elasticsearch.index.engine.RecoveryEngineException; @@ -55,7 +54,7 @@ import org.elasticsearch.indices.recovery.RecoverFilesRecoveryException; import org.elasticsearch.percolator.PercolateException; import org.elasticsearch.repositories.RepositoryException; import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException; +import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesNotFoundException; import org.elasticsearch.search.SearchContextMissingException; import org.elasticsearch.search.SearchException; import org.elasticsearch.search.SearchParseException; @@ -209,13 +208,13 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { public void testQueryParsingException() throws IOException { QueryParsingException ex = serialize(new QueryParsingException(new Index("foo"), 1, 2, "fobar", null)); - assertEquals(ex.index(), new Index("foo")); + assertEquals(ex.getIndex(), "foo"); assertEquals(ex.getMessage(), "fobar"); assertEquals(ex.getLineNumber(),1); assertEquals(ex.getColumnNumber(), 2); ex = serialize(new QueryParsingException(null, 1, 2, null, null)); - assertNull(ex.index()); + assertNull(ex.getIndex()); assertNull(ex.getMessage()); assertEquals(ex.getLineNumber(),1); assertEquals(ex.getColumnNumber(), 2); @@ -235,7 +234,7 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { public void testAlreadyExpiredException() throws IOException { AlreadyExpiredException alreadyExpiredException = serialize(new AlreadyExpiredException("index", "type", "id", 1, 2, 3)); - assertEquals("index", alreadyExpiredException.index()); + assertEquals("index", alreadyExpiredException.getIndex()); assertEquals("type", alreadyExpiredException.type()); assertEquals("id", alreadyExpiredException.id()); assertEquals(2, alreadyExpiredException.ttl()); @@ -243,7 +242,7 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { assertEquals(3, alreadyExpiredException.now()); alreadyExpiredException = serialize(new AlreadyExpiredException(null, null, null, -1, -2, -3)); - assertNull(alreadyExpiredException.index()); + assertNull(alreadyExpiredException.getIndex()); assertNull(alreadyExpiredException.type()); assertNull(alreadyExpiredException.id()); assertEquals(-2, alreadyExpiredException.ttl()); @@ -253,13 +252,13 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { public void testCreateFailedEngineException() throws IOException { CreateFailedEngineException ex = serialize(new CreateFailedEngineException(new ShardId("idx", 2), "type", "id", null)); - assertEquals(ex.shardId(), new ShardId("idx", 2)); + assertEquals(ex.getShardId(), new ShardId("idx", 2)); assertEquals("type", ex.type()); assertEquals("id", ex.id()); assertNull(ex.getCause()); ex = serialize(new CreateFailedEngineException(null, "type", "id", new NullPointerException())); - assertNull(ex.shardId()); + assertNull(ex.getShardId()); assertEquals("type", ex.type()); assertEquals("id", ex.id()); assertTrue(ex.getCause() instanceof NullPointerException); @@ -292,14 +291,14 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { ShardId id = new ShardId("foo", 1); ByteSizeValue bytes = new ByteSizeValue(randomIntBetween(0, 10000)); RecoverFilesRecoveryException ex = serialize(new RecoverFilesRecoveryException(id, 10, bytes, null)); - assertEquals(ex.shardId(), id); + assertEquals(ex.getShardId(), id); assertEquals(ex.numberOfFiles(), 10); assertEquals(ex.totalFilesSize(), bytes); assertEquals(ex.getMessage(), "Failed to transfer [10] files with total size of [" + bytes + "]"); assertNull(ex.getCause()); ex = serialize(new RecoverFilesRecoveryException(null, 10, bytes, new NullPointerException())); - assertNull(ex.shardId()); + assertNull(ex.getShardId()); assertEquals(ex.numberOfFiles(), 10); assertEquals(ex.totalFilesSize(), bytes); assertEquals(ex.getMessage(), "Failed to transfer [10] files with total size of [" + bytes + "]"); @@ -319,13 +318,13 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { public void testBatchOperationException() throws IOException { ShardId id = new ShardId("foo", 1); TranslogRecoveryPerformer.BatchOperationException ex = serialize(new TranslogRecoveryPerformer.BatchOperationException(id, "batched the fucker", 666, null)); - assertEquals(ex.shardId(), id); + assertEquals(ex.getShardId(), id); assertEquals(666, ex.completedOperations()); assertEquals("batched the fucker", ex.getMessage()); assertNull(ex.getCause()); ex = serialize(new TranslogRecoveryPerformer.BatchOperationException(null, "batched the fucker", -1, new NullPointerException())); - assertNull(ex.shardId()); + assertNull(ex.getShardId()); assertEquals(-1, ex.completedOperations()); assertEquals("batched the fucker", ex.getMessage()); assertTrue(ex.getCause() instanceof NullPointerException); @@ -390,22 +389,23 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { public void testIndexFailedEngineException() throws IOException { ShardId id = new ShardId("foo", 1); IndexFailedEngineException ex = serialize(new IndexFailedEngineException(id, "type", "id", null)); - assertEquals(ex.shardId(), new ShardId("foo", 1)); + assertEquals(ex.getShardId(), new ShardId("foo", 1)); assertEquals("type", ex.type()); assertEquals("id", ex.id()); assertNull(ex.getCause()); ex = serialize(new IndexFailedEngineException(null, "type", "id", new NullPointerException())); - assertNull(ex.shardId()); + assertNull(ex.getShardId()); assertEquals("type", ex.type()); assertEquals("id", ex.id()); assertTrue(ex.getCause() instanceof NullPointerException); } public void testAliasesMissingException() throws IOException { - AliasesMissingException ex = serialize(new AliasesMissingException("one", "two", "three")); + AliasesNotFoundException ex = serialize(new AliasesNotFoundException("one", "two", "three")); assertEquals("aliases [one, two, three] missing", ex.getMessage()); - assertArrayEquals(new String[]{"one", "two", "three"}, ex.names()); + assertEquals("aliases", ex.getResourceType()); + assertArrayEquals(new String[]{"one", "two", "three"}, ex.getResourceId().toArray(new String[0])); } public void testSearchParseException() throws IOException { @@ -421,7 +421,7 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { ShardId id = new ShardId("foo", 1); IndexShardState state = randomFrom(IndexShardState.values()); IllegalIndexShardStateException ex = serialize(new IllegalIndexShardStateException(id, state, "come back later buddy")); - assertEquals(id, ex.shardId()); + assertEquals(id, ex.getShardId()); assertEquals("CurrentState[" + state.name() + "] come back later buddy", ex.getMessage()); assertEquals(state, ex.currentState()); } @@ -462,9 +462,9 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { public void testRoutingMissingException() throws IOException { RoutingMissingException ex = serialize(new RoutingMissingException("idx", "type", "id")); - assertEquals("idx", ex.index()); - assertEquals("type", ex.type()); - assertEquals("id", ex.id()); + assertEquals("idx", ex.getIndex()); + assertEquals("type", ex.getType()); + assertEquals("id", ex.getId()); assertEquals("routing is required for [idx]/[type]/[id]", ex.getMessage()); } @@ -494,24 +494,15 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { assertNull(ex.name()); } - public void testIndexException() throws IOException { - IndexException ex = serialize(new IndexException(new Index("foo"), "blub")); - assertEquals("blub", ex.getMessage()); - assertEquals(new Index("foo"), ex.index()); - - ex = serialize(new IndexException(null, "blub")); - assertEquals("blub", ex.getMessage()); - assertNull(ex.index()); - } public void testRecoveryEngineException() throws IOException { ShardId id = new ShardId("foo", 1); RecoveryEngineException ex = serialize(new RecoveryEngineException(id, 10, "total failure", new NullPointerException())); - assertEquals(id, ex.shardId()); + assertEquals(id, ex.getShardId()); assertEquals("Phase[10] total failure", ex.getMessage()); assertEquals(10, ex.phase()); ex = serialize(new RecoveryEngineException(null, -1, "total failure", new NullPointerException())); - assertNull(ex.shardId()); + assertNull(ex.getShardId()); assertEquals(-1, ex.phase()); assertTrue(ex.getCause() instanceof NullPointerException); } @@ -529,18 +520,6 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { assertEquals(1, ex.blocks().size()); } - public void testIndexShardException() throws IOException { - ShardId id = new ShardId("foo", 1); - IndexShardException ex = serialize(new IndexShardException(id, "boom", new NullPointerException())); - assertEquals(id, ex.shardId()); - assertEquals("boom", ex.getMessage()); - assertEquals(new Index("foo"), ex.index()); - assertTrue(ex.getCause() instanceof NullPointerException); - ex = serialize(new IndexShardException(null, "boom", new NullPointerException())); - assertEquals("boom", ex.getMessage()); - assertNull(ex.index()); - assertNull(ex.shardId()); - } private String toXContent(ToXContent x) { try { XContentBuilder builder = XContentFactory.jsonBuilder(); diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexTests.java index d2e996d623..e8d24c774e 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexTests.java @@ -20,13 +20,14 @@ package org.elasticsearch.action.admin.indices.get; import com.google.common.collect.ImmutableList; +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.admin.indices.get.GetIndexRequest.Feature; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.search.warmer.IndexWarmersMetaData.Entry; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; @@ -68,7 +69,7 @@ public class GetIndexTests extends ElasticsearchIntegrationTest { assertWarmers(response, "idx"); } - @Test(expected=IndexMissingException.class) + @Test(expected=IndexNotFoundException.class) public void testSimpleUnknownIndex() { client().admin().indices().prepareGetIndex().addIndices("missing_idx").get(); } diff --git a/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsTests.java b/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsTests.java index 800a49453c..d450d2399c 100644 --- a/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsTests.java @@ -47,7 +47,7 @@ public class BulkProcessorClusterSettingsTests extends ElasticsearchIntegrationT assertEquals(3, responses.length); assertFalse("Operation on existing index should succeed", responses[0].isFailed()); assertTrue("Missing index should have been flagged", responses[1].isFailed()); - assertEquals("[wontwork] no such index", responses[1].getFailureMessage()); + assertEquals("[wontwork] IndexNotFoundException[no such index]", responses[1].getFailureMessage()); assertFalse("Operation on existing index should succeed", responses[2].isFailed()); } } diff --git a/core/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTests.java b/core/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTests.java index 31d5af8d8b..06b21bbaab 100644 --- a/core/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTests.java +++ b/core/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTests.java @@ -40,7 +40,7 @@ import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.common.inject.internal.Join; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.*; import org.elasticsearch.test.ElasticsearchIntegrationTest; import java.io.IOException; @@ -262,7 +262,7 @@ public abstract class AbstractTermVectorsTests extends ElasticsearchIntegrationT } // always adds a test that fails configs.add(new TestConfig(new TestDoc("doesnt_exist", new TestFieldSetting[]{}, new String[]{}).index("doesn't_exist").alias("doesn't_exist"), - new String[]{"doesnt_exist"}, true, true, true).expectedException(IndexMissingException.class)); + new String[]{"doesnt_exist"}, true, true, true).expectedException(org.elasticsearch.index.IndexNotFoundException.class)); refresh(); diff --git a/core/src/test/java/org/elasticsearch/aliases/IndexAliasesTests.java b/core/src/test/java/org/elasticsearch/aliases/IndexAliasesTests.java index dd8d66469b..e4c873dd6f 100644 --- a/core/src/test/java/org/elasticsearch/aliases/IndexAliasesTests.java +++ b/core/src/test/java/org/elasticsearch/aliases/IndexAliasesTests.java @@ -38,7 +38,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException; +import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesNotFoundException; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.AggregationBuilders; @@ -529,7 +529,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest { } - @Test(expected = AliasesMissingException.class) + @Test(expected = AliasesNotFoundException.class) public void testIndicesRemoveNonExistingAliasResponds404() throws Exception { logger.info("--> creating index [test]"); createIndex("test"); diff --git a/core/src/test/java/org/elasticsearch/benchmark/recovery/ReplicaRecoveryBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/recovery/ReplicaRecoveryBenchmark.java index 0d3375d1c6..9648947af6 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/recovery/ReplicaRecoveryBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/recovery/ReplicaRecoveryBenchmark.java @@ -29,7 +29,7 @@ import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.SizeValue; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.node.Node; import org.elasticsearch.test.BackgroundIndexer; import org.elasticsearch.transport.TransportModule; @@ -81,7 +81,7 @@ public class ReplicaRecoveryBenchmark { indexer.setMaxFieldSize(150); try { client1.admin().indices().prepareDelete(INDEX_NAME).get(); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { } client1.admin().indices().prepareCreate(INDEX_NAME).get(); indexer.start(DOC_COUNT / 2); diff --git a/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java b/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java index 7dd1839c61..76d44642e4 100644 --- a/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java +++ b/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java @@ -24,6 +24,7 @@ import com.google.common.util.concurrent.ListenableFuture; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.get.GetIndexResponse; import org.elasticsearch.action.get.GetResponse; @@ -38,7 +39,6 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.MultiDataPathUpgrader; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.env.NodeEnvironment; -import org.elasticsearch.index.IndexException; import org.elasticsearch.index.engine.EngineConfig; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.shard.MergePolicyConfig; @@ -304,8 +304,8 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio try { client().admin().indices().prepareOpen(indexName).get(); fail("Shouldn't be able to open an old index"); - } catch (IndexException ex) { - assertThat(ex.getMessage(), containsString("cannot open the index due to upgrade failure")); + } catch (IllegalStateException ex) { + assertThat(ex.getMessage(), containsString("was created before v0.90.0 and wasn't upgraded")); } unloadIndex(indexName); logger.info("--> Done testing " + index + ", took " + ((System.currentTimeMillis() - startTime) / 1000.0) + " seconds"); diff --git a/core/src/test/java/org/elasticsearch/cluster/SimpleClusterStateTests.java b/core/src/test/java/org/elasticsearch/cluster/SimpleClusterStateTests.java index c102251862..d3b26ac630 100644 --- a/core/src/test/java/org/elasticsearch/cluster/SimpleClusterStateTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/SimpleClusterStateTests.java @@ -30,7 +30,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.hamcrest.CollectionAssertions; import org.junit.Before; @@ -195,14 +195,14 @@ public class SimpleClusterStateTests extends ElasticsearchIntegrationTest { assertThat(clusterStateResponse.getState().metaData().indices().isEmpty(), is(true)); } - @Test(expected=IndexMissingException.class) + @Test(expected=IndexNotFoundException.class) public void testIndicesOptionsOnAllowNoIndicesFalse() throws Exception { // empty wildcard expansion throws exception when allowNoIndices is turned off IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, false, true, false); client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("a*").setIndicesOptions(allowNoIndices).get(); } - @Test(expected=IndexMissingException.class) + @Test(expected=IndexNotFoundException.class) public void testIndicesIgnoreUnavailableFalse() throws Exception { // ignore_unavailable set to false throws exception when allowNoIndices is turned off IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, true, true, false); diff --git a/core/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java b/core/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java index 6f6b6685d7..9ffaaa6c33 100644 --- a/core/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java @@ -26,8 +26,8 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData.State; import org.elasticsearch.common.Strings; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.IndexClosedException; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; @@ -63,8 +63,8 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { try { indexNameExpressionResolver.concreteIndices(context, "bar"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("bar")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("bar")); } results = indexNameExpressionResolver.concreteIndices(context, "foofoo", "foobar"); @@ -78,15 +78,15 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { try { indexNameExpressionResolver.concreteIndices(context, "bar"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("bar")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("bar")); } try { indexNameExpressionResolver.concreteIndices(context, "foo", "bar"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("bar")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("bar")); } results = indexNameExpressionResolver.concreteIndices(context, "barbaz", "foobar"); @@ -96,8 +96,8 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { try { indexNameExpressionResolver.concreteIndices(context, "barbaz", "bar"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("bar")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("bar")); } results = indexNameExpressionResolver.concreteIndices(context, "baz*"); @@ -225,22 +225,22 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { try { indexNameExpressionResolver.concreteIndices(context, "bar"); fail(); - } catch(IndexMissingException e) { - assertThat(e.index().name(), equalTo("bar")); + } catch(IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("bar")); } try { indexNameExpressionResolver.concreteIndices(context, "baz*"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("baz*")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("baz*")); } try { indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("baz*")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("baz*")); } } @@ -320,8 +320,8 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { try { indexNameExpressionResolver.concreteIndices(context, "-*"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("-*")); + } catch (IndexNotFoundException e) { + assertThat(e.getResourceId().toString(), equalTo("[-*]")); } } @@ -364,8 +364,8 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { try { indexNameExpressionResolver.concreteIndices(context, "baz*"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("baz*")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("baz*")); } String[] results = indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); @@ -387,8 +387,8 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { try { indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("baz*")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("baz*")); } results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); @@ -403,15 +403,15 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { try { indexNameExpressionResolver.concreteIndices(context, "baz*"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("baz*")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("baz*")); } try { indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("baz*")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("baz*")); } String[] results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); @@ -436,16 +436,16 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); indexNameExpressionResolver.concreteIndices(context, "baz*"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("baz*")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("baz*")); } try { IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("baz*")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("baz*")); } try { @@ -470,7 +470,7 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { fail(); } catch(IndexClosedException e) { assertThat(e.getMessage(), equalTo("closed")); - assertEquals(e.index().getName(), "foofoo-closed"); + assertEquals(e.getIndex(), "foofoo-closed"); } IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); @@ -491,16 +491,16 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { try { indexNameExpressionResolver.concreteIndices(context, "foo"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("foo")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("foo")); } results = indexNameExpressionResolver.concreteIndices(context, "foo*"); assertThat(results, emptyArray()); try { indexNameExpressionResolver.concreteIndices(context, "foo*", "bar"); fail(); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("bar")); + } catch (IndexNotFoundException e) { + assertThat(e.getIndex(), equalTo("bar")); } @@ -517,8 +517,8 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false)); try { indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); - } catch (IndexMissingException e) { - assertThat(e.index().name(), equalTo("[_all]")); + } catch (IndexNotFoundException e) { + assertThat(e.getResourceId().toString(), equalTo("[_all]")); } } @@ -526,7 +526,7 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { return IndexMetaData.builder(index).settings(settings(Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); } - @Test(expected = IndexMissingException.class) + @Test(expected = IndexNotFoundException.class) public void testConcreteIndicesIgnoreIndicesOneMissingIndex() { MetaData.Builder mdBuilder = MetaData.builder() .put(indexBuilder("testXXX")) @@ -550,7 +550,7 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { assertThat(newHashSet(indexNameExpressionResolver.concreteIndices(context, "testXXX", "testZZZ")), equalTo(newHashSet("testXXX"))); } - @Test(expected = IndexMissingException.class) + @Test(expected = IndexNotFoundException.class) public void testConcreteIndicesIgnoreIndicesAllMissing() { MetaData.Builder mdBuilder = MetaData.builder() .put(indexBuilder("testXXX")) @@ -659,7 +659,7 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { try { indexNameExpressionResolver.concreteIndices(context, allIndices); fail("wildcard expansion on should trigger IndexMissingException"); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { // expected } } @@ -688,7 +688,7 @@ public class IndexNameExpressionResolverTests extends ElasticsearchTestCase { try { indexNameExpressionResolver.concreteIndices(context, "Foo*"); fail("expecting exeption when result empty and allowNoIndicec=false"); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { // expected exception } } diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTest.java b/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTest.java index 23fad2de2e..28e93ad693 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTest.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTest.java @@ -28,7 +28,7 @@ import org.elasticsearch.cluster.node.DiscoveryNodes.Builder; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.test.ElasticsearchAllocationTestCase; import org.junit.Before; import org.junit.Test; @@ -116,7 +116,7 @@ public class RoutingTableTest extends ElasticsearchAllocationTestCase { try { assertThat(this.testRoutingTable.allShards("not_existing").size(), is(0)); fail("Exception expected when calling allShards() with non existing index name"); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { // expected } } @@ -191,7 +191,7 @@ public class RoutingTableTest extends ElasticsearchAllocationTestCase { try { this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, true); fail("Calling with non-existing index name should raise IndexMissingException"); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { // expected } } @@ -220,7 +220,7 @@ public class RoutingTableTest extends ElasticsearchAllocationTestCase { try { this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, true); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { fail("Calling with non-existing index should be ignored at the moment"); } } @@ -239,7 +239,7 @@ public class RoutingTableTest extends ElasticsearchAllocationTestCase { try { this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, false); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { fail("Calling with non-existing index should be ignored at the moment"); } } diff --git a/core/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java b/core/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java index baa1f087cb..0e6a9559d7 100644 --- a/core/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java +++ b/core/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java @@ -191,7 +191,7 @@ public class CorruptedFileTest extends ElasticsearchIntegrationTest { CheckIndex.Status status = checkIndex.checkIndex(); if (!status.clean) { logger.warn("check index [failure]\n{}", new String(os.bytes().toBytes(), Charsets.UTF_8)); - throw new IndexShardException(sid, "index check failure"); + throw new IOException("index check failure"); } } } catch (Throwable t) { diff --git a/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java b/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java index baec5760b7..ff0110b39f 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java +++ b/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.indices; +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequestBuilder; @@ -50,6 +51,7 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.suggest.SuggestBuilders; import org.elasticsearch.search.warmer.IndexWarmersMetaData; @@ -525,7 +527,7 @@ public class IndicesOptionsIntegrationTests extends ElasticsearchIntegrationTest .setQuery(matchAllQuery()) .execute().actionGet(); fail("Exception should have been thrown."); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { } try { @@ -533,7 +535,7 @@ public class IndicesOptionsIntegrationTests extends ElasticsearchIntegrationTest .setQuery(matchAllQuery()) .execute().actionGet(); fail("Exception should have been thrown."); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { } //you should still be able to run empty searches without things blowing up @@ -892,8 +894,8 @@ public class IndicesOptionsIntegrationTests extends ElasticsearchIntegrationTest } else { try { requestBuilder.get(); - fail("IndexMissingException or IndexClosedException was expected"); - } catch (IndexMissingException | IndexClosedException e) {} + fail("IndexNotFoundException or IndexClosedException was expected"); + } catch (IndexNotFoundException | IndexClosedException e) {} } } else { if (requestBuilder instanceof SearchRequestBuilder) { diff --git a/core/src/test/java/org/elasticsearch/indices/exists/types/TypesExistsTests.java b/core/src/test/java/org/elasticsearch/indices/exists/types/TypesExistsTests.java index f72609298e..0191c56831 100644 --- a/core/src/test/java/org/elasticsearch/indices/exists/types/TypesExistsTests.java +++ b/core/src/test/java/org/elasticsearch/indices/exists/types/TypesExistsTests.java @@ -18,11 +18,12 @@ */ package org.elasticsearch.indices.exists.types; +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; @@ -61,11 +62,11 @@ public class TypesExistsTests extends ElasticsearchIntegrationTest { try { client.admin().indices().prepareTypesExists("notExist").setTypes("type1").execute().actionGet(); fail("Exception should have been thrown"); - } catch (IndexMissingException e) {} + } catch (IndexNotFoundException e) {} try { client.admin().indices().prepareTypesExists("notExist").setTypes("type0").execute().actionGet(); fail("Exception should have been thrown"); - } catch (IndexMissingException e) {} + } catch (IndexNotFoundException e) {} response = client.admin().indices().prepareTypesExists("alias1").setTypes("type1").execute().actionGet(); assertThat(response.isExists(), equalTo(true)); response = client.admin().indices().prepareTypesExists("*").setTypes("type1").execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTest.java b/core/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTest.java index 5d65c1acb7..8cd791b5c0 100644 --- a/core/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTest.java +++ b/core/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTest.java @@ -23,10 +23,12 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.Strings; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.index.shard.ShardNotFoundException; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.test.ElasticsearchSingleNodeTest; @@ -136,7 +138,8 @@ public class SyncedFlushSingleNodeTest extends ElasticsearchSingleNodeTest { listener.latch.await(); assertNotNull(listener.error); assertNull(listener.result); - assertEquals("missing", listener.error.getMessage()); + assertEquals(ShardNotFoundException.class, listener.error.getClass()); + assertEquals("no such shard", listener.error.getMessage()); final ShardId shardId = shard.shardId(); @@ -149,7 +152,7 @@ public class SyncedFlushSingleNodeTest extends ElasticsearchSingleNodeTest { assertEquals("closed", listener.error.getMessage()); listener = new SyncedFlushUtil.LatchedListener(); - flushService.attemptSyncedFlush(new ShardId("nosuchindex", 0), listener); + flushService.attemptSyncedFlush(new ShardId("index not found", 0), listener); listener.latch.await(); assertNotNull(listener.error); assertNull(listener.result); diff --git a/core/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexTests.java b/core/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexTests.java index 4ba9722775..d1b461ef20 100644 --- a/core/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexTests.java +++ b/core/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.indices.state; +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; @@ -31,8 +32,8 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; @@ -63,19 +64,19 @@ public class OpenCloseIndexTests extends ElasticsearchIntegrationTest { assertIndexIsOpened("test1"); } - @Test(expected = IndexMissingException.class) + @Test(expected = IndexNotFoundException.class) public void testSimpleCloseMissingIndex() { Client client = client(); client.admin().indices().prepareClose("test1").execute().actionGet(); } - @Test(expected = IndexMissingException.class) + @Test(expected = IndexNotFoundException.class) public void testSimpleOpenMissingIndex() { Client client = client(); client.admin().indices().prepareOpen("test1").execute().actionGet(); } - @Test(expected = IndexMissingException.class) + @Test(expected = IndexNotFoundException.class) public void testCloseOneMissingIndex() { Client client = client(); createIndex("test1"); @@ -96,7 +97,7 @@ public class OpenCloseIndexTests extends ElasticsearchIntegrationTest { assertIndexIsClosed("test1"); } - @Test(expected = IndexMissingException.class) + @Test(expected = IndexNotFoundException.class) public void testOpenOneMissingIndex() { Client client = client(); createIndex("test1"); diff --git a/core/src/test/java/org/elasticsearch/indices/state/SimpleIndexStateTests.java b/core/src/test/java/org/elasticsearch/indices/state/SimpleIndexStateTests.java index 9c1a78f2f0..0d162b7c52 100644 --- a/core/src/test/java/org/elasticsearch/indices/state/SimpleIndexStateTests.java +++ b/core/src/test/java/org/elasticsearch/indices/state/SimpleIndexStateTests.java @@ -31,8 +31,8 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.IndexClosedException; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; @@ -141,7 +141,7 @@ public class SimpleIndexStateTests extends ElasticsearchIntegrationTest { logger.info("--> deleting test index...."); try { client().admin().indices().prepareDelete("test").get(); - } catch (IndexMissingException ex) { + } catch (IndexNotFoundException ex) { // Ignore } diff --git a/core/src/test/java/org/elasticsearch/script/ScriptIndexSettingsTest.java b/core/src/test/java/org/elasticsearch/script/ScriptIndexSettingsTest.java index db8770a220..1a57c5155e 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptIndexSettingsTest.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptIndexSettingsTest.java @@ -26,7 +26,7 @@ import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; import org.elasticsearch.action.indexedscripts.get.GetIndexedScriptResponse; import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptResponse; import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; @@ -79,7 +79,7 @@ public class ScriptIndexSettingsTest extends ElasticsearchIntegrationTest{ try { GetIndexedScriptResponse response = client().prepareGetIndexedScript("groovy","foobar").get(); assertTrue(false); //This should not happen - } catch (IndexMissingException ime) { + } catch (IndexNotFoundException ime) { assertTrue(true); } } diff --git a/core/src/test/java/org/elasticsearch/test/TestCluster.java b/core/src/test/java/org/elasticsearch/test/TestCluster.java index a1f5f016a8..322ed74197 100644 --- a/core/src/test/java/org/elasticsearch/test/TestCluster.java +++ b/core/src/test/java/org/elasticsearch/test/TestCluster.java @@ -25,7 +25,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.IndexTemplateMissingException; import org.elasticsearch.repositories.RepositoryMissingException; @@ -135,7 +135,7 @@ public abstract class TestCluster implements Iterable<Client>, Closeable { if (size() > 0) { try { assertAcked(client().admin().indices().prepareDelete(indices)); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { // ignore } catch (IllegalArgumentException e) { // Happens if `action.destructive_requires_name` is set to true diff --git a/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java b/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java index 036d98cc18..5be741b9dc 100644 --- a/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java +++ b/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java @@ -136,7 +136,7 @@ public class MockFSDirectoryService extends FsDirectoryService { throw new UnsupportedOperationException(); } - public void checkIndex(Store store, ShardId shardId) throws IndexShardException { + public void checkIndex(Store store, ShardId shardId) { if (store.tryIncRef()) { logger.info("start check index"); try { @@ -159,7 +159,7 @@ public class MockFSDirectoryService extends FsDirectoryService { logger.warn("check index [failure] index files={}\n{}", Arrays.toString(dir.listAll()), new String(os.bytes().toBytes(), Charsets.UTF_8)); - throw new IndexShardException(shardId, "index check failure"); + throw new IOException("index check failure"); } else { if (logger.isDebugEnabled()) { logger.debug("check index [success]\n{}", new String(os.bytes().toBytes(), Charsets.UTF_8)); diff --git a/core/src/test/java/org/elasticsearch/validate/SimpleValidateQueryTests.java b/core/src/test/java/org/elasticsearch/validate/SimpleValidateQueryTests.java index 5f40da8171..0026957fe7 100644 --- a/core/src/test/java/org/elasticsearch/validate/SimpleValidateQueryTests.java +++ b/core/src/test/java/org/elasticsearch/validate/SimpleValidateQueryTests.java @@ -27,9 +27,9 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import org.elasticsearch.test.ElasticsearchIntegrationTest.Scope; @@ -145,7 +145,7 @@ public class SimpleValidateQueryTests extends ElasticsearchIntegrationTest { assertThat(response.isValid(), equalTo(true)); } - @Test(expected = IndexMissingException.class) + @Test(expected = IndexNotFoundException.class) public void validateEmptyCluster() { client().admin().indices().prepareValidateQuery().get(); } diff --git a/plugins/delete-by-query/src/test/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryTests.java b/plugins/delete-by-query/src/test/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryTests.java index ed0957963a..16b96be179 100644 --- a/plugins/delete-by-query/src/test/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryTests.java +++ b/plugins/delete-by-query/src/test/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryTests.java @@ -33,9 +33,9 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.query.MatchQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import org.junit.Test; @@ -151,7 +151,7 @@ public class DeleteByQueryTests extends ElasticsearchIntegrationTest { try { delete.get(); fail("should have thrown an exception because of a missing index"); - } catch (IndexMissingException e) { + } catch (IndexNotFoundException e) { // Ok } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/mpercolate/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/mpercolate/10_basic.yaml index 9f949c21cd..cb1cb2ed02 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/mpercolate/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/mpercolate/10_basic.yaml @@ -37,5 +37,5 @@ foo: bar - match: { responses.0.total: 1 } - - match: { responses.1.error: "/IndexMissingException.no.such.index./" } + - match: { responses.1.error: "/IndexNotFoundException.no.such.index./" } - match: { responses.2.total: 1 } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yaml index 76ef7c4230..8b736b860b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yaml @@ -39,7 +39,7 @@ match: {foo: bar} - match: { responses.0.hits.total: 3 } - - match: { responses.1.error.root_cause.0.type: index_missing_exception } + - match: { responses.1.error.root_cause.0.type: index_not_found_exception } - match: { responses.1.error.root_cause.0.reason: "/no.such.index/" } - match: { responses.1.error.root_cause.0.index: test_2 } - match: { responses.2.hits.total: 1 } |