ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vbrodets...@apache.org
Subject ambari git commit: AMBARI-17491. Hive Database URL config updated by Ambari stack advisor recommendation.(vbrodetskyi)
Date Sat, 02 Jul 2016 19:06:27 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 7117d092c -> 33423c71c


AMBARI-17491. Hive Database URL config updated by Ambari stack advisor recommendation.(vbrodetskyi)


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

Branch: refs/heads/trunk
Commit: 33423c71c68e46d171b1e602ca44e94745f39874
Parents: 7117d09
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Fri Jul 1 23:53:25 2016 +0300
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Fri Jul 1 23:53:25 2016 +0300

----------------------------------------------------------------------
 .../stacks/HDP/2.1/services/stack_advisor.py    | 34 +++++++++++++++++---
 .../stacks/2.1/common/test_stack_advisor.py     | 10 +++++-
 2 files changed, 39 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/33423c71/ambari-server/src/main/resources/stacks/HDP/2.1/services/stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.1/services/stack_advisor.py b/ambari-server/src/main/resources/stacks/HDP/2.1/services/stack_advisor.py
index 3d6ca4c..6ec4b8d 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.1/services/stack_advisor.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.1/services/stack_advisor.py
@@ -65,9 +65,15 @@ class HDP21StackAdvisor(HDP206StackAdvisor):
       putOozieProperty('oozie.service.JPAService.jdbc.driver', self.getDBDriver(oozieEnvProperties['oozie_database']))
     if oozieSiteProperties and oozieEnvProperties and self.checkSiteProperties(oozieSiteProperties,
'oozie.db.schema.name', 'oozie.service.JPAService.jdbc.url') and self.checkSiteProperties(oozieEnvProperties,
'oozie_database'):
       oozieServerHost = self.getHostWithComponent('OOZIE', 'OOZIE_SERVER', services, hosts)
+      oozieDBConnectionURL = oozieSiteProperties['oozie.service.JPAService.jdbc.url']
+      protocol = self.getProtocol(oozieEnvProperties['oozie_database'])
+      oldSchemaName = getOldValue(self, services, "oozie-site", "oozie.db.schema.name")
+      # under these if constructions we are checking if oozie server hostname available,
+      # if schema name was changed or if protocol according to current db type differs with
protocol in db connection url(db type was changed)
       if oozieServerHost is not None:
-        dbConnection = self.getDBConnectionString(oozieEnvProperties['oozie_database']).format(oozieServerHost['Hosts']['host_name'],
oozieSiteProperties['oozie.db.schema.name'])
-        putOozieProperty('oozie.service.JPAService.jdbc.url', dbConnection)
+        if oldSchemaName or (protocol and oozieDBConnectionURL and not oozieDBConnectionURL.startswith(protocol)):
+          dbConnection = self.getDBConnectionString(oozieEnvProperties['oozie_database']).format(oozieServerHost['Hosts']['host_name'],
oozieSiteProperties['oozie.db.schema.name'])
+          putOozieProperty('oozie.service.JPAService.jdbc.url', dbConnection)
 
   def recommendHiveConfigurations(self, configurations, clusterData, services, hosts):
     hiveSiteProperties = getSiteProperties(services['configurations'], 'hive-site')
@@ -89,9 +95,17 @@ class HDP21StackAdvisor(HDP206StackAdvisor):
       putHiveProperty('javax.jdo.option.ConnectionDriverName', self.getDBDriver(hiveEnvProperties['hive_database']))
     if hiveSiteProperties and hiveEnvProperties and self.checkSiteProperties(hiveSiteProperties,
'ambari.hive.db.schema.name', 'javax.jdo.option.ConnectionURL') and self.checkSiteProperties(hiveEnvProperties,
'hive_database'):
       hiveServerHost = self.getHostWithComponent('HIVE', 'HIVE_SERVER', services, hosts)
+      hiveDBConnectionURL = hiveSiteProperties['javax.jdo.option.ConnectionURL']
+      protocol = self.getProtocol(hiveEnvProperties['hive_database'])
+      oldSchemaName = getOldValue(self, services, "hive-site", "ambari.hive.db.schema.name")
+      oldDBType = getOldValue(self, services, "hive-env", "hive_database")
+      # under these if constructions we are checking if hive server hostname available,
+      # if it's default db connection url with "localhost" or if schema name was changed
or if db type was changed (only for db type change from default mysql to existing mysql)
+      # or if protocol according to current db type differs with protocol in db connection
url(other db types changes)
       if hiveServerHost is not None:
-        dbConnection = self.getDBConnectionString(hiveEnvProperties['hive_database']).format(hiveServerHost['Hosts']['host_name'],
hiveSiteProperties['ambari.hive.db.schema.name'])
-        putHiveProperty('javax.jdo.option.ConnectionURL', dbConnection)
+        if (hiveDBConnectionURL and "//localhost" in hiveDBConnectionURL) or oldSchemaName
or oldDBType or (protocol and hiveDBConnectionURL and not hiveDBConnectionURL.startswith(protocol)):
+          dbConnection = self.getDBConnectionString(hiveEnvProperties['hive_database']).format(hiveServerHost['Hosts']['host_name'],
hiveSiteProperties['ambari.hive.db.schema.name'])
+          putHiveProperty('javax.jdo.option.ConnectionURL', dbConnection)
 
     servicesList = [service["StackServices"]["service_name"] for service in services["services"]]
     if "PIG" in servicesList:
@@ -182,6 +196,18 @@ class HDP21StackAdvisor(HDP206StackAdvisor):
     }
     return driverDict.get(databaseType.upper())
 
+  def getProtocol(self, databaseType):
+    first_parts_of_connection_string = {
+      'NEW MYSQL DATABASE': 'jdbc:mysql',
+      'NEW DERBY DATABASE': 'jdbc:derby',
+      'EXISTING MYSQL DATABASE': 'jdbc:mysql',
+      'EXISTING MYSQL / MARIADB DATABASE': 'jdbc:mysql',
+      'EXISTING POSTGRESQL DATABASE': 'jdbc:postgresql',
+      'EXISTING ORACLE DATABASE': 'jdbc:oracle',
+      'EXISTING SQL ANYWHERE DATABASE': 'jdbc:sqlanywhere'
+    }
+    return first_parts_of_connection_string.get(databaseType.upper())
+
   def getDBTypeAlias(self, databaseType):
     driverDict = {
       'NEW MYSQL DATABASE': 'mysql',

http://git-wip-us.apache.org/repos/asf/ambari/blob/33423c71/ambari-server/src/test/python/stacks/2.1/common/test_stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.1/common/test_stack_advisor.py b/ambari-server/src/test/python/stacks/2.1/common/test_stack_advisor.py
index abea76e..1232d97 100644
--- a/ambari-server/src/test/python/stacks/2.1/common/test_stack_advisor.py
+++ b/ambari-server/src/test/python/stacks/2.1/common/test_stack_advisor.py
@@ -207,7 +207,7 @@ class TestHDP21StackAdvisor(TestCase):
         "properties": {
           "javax.jdo.option.ConnectionDriverName": "",
           "ambari.hive.db.schema.name": "hive_name",
-          "javax.jdo.option.ConnectionURL": ""
+          "javax.jdo.option.ConnectionURL": "jdbc:mysql://localhost/hive?createDatabaseIfNotExist=true"
         }
       },
       "hive-env": {
@@ -216,7 +216,15 @@ class TestHDP21StackAdvisor(TestCase):
         }
       }
     }
+    changed_configurations = [{
+                               "type" : "hive-env",
+                               "name" : "hive_database",
+                               "old_value" : "New Database"
+                             }]
+
+
     services['configurations'] = configurations
+    services['changed-configurations'] = changed_configurations
     hosts = {
       "items": [
         {


Mime
View raw message