Search in sources :

Example 1 with ShardOperationFailedException

use of org.elasticsearch.action.ShardOperationFailedException in project crate by crate.

the class FailedShardsExceptionTest method testShardFailureReasonIsNull.

@Test
public void testShardFailureReasonIsNull() throws Exception {
    FailedShardsException exception = new FailedShardsException(new ShardOperationFailedException[] { new ShardOperationFailedException() {

        @Override
        public String index() {
            return null;
        }

        @Override
        public int shardId() {
            return 0;
        }

        @Override
        public String reason() {
            return null;
        }

        @Override
        public RestStatus status() {
            return null;
        }

        @Override
        public void readFrom(StreamInput in) throws IOException {
        }

        @Override
        public void writeTo(StreamOutput out) throws IOException {
        }

        @Override
        public Throwable getCause() {
            return null;
        }

        @Override
        public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
            return null;
        }
    }, null });
    assertThat(exception.getMessage(), is("query failed on shards 0 ( null )"));
}
Also used : RestStatus(org.elasticsearch.rest.RestStatus) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) IOException(java.io.IOException) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with ShardOperationFailedException

use of org.elasticsearch.action.ShardOperationFailedException in project elasticsearch by elastic.

the class ElasticsearchAssertions method assertBlocked.

/**
     * Checks that all shard requests of a replicated broadcast request failed due to a cluster block
     *
     * @param replicatedBroadcastResponse the response that should only contain failed shard responses
     *
     * */
public static void assertBlocked(BroadcastResponse replicatedBroadcastResponse) {
    assertThat("all shard requests should have failed", replicatedBroadcastResponse.getFailedShards(), Matchers.equalTo(replicatedBroadcastResponse.getTotalShards()));
    for (ShardOperationFailedException exception : replicatedBroadcastResponse.getShardFailures()) {
        ClusterBlockException clusterBlockException = (ClusterBlockException) ExceptionsHelper.unwrap(exception.getCause(), ClusterBlockException.class);
        assertNotNull("expected the cause of failure to be a ClusterBlockException but got " + exception.getCause().getMessage(), clusterBlockException);
        assertThat(clusterBlockException.blocks().size(), greaterThan(0));
        assertThat(clusterBlockException.status(), CoreMatchers.equalTo(RestStatus.FORBIDDEN));
    }
}
Also used : ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException)

Example 3 with ShardOperationFailedException

use of org.elasticsearch.action.ShardOperationFailedException in project elasticsearch by elastic.

the class ESIntegTestCase method flush.

/**
     * Flush some or all indices in the cluster.
     */
protected final FlushResponse flush(String... indices) {
    waitForRelocation();
    FlushResponse actionGet = client().admin().indices().prepareFlush(indices).execute().actionGet();
    for (ShardOperationFailedException failure : actionGet.getShardFailures()) {
        assertThat("unexpected flush failure " + failure.reason(), failure.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
    }
    return actionGet;
}
Also used : FlushResponse(org.elasticsearch.action.admin.indices.flush.FlushResponse) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException)

Example 4 with ShardOperationFailedException

use of org.elasticsearch.action.ShardOperationFailedException in project elasticsearch by elastic.

the class SearchPhaseExecutionException method metadataToXContent.

@Override
protected void metadataToXContent(XContentBuilder builder, Params params) throws IOException {
    builder.field("phase", phaseName);
    // we group by default
    final boolean group = params.paramAsBoolean("group_shard_failures", true);
    // notify that it's grouped
    builder.field("grouped", group);
    builder.field("failed_shards");
    builder.startArray();
    ShardOperationFailedException[] failures = params.paramAsBoolean("group_shard_failures", true) ? ExceptionsHelper.groupBy(shardFailures) : shardFailures;
    for (ShardOperationFailedException failure : failures) {
        builder.startObject();
        failure.toXContent(builder, params);
        builder.endObject();
    }
    builder.endArray();
}
Also used : ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException)

Example 5 with ShardOperationFailedException

use of org.elasticsearch.action.ShardOperationFailedException in project elasticsearch by elastic.

the class BroadcastResponse method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeVInt(totalShards);
    out.writeVInt(successfulShards);
    out.writeVInt(failedShards);
    out.writeVInt(shardFailures.length);
    for (ShardOperationFailedException exp : shardFailures) {
        exp.writeTo(out);
    }
}
Also used : ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException)

Aggregations

ShardOperationFailedException (org.elasticsearch.action.ShardOperationFailedException)16 ArrayList (java.util.ArrayList)8 List (java.util.List)4 DefaultShardOperationFailedException (org.elasticsearch.action.support.DefaultShardOperationFailedException)4 IOException (java.io.IOException)2 FlushResponse (org.elasticsearch.action.admin.indices.flush.FlushResponse)2 StoreStatus.readStoreStatus (org.elasticsearch.action.admin.indices.shards.IndicesShardStoresResponse.StoreStatus.readStoreStatus)2 BroadcastShardOperationFailedException (org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException)2 ImmutableOpenIntMap (org.elasticsearch.common.collect.ImmutableOpenIntMap)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1