in ambari-server/src/main/python/ambari-server.py [0:0]
def reset(args):
#force reset if silent option provided
global SILENT
if SILENT:
default = "yes"
else:
default = "no"
if not is_root():
err = 'Ambari-server reset should be run with ' \
'root-level privileges'
raise FatalException(4, err)
status, pid = is_server_runing()
if status:
err = 'Ambari-server must be stopped to reset'
raise FatalException(1, err)
choice = get_YN_input("**** WARNING **** You are about to reset and clear the "
"Ambari Server database. This will remove all cluster "
"host and configuration information from the database. "
"You will be required to re-configure the Ambari server "
"and re-run the cluster wizard. \n"
"Are you SURE you want to perform the reset "
"[yes/no] ({0})? ".format(default), SILENT)
okToRun = choice
if not okToRun:
err = "Ambari Server 'reset' cancelled"
raise FatalException(1, err)
okToRun = get_YN_input("Confirm server reset [yes/no]({0})? ".format(default), SILENT)
if not okToRun:
err = "Ambari Server 'reset' cancelled"
raise FatalException(1, err)
print "Resetting the Server database..."
check_database_name_property()
parse_properties_file(args)
# configure_database_username_password(args)
if args.persistence_type=="remote":
client_desc = DATABASE_NAMES[DATABASE_INDEX] + ' ' + DATABASE_CLI_TOOLS_DESC[DATABASE_INDEX]
client_usage_cmd_drop = DATABASE_CLI_TOOLS_USAGE[DATABASE_INDEX].format(DATABASE_DROP_SCRIPTS[DATABASE_INDEX], args.database_username,
BLIND_PASSWORD, args.database_name)
client_usage_cmd_init = DATABASE_CLI_TOOLS_USAGE[DATABASE_INDEX].format(DATABASE_INIT_SCRIPTS[DATABASE_INDEX], args.database_username,
BLIND_PASSWORD, args.database_name)
if get_db_cli_tool(args) != -1:
retcode, out, err = execute_remote_script(args, DATABASE_DROP_SCRIPTS[DATABASE_INDEX])
if not retcode == 0:
if retcode == -1:
print_warning_msg('Cannot find ' + client_desc +
' client in the path to reset the Ambari Server ' +
'schema. To reset Ambari Server schema ' +
'you must run the following DDL against the database ' +
'to drop the schema:' + os.linesep + client_usage_cmd_drop
+ os.linesep + 'Then you must run the following DDL '
+ 'against the database to create the schema: ' + os.linesep
+ client_usage_cmd_init + os.linesep )
raise NonFatalException(err)
if err:
print_warning_msg(err)
retcode, out, err = execute_remote_script(args, DATABASE_INIT_SCRIPTS[DATABASE_INDEX])
if not retcode == 0:
if retcode == -1:
print_warning_msg('Cannot find ' + client_desc + ' client in the path to ' +
'reset the Ambari Server schema. To reset Ambari Server schema ' +
'you must run the following DDL against the database to '
+ 'drop the schema:' + os.linesep + client_usage_cmd_drop
+ os.linesep + 'Then you must run the following DDL ' +
'against the database to create the schema: ' + os.linesep +
client_usage_cmd_init + os.linesep )
raise NonFatalException(err)
if err:
print_warning_msg(err)
else:
err = 'Cannot find ' + client_desc + ' client in the path to reset the Ambari ' +\
'Server schema. To reset Ambari Server schema ' + \
'you must run the following DDL against the database to drop the schema:' + \
os.linesep + client_usage_cmd_drop + os.linesep + \
'Then you must run the following DDL against the database to create the ' + \
'schema: ' + os.linesep + client_usage_cmd_init + os.linesep
raise NonFatalException(err)
else:
dbname = args.database_name
filename = args.drop_script_file
username = args.database_username
password = args.database_password
command = SETUP_DB_CMD[:]
command[-1] = command[-1].format(filename, username, password, dbname)
drop_retcode, drop_outdata, drop_errdata = run_os_command(command)
if not drop_retcode == 0:
raise FatalException(1, drop_errdata)
if drop_errdata and PG_ERROR_BLOCKED in drop_errdata:
raise FatalException(1, "Database is in use. Please, make sure all connections to the database are closed")
if drop_errdata and VERBOSE:
print_warning_msg(drop_errdata)
print_info_msg ("About to run database setup")
retcode, outdata, errdata = setup_db(args)
if errdata and VERBOSE:
print_warning_msg(errdata)
if (errdata and 'ERROR' in errdata.upper()) or (drop_errdata and 'ERROR' in drop_errdata.upper()):
if not VERBOSE:
raise NonFatalException("Non critical error in DDL, use --verbose for more information")
else:
raise NonFatalException("Non critical error in DDL")