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 plan(migration): new_plan = True if os.path.exists(migration.shard_plan_path): new_plan = ask("Plan already exists. Do you want to overwrite it?") if new_plan: shard_allocations = generate_shard_plan(migration) else: shard_allocations = migration.shard_plan print_shard_table([shard_allocation_doc for shard_allocation_doc in shard_allocations]) return 0
def plan(migration): new_plan = True if os.path.exists(migration.shard_plan_path): new_plan = ask("Plan already exists. Do you want to overwrite it?") if new_plan: shard_allocations = generate_shard_plan(migration) else: shard_allocations = migration.shard_plan print_shard_table([shard_allocation_doc for shard_allocation_doc in shard_allocations]) 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 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 print_allocation(migration): printable_docs = _get_aliased_allocation_docs(migration) print_shard_table(printable_docs)
def print_allocation(migration): printable_docs = _get_aliased_allocation_docs(migration) print_shard_table(printable_docs)