Search in sources :

Example 1 with IndexShardRecoveringException

use of org.elasticsearch.index.shard.IndexShardRecoveringException in project elasticsearch by elastic.

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 = randomAsciiOfLength(random, 5);
    String indexUuid = randomAsciiOfLength(random, 5);
    int shardId = randomIntBetween(random, 1, 10);
    String nodeId = randomAsciiOfLength(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;
    ElasticsearchException expectedException;
    int type = randomIntBetween(random, 0, 3);
    switch(type) {
        case 0:
            actualException = new ClusterBlockException(singleton(DiscoverySettings.NO_MASTER_BLOCK_WRITES));
            expectedException = new ElasticsearchException("Elasticsearch exception [type=cluster_block_exception, " + "reason=blocked by: [SERVICE_UNAVAILABLE/2/no master];]");
            break;
        case 1:
            actualException = new ShardNotFoundException(shard);
            expectedException = new ElasticsearchException("Elasticsearch 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 ElasticsearchException("Elasticsearch exception [type=illegal_argument_exception, " + "reason=Closed resource]", new ElasticsearchException("Elasticsearch exception [type=runtime_exception, reason=Resource]"));
            break;
        case 3:
            actualException = new IndexShardRecoveringException(shard);
            expectedException = new ElasticsearchException("Elasticsearch 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.elasticsearch.index.shard.IndexShardRecoveringException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexShardRecoveringException(org.elasticsearch.index.shard.IndexShardRecoveringException) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) ShardId(org.elasticsearch.index.shard.ShardId) RestStatus(org.elasticsearch.rest.RestStatus) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) Failure(org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo.Failure)

Example 2 with IndexShardRecoveringException

use of org.elasticsearch.index.shard.IndexShardRecoveringException in project crate by crate.

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;
    ElasticsearchException expectedException;
    int type = randomIntBetween(random, 0, 3);
    switch(type) {
        case 0:
            actualException = new ClusterBlockException(singleton(DiscoverySettings.NO_MASTER_BLOCK_WRITES));
            expectedException = new ElasticsearchException("Elasticsearch exception [type=cluster_block_exception, " + "reason=blocked by: [SERVICE_UNAVAILABLE/2/no master];]");
            break;
        case 1:
            actualException = new ShardNotFoundException(shard);
            expectedException = new ElasticsearchException("Elasticsearch 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 ElasticsearchException("Elasticsearch exception [type=illegal_argument_exception, " + "reason=Closed resource]", new ElasticsearchException("Elasticsearch exception [type=runtime_exception, reason=Resource]"));
            break;
        case 3:
            actualException = new IndexShardRecoveringException(shard);
            expectedException = new ElasticsearchException("Elasticsearch 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.elasticsearch.index.shard.IndexShardRecoveringException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexShardRecoveringException(org.elasticsearch.index.shard.IndexShardRecoveringException) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) ShardId(org.elasticsearch.index.shard.ShardId) RestStatus(org.elasticsearch.rest.RestStatus) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) Failure(org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo.Failure)

Aggregations

IOException (java.io.IOException)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 Failure (org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo.Failure)2 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)2 IndexShardRecoveringException (org.elasticsearch.index.shard.IndexShardRecoveringException)2 ShardId (org.elasticsearch.index.shard.ShardId)2 ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)2 RestStatus (org.elasticsearch.rest.RestStatus)2