瀏覽代碼

AMBARI-2570. Ambari server with Oracle DB doesn't reset via ambari-server reset. (Myorslav via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1499890 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 12 年之前
父節點
當前提交
b79210efb7
共有 2 個文件被更改,包括 50 次插入35 次删除
  1. 45 28
      ambari-server/src/main/python/ambari-server.py
  2. 5 7
      ambari-server/src/test/python/TestAmbaryServer.py

+ 45 - 28
ambari-server/src/main/python/ambari-server.py

@@ -422,6 +422,15 @@ class FatalException(Exception):
     def _get_message(self):
       return str(self)
 
+class NonFatalException(Exception):
+  def __init__(self, reason):
+    self.reason = reason
+
+  def __str__(self):
+    return repr("NonFatal exception: %s" % self.reason)
+
+  def _get_message(self):
+    return str(self)
 
 def is_root():
   '''
@@ -1894,20 +1903,13 @@ def setup(args):
     retcode = setup_remote_db(args)
     if retcode == -1:
       err =  "The cli was not found"
-      raise FatalException(retcode, err)
+      raise NonFatalException(err)
 
     if not retcode == 0:
       err = 'Error while configuring connection properties. Exiting'
       raise FatalException(retcode, err)
     check_jdbc_drivers(args)
 
-  if args.warnings:
-    print "Ambari Server 'setup' finished with warnings:"
-    for warning in args.warnings:
-      print warning
-  else:
-    print "Ambari Server 'setup' finished successfully"
-
 
 
 #
@@ -1953,24 +1955,36 @@ def reset(args):
       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 FatalException(retcode, err)
+          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)
 
       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 FatalException(retcode, err)
+          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)
 
     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 FatalException(-1, err)
+      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
@@ -1986,8 +2000,6 @@ def reset(args):
     print_info_msg ("About to run database setup")
     setup_db(args)
 
-  print "Ambari Server 'reset' complete"
-
 
 
 #
@@ -2109,13 +2121,14 @@ def start(args):
     param_list = ["/bin/sh", "-c", command]
   print "Running server: " + str(param_list)
   server_process = subprocess.Popen(param_list, env=environ)
-  print "done."
 
 
 #
 # Stops the Ambari Server.
 #
 def stop(args):
+  if (args != None):
+    args.exit_message = None
   if os.path.exists(PID_DIR + os.sep + PID_NAME):
     f = open(PID_DIR + os.sep + PID_NAME, "r")
     pid = int(f.readline())
@@ -2208,13 +2221,13 @@ def upgrade(args):
     print_warning_msg(warn)
   else:
     adjust_directory_permissions(user)
-  print "Ambari Server 'upgrade' finished successfully"
 
 
 #
 # The Ambari Server status.
 #
 def status(args):
+  args.exit_message = None
   status, pid = is_server_runing()
   if status:
     print "Ambari Server running"
@@ -2407,7 +2420,6 @@ def setup_ldap():
     update_properties(ldap_property_value_map)
     print 'Saving...done'
 
-  print "Ambari Server 'LDAP setup' completed successfully. Exiting."
   return 0
 
 
@@ -2800,8 +2812,6 @@ def setup_https(args):
   if ambari_user:
     adjust_directory_permissions(ambari_user)
 
-  print "Ambari Server 'HTTPS setup' completed successfully. Exiting."
-  
 def is_server_runing():
   if os.path.exists(PID_DIR + os.sep + PID_NAME):
     f = open(PID_DIR + os.sep + PID_NAME, "r")
@@ -3021,7 +3031,8 @@ def main():
   if len(args) < args_number_required:
     print parser.print_help()
     parser.error("Invalid number of arguments. Entered: " + str(len(args)) + ", required: " + str(args_number_required))
- 
+
+  options.exit_message = "Ambari Server '%s' completed successfully." % action
   try:
     if action == SETUP_ACTION:
       setup(options)
@@ -3052,7 +3063,13 @@ def main():
     if e.reason is not None:
       print_error_msg("Exiting with exit code {0}. Reason: {1}".format(e.code, e.reason))
     sys.exit(e.code)
+  except NonFatalException as e:
+    options.exit_message = "Ambari Server '%s' completed with warnings." % action
+    if e.reason is not None:
+      print_warning_msg(e.reason)
 
+  if options.exit_message is not None:
+    print options.exit_message
 
 
 # A Python replacement for java.util.Properties

+ 5 - 7
ambari-server/src/test/python/TestAmbaryServer.py

@@ -33,6 +33,7 @@ from pwd import getpwnam
 # We have to use this import HACK because the filename contains a dash
 ambari_server = __import__('ambari-server')
 FatalException = ambari_server.FatalException
+NonFatalException = ambari_server.NonFatalException
 
 
 class TestAmbariServer(TestCase):
@@ -1576,8 +1577,6 @@ class TestAmbariServer(TestCase):
       result = ambari_server.setup(args)
     except FatalException:
       self.fail("Setup should be successful")
-
-
     self.assertEqual(None, result)
     self.assertEquals(True, store_local_properties_mock.called)
     self.assertEquals(False, store_remote_properties_mock.called)
@@ -1590,9 +1589,8 @@ class TestAmbariServer(TestCase):
     try:
       result = ambari_server.setup(args)
       self.fail("Should throw exception")
-    except FatalException as fe:
-      self.assertEquals(-1, fe.code)
-
+    except NonFatalException as fe:
+      self.assertTrue("cli was not found" in fe.reason)
 
 
 
@@ -2454,7 +2452,7 @@ class TestAmbariServer(TestCase):
     try:
       ambari_server.setup(args)
       self.fail("Should throw exception")
-    except FatalException as fe:
+    except NonFatalException as fe:
       # Expected
       self.assertTrue("The cli was not found" in fe.reason)
 
@@ -2477,7 +2475,7 @@ class TestAmbariServer(TestCase):
     try:
       ambari_server.reset(args)
       self.fail("Should throw exception")
-    except FatalException as fe:
+    except NonFatalException as fe:
       # Expected
       self.assertTrue("Client wasn't found" in fe.reason)
       pass