use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class CloseIndexResponseTests method createServerTestInstance.
@Override
protected org.opensearch.action.admin.indices.close.CloseIndexResponse createServerTestInstance(XContentType xContentType) {
boolean acknowledged = true;
final String[] indicesNames = generateRandomStringArray(10, 10, false, true);
final List<org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult> indexResults = new ArrayList<>();
for (String indexName : indicesNames) {
final Index index = new Index(indexName, randomAlphaOfLength(5));
if (randomBoolean()) {
indexResults.add(new org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult(index));
} else {
if (randomBoolean()) {
acknowledged = false;
Exception exception = randomFrom(new IndexNotFoundException(index), new ActionNotFoundTransportException("test"));
indexResults.add(new org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult(index, exception));
} else {
final int nbShards = randomIntBetween(1, 5);
org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult[] shards = new org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult[nbShards];
for (int i = 0; i < nbShards; i++) {
org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult.Failure[] failures = null;
if (randomBoolean()) {
acknowledged = false;
int nbFailures = randomIntBetween(1, 3);
failures = new org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult.Failure[nbFailures];
for (int j = 0; j < failures.length; j++) {
String nodeId = null;
if (frequently()) {
nodeId = randomAlphaOfLength(5);
}
failures[j] = newFailure(indexName, i, nodeId);
}
}
shards[i] = new org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult(i, failures);
}
indexResults.add(new org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult(index, shards));
}
}
}
final boolean shardsAcknowledged = acknowledged ? randomBoolean() : false;
return new org.opensearch.action.admin.indices.close.CloseIndexResponse(acknowledged, shardsAcknowledged, indexResults);
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class TypesExistsIT method testSimple.
public void testSimple() throws Exception {
Client client = client();
CreateIndexResponse response1 = client.admin().indices().prepareCreate("test1").addMapping("type1", jsonBuilder().startObject().startObject("type1").endObject().endObject()).execute().actionGet();
CreateIndexResponse response2 = client.admin().indices().prepareCreate("test2").addMapping("type2", jsonBuilder().startObject().startObject("type2").endObject().endObject()).execute().actionGet();
client.admin().indices().prepareAliases().addAlias("test1", "alias1").execute().actionGet();
assertAcked(response1);
assertAcked(response2);
TypesExistsResponse response = client.admin().indices().prepareTypesExists("test1").setTypes("type1").execute().actionGet();
assertThat(response.isExists(), equalTo(true));
response = client.admin().indices().prepareTypesExists("test1").setTypes("type2").execute().actionGet();
assertThat(response.isExists(), equalTo(false));
try {
client.admin().indices().prepareTypesExists("notExist").setTypes("type1").execute().actionGet();
fail("Exception should have been thrown");
} catch (IndexNotFoundException e) {
}
try {
client.admin().indices().prepareTypesExists("notExist").setTypes("type0").execute().actionGet();
fail("Exception should have been thrown");
} 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();
assertThat(response.isExists(), equalTo(false));
response = client.admin().indices().prepareTypesExists("test1", "test2").setTypes("type1").execute().actionGet();
assertThat(response.isExists(), equalTo(false));
response = client.admin().indices().prepareTypesExists("test1", "test2").setTypes("type2").execute().actionGet();
assertThat(response.isExists(), equalTo(false));
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class TransportValidateQueryAction method doExecute.
@Override
protected void doExecute(Task task, ValidateQueryRequest request, ActionListener<ValidateQueryResponse> listener) {
request.nowInMillis = System.currentTimeMillis();
LongSupplier timeProvider = () -> request.nowInMillis;
ActionListener<org.opensearch.index.query.QueryBuilder> rewriteListener = ActionListener.wrap(rewrittenQuery -> {
request.query(rewrittenQuery);
super.doExecute(task, request, listener);
}, ex -> {
if (ex instanceof IndexNotFoundException || ex instanceof IndexClosedException) {
listener.onFailure(ex);
return;
}
List<QueryExplanation> explanations = new ArrayList<>();
explanations.add(new QueryExplanation(null, QueryExplanation.RANDOM_SHARD, false, null, ex.getMessage()));
listener.onResponse(new ValidateQueryResponse(false, explanations, // which is 0 since the failure is happening on the coordinating node.
0, 0, 0, null));
});
if (request.query() == null) {
rewriteListener.onResponse(request.query());
} else {
Rewriteable.rewriteAndFetch(request.query(), searchService.getRewriteContext(timeProvider), rewriteListener);
}
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class CreateIndexIT method testCreateAndDeleteIndexConcurrently.
public void testCreateAndDeleteIndexConcurrently() throws InterruptedException {
createIndex("test");
final AtomicInteger indexVersion = new AtomicInteger(0);
final Object indexVersionLock = new Object();
final CountDownLatch latch = new CountDownLatch(1);
int numDocs = randomIntBetween(1, 10);
for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test").setSource("index_version", indexVersion.get()).get();
}
synchronized (indexVersionLock) {
// not necessarily needed here but for completeness we lock here too
indexVersion.incrementAndGet();
}
client().admin().indices().prepareDelete("test").execute(new // this happens async!!!
ActionListener<AcknowledgedResponse>() {
@Override
public void onResponse(AcknowledgedResponse deleteIndexResponse) {
Thread thread = new Thread() {
@Override
public void run() {
try {
// recreate that index
client().prepareIndex("test").setSource("index_version", indexVersion.get()).get();
synchronized (indexVersionLock) {
// we sync here since we have to ensure that all indexing operations below for a given ID are done before
// we increment the index version otherwise a doc that is in-flight could make it into an index that it
// was supposed to be deleted for and our assertion fail...
indexVersion.incrementAndGet();
}
// from here on all docs with index_version == 0|1 must be gone!!!! only 2 are ok;
assertAcked(client().admin().indices().prepareDelete("test").get());
} finally {
latch.countDown();
}
}
};
thread.start();
}
@Override
public void onFailure(Exception e) {
throw new RuntimeException(e);
}
});
numDocs = randomIntBetween(100, 200);
for (int i = 0; i < numDocs; i++) {
try {
synchronized (indexVersionLock) {
client().prepareIndex("test").setSource("index_version", indexVersion.get()).setTimeout(TimeValue.timeValueSeconds(10)).get();
}
} catch (IndexNotFoundException inf) {
// fine
} catch (UnavailableShardsException ex) {
assertEquals(ex.getCause().getClass(), IndexNotFoundException.class);
// fine we run into a delete index while retrying
}
}
latch.await();
refresh();
// we only really assert that we never reuse segments of old indices or anything like this here and that nothing fails with
// crazy exceptions
SearchResponse expected = client().prepareSearch("test").setIndicesOptions(IndicesOptions.lenientExpandOpen()).setQuery(new RangeQueryBuilder("index_version").from(indexVersion.get(), true)).get();
SearchResponse all = client().prepareSearch("test").setIndicesOptions(IndicesOptions.lenientExpandOpen()).get();
assertEquals(expected + " vs. " + all, expected.getHits().getTotalHits().value, all.getHits().getTotalHits().value);
logger.info("total: {}", expected.getHits().getTotalHits().value);
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class CloseIndexIT method testCloseMissingIndex.
public void testCloseMissingIndex() {
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareClose("test").get());
assertThat(e.getMessage(), is("no such index [test]"));
}
Aggregations