Search in sources :

Example 1 with Failure

use of org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo.Failure 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 Failure

use of org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo.Failure in project elasticsearch by elastic.

the class RandomObjects method randomShardInfo.

/**
     * Returns a tuple that contains a randomized {@link ShardInfo} 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#fromXContent(XContentParser)}. A `withShardFailures` parameter indicates if
     * the randomized ShardInfo must or must not contain shard failures.
     *
     * @param random            Random generator
     * @param withShardFailures indicates if the generated ShardInfo must contain shard failures
     */
public static Tuple<ShardInfo, ShardInfo> randomShardInfo(Random random, boolean withShardFailures) {
    int total = randomIntBetween(random, 1, 10);
    if (withShardFailures == false) {
        return Tuple.tuple(new ShardInfo(total, total), new ShardInfo(total, total));
    }
    int successful = randomIntBetween(random, 1, Math.max(1, (total - 1)));
    int failures = Math.max(1, (total - successful));
    Failure[] actualFailures = new Failure[failures];
    Failure[] expectedFailures = new Failure[failures];
    for (int i = 0; i < failures; i++) {
        Tuple<Failure, Failure> failure = randomShardInfoFailure(random);
        actualFailures[i] = failure.v1();
        expectedFailures[i] = failure.v2();
    }
    return Tuple.tuple(new ShardInfo(total, successful, actualFailures), new ShardInfo(total, successful, expectedFailures));
}
Also used : Failure(org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo.Failure) ShardInfo(org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo)

Aggregations

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