You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2014/05/02 02:52:04 UTC

[3/4] git commit: AMBARI-5644. For remote database configuration, ambari server script should not run DDL. (swagle)

AMBARI-5644. For remote database configuration, ambari server script should not run DDL. (swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e75bbc65
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e75bbc65
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e75bbc65

Branch: refs/heads/branch-1.6.0
Commit: e75bbc65fba3860fcb43c5aa14ecc1f27178e8be
Parents: f890ca8
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Thu May 1 13:04:06 2014 -0700
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Thu May 1 17:26:08 2014 -0700

----------------------------------------------------------------------
 ambari-server/src/main/python/ambari-server.py  | 91 ++++++--------------
 .../src/test/python/TestAmbariServer.py         | 36 +-------
 2 files changed, 29 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e75bbc65/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index e5b4f4c..e82b68b 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -1355,25 +1355,15 @@ def store_remote_properties(args):
 # Initialize remote database schema
 def setup_remote_db(args):
 
-  not_found_msg = "Cannot find {0} {1} client in the path to load the Ambari Server schema.\
- Before starting Ambari Server, you must run the following DDL against the database to create \
-the schema ".format(DATABASE_NAMES[DATABASE_INDEX], str(DATABASE_CLI_TOOLS_DESC[DATABASE_INDEX]))
-  client_usage_cmd = DATABASE_CLI_TOOLS_USAGE[DATABASE_INDEX].format(DATABASE_INIT_SCRIPTS[DATABASE_INDEX], args.database_username,
-                                                     BLIND_PASSWORD, args.database_name)
+  setup_msg = "Before starting Ambari Server, you must run the following DDL " \
+              "against the database to create the schema: {0}".format(DATABASE_INIT_SCRIPTS[DATABASE_INDEX])
 
-  retcode, out, err = execute_remote_script(args, DATABASE_INIT_SCRIPTS[DATABASE_INDEX])
-  if retcode != 0:
-    if retcode == -1:
-      print_warning_msg(not_found_msg + os.linesep + client_usage_cmd)
-      if not SILENT:
-        raw_input(PRESS_ENTER_MSG)
-      return retcode
+  print_warning_msg(setup_msg)
 
-    print err
-    print_error_msg('Database bootstrap failed. Please, provide correct connection properties.')
-    return retcode
+  proceed = get_YN_input("Proceed with configuring remote database connection properties [y/n] (n)? ", True)
+  retCode = 0 if proceed else -1
 
-  return 0
+  return retCode
 
 
 # Get database client executable path
@@ -1387,8 +1377,9 @@ def get_db_cli_tool(args):
   return None
 
 
-#execute SQL script on remote database
+#execute SQL script on remote database: Deprecated
 def execute_remote_script(args, scriptPath):
+  print_warning_msg("Deprecated method called.")
   tool = get_db_cli_tool(args)
   if not tool:
     # args.warnings.append('{0} not found. Please, run DDL script manually'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
@@ -2261,7 +2252,7 @@ def setup(args):
     print 'Configuring remote database connection properties...'
     retcode = setup_remote_db(args)
     if retcode == -1:
-      err = "The cli was not found"
+      err = "Remote database setup aborted."
       raise NonFatalException(err)
 
     if not retcode == 0:
@@ -2302,63 +2293,31 @@ def reset(args):
     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)
-
+    print_warning_msg('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)
   else:
+    # Run automatic reset only for embedded DB
+    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..."
+
     dbname = args.database_name
     filename = args.drop_script_file
     username = args.database_username
@@ -2381,6 +2340,8 @@ def reset(args):
         raise NonFatalException("Non critical error in DDL, use --verbose for more information")
       else:
         raise NonFatalException("Non critical error in DDL")
+    pass
+  pass
 
 
 #

http://git-wip-us.apache.org/repos/asf/ambari/blob/e75bbc65/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index c781516..f980309 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -2333,7 +2333,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       result = ambari_server.setup(args)
       self.fail("Should throw exception")
     except NonFatalException as fe:
-      self.assertTrue("cli was not found" in fe.reason)
+      self.assertTrue("Remote database setup aborted." in fe.reason)
 
   @patch.object(ambari_server, 'is_server_runing')
   @patch.object(ambari_server, "get_YN_input")
@@ -2342,10 +2342,9 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch.object(ambari_server, "run_os_command")
   @patch.object(ambari_server, "configure_database_username_password")
   @patch.object(ambari_server, "parse_properties_file")
-  @patch.object(ambari_server, "execute_remote_script")
   @patch.object(ambari_server, "is_root")
   @patch.object(ambari_server, "check_database_name_property")
-  def test_reset(self, check_database_name_property_mock, is_root_mock, execute_remote_script_mock,
+  def test_reset(self, check_database_name_property_mock, is_root_mock,
                  parse_properties_file_mock, configure_database_username_password_mock,
                  run_os_command_mock, print_info_msg_mock,
                  setup_db_mock, get_YN_inputMock, is_server_running_mock):
@@ -2409,10 +2408,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
 
     #remote db case
     args.persistence_type = "remote"
-    execute_remote_script_mock.return_value = (0, None, None)
     rcode = ambari_server.reset(args)
     self.assertEqual(None, rcode)
-    self.assertTrue(execute_remote_script_mock.called)
 
   @patch.object(ambari_server, "get_YN_input")
   @patch("__builtin__.raw_input")
@@ -3410,7 +3407,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       self.fail("Should throw exception")
     except NonFatalException as fe:
       # Expected
-      self.assertTrue("The cli was not found" in fe.reason)
+      self.assertTrue("Remote database setup aborted." in fe.reason)
 
   @patch.object(ambari_server, 'verify_setup_allowed')
   @patch("sys.exit")
@@ -3478,33 +3475,6 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
 
     self.assertTrue(found)
 
-  @patch.object(ambari_server, "parse_properties_file")
-  @patch.object(ambari_server, "get_db_cli_tool")
-  @patch.object(ambari_server, "print_error_msg")
-  @patch.object(ambari_server, "get_YN_input")
-  @patch.object(ambari_server, "setup_db")
-  @patch.object(ambari_server, "run_os_command")
-  @patch.object(ambari_server, "is_root")
-  @patch.object(ambari_server, "check_database_name_property")
-  @patch.object(ambari_server, 'is_server_runing')
-  def test_reset_remote_db_wo_client(self, is_server_runing_mock, check_database_name_property_mock, is_root_mock, run_os_command_mock,
-                                     setup_db_mock,
-                                     get_YN_inputMock, print_error_msg_mock, get_db_cli_tool_mock,
-                                     parse_properties_file_mock):
-    args = MagicMock()
-    get_YN_inputMock.return_value = True
-    run_os_command_mock.return_value = (0, None, None)
-    args.persistence_type = "remote"
-    get_db_cli_tool_mock.return_value = None
-    is_root_mock.return_value = True
-    is_server_runing_mock.return_value = (False, 0)
-    try:
-      ambari_server.reset(args)
-      self.fail("Should throw exception")
-    except NonFatalException as fe:
-      # Expected
-      self.assertTrue("Client wasn't found" in fe.reason)
-      pass
 
   @patch.object(ambari_server, "find_properties_file")
   def test_get_ambari_properties(self, find_properties_file_mock):