Bläddra i källkod

AMBARI-4038. Local stack upgrade should update the database as well. (ncole)

Nate Cole 11 år sedan
förälder
incheckning
1c4f148952

+ 26 - 0
ambari-server/src/main/python/ambari-server.py

@@ -380,8 +380,12 @@ STACK_LOCATION_DEFAULT = '/var/lib/ambari-server/resources/stacks'
 DATABASE_INSERT_METAINFO_SCRIPTS = ['/var/lib/ambari-server/resources/upgrade/dml/Ambari-DML-Postgres-INSERT_METAINFO.sql',
 DATABASE_INSERT_METAINFO_SCRIPTS = ['/var/lib/ambari-server/resources/upgrade/dml/Ambari-DML-Postgres-INSERT_METAINFO.sql',
                                   '/var/lib/ambari-server/resources/upgrade/dml/Ambari-DML-Oracle-INSERT_METAINFO.sql',
                                   '/var/lib/ambari-server/resources/upgrade/dml/Ambari-DML-Oracle-INSERT_METAINFO.sql',
                                   '/var/lib/ambari-server/resources/upgrade/dml/Ambari-DML-MySQL-INSERT_METAINFO.sql']
                                   '/var/lib/ambari-server/resources/upgrade/dml/Ambari-DML-MySQL-INSERT_METAINFO.sql']
+DATABASE_FIX_LOCAL_REPO_SCRIPTS = ['/var/lib/ambari-server/resources/upgrade/dml/Ambari-DML-Postgres-FIX_LOCAL_REPO.sql',
+                                  '/var/lib/ambari-server/resources/upgrade/dml/Ambari-DML-Oracle-FIX_LOCAL_REPO.sql',
+                                  '/var/lib/ambari-server/resources/upgrade/dml/Ambari-DML-MySQL-FIX_LOCAL_REPO.sql']
 INSERT_METAINFO_CMD = ['su', 'postgres',
 INSERT_METAINFO_CMD = ['su', 'postgres',
         '--command=psql -f {0} -v metainfo_key="\'{1}\'" -v metainfo_value="\'{2}\'" -v dbname="{3}"']
         '--command=psql -f {0} -v metainfo_key="\'{1}\'" -v metainfo_value="\'{2}\'" -v dbname="{3}"']
+FIX_LOCAL_REPO_CMD = ['su', 'postgres', '--command=psql -f {0} -v dbname="{1}"']
 
 
 #Apache License Header
 #Apache License Header
 ASF_LICENSE_HEADER = '''
 ASF_LICENSE_HEADER = '''
@@ -2490,6 +2494,18 @@ def upgrade_local_repo_remote_db(args, sqlfile, dbkey, dbvalue):
       dbkey,
       dbkey,
       dbvalue
       dbvalue
     )))
     )))
+
+    retcode, out, err = run_in_shell('{0} {1}'.format(tool, ORACLE_UPGRADE_STACK_ARGS.format(
+      args.database_username,
+      args.database_password,
+      args.database_host,
+      args.database_port,
+      args.database_name,
+      DATABASE_FIX_LOCAL_REPO_SCRIPTS[DATABASE_INDEX],
+      sid_or_sname,
+      '',
+      ''
+    )))
     return retcode, out, err
     return retcode, out, err
 
 
   return -2, "Wrong database", "Wrong database"
   return -2, "Wrong database", "Wrong database"
@@ -2535,6 +2551,16 @@ def upgrade_local_repo_db(args, dbkey, dbvalue):
       raise FatalException(retcode, errdata)
       raise FatalException(retcode, errdata)
     if errdata:
     if errdata:
       print_warning_msg(errdata)
       print_warning_msg(errdata)
+
+    sqlfile = DATABASE_FIX_LOCAL_REPO_SCRIPTS[0]
+    command = FIX_LOCAL_REPO_CMD[:]
+    command[-1] = command[-1].format(sqlfile, dbname)
+    retcode, outdata, errdata = run_os_command(command)
+    if not retcode == 0:
+      raise FatalException(retcode, errdata)
+    if errdata:
+      print_warning_msg(errdata)
+
     return retcode
     return retcode
   pass
   pass
 
 

+ 45 - 0
ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Oracle-FIX_LOCAL_REPO.sql

@@ -0,0 +1,45 @@
+--
+-- 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.
+--
+
+-- Remove HDPLocal in the stack
+
+UPDATE ambari.clusters
+  SET desired_stack_version = replace(desired_stack_version, 'HDPLocal', 'HDP')
+  WHERE INSTR(desired_stack_version, 'HDPLocal') > 0;
+
+UPDATE ambari.clusterstate
+  SET current_stack_version = replace(current_stack_version, 'HDPLocal', 'HDP')
+  WHERE INSTR('HDPLocal' in current_stack_version) > 0;
+
+UPDATE ambari.hostcomponentdesiredstate
+  SET desired_stack_version = replace(desired_stack_version, 'HDPLocal', 'HDP')
+  WHERE INSTR('HDPLocal' in desired_stack_version) > 0;
+
+UPDATE ambari.hostcomponentstate
+  SET current_stack_version = replace(current_stack_version, 'HDPLocal', 'HDP')
+  WHERE INSTR('HDPLocal' in current_stack_version) > 0;
+
+UPDATE ambari.servicecomponentdesiredstate
+  SET desired_stack_version = replace(desired_stack_version, 'HDPLocal', 'HDP')
+  WHERE INSTR('HDPLocal' in desired_stack_version) > 0;
+
+UPDATE ambari.servicedesiredstate
+  SET desired_stack_version = replace(desired_stack_version, 'HDPLocal', 'HDP')
+  WHERE INSTR('HDPLocal' in desired_stack_version) > 0;
+
+commit;

+ 44 - 0
ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Postgres-FIX_LOCAL_REPO.sql

@@ -0,0 +1,44 @@
+--
+-- 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 :dbname;
+
+UPDATE ambari.clusters
+  SET desired_stack_version = replace(desired_stack_version, 'HDPLocal', 'HDP')
+  WHERE position('HDPLocal' in desired_stack_version) > 0;
+
+UPDATE ambari.clusterstate
+  SET current_stack_version = replace(current_stack_version, 'HDPLocal', 'HDP')
+  WHERE position('HDPLocal' in current_stack_version) > 0;
+
+UPDATE ambari.hostcomponentdesiredstate
+  SET desired_stack_version = replace(desired_stack_version, 'HDPLocal', 'HDP')
+  WHERE position('HDPLocal' in desired_stack_version) > 0;
+
+UPDATE ambari.hostcomponentstate
+  SET current_stack_version = replace(current_stack_version, 'HDPLocal', 'HDP')
+  WHERE position('HDPLocal' in current_stack_version) > 0;
+
+UPDATE ambari.servicecomponentdesiredstate
+  SET desired_stack_version = replace(desired_stack_version, 'HDPLocal', 'HDP')
+  WHERE position('HDPLocal' in desired_stack_version) > 0;
+
+UPDATE ambari.servicedesiredstate
+  SET desired_stack_version = replace(desired_stack_version, 'HDPLocal', 'HDP')
+  WHERE position('HDPLocal' in desired_stack_version) > 0;
+
+