use of org.elasticsearch.cluster.routing.ShardIterator in project crate by crate.
the class BlobService method getRedirectAddress.
/**
* @param index the name of blob-enabled index
* @param digest sha-1 hash value of the file
* @return null if no redirect is required, Otherwise the address to which should be redirected.
*/
public String getRedirectAddress(String index, String digest) throws MissingHTTPEndpointException {
ShardIterator shards = clusterService.operationRouting().getShards(clusterService.state(), index, null, null, digest, "_local");
String localNodeId = clusterService.state().nodes().getLocalNodeId();
DiscoveryNodes nodes = clusterService.state().getNodes();
ShardRouting shard;
while ((shard = shards.nextOrNull()) != null) {
if (!shard.active()) {
continue;
}
if (shard.currentNodeId().equals(localNodeId)) {
// no redirect required if the shard is on this node
return null;
}
DiscoveryNode node = nodes.get(shard.currentNodeId());
String httpAddress = node.getAttributes().get("http_address");
if (httpAddress != null) {
return httpAddress + "/_blobs/" + BlobIndex.stripPrefix(index) + "/" + digest;
}
}
throw new MissingHTTPEndpointException("Can't find a suitable http server to serve the blob");
}
use of org.elasticsearch.cluster.routing.ShardIterator in project crate by crate.
the class TransportStartBlobAction method resolveRequest.
@Override
protected void resolveRequest(MetaData metaData, String concreteIndex, StartBlobRequest request) {
ShardIterator shardIterator = clusterService.operationRouting().indexShards(clusterService.state(), concreteIndex, null, request.id(), null);
request.setShardId(shardIterator.shardId());
}
use of org.elasticsearch.cluster.routing.ShardIterator in project crate by crate.
the class TransportDeleteBlobAction method resolveRequest.
@Override
protected void resolveRequest(MetaData metaData, String concreteIndex, DeleteBlobRequest request) {
ShardIterator shardIterator = clusterService.operationRouting().indexShards(clusterService.state(), concreteIndex, null, request.id(), null);
request.setShardId(shardIterator.shardId());
}
use of org.elasticsearch.cluster.routing.ShardIterator in project crate by crate.
the class BlobTableInfo method getRouting.
@Override
public Routing getRouting(WhereClause whereClause, @Nullable String preference) {
Map<String, Map<String, List<Integer>>> locations = new TreeMap<>();
GroupShardsIterator shardIterators = clusterService.operationRouting().searchShards(clusterService.state(), new String[] { index }, null, preference);
ShardRouting shardRouting;
for (ShardIterator shardIterator : shardIterators) {
shardRouting = shardIterator.nextOrNull();
processShardRouting(locations, shardRouting, shardIterator.shardId());
}
return new Routing(locations);
}
use of org.elasticsearch.cluster.routing.ShardIterator in project elasticsearch by elastic.
the class SearchStatsIT method nodeIdsWithIndex.
private Set<String> nodeIdsWithIndex(String... indices) {
ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState();
GroupShardsIterator allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true);
Set<String> nodes = new HashSet<>();
for (ShardIterator shardIterator : allAssignedShardsGrouped) {
for (ShardRouting routing : shardIterator.asUnordered()) {
if (routing.active()) {
nodes.add(routing.currentNodeId());
}
}
}
return nodes;
}
Aggregations