def routers(cluster_id): logger.debug("routers({cluster_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) router_docs = [] for router_info in ShardedClusters().routers(cluster_id): # Server id is the same as router id. server_id = router_info['id'] links = [ sharded_cluster_link('delete-router', cluster_id, router_id=server_id), server_link('get-server-info', server_id) ] router_info['links'] = links router_docs.append(router_info) result = { 'routers': router_docs, 'links': [ sharded_cluster_link('get-sharded-cluster-info', cluster_id), sharded_cluster_link('get-shards', cluster_id), sharded_cluster_link('get-configsvrs', cluster_id), sharded_cluster_link('get-routers', cluster_id, self_rel=True) ] } return send_result(200, result)
def routers(cluster_id): logger.debug("routers({cluster_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) router_docs = [] for router_info in ShardedClusters().routers(cluster_id): # Server id is the same as router id. server_id = router_info['id'] links = [ sharded_cluster_link('delete-router', cluster_id, router_id=server_id), server_link('get-server-info', server_id) ] router_info['links'] = links router_docs.append(router_info) result = { 'routers': router_docs, 'links': [ sharded_cluster_link('get-sharded-cluster-info', cluster_id), sharded_cluster_link('get-shards', cluster_id), sharded_cluster_link('get-configsvrs', cluster_id), sharded_cluster_link('get-routers', cluster_id, self_rel=True) ] } return send_result(200, result)
def sh_create(): logger.debug("sh_create()") data = get_json(request.body) data = preset_merge(data, 'sharded_clusters') result = _sh_create(data) result['links'].extend([ base_link('service'), base_link('get-releases'), sharded_cluster_link('get-sharded-clusters'), sharded_cluster_link('add-sharded-cluster', self_rel=True), replica_set_link('get-replica-sets'), server_link('get-servers') ]) return send_result(200, result)
def sh_create(): logger.debug("sh_create()") data = get_json(request.body) data = preset_merge(data, 'sharded_clusters') result = _sh_create(data) result['links'].extend([ base_link('service'), base_link('get-releases'), sharded_cluster_link('get-sharded-clusters'), sharded_cluster_link('add-sharded-cluster', self_rel=True), replica_set_link('get-replica-sets'), server_link('get-servers') ]) return send_result(200, result)
def router_add(cluster_id): logger.debug("router_add({cluster_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) data = get_json(request.body) result = ShardedClusters().router_add(cluster_id, data) router_id = result['id'] result['links'] = [ server_link('get-server-info', router_id), sharded_cluster_link('add-router', cluster_id, self_rel=True), sharded_cluster_link('delete-router', cluster_id, router_id=router_id), sharded_cluster_link('get-sharded-cluster-info', cluster_id), sharded_cluster_link('get-routers', cluster_id), ] return send_result(200, result)
def router_add(cluster_id): logger.debug("router_add({cluster_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) data = get_json(request.body) result = ShardedClusters().router_add(cluster_id, data) router_id = result['id'] result['links'] = [ server_link('get-server-info', router_id), sharded_cluster_link('add-router', cluster_id, self_rel=True), sharded_cluster_link('delete-router', cluster_id, router_id=router_id), sharded_cluster_link('get-sharded-cluster-info', cluster_id), sharded_cluster_link('get-routers', cluster_id), ] return send_result(200, result)
def shard_add(cluster_id): logger.debug("shard_add({cluster_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) data = get_json(request.body) result = ShardedClusters().member_add(cluster_id, data) resource_id = result['_id'] shard_id = result['id'] result['links'] = [ sharded_cluster_link('get-shard-info', cluster_id, shard_id), sharded_cluster_link('delete-shard', cluster_id, shard_id), sharded_cluster_link('add-shard', cluster_id, self_rel=True), sharded_cluster_link('get-sharded-cluster-info', cluster_id), sharded_cluster_link('get-shards', cluster_id) ] result['links'].append(_server_or_rs_link(result)) return send_result(200, result)
def shard_info(cluster_id, shard_id): logger.debug("shard_info({cluster_id}, {shard_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) result = ShardedClusters().member_info(cluster_id, shard_id) resource_id = result['_id'] shard_id = result['id'] result['links'] = [ sharded_cluster_link( 'get-shard-info', cluster_id, shard_id, self_rel=True), sharded_cluster_link('delete-shard', cluster_id, shard_id), sharded_cluster_link('add-shard', cluster_id), sharded_cluster_link('get-sharded-cluster-info', cluster_id), sharded_cluster_link('get-shards', cluster_id) ] result['links'].append(_server_or_rs_link(result)) return send_result(200, result)
def shards(cluster_id): logger.debug("shards({cluster_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) shard_docs = [] for shard_info in ShardedClusters().members(cluster_id): shard_id = shard_info['id'] resource_id = shard_info['_id'] shard_info['links'] = [ sharded_cluster_link('get-shard-info', cluster_id, shard_id), sharded_cluster_link('delete-shard', cluster_id, shard_id), sharded_cluster_link('get-sharded-cluster-info', cluster_id), ] shard_info['links'].append(_server_or_rs_link(shard_info)) shard_docs.append(shard_info) result = { 'shards': shard_docs, 'links': [ sharded_cluster_link('get-sharded-cluster-info', cluster_id), sharded_cluster_link('get-shards', cluster_id, self_rel=True), sharded_cluster_link('get-configsvrs', cluster_id), sharded_cluster_link('get-routers', cluster_id) ] } return send_result(200, result)
def shards(cluster_id): logger.debug("shards({cluster_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) shard_docs = [] for shard_info in ShardedClusters().members(cluster_id): shard_id = shard_info['id'] resource_id = shard_info['_id'] shard_info['links'] = [ sharded_cluster_link('get-shard-info', cluster_id, shard_id), sharded_cluster_link('delete-shard', cluster_id, shard_id), sharded_cluster_link('get-sharded-cluster-info', cluster_id), ] shard_info['links'].append(_server_or_rs_link(shard_info)) shard_docs.append(shard_info) result = { 'shards': shard_docs, 'links': [ sharded_cluster_link('get-sharded-cluster-info', cluster_id), sharded_cluster_link('get-shards', cluster_id, self_rel=True), sharded_cluster_link('get-configsvrs', cluster_id), sharded_cluster_link('get-routers', cluster_id) ] } return send_result(200, result)
def sh_list(): logger.debug("sh_list()") sharded_clusters = [] for cluster_id in ShardedClusters(): cluster_info = {'id': cluster_id} cluster_info['links'] = all_sharded_cluster_links( cluster_id, rel_to='get-sharded-clusters') sharded_clusters.append(cluster_info) response = {'links': [ base_link('service'), base_link('get-releases'), sharded_cluster_link('get-sharded-clusters', self_rel=True), sharded_cluster_link('add-sharded-cluster'), replica_set_link('get-replica-sets'), server_link('get-servers') ]} response['sharded_clusters'] = sharded_clusters return send_result(200, response)
def sh_list(): logger.debug("sh_list()") sharded_clusters = [] for cluster_id in ShardedClusters(): cluster_info = {'id': cluster_id} cluster_info['links'] = all_sharded_cluster_links( cluster_id, rel_to='get-sharded-clusters') sharded_clusters.append(cluster_info) response = { 'links': [ base_link('service'), base_link('get-releases'), sharded_cluster_link('get-sharded-clusters', self_rel=True), sharded_cluster_link('add-sharded-cluster'), replica_set_link('get-replica-sets'), server_link('get-servers') ] } response['sharded_clusters'] = sharded_clusters return send_result(200, response)
def configsvrs(cluster_id): logger.debug("configsvrs({cluster_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) config_docs = [] for config_info in ShardedClusters().configsvrs(cluster_id): server_id = config_info['id'] config_info['links'] = [server_link('get-server-info', server_id)] config_docs.append(config_info) result = { 'configsvrs': config_docs, 'links': [ sharded_cluster_link('get-sharded-cluster-info', cluster_id), sharded_cluster_link('get-shards', cluster_id), sharded_cluster_link('get-configsvrs', cluster_id, self_rel=True), sharded_cluster_link('get-routers', cluster_id) ] } return send_result(200, result)
def configsvrs(cluster_id): logger.debug("configsvrs({cluster_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) config_docs = [] for config_info in ShardedClusters().configsvrs(cluster_id): server_id = config_info['id'] config_info['links'] = [ server_link('get-server-info', server_id) ] config_docs.append(config_info) result = { 'configsvrs': config_docs, 'links': [ sharded_cluster_link('get-sharded-cluster-info', cluster_id), sharded_cluster_link('get-shards', cluster_id), sharded_cluster_link('get-configsvrs', cluster_id, self_rel=True), sharded_cluster_link('get-routers', cluster_id) ] } return send_result(200, result)
def host_create_by_id(host_id): data = get_json(request.body) data = preset_merge(data, 'servers') data['id'] = host_id result = _host_create(data) result['links'].extend([ base_link('service'), base_link('get-releases'), server_link('get-servers'), server_link('add-server'), server_link('add-server-by-id', host_id, self_rel=True), replica_set_link('get-replica-sets'), sharded_cluster_link('get-sharded-clusters') ]) return send_result(200, result)
def rs_create_by_id(rs_id): logger.debug("rs_create_by_id()") data = get_json(request.body) data = preset_merge(data, 'replica_sets') data['id'] = rs_id result = _rs_create(data) result['links'].extend([ base_link('service'), base_link('get-releases'), sharded_cluster_link('get-sharded-clusters'), replica_set_link('get-replica-sets'), replica_set_link('add-replica-set'), replica_set_link('add-replica-set-by-id', rs_id, self_rel=True), server_link('get-servers') ]) return send_result(200, result)
def _sh_create(params): cluster_id = ShardedClusters().create(params) result = ShardedClusters().info(cluster_id) result['links'] = all_sharded_cluster_links(cluster_id) for router in result['routers']: router['links'] = [ server_link('get-server-info', server_id=router['id']) ] for cfg in result['configsvrs']: cfg['links'] = [server_link('get-server-info', server_id=cfg['id'])] for sh in result['shards']: sh['links'] = [ sharded_cluster_link('get-shard-info', cluster_id, sh['id']), _server_or_rs_link(sh) ] return result
def rs_create_by_id(rs_id): logger.debug("rs_create_by_id()") data = get_json(request.body) data = preset_merge(data, 'replica_sets') data['id'] = rs_id result = _rs_create(data) result['links'].extend([ base_link('service'), base_link('get-releases'), sharded_cluster_link('get-sharded-clusters'), replica_set_link('get-replica-sets'), replica_set_link('add-replica-set'), replica_set_link('add-replica-set-by-id', rs_id, self_rel=True), server_link('get-servers') ]) return send_result(200, result)
def rs_list(): logger.debug("rs_list()") replica_sets = [] for rs_id in ReplicaSets(): repl_info = {'id': rs_id} repl_info['links'] = all_replica_set_links(rs_id, 'get-replica-sets') replica_sets.append(repl_info) response = {'links': [ base_link('service'), base_link('get-releases'), sharded_cluster_link('get-sharded-clusters'), replica_set_link('get-replica-sets', self_rel=True), replica_set_link('add-replica-set'), server_link('get-servers') ]} response['replica_sets'] = replica_sets return send_result(200, response)
def rs_list(): logger.debug("rs_list()") replica_sets = [] for rs_id in ReplicaSets(): repl_info = {'id': rs_id} repl_info['links'] = all_replica_set_links(rs_id, 'get-replica-sets') replica_sets.append(repl_info) response = {'links': [ base_link('service'), base_link('get-releases'), sharded_cluster_link('get-sharded-clusters'), replica_set_link('get-replica-sets', self_rel=True), replica_set_link('add-replica-set'), server_link('get-servers') ]} response['replica_sets'] = replica_sets return send_result(200, response)
def _sh_create(params): cluster_id = ShardedClusters().create(params) result = ShardedClusters().info(cluster_id) result['links'] = all_sharded_cluster_links(cluster_id) for router in result['routers']: router['links'] = [ server_link('get-server-info', server_id=router['id']) ] for cfg in result['configsvrs']: cfg['links'] = [ server_link('get-server-info', server_id=cfg['id']) ] for sh in result['shards']: sh['links'] = [ sharded_cluster_link('get-shard-info', cluster_id, sh['id']), _server_or_rs_link(sh) ] return result
def info(cluster_id): logger.debug("info({cluster_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) result = ShardedClusters().info(cluster_id) result['links'] = all_sharded_cluster_links( cluster_id, rel_to='get-sharded-cluster-info') for router in result['routers']: router['links'] = [ server_link('get-server-info', server_id=router['id']) ] for cfg in result['configsvrs']: cfg['links'] = [server_link('get-server-info', server_id=cfg['id'])] for sh in result['shards']: sh['links'] = [ sharded_cluster_link('get-shard-info', cluster_id, sh['id']), _server_or_rs_link(sh) ] return send_result(200, result)
def info(cluster_id): logger.debug("info({cluster_id})".format(**locals())) if cluster_id not in ShardedClusters(): return send_result(404) result = ShardedClusters().info(cluster_id) result['links'] = all_sharded_cluster_links( cluster_id, rel_to='get-sharded-cluster-info') for router in result['routers']: router['links'] = [ server_link('get-server-info', server_id=router['id']) ] for cfg in result['configsvrs']: cfg['links'] = [ server_link('get-server-info', server_id=cfg['id']) ] for sh in result['shards']: sh['links'] = [ sharded_cluster_link('get-shard-info', cluster_id, sh['id']), _server_or_rs_link(sh) ] return send_result(200, result)