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 commit(migration, ansible_context): print_allocation(migration) alloc_docs_by_db = {plan.db_name: plan for plan in migration.shard_plan} puts(color_summary("Checking shards on disk vs plan. Please wait.")) if not assert_files(migration, alloc_docs_by_db, ansible_context): puts(color_error("Some shard files are not where we expect. Have you run 'migrate'?")) puts(color_error("Aborting")) return 1 else: puts(color_success("All shards appear to be where we expect according to the plan.")) if ask("Are you sure you want to update the Couch Database config?"): commit_migration(migration) diff_with_db = diff_plan(migration) if diff_with_db: puts(color_error('DB allocation differs from expected:\n')) puts("{}\n\n".format(diff_with_db)) puts("Check the DB state and logs and maybe try running 'commit' again?") return 1 puts(color_highlight("New shard allocation:\n")) 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 commit(migration, ansible_context): print_allocation(migration) alloc_docs_by_db = {plan.db_name: plan for plan in migration.shard_plan} puts(colored.yellow("Checking shards on disk vs plan. Please wait.")) if not assert_files(migration, alloc_docs_by_db, ansible_context): puts(colored.red("Some shard files are not where we expect. Have you run 'migrate'?")) puts(colored.red("Aborting")) return 1 else: puts(colored.yellow("All shards appear to be where we expect according to the plan.")) if ask("Are you sure you want to update the Couch Database config?"): commit_migration(migration) diff_with_db = diff_plan(migration) if diff_with_db: puts(colored.red('DB allocation differs from expected:\n')) puts("{}\n\n".format(diff_with_db)) puts("Check the DB state and logs and maybe try running 'commit' again?") return 1 puts(colored.yellow("New shard allocation:\n")) 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 commit(migration): if ask("Are you sure you want to update the Couch Database config?"): commit_migration(migration) # TODO: verify that shard config in DB matches what we expect puts(colored.yellow("New shard allocation:\n")) 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 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_db_allocations(couch_config): return { db_name: get_shard_allocation(couch_config, db_name) for db_name in sorted(get_db_list(couch_config.get_control_node())) }