def describe(migration): puts('\nMembership') with indent(): puts(get_membership(migration.target_couch_config).get_printable()) puts('\nDB Info') print_db_info(migration.target_couch_config) puts('\nShard allocation') diff_with_db = None if os.path.exists(migration.shard_plan_path): diff_with_db = diff_plan(migration) if diff_with_db: puts(color_highlight('DB allocation differs from plan:\n')) puts("{}\n\n".format(diff_with_db)) else: puts(color_success('DB allocation matches plan.')) if not diff_with_db: print_shard_table([ get_shard_allocation(migration.target_couch_config, db_name) for db_name in sorted( get_db_list(migration.target_couch_config.get_control_node())) ]) puts('\nShard count by node') print_shard_allocation_by_node([ get_shard_allocation(migration.target_couch_config, db_name) for db_name in sorted( get_db_list(migration.target_couch_config.get_control_node())) ]) return 0
def describe(migration): print u'\nMembership' with indent(): puts(get_membership(migration.target_couch_config).get_printable()) print u'\nDB Info' print_db_info(migration.target_couch_config) print u'\nShards' print_shard_table([ get_shard_allocation(migration.target_couch_config, db_name) for db_name in sorted( get_db_list(migration.target_couch_config.get_control_node())) ]) return 0
def run(self, args, unknown_args): environment = get_environment(args.env_name) couch_config = get_couch_config(environment) puts(u'\nMembership') with indent(): puts(get_membership(couch_config).get_printable()) puts(u'\nDB Info') print_db_info(couch_config) puts(u'\nShard allocation') print_shard_table([ get_shard_allocation(couch_config, db_name) for db_name in sorted(get_db_list(couch_config.get_control_node())) ]) return 0
def describe(migration): puts(u'\nMembership') with indent(): puts(get_membership(migration.target_couch_config).get_printable()) puts(u'\nDB Info') print_db_info(migration.target_couch_config) puts(u'\nShard allocation') diff_with_db = diff_plan(migration) if diff_with_db: puts(colored.yellow('DB allocation differs from plan:\n')) puts("{}\n\n".format(diff_with_db)) else: puts(colored.green('DB allocation matches plan.')) print_shard_table([ get_shard_allocation(migration.target_couch_config, db_name) for db_name in sorted(get_db_list(migration.target_couch_config.get_control_node())) ]) return 0
def run(self, args, unknown_args): environment = get_environment(args.env_name) couch_config = get_couch_config(environment, port=args.couch_port, local_port=args.couch_local_port, couchdb_version=args.couchdb_version) db_list = sorted(get_db_list(couch_config.get_control_node())) if args.database: if args.database not in db_list: raise CommandError("Database not present in cluster: {}".format(args.database)) db_list = [args.database] shard_allocations = [get_shard_allocation(couch_config, db_name) for db_name in db_list] shard_details = [] if args.shard_counts: shard_details = get_cluster_shard_details(couch_config, db_list) if args.raw: plan = { shard_allocation_doc.db_name: shard_allocation_doc.to_plan_json() for shard_allocation_doc in shard_allocations } if shard_details: shard_details = sorted(shard_details, key=attrgetter('db_name')) for db_name, shards in itertools.groupby(shard_details, key=attrgetter('db_name')): by_node = defaultdict(list) for shard_detail in shards: by_node[shard_detail.node].append(shard_detail.to_json()) plan[db_name]["shard_details"] = by_node # hack - yaml didn't want to dump this directly yaml.safe_dump(json.loads(json.dumps(plan)), sys.stdout, indent=2) return 0 if not args.database: puts('\nMembership') with indent(): puts(get_membership(couch_config).get_printable()) puts('\nDB Info') print_db_info(couch_config, db_list) puts('\nShard allocation') print_shard_table(shard_allocations, shard_details) return 0
def describe(migration): puts(u'\nMembership') with indent(): puts(get_membership(migration.target_couch_config).get_printable()) puts(u'\nDB Info') print_db_info(migration.target_couch_config) puts(u'\nShard allocation') diff_with_db = diff_plan(migration) if diff_with_db: puts(colored.yellow('DB allocation differs from plan:\n')) puts("{}\n\n".format(diff_with_db)) else: puts(colored.green('DB allocation matches plan.')) print_shard_table([ get_shard_allocation(migration.target_couch_config, db_name) for db_name in sorted( get_db_list(migration.target_couch_config.get_control_node())) ]) return 0
def get_nodes(config): """ :return: list of tuple(node_name, NodeDetails) """ node_details = [] nodes = get_membership(config).cluster_nodes for member in nodes: address = member.split('@')[1] if address in ("localhost", "127.0.0.1"): assert len(nodes) == 1 address = config.control_node_ip node_details.append((member, NodeDetails( address, config.control_node_port, config.control_node_local_port, config.username, config._password, None ))) return node_details