浏览代码

AMBARI-1586. Upgrade of Ambari DB on upgrade to 1.2.2 should restore/keep the configuration data for MAPREDUCE. (Sumit Mohanty via swagle)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1454564 13f79535-47bb-0310-9956-ffa450edef68
Siddharth Wagle 12 年之前
父节点
当前提交
12be9a1a12

+ 3 - 0
CHANGES.txt

@@ -451,6 +451,9 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1586. Upgrade of Ambari DB on upgrade to 1.2.2 should restore/keep 
+ the configuration data for MAPREDUCE. (Sumit Mohanty via swagle)
+
  AMBARI-1594. Ambari UI shows failed services while processes are running 
  on the server. (swagle) 
 

+ 3 - 1
ambari-server/pom.xml

@@ -253,7 +253,9 @@
               <groupname>root</groupname>
               <sources>
                 <source>
-                  <location>src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.2.1.sql</location>
+                  <location>src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.2.2.sql</location>
+                  <location>src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.2.2.Fix.sql</location>
+                  <location>src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.2.2.Check.sql</location>
                 </source>
               </sources>
             </mapping>

+ 42 - 10
ambari-server/src/main/python/ambari-server.py

@@ -241,8 +241,6 @@ def write_property(key, value):
   return 0
 
 
-
-
 def setup_db(args):
   #password access to ambari-server and mapred
   configure_postgres_username_password(args)
@@ -258,12 +256,10 @@ def setup_db(args):
   return retcode
 
 
-
-def upgrade_db(args):
+def execute_db_script(args, file):
   #password access to ambari-server and mapred
   configure_postgres_username_password(args)
   dbname = args.postgredbname
-  file = args.upgrade_script_file
   username = args.postgres_username
   password = args.postgres_password
   command = SETUP_DB_CMD[:]
@@ -273,6 +269,28 @@ def upgrade_db(args):
     print errdata
   return retcode
 
+
+def check_db_consistency(args, file):
+  #password access to ambari-server and mapred
+  configure_postgres_username_password(args)
+  dbname = args.postgredbname
+  username = args.postgres_username
+  password = args.postgres_password
+  command = SETUP_DB_CMD[:]
+  command[-1] = command[-1].format(file, username, password)
+  retcode, outdata, errdata = run_os_command(command)
+  if not retcode == 0:
+    print errdata
+    return retcode
+  else:
+    # Assumes that the output is of the form ...\n<count>
+    print_info_msg("Parsing output: " + outdata)
+    lines = outdata.splitlines()
+    if (lines[-1] == '3'):
+      return 0
+  return -1
+
+
 def upgrade_stack(args, stack_id):
   #password access to ambari-server and mapred
   configure_postgres_username_password(args)
@@ -879,19 +897,33 @@ def stop(args):
 # Upgrades the Ambari Server.
 #
 def upgrade(args):
-
   print 'Checking PostgreSQL...'
   retcode = check_postgre_up()
   if not retcode == 0:
-    printErrorMsg ('PostgreSQL server not running. Exiting')
+    printErrorMsg('PostgreSQL server not running. Exiting')
     sys.exit(retcode)
 
+  file = args.upgrade_script_file
   print 'Upgrading database...'
-  retcode = upgrade_db(args)
+  retcode = execute_db_script(args, file)
   if not retcode == 0:
-    printErrorMsg  ('Database upgrade script has failed. Exiting.')
+    printErrorMsg('Database upgrade script has failed. Exiting.')
     sys.exit(retcode)
 
+  print 'Checking database integrity...'
+  check_file = file[:-3] + "Check" + file[-4:]
+  retcode = check_db_consistency(args, check_file)
+
+  if not retcode == 0:
+    print 'Found inconsistency. Trying to fix...'
+    fix_file = file[:-3] + "Fix" + file[-4:]
+    retcode = execute_db_script(args, fix_file)
+
+    if not retcode == 0:
+      printErrorMsg('Database cannot be fixed. Exiting.')
+      sys.exit(retcode)
+  else:
+    print 'Database is consistent.'
   print "Ambari Server 'upgrade' finished successfully"
 
 
@@ -1088,7 +1120,7 @@ def main():
                       help="File with drop script")
   parser.add_option('-u', '--upgrade-script-file', default="/var/lib/"
                               "ambari-server/resources/upgrade/ddl/"
-                              "Ambari-DDL-Postgres-UPGRADE-1.2.1.sql",
+                              "Ambari-DDL-Postgres-UPGRADE-1.2.2.sql",
                       help="File with upgrade script")
   parser.add_option('-t', '--upgrade-stack-script-file', default="/var/lib/"
                               "ambari-server/resources/upgrade/dml/"

+ 20 - 0
ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.2.2.Check.sql

@@ -0,0 +1,20 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+\connect ambari;
+
+COPY (SELECT count(*) FROM ambari.serviceconfigmapping WHERE service_name = 'MAPREDUCE') TO STDOUT WITH CSV;

+ 26 - 0
ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.2.2.Fix.sql

@@ -0,0 +1,26 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+\connect ambari;
+
+INSERT INTO ambari.serviceconfigmapping (cluster_id, service_name, config_type, config_tag, timestamp)
+    SELECT cluster_id, 'MAPREDUCE', type_name, version_tag, create_timestamp from ambari.clusterconfig 
+        WHERE type_name = 'global' ORDER BY create_timestamp DESC LIMIT 1;
+
+INSERT INTO ambari.serviceconfigmapping (cluster_id, service_name, config_type, config_tag, timestamp)
+    SELECT cluster_id, 'MAPREDUCE', type_name, version_tag, create_timestamp from ambari.clusterconfig
+         WHERE type_name = 'mapred-site' ORDER BY create_timestamp DESC LIMIT 1;

+ 21 - 0
ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.2.2.sql

@@ -0,0 +1,21 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+\connect ambari;
+
+ALTER TABLE ambari.hosts
+  ALTER COLUMN disks_info TYPE VARCHAR(10000);