Trim down usages of `ShardOperationFailedException` interface (elastic/x-pack-elasticsearch#3662)

In many cases we use the `ShardOperationFailedException` interface to abstract an exception that can only be of one type, namely `DefaultShardOperationException`. There is no need to use the interface in such cases, the concrete type should be used instead. That has the additional advantage of simplifying parsing such exceptions back from rest responses for the high-level REST client.

Original commit: elastic/x-pack-elasticsearch@b2259afcbf
This commit is contained in:
Luca Cavanna 2018-01-22 15:51:55 +01:00 committed by GitHub
parent 8ee5b608e0
commit d9eb4c049f
3 changed files with 5 additions and 9 deletions

View File

@ -5,7 +5,7 @@
*/ */
package org.elasticsearch.action.admin.indices.stats; package org.elasticsearch.action.admin.indices.stats;
import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import java.util.List; import java.util.List;
@ -14,8 +14,8 @@ public class IndicesStatsResponseTestUtils {
/** /**
* Gives access to package private IndicesStatsResponse constructor for test purpose. * Gives access to package private IndicesStatsResponse constructor for test purpose.
**/ **/
public static IndicesStatsResponse newIndicesStatsResponse(ShardStats[] shards, int totalShards, int successfulShards, public static IndicesStatsResponse newIndicesStatsResponse(ShardStats[] shards, int totalShards, int successfulShards, int failedShards,
int failedShards, List<ShardOperationFailedException> shardFailures) { List<DefaultShardOperationFailedException> shardFailures) {
return new IndicesStatsResponse(shards, totalShards, successfulShards, failedShards, shardFailures); return new IndicesStatsResponse(shards, totalShards, successfulShards, failedShards, shardFailures);
} }
} }

View File

@ -759,10 +759,6 @@ public class TransportGraphExploreAction extends HandledTransportAction<GraphExp
return (startTime + request.timeout().millis()) - threadPool.relativeTimeInMillis(); return (startTime + request.timeout().millis()) - threadPool.relativeTimeInMillis();
} }
void addShardFailure(ShardOperationFailedException failure) {
addShardFailures(new ShardOperationFailedException[]{failure});
}
void addShardFailures(ShardOperationFailedException[] failures) { void addShardFailures(ShardOperationFailedException[] failures) {
if (!CollectionUtils.isEmpty(failures)) { if (!CollectionUtils.isEmpty(failures)) {
ShardOperationFailedException[] duplicates = new ShardOperationFailedException[shardFailures.length + failures.length]; ShardOperationFailedException[] duplicates = new ShardOperationFailedException[shardFailures.length + failures.length];

View File

@ -6,9 +6,9 @@
package org.elasticsearch.xpack.monitoring.collector.indices; package org.elasticsearch.xpack.monitoring.collector.indices;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse;
import org.elasticsearch.action.admin.indices.shards.IndicesShardStoresResponse; import org.elasticsearch.action.admin.indices.shards.IndicesShardStoresResponse;
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.RecoverySource;
import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRouting;
@ -104,7 +104,7 @@ public class IndexRecoveryMonitoringDocTests extends BaseMonitoringDocTestCase<I
final RecoveryState.Timer timer = recoveryState.getTimer(); final RecoveryState.Timer timer = recoveryState.getTimer();
timer.stop(); timer.stop();
final List<ShardOperationFailedException> shardFailures = new ArrayList<>(); final List<DefaultShardOperationFailedException> shardFailures = new ArrayList<>();
final Throwable reason = new NodeDisconnectedException(discoveryNodeZero, ""); final Throwable reason = new NodeDisconnectedException(discoveryNodeZero, "");
shardFailures.add(new IndicesShardStoresResponse.Failure("_failed_node_id", "_failed_index", 1, reason)); shardFailures.add(new IndicesShardStoresResponse.Failure("_failed_node_id", "_failed_index", 1, reason));