use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class TransportBulkActionIndicesThatCannotBeCreatedTests method testAllFail.
public void testAllFail() {
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(new IndexRequest("no"));
bulkRequest.add(new IndexRequest("can't"));
bulkRequest.add(new DeleteRequest("do").version(0).versionType(VersionType.EXTERNAL));
bulkRequest.add(new UpdateRequest("nothin", randomAlphaOfLength(5)));
indicesThatCannotBeCreatedTestCase(new HashSet<>(Arrays.asList("no", "can't", "do", "nothin")), bulkRequest, index -> {
throw new IndexNotFoundException("Can't make it because I say so");
});
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class IndexNameExpressionResolverTests method testConcreteIndicesNoIndicesErrorMessageNoExpand.
public void testConcreteIndicesNoIndicesErrorMessageNoExpand() {
Metadata.Builder mdBuilder = Metadata.builder();
ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(false, false, false, false), false);
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndices(context, new String[] {}));
assertThat(infe.getMessage(), is("no such index [_all] and no indices exist"));
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class IndexNameExpressionResolverTests method testIndexOptionsAllowUnavailableDisallowEmpty.
public void testIndexOptionsAllowUnavailableDisallowEmpty() {
Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("foo")).put(indexBuilder("foobar")).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();
IndicesOptions expandOpen = IndicesOptions.fromOptions(true, false, true, false);
IndicesOptions expand = IndicesOptions.fromOptions(true, false, true, true);
IndicesOptions[] indicesOptions = new IndicesOptions[] { expandOpen, expand };
for (IndicesOptions options : indicesOptions) {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, false);
String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo");
assertEquals(1, results.length);
assertEquals("foo", results[0]);
{
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "bar"));
assertThat(infe.getIndex().getName(), equalTo("bar"));
}
{
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "baz*"));
assertThat(infe.getIndex().getName(), equalTo("baz*"));
}
{
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"));
assertThat(infe.getIndex().getName(), equalTo("baz*"));
}
}
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, expandOpen, false);
String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(3, results.length);
context = new IndexNameExpressionResolver.Context(state, expand, false);
results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(4, results.length);
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class MetadataIndexAliasesServiceTests method testAddAliasToRemovedIndex.
public void testAddAliasToRemovedIndex() {
// Create "test"
ClusterState before = createIndex(ClusterState.builder(ClusterName.DEFAULT).build(), "test");
// Attempt to add an alias to "test" at the same time as we remove it
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> service.applyAliasActions(before, Arrays.asList(new AliasAction.Add("test", "alias", null, null, null, null, null), new AliasAction.RemoveIndex("test"))));
assertEquals("test", e.getIndex().getName());
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class IndexShard method startRecovery.
public void startRecovery(RecoveryState recoveryState, PeerRecoveryTargetService recoveryTargetService, PeerRecoveryTargetService.RecoveryListener recoveryListener, RepositoriesService repositoriesService, Consumer<MappingMetadata> mappingUpdateConsumer, IndicesService indicesService) {
// }
assert recoveryState.getRecoverySource().equals(shardRouting.recoverySource());
switch(recoveryState.getRecoverySource().getType()) {
case EMPTY_STORE:
case EXISTING_STORE:
executeRecovery("from store", recoveryState, recoveryListener, this::recoverFromStore);
break;
case PEER:
try {
markAsRecovering("from " + recoveryState.getSourceNode(), recoveryState);
recoveryTargetService.startRecovery(this, recoveryState.getSourceNode(), recoveryListener);
} catch (Exception e) {
failShard("corrupted preexisting index", e);
recoveryListener.onRecoveryFailure(recoveryState, new RecoveryFailedException(recoveryState, null, e), true);
}
break;
case SNAPSHOT:
final String repo = ((SnapshotRecoverySource) recoveryState.getRecoverySource()).snapshot().getRepository();
executeRecovery("from snapshot", recoveryState, recoveryListener, l -> restoreFromRepository(repositoriesService.repository(repo), l));
break;
case LOCAL_SHARDS:
final IndexMetadata indexMetadata = indexSettings().getIndexMetadata();
final Index resizeSourceIndex = indexMetadata.getResizeSourceIndex();
final List<IndexShard> startedShards = new ArrayList<>();
final IndexService sourceIndexService = indicesService.indexService(resizeSourceIndex);
final Set<ShardId> requiredShards;
final int numShards;
if (sourceIndexService != null) {
requiredShards = IndexMetadata.selectRecoverFromShards(shardId().id(), sourceIndexService.getMetadata(), indexMetadata.getNumberOfShards());
for (IndexShard shard : sourceIndexService) {
if (shard.state() == IndexShardState.STARTED && requiredShards.contains(shard.shardId())) {
startedShards.add(shard);
}
}
numShards = requiredShards.size();
} else {
numShards = -1;
requiredShards = Collections.emptySet();
}
if (numShards == startedShards.size()) {
assert requiredShards.isEmpty() == false;
executeRecovery("from local shards", recoveryState, recoveryListener, l -> recoverFromLocalShards(mappingUpdateConsumer, startedShards.stream().filter((s) -> requiredShards.contains(s.shardId())).collect(Collectors.toList()), l));
} else {
final RuntimeException e;
if (numShards == -1) {
e = new IndexNotFoundException(resizeSourceIndex);
} else {
e = new IllegalStateException("not all required shards of index " + resizeSourceIndex + " are started yet, expected " + numShards + " found " + startedShards.size() + " can't recover shard " + shardId());
}
throw e;
}
break;
default:
throw new IllegalArgumentException("Unknown recovery source " + recoveryState.getRecoverySource());
}
}
Aggregations