incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject svn commit: r1495152 - in /incubator/ambari/branches/branch-1.2.4/ambari-server/src: main/python/ambari-server.py test/python/TestAmbaryServer.py
Date Thu, 20 Jun 2013 19:54:16 GMT
Author: smohanty
Date: Thu Jun 20 19:54:15 2013
New Revision: 1495152

URL: http://svn.apache.org/r1495152
Log:
AMBARI-2450. Check for SID/Service input for ambari server setup with Oracle since the user
can provide both. (smohanty)

Modified:
    incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py
    incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py

Modified: incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py?rev=1495152&r1=1495151&r2=1495152&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py
(original)
+++ incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py
Thu Jun 20 19:54:15 2013
@@ -161,7 +161,14 @@ DATABASE_NAMES =["postgres", "oracle"]
 DATABASE_STORAGE_NAMES =["Database","Service","Schema"]
 DATABASE_PORTS =["5432", "1521", "3306"]
 DATABASE_DRIVER_NAMES = ["org.postgresql.Driver", "oracle.jdbc.driver.OracleDriver", "com.mysql.jdbc.Driver"]
-DATABASE_CONNECTION_STRINGS = ["jdbc:postgresql://{0}:{1}/{2}", "jdbc:oracle:thin:@{0}:{1}/{2}",
"jdbc:mysql://{0}:{1}/{2}"]
+DATABASE_CONNECTION_STRINGS = [
+                  "jdbc:postgresql://{0}:{1}/{2}",
+                  "jdbc:oracle:thin:@{0}:{1}/{2}",
+                  "jdbc:mysql://{0}:{1}/{2}"]
+DATABASE_CONNECTION_STRINGS_ALT = [
+                  "jdbc:postgresql://{0}:{1}/{2}",
+                  "jdbc:oracle:thin:@{0}:{1}:{2}",
+                  "jdbc:mysql://{0}:{1}/{2}"]
 DATABASE_CLI_TOOLS = [["psql"], ["sqlplus", "sqlplus64"], ["mysql"]]
 DATABASE_CLI_TOOLS_DESC = ["psql", "sqlplus", "mysql"]
 DATABASE_CLI_TOOLS_USAGE = ['su -postgres --command=psql -f {0} -v username=\'"{1}"\' -v
password="\'{2}\'"',
@@ -174,9 +181,6 @@ DATABASE_INIT_SCRIPTS = ['/var/lib/ambar
 DATABASE_DROP_SCRIPTS = ['/var/lib/ambari-server/resources/Ambari-DDL-Postgres-REMOTE-DROP.sql',
                          '/var/lib/ambari-server/resources/Ambari-DDL-Oracle-DROP.sql',
                          '/var/lib/ambari-server/resources/Ambari-DDL-MySQL-DROP.sql']
-DATABASE_URL_REGEX = ["jdbc:postgresql://([a-zA-Z0-9._]+):(\d+)/(.+)",
-                     "jdbc:oracle:thin:@([a-zA-Z0-9._]+):(\d+)/(.+)",
-                     "jdbc:mysql://([a-zA-Z0-9._]+):(\d*)/(.+)"]
 
 REGEX_IP_ADDRESS = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
 REGEX_HOSTNAME = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$"
@@ -188,6 +192,7 @@ MYSQL_EXEC_ARGS = "--host={0} --port={1}
 
 JDBC_PATTERNS = {"oracle":"*ojdbc*.jar", "mysql":"*mysql*.jar"}
 DATABASE_FULL_NAMES = {"oracle":"Oracle", "mysql":"MySQL", "postgres":"PostgreSQL"}
+ORACLE_DB_ID_TYPES = ["Service Name", "Service ID"]
 
 
 # jdk commands
@@ -1254,6 +1259,7 @@ def load_default_db_properties(args):
   args.database_name = "ambari"
   args.database_username = "ambari"
   args.database_password = "bigdata"
+  args.sid_or_sname = "sname"
   pass
 
 # Ask user for database conenction properties
@@ -1294,19 +1300,46 @@ def prompt_db_properties(args):
           "Invalid port.",
           False
         )
+
+        if args.database == "oracle":
+          # Oracle uses service name or service id
+          idType = "1"
+          idType = get_validated_string_input(
+            "Select type of id to use:\n1 - " + ORACLE_DB_ID_TYPES[0] +
+            "\n2 - " + ORACLE_DB_ID_TYPES[1] + "\n[" + idType + "]:",
+            idType,
+            "^[12]$",
+            "Invalid number.",
+            False
+          )
+
+          if idType == "2":
+            args.sid_or_sname = "sid"
+
+          IDTYPE_INDEX = int(idType) - 1
+          args.database_name = get_validated_string_input(
+            ORACLE_DB_ID_TYPES[IDTYPE_INDEX] + " [" + args.database_name + "]:",
+            args.database_name,
+            "^[a-zA-Z0-9.\-]*$",
+            "Invalid " + ORACLE_DB_ID_TYPES[IDTYPE_INDEX] + ".",
+            False
+          )
+        else:
+          # MySQL and other DB types
+          pass
         pass
       else:
         args.database_host = "localhost"
         args.database_port = DATABASE_PORTS[DATABASE_INDEX]
-        pass
 
-      args.database_name = get_validated_string_input(
-        DATABASE_STORAGE_NAMES[DATABASE_INDEX] + " Name [" + args.database_name + "]:",
-        args.database_name,
-        "^[a-zA-z\-\"]+$",
-        "Invalid " + DATABASE_STORAGE_NAMES[DATABASE_INDEX] + " name.",
-        False
-      )
+        args.database_name = get_validated_string_input(
+          DATABASE_STORAGE_NAMES[DATABASE_INDEX] + " Name [" + args.database_name + "]:",
+          args.database_name,
+          "^[a-zA-z\-\"]+$",
+          "Invalid " + DATABASE_STORAGE_NAMES[DATABASE_INDEX] + " name.",
+          False
+        )
+      pass
 
       args.database_username = get_validated_string_input(
         'Username [' + args.database_username + ']: ',
@@ -1351,12 +1384,15 @@ def store_remote_properties(args):
   if (args.database_host == "localhost"):
     jdbc_hostname = socket.getfqdn();
     
-  properties.process_pair(JDBC_URL_PROPERTY, DATABASE_CONNECTION_STRINGS[DATABASE_INDEX].format(jdbc_hostname,
args.database_port, args.database_name))
+  connectionStringFormat = DATABASE_CONNECTION_STRINGS
+  if args.sid_or_sname == "sid":
+    connectionStringFormat = DATABASE_CONNECTION_STRINGS_ALT
+  properties.process_pair(JDBC_URL_PROPERTY, connectionStringFormat[DATABASE_INDEX].format(jdbc_hostname,
args.database_port, args.database_name))
   properties.process_pair(JDBC_USER_NAME_PROPERTY, args.database_username)
   properties.process_pair(JDBC_PASSWORD_FILE_PROPERTY, store_password_file(args.database_password,
JDBC_PASSWORD_FILENAME))
 
   properties.process_pair(JDBC_RCA_DRIVER_PROPERTY, DATABASE_DRIVER_NAMES[DATABASE_INDEX])
-  properties.process_pair(JDBC_RCA_URL_PROPERTY, DATABASE_CONNECTION_STRINGS[DATABASE_INDEX].format(jdbc_hostname,
args.database_port, args.database_name))
+  properties.process_pair(JDBC_RCA_URL_PROPERTY, connectionStringFormat[DATABASE_INDEX].format(jdbc_hostname,
args.database_port, args.database_name))
   properties.process_pair(JDBC_RCA_USER_NAME_PROPERTY, args.database_username)
   properties.process_pair(JDBC_RCA_PASSWORD_FILE_PROPERTY, store_password_file(args.database_password,
JDBC_PASSWORD_FILENAME))
 
@@ -1603,9 +1639,12 @@ def main():
   parser.add_option('--database', default=None, help ="Database to use postgres|oracle",
dest="database")
   parser.add_option('--databasehost', default=None, help="Hostname of database server", dest="database_host")
   parser.add_option('--databaseport', default=None, help="Database port", dest="database_port")
-  parser.add_option('--databasename', default=None, help="Database/Schema/Service name",
dest="database_name")
+  parser.add_option('--databasename', default=None, help="Database/Schema/Service name or
ServiceID",
+                    dest="database_name")
   parser.add_option('--databaseusername', default=None, help="Database user login", dest="database_username")
   parser.add_option('--databasepassword', default=None, help="Database user password", dest="database_password")
+  parser.add_option('--sidorsname', default="sname", help="Oracle database identifier type,
Service ID/Service "
+                                                         "Name sid|sname", dest="sid_or_sname")
 
   (options, args) = parser.parse_args()
 
@@ -1664,7 +1703,15 @@ def main():
       print "Incorrect database port " + options.database_port
       parser.print_help()
       exit(-1)
-      
+
+  if options.sid_or_sname.lower() not in ["sid", "sname"]:
+    print "WARNING: Valid values for sid_or_sname are 'sid' or 'sname'. Use 'sid' if the
db identifier type is " \
+          "Service ID. Use 'sname' if the db identifier type is Service Name"
+    parser.print_help()
+    exit(-1)
+  else:
+    options.sid_or_sname = options.sid_or_sname.lower()
+
   if options.database is not None and options.database == "postgres":
     print "WARNING: HostName for postgres server " + options.database_host + \
      " will be ignored: using localhost."

Modified: incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py?rev=1495152&r1=1495151&r2=1495152&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py
(original)
+++ incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py
Thu Jun 20 19:54:15 2013
@@ -196,6 +196,7 @@ class TestAmbariServer(TestCase):
     opm.parse_args.return_value = (options, args)
 
     options.database=None
+    options.sid_or_sname = "sid"
     ambari_server.main()
 
     self.assertTrue(setup_method.called)
@@ -207,7 +208,6 @@ class TestAmbariServer(TestCase):
     self.assertFalse(False, ambari_server.SILENT)
 
 
-
   @patch.object(ambari_server, 'setup')
   @patch.object(ambari_server, 'start')
   @patch.object(ambari_server, 'stop')
@@ -220,8 +220,8 @@ class TestAmbariServer(TestCase):
     args = ["setup"]
     opm.parse_args.return_value = (options, args)
     options.database=None
+    options.sid_or_sname = "sid"
 
-    options.database=None
     ambari_server.main()
 
     self.assertTrue(setup_method.called)
@@ -247,8 +247,7 @@ class TestAmbariServer(TestCase):
     opm.parse_args.return_value = (options, args)
 
     options.database = None
-
-    options.database=None
+    options.sid_or_sname = "sname"
 
     ambari_server.main()
 
@@ -275,6 +274,7 @@ class TestAmbariServer(TestCase):
     args = ["reset"]
     opm.parse_args.return_value = (options, args)
     options.database=None
+    options.sid_or_sname = "sid"
 
     ambari_server.main()
 
@@ -1173,6 +1173,80 @@ class TestAmbariServer(TestCase):
 
     sys.stdout = sys.__stdout__
 
+  def test_prompt_db_properties_default(self):
+    args = MagicMock()
+    ambari_server.load_default_db_properties(args)
+    ambari_server.prompt_db_properties(args)
+    self.assertEqual(args.database, "postgres")
+    self.assertEqual(args.database_host, "localhost")
+    self.assertEqual(args.database_name, "ambari")
+    self.assertEqual(args.database_port, "5432")
+
+  @patch.object(ambari_server, "read_password")
+  @patch.object(ambari_server, "get_validated_string_input")
+  @patch.object(ambari_server, "get_YN_input")
+  def test_prompt_db_properties_oracle_sname(self, gyni_mock, gvsi_mock, rp_mock):
+    ambari_server.PROMPT_DATABASE_OPTIONS = True
+    gyni_mock.return_value = True
+    list_of_return_values= ["ambari-server", "ambari", "1", "1521", "localhost", "2"]
+    def side_effect(*args, **kwargs):
+      return list_of_return_values.pop()
+    gvsi_mock.side_effect = side_effect
+    rp_mock.return_value = "password"
+
+    args = MagicMock()
+    ambari_server.load_default_db_properties(args)
+    ambari_server.prompt_db_properties(args)
+    self.assertEqual(args.database, "oracle")
+    self.assertEqual(args.database_port, "1521")
+    self.assertEqual(args.database_host, "localhost")
+    self.assertEqual(args.database_name, "ambari")
+    self.assertEqual(args.database_username, "ambari-server")
+    self.assertEqual(args.sid_or_sname, "sname")
+
+  @patch.object(ambari_server, "read_password")
+  @patch.object(ambari_server, "get_validated_string_input")
+  @patch.object(ambari_server, "get_YN_input")
+  def test_prompt_db_properties_oracle_sid(self, gyni_mock, gvsi_mock, rp_mock):
+    ambari_server.PROMPT_DATABASE_OPTIONS = True
+    gyni_mock.return_value = True
+    list_of_return_values= ["ambari-server", "ambari", "2", "1521", "localhost", "2"]
+    def side_effect(*args, **kwargs):
+      return list_of_return_values.pop()
+    gvsi_mock.side_effect = side_effect
+    rp_mock.return_value = "password"
+
+    args = MagicMock()
+    ambari_server.load_default_db_properties(args)
+    ambari_server.prompt_db_properties(args)
+    self.assertEqual(args.database, "oracle")
+    self.assertEqual(args.database_port, "1521")
+    self.assertEqual(args.database_host, "localhost")
+    self.assertEqual(args.database_name, "ambari")
+    self.assertEqual(args.database_username, "ambari-server")
+    self.assertEqual(args.sid_or_sname, "sid")
+
+  @patch.object(ambari_server, "read_password")
+  @patch.object(ambari_server, "get_validated_string_input")
+  @patch.object(ambari_server, "get_YN_input")
+  def test_prompt_db_properties_postgre_adv(self, gyni_mock, gvsi_mock, rp_mock):
+    ambari_server.PROMPT_DATABASE_OPTIONS = True
+    gyni_mock.return_value = True
+    list_of_return_values= ["ambari-server", "ambari", "1"]
+    def side_effect(*args, **kwargs):
+      return list_of_return_values.pop()
+    gvsi_mock.side_effect = side_effect
+    rp_mock.return_value = "password"
+
+    args = MagicMock()
+    ambari_server.load_default_db_properties(args)
+    ambari_server.prompt_db_properties(args)
+    self.assertEqual(args.database, "postgres")
+    self.assertEqual(args.database_port, "5432")
+    self.assertEqual(args.database_host, "localhost")
+    self.assertEqual(args.database_name, "ambari")
+    self.assertEqual(args.database_username, "ambari-server")
+    self.assertEqual(args.sid_or_sname, "sname")
 
   def get_sample(self, sample):
     """
@@ -1181,8 +1255,6 @@ class TestAmbariServer(TestCase):
     path = self.get_samples_dir(sample)
     return self.get_file_string(path)
 
-
-
   def get_file_string(self, file):
     """
     Returns file content as string with normalized line endings



Mime
View raw message