Search in sources :

Example 1 with IndexShardRecoveringException

use of org.opensearch.index.shard.IndexShardRecoveringException in project OpenSearch by opensearch-project.

the class RandomObjects method randomShardInfoFailure.

/**
 * Returns a tuple that contains a randomized {@link Failure} value (left side) and its corresponding
 * value (right side) after it has been printed out as a {@link ToXContent} and parsed back using a parsing
 * method like {@link ShardInfo.Failure#fromXContent(XContentParser)}.
 *
 * @param random Random generator
 */
private static Tuple<Failure, Failure> randomShardInfoFailure(Random random) {
    String index = randomAsciiLettersOfLength(random, 5);
    String indexUuid = randomAsciiLettersOfLength(random, 5);
    int shardId = randomIntBetween(random, 1, 10);
    String nodeId = randomAsciiLettersOfLength(random, 5);
    RestStatus status = randomFrom(random, RestStatus.INTERNAL_SERVER_ERROR, RestStatus.FORBIDDEN, RestStatus.NOT_FOUND);
    boolean primary = random.nextBoolean();
    ShardId shard = new ShardId(index, indexUuid, shardId);
    Exception actualException;
    OpenSearchException expectedException;
    int type = randomIntBetween(random, 0, 3);
    switch(type) {
        case 0:
            actualException = new ClusterBlockException(singleton(NoMasterBlockService.NO_MASTER_BLOCK_WRITES));
            expectedException = new OpenSearchException("OpenSearch exception [type=cluster_block_exception, " + "reason=blocked by: [SERVICE_UNAVAILABLE/2/no master];]");
            break;
        case 1:
            actualException = new ShardNotFoundException(shard);
            expectedException = new OpenSearchException("OpenSearch exception [type=shard_not_found_exception, " + "reason=no such shard]");
            expectedException.setShard(shard);
            break;
        case 2:
            actualException = new IllegalArgumentException("Closed resource", new RuntimeException("Resource"));
            expectedException = new OpenSearchException("OpenSearch exception [type=illegal_argument_exception, " + "reason=Closed resource]", new OpenSearchException("OpenSearch exception [type=runtime_exception, reason=Resource]"));
            break;
        case 3:
            actualException = new IndexShardRecoveringException(shard);
            expectedException = new OpenSearchException("OpenSearch exception [type=index_shard_recovering_exception, " + "reason=CurrentState[RECOVERING] Already recovering]");
            expectedException.setShard(shard);
            break;
        default:
            throw new UnsupportedOperationException("No randomized exceptions generated for type [" + type + "]");
    }
    Failure actual = new Failure(shard, nodeId, actualException, status, primary);
    Failure expected = new Failure(new ShardId(index, INDEX_UUID_NA_VALUE, shardId), nodeId, expectedException, status, primary);
    return Tuple.tuple(actual, expected);
}
Also used : IndexShardRecoveringException(org.opensearch.index.shard.IndexShardRecoveringException) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) OpenSearchException(org.opensearch.OpenSearchException) IndexShardRecoveringException(org.opensearch.index.shard.IndexShardRecoveringException) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) ShardNotFoundException(org.opensearch.index.shard.ShardNotFoundException) ShardId(org.opensearch.index.shard.ShardId) RestStatus(org.opensearch.rest.RestStatus) ShardNotFoundException(org.opensearch.index.shard.ShardNotFoundException) OpenSearchException(org.opensearch.OpenSearchException) Failure(org.opensearch.action.support.replication.ReplicationResponse.ShardInfo.Failure)

Aggregations

IOException (java.io.IOException)1 OpenSearchException (org.opensearch.OpenSearchException)1 Failure (org.opensearch.action.support.replication.ReplicationResponse.ShardInfo.Failure)1 ClusterBlockException (org.opensearch.cluster.block.ClusterBlockException)1 IndexShardRecoveringException (org.opensearch.index.shard.IndexShardRecoveringException)1 ShardId (org.opensearch.index.shard.ShardId)1 ShardNotFoundException (org.opensearch.index.shard.ShardNotFoundException)1 RestStatus (org.opensearch.rest.RestStatus)1