in ambari-infra-solr-client/src/main/python/migrationHelper.py [0:0]
def check_shard_for_collection(config, collection, skip_index_size = False):
result = {}
active_shards = []
all_shards = []
index_size_map = {}
host_index_size_map = {}
collections_data = get_collections_data(COLLECTIONS_DATA_JSON_LOCATION.format("check_collections.json"))
print "Checking available shards for '{0}' collection...".format(collection)
if collection in collections_data:
collection_details = collections_data[collection]
if 'shards' in collection_details:
for shard in collection_details['shards']:
all_shards.append(shard)
if 'replicas' in collection_details['shards'][shard]:
for replica in collection_details['shards'][shard]['replicas']:
if 'state' in collection_details['shards'][shard]['replicas'][replica] \
and collection_details['shards'][shard]['replicas'][replica]['state'].lower() == 'active' \
and 'leader' in collection_details['shards'][shard]['replicas'][replica]['properties'] \
and collection_details['shards'][shard]['replicas'][replica]['properties']['leader'] == 'true' :
logger.debug("Found active shard for {0} (collection: {1})".format(shard, collection))
active_shards.append(shard)
if not skip_index_size:
core_url = collection_details['shards'][shard]['replicas'][replica]['coreUrl']
core_name = collection_details['shards'][shard]['replicas'][replica]['coreName']
node_name = collection_details['shards'][shard]['replicas'][replica]['nodeName']
hostname = node_name.split(":")[0]
index_size = get_replica_index_size(config, core_url, core_name)
index_bytes = parse_size(index_size)
if hostname in host_index_size_map:
last_value = host_index_size_map[hostname]
host_index_size_map[hostname] = last_value + index_bytes
else:
host_index_size_map[hostname] = index_bytes
index_size_map[shard] = index_bytes
result['active_shards'] = active_shards
result['all_shards'] = all_shards
if not skip_index_size:
result['index_size_map'] = index_size_map
result['host_index_size_map'] = host_index_size_map
return result