use of io.crate.blob.exceptions.MissingHTTPEndpointException 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");
}
Aggregations