use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.
the class IndexNameExpressionResolverTests method testIndexOptionsNoExpandWildcards.
public void testIndexOptionsNoExpandWildcards() {
MetaData.Builder mdBuilder = MetaData.builder().put(indexBuilder("foo").putAlias(AliasMetaData.builder("foofoobar"))).put(indexBuilder("foobar").putAlias(AliasMetaData.builder("foofoobar"))).put(indexBuilder("foofoo-closed").state(IndexMetaData.State.CLOSE)).put(indexBuilder("foofoo").putAlias(AliasMetaData.builder("barbaz")));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
//ignore unavailable and allow no indices
{
IndicesOptions noExpandLenient = IndicesOptions.fromOptions(true, true, false, false);
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient);
String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
assertEquals(1, results.length);
assertEquals("foo", results[0]);
results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
results = indexNameExpressionResolver.concreteIndexNames(context, (String[]) null);
assertEquals(0, results.length);
results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(0, results.length);
}
//ignore unavailable but don't allow no indices
{
IndicesOptions noExpandDisallowEmpty = IndicesOptions.fromOptions(true, false, false, false);
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty);
try {
indexNameExpressionResolver.concreteIndexNames(context, "baz*");
fail();
} catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*"));
}
String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
assertEquals(1, results.length);
assertEquals("foo", results[0]);
results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
}
//error on unavailable but allow no indices
{
IndicesOptions noExpandErrorUnavailable = IndicesOptions.fromOptions(false, true, false, false);
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable);
String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
assertThat(results, emptyArray());
try {
indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
fail();
} catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*"));
}
results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
}
//error on both unavailable and no indices
{
IndicesOptions noExpandStrict = IndicesOptions.fromOptions(false, false, false, false);
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict);
try {
indexNameExpressionResolver.concreteIndexNames(context, "baz*");
fail();
} catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*"));
}
try {
indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
fail();
} catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*"));
}
String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
}
}
use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.
the class IndexNameExpressionResolverTests method testIndexOptionsEmptyCluster.
public void testIndexOptionsEmptyCluster() {
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(MetaData.builder().build()).build();
IndicesOptions options = IndicesOptions.strictExpandOpen();
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertThat(results, emptyArray());
try {
indexNameExpressionResolver.concreteIndexNames(context, "foo");
fail();
} catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("foo"));
}
results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
assertThat(results, emptyArray());
try {
indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar");
fail();
} catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("bar"));
}
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndexNames(context, "foo");
assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar");
assertThat(results, emptyArray());
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false));
try {
indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
} catch (IndexNotFoundException e) {
assertThat(e.getResourceId().toString(), equalTo("[_all]"));
}
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class HttpBlobHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
Throwable ex = e.getCause();
if (ex instanceof ClosedChannelException) {
LOGGER.trace("channel closed: {}", ex.toString());
return;
} else if (ex instanceof IOException) {
String message = ex.getMessage();
if (message != null && message.contains("Connection reset by peer")) {
LOGGER.debug(message);
} else {
LOGGER.warn(message, e);
}
return;
}
HttpResponseStatus status;
String body = null;
if (ex instanceof DigestMismatchException || ex instanceof BlobsDisabledException || ex instanceof IllegalArgumentException) {
status = HttpResponseStatus.BAD_REQUEST;
body = String.format(Locale.ENGLISH, "Invalid request sent: %s", ex.getMessage());
} else if (ex instanceof DigestNotFoundException || ex instanceof IndexNotFoundException) {
status = HttpResponseStatus.NOT_FOUND;
} else if (ex instanceof EsRejectedExecutionException) {
status = TOO_MANY_REQUESTS;
body = String.format(Locale.ENGLISH, "Rejected execution: %s", ex.getMessage());
} else {
status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
body = String.format(Locale.ENGLISH, "Unhandled exception: %s", ex);
}
if (body != null) {
LOGGER.debug(body);
}
simpleResponse(status, body);
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class FetchContext method innerPrepare.
@Override
public void innerPrepare() {
HashMap<String, TableIdent> index2TableIdent = new HashMap<>();
for (Map.Entry<TableIdent, Collection<String>> entry : phase.tableIndices().asMap().entrySet()) {
for (String indexName : entry.getValue()) {
index2TableIdent.put(indexName, entry.getKey());
}
}
Set<TableIdent> tablesWithFetchRefs = new HashSet<>();
for (Reference reference : phase.fetchRefs()) {
tablesWithFetchRefs.add(reference.ident().tableIdent());
}
for (Routing routing : routingIterable) {
Map<String, Map<String, List<Integer>>> locations = routing.locations();
Map<String, List<Integer>> indexShards = locations.get(localNodeId);
for (Map.Entry<String, List<Integer>> indexShardsEntry : indexShards.entrySet()) {
String index = indexShardsEntry.getKey();
Integer base = phase.bases().get(index);
if (base == null) {
continue;
}
TableIdent ident = index2TableIdent.get(index);
assert ident != null : "no tableIdent found for index " + index;
tableIdents.put(base, ident);
toFetch.put(ident, new ArrayList<Reference>());
for (Integer shard : indexShardsEntry.getValue()) {
ShardId shardId = new ShardId(index, shard);
int readerId = base + shardId.id();
SharedShardContext shardContext = shardContexts.get(readerId);
if (shardContext == null) {
shardContext = sharedShardContexts.createContext(shardId, readerId);
shardContexts.put(readerId, shardContext);
if (tablesWithFetchRefs.contains(ident)) {
try {
searchers.put(readerId, shardContext.acquireSearcher());
} catch (IndexNotFoundException e) {
if (!PartitionName.isPartition(index)) {
throw e;
}
}
}
}
}
}
}
for (Reference reference : phase.fetchRefs()) {
Collection<Reference> references = toFetch.get(reference.ident().tableIdent());
if (references != null) {
references.add(reference);
}
}
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class BulkRetryCoordinatorPool method coordinator.
public BulkRetryCoordinator coordinator(ShardId shardId) throws IndexNotFoundException, ShardNotFoundException {
synchronized (coordinatorsByShardId) {
BulkRetryCoordinator coordinator = coordinatorsByShardId.get(shardId);
if (coordinator == null) {
IndexRoutingTable indexRoutingTable = clusterService.state().routingTable().index(shardId.getIndex());
if (indexRoutingTable == null) {
throw new IndexNotFoundException("cannot find index " + shardId.index());
}
IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId.id());
if (shardRoutingTable == null) {
throw new ShardNotFoundException(shardId);
}
String nodeId = shardRoutingTable.primaryShard().currentNodeId();
// wow, that is a long comment!
synchronized (coordinatorsByNodeId) {
coordinator = coordinatorsByNodeId.get(nodeId);
if (coordinator == null) {
LOGGER.debug("create new coordinator for node {} and shard {}", nodeId, shardId);
coordinator = new BulkRetryCoordinator(threadPool);
coordinatorsByNodeId.put(nodeId, coordinator);
}
}
coordinatorsByShardId.put(shardId, coordinator);
}
return coordinator;
}
}
Aggregations