Search in sources :

Example 6 with DefaultShardOperationFailedException

use of org.elasticsearch.action.support.DefaultShardOperationFailedException in project crate by crate.

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(), equalTo(replicatedBroadcastResponse.getTotalShards()));
    for (DefaultShardOperationFailedException 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 : ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) DefaultShardOperationFailedException(org.elasticsearch.action.support.DefaultShardOperationFailedException)

Example 7 with DefaultShardOperationFailedException

use of org.elasticsearch.action.support.DefaultShardOperationFailedException in project crate by crate.

the class ElasticsearchAssertions method formatShardStatus.

public static String formatShardStatus(BroadcastResponse response) {
    StringBuilder msg = new StringBuilder();
    msg.append(" Total shards: ").append(response.getTotalShards()).append(" Successful shards: ").append(response.getSuccessfulShards()).append(" & ").append(response.getFailedShards()).append(" shard failures:");
    for (DefaultShardOperationFailedException failure : response.getShardFailures()) {
        msg.append("\n ").append(failure);
    }
    return msg.toString();
}
Also used : DefaultShardOperationFailedException(org.elasticsearch.action.support.DefaultShardOperationFailedException)

Aggregations

DefaultShardOperationFailedException (org.elasticsearch.action.support.DefaultShardOperationFailedException)7 BroadcastShardOperationFailedException (org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException)4 ArrayList (java.util.ArrayList)2 FailedNodeException (org.elasticsearch.action.FailedNodeException)2 ShardOperationFailedException (org.elasticsearch.action.ShardOperationFailedException)2 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)2 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)1