#NEWLINE# def parse_command_line( ) : #NEWLINE# #INDENT# parser = argparse . ArgumentParser ( formatter_class = argparse . ArgumentDefaultsHelpFormatter , description = 'Manage the hadoop cluster.' ) #NEWLINE# parser . add_argument ( '--version' , action = 'version' , version = '%(prog)s 1.0.0-beta' ) #NEWLINE# parser . add_argument ( '-v' , '--verbosity' , default = 0 , type = int , help = 'The verbosity level of log, higher value, more details.' ) #NEWLINE# parser . add_argument ( '--remote_user' , default = 'work' , help = 'The user to login remote machines.' ) #NEWLINE# subparsers = parser . add_subparsers ( title = 'commands' , help = "Type '%(prog)s command -h' to get more help for individual command." ) #NEWLINE# sub_parser = subparsers . add_parser ( 'install' , formatter_class = argparse . ArgumentDefaultsHelpFormatter , help = 'Install binary packages to a cluster according to specified configuration. Only binary package (tarball) would be installed, config files and start/stop scripts would NOT be installed.' ) #NEWLINE# sub_parser . add_argument ( '--make_current' , action = 'store_false' , help = 'Make the installed pacakge as current version.' ) #NEWLINE# add_service_arguments ( sub_parser ) #NEWLINE# sub_parser . set_defaults ( handler = process_command_install ) #NEWLINE# sub_parser = subparsers . add_parser ( 'cleanup' , formatter_class = argparse . ArgumentDefaultsHelpFormatter , help = "Cleanup all data files of a service. Used when you want to re-deploy a service and discard all old data.\nNOTE: before using it, make sure you know what's going to happen!" ) #NEWLINE# add_service_arguments ( sub_parser ) #NEWLINE# sub_parser . set_defaults ( handler = process_command_cleanup ) #NEWLINE# sub_parser = subparsers . add_parser ( 'bootstrap' , formatter_class = argparse . ArgumentDefaultsHelpFormatter , help = 'Bootstrap a new cluster for a service. It would fail if old data of this service exists.' ) #NEWLINE# add_specify_version_options ( sub_parser ) #NEWLINE# sub_parser . add_argument ( '--update_config' , action = 'store_true' , default = False , help = 'Update the config files' ) #NEWLINE# add_service_arguments ( sub_parser ) #NEWLINE# sub_parser . set_defaults ( handler = process_command_bootstrap ) #NEWLINE# sub_parser = subparsers . add_parser ( 'start' , formatter_class = argparse . ArgumentDefaultsHelpFormatter , help = 'Start whole service on the specified cluster. Config files and control scripts (start/stop/restart, etc) would be generated at this phase and copied to destination hosts.' ) #NEWLINE# add_specify_version_options ( sub_parser ) #NEWLINE# sub_parser . add_argument ( '--skip_confirm' , action = 'store_true' , default = False , help = 'Whether skip the confirmation or not' ) #NEWLINE# sub_parser . add_argument ( '--update_config' , action = 'store_true' , default = False , help = 'Update the config files' ) #NEWLINE# add_service_arguments ( sub_parser ) #NEWLINE# sub_parser . set_defaults ( handler = process_command_start ) #NEWLINE# sub_parser = subparsers . add_parser ( 'stop' , formatter_class = argparse . ArgumentDefaultsHelpFormatter , help = 'Stop whole service on the specified cluster.' ) #NEWLINE# add_service_arguments ( sub_parser ) #NEWLINE# sub_parser . add_argument ( '--skip_confirm' , action = 'store_true' , default = False , help = 'Whether skip the confirmation or not' ) #NEWLINE# sub_parser . set_defaults ( handler = process_command_stop ) #NEWLINE# sub_parser = subparsers . add_parser ( 'restart' , formatter_class = argparse . ArgumentDefaultsHelpFormatter , help = 'Restart whole service on the specified cluster.' ) #NEWLINE# add_specify_version_options ( sub_parser ) #NEWLINE# sub_parser . add_argument ( '--skip_confirm' , action = 'store_true' , default = False , help = 'Whether skip the confirmation or not' ) #NEWLINE# sub_parser . add_argument ( '--update_config' , action = 'store_true' , default = False , help = 'Update the config files' ) #NEWLINE# add_service_arguments ( sub_parser ) #NEWLINE# sub_parser . set_defaults ( handler = process_command_restart ) #NEWLINE# sub_parser = subparsers . add_parser ( 'show' , formatter_class = argparse . ArgumentDefaultsHelpFormatter , help = 'Show status of packages/services/jobs/tasks.' ) #NEWLINE# add_service_arguments ( sub_parser ) #NEWLINE# sub_parser . set_defaults ( handler = process_command_show ) #NEWLINE# sub_parser = subparsers . add_parser ( 'shell' , formatter_class = argparse . ArgumentDefaultsHelpFormatter , help = ( 'Run the shell of specified service %s' % SERVICE_DEPLOY_TOOL_MAP . keys ( ) ) ) #NEWLINE# add_specify_version_options ( sub_parser ) #NEWLINE# add_service_arguments ( sub_parser ) #NEWLINE# sub_parser . add_argument ( 'command' , nargs = argparse . REMAINDER , help = 'The command to execute' ) #NEWLINE# sub_parser . set_defaults ( handler = process_command_shell ) #NEWLINE# sub_parser = subparsers . add_parser ( 'pack' , formatter_class = argparse . ArgumentDefaultsHelpFormatter , help = 'Pack client utilities of Hadoop/Hbase/Zookeeper for users' ) #NEWLINE# add_specify_version_options ( sub_parser ) #NEWLINE# sub_parser . add_argument ( '--package_root' , default = './packages' , help = 'The local root to store the packed pacakges' ) #NEWLINE# sub_parser . add_argument ( '--skip_tarball' , action = 'store_true' , help = 'Skip make the tarball of the packed package' ) #NEWLINE# add_service_arguments ( sub_parser ) #NEWLINE# sub_parser . set_defaults ( handler = process_command_pack ) #NEWLINE# sub_parser = subparsers . add_parser ( 'rolling_update' , formatter_class = argparse . ArgumentDefaultsHelpFormatter , help = 'Rolling update the specified job, users must specify the job through the --job option' ) #NEWLINE# sub_parser . add_argument ( '--skip_confirm' , action = 'store_true' , default = False , help = 'Whether skip the confirmation or not' ) #NEWLINE# sub_parser . add_argument ( '--vacate_rs' , action = 'store_true' , default = False , help = 'Whether to vacate region server before restart it' ) #NEWLINE# sub_parser . add_argument ( '--time_interval' , default = 120 , type = int , help = 'The time interval between rolling update tasks' ) #NEWLINE# sub_parser . add_argument ( '--update_config' , action = 'store_true' , default = False , help = 'Update the config files' ) #NEWLINE# add_specify_version_options ( sub_parser ) #NEWLINE# add_service_arguments ( sub_parser ) #NEWLINE# sub_parser . set_defaults ( handler = process_command_rolling_update ) #NEWLINE# args = parser . parse_args ( ) #NEWLINE# Log . verbosity = args . verbosity #NEWLINE# return args