incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1447983 - in /incubator/ambari/trunk: ./ ambari-server/ ambari-server/sbin/ ambari-server/src/main/python/ ambari-server/src/main/resources/upgrade/dml/
Date Wed, 20 Feb 2013 00:54:01 GMT
Author: mahadev
Date: Wed Feb 20 00:54:01 2013
New Revision: 1447983

URL: http://svn.apache.org/r1447983
Log:
AMBARI-1448. Enabling stack upgrade via Ambari Server. (mahadev)

Added:
    incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/dml/
    incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Postgres-UPGRADE_STACK.sql
Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-server/pom.xml
    incubator/ambari/trunk/ambari-server/sbin/ambari-server
    incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1447983&r1=1447982&r2=1447983&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Wed Feb 20 00:54:01 2013
@@ -291,6 +291,8 @@ Trunk (unreleased changes):
 
  AMBARI-1438. Add new stack definition for new stacks. (mahadev)
 
+ AMBARI-1448. Enabling stack upgrade via Ambari Server. (mahadev)
+
  BUG FIXES
 
  AMBARI-1445. Redirect to main app page when testMode flag is set True and

Modified: incubator/ambari/trunk/ambari-server/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/pom.xml?rev=1447983&r1=1447982&r2=1447983&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/pom.xml (original)
+++ incubator/ambari/trunk/ambari-server/pom.xml Wed Feb 20 00:54:01 2013
@@ -258,6 +258,17 @@
               </sources>
             </mapping>
             <mapping>
+              <directory>/var/lib/ambari-server/resources/upgrade/dml</directory>
+              <filemode>755</filemode>
+              <username>root</username>
+              <groupname>root</groupname>
+              <sources>
+                <source>
+                  <location>src/main/resources/upgrade/dml/Ambari-DML-Postgres-UPGRADE_STACK.sql</location>
+                </source>
+              </sources>
+            </mapping>
+            <mapping>
               <directory>/var/lib/ambari-server/resources/stacks</directory>
               <filemode>755</filemode>
               <username>root</username>

Modified: incubator/ambari/trunk/ambari-server/sbin/ambari-server
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/sbin/ambari-server?rev=1447983&r1=1447982&r2=1447983&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/sbin/ambari-server (original)
+++ incubator/ambari/trunk/ambari-server/sbin/ambari-server Wed Feb 20 00:54:01 2013
@@ -77,6 +77,10 @@ case "$1" in
         echo -e "Upgrading ambari-server"
         $PYTHON /usr/sbin/ambari-server.py $@
         ;;
+  upgradestack)
+        echo -e "Upgrading stack of ambari-server"
+        $PYTHON /usr/sbin/ambari-server.py $@
+        ;;
   setup)
         echo -e "Run postgresql initdb"
         initdb_res=`/sbin/service postgresql initdb`
@@ -89,7 +93,7 @@ case "$1" in
         $PYTHON /usr/sbin/ambari-server.py $@
         ;;
   *)
-        echo "Usage: /usr/sbin/ambari-server {start|stop|restart|setup|upgrade} [options]"
+        echo "Usage: /usr/sbin/ambari-server {start|stop|restart|setup|upgrade|upgradestack}
[options]"
         exit 1
 esac
 

Modified: incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py?rev=1447983&r1=1447982&r2=1447983&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py (original)
+++ incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py Wed Feb 20 00:54:01
2013
@@ -45,6 +45,7 @@ START_ACTION = "start"
 STOP_ACTION = "stop"
 RESET_ACTION = "reset"
 UPGRADE_ACTION = "upgrade"
+UPGRADE_STACK_ACTION = "upgradestack"
 
 # selinux commands
 GET_SE_LINUX_ST_CMD = "/usr/sbin/sestatus"
@@ -65,6 +66,9 @@ IP_TBLS_SRVC_NT_FND = "iptables: unrecog
 ambari_provider_module_option = ""
 ambari_provider_module = os.environ.get('AMBARI_PROVIDER_MODULE')
 
+# constants
+STACK_NAME_VER_SEP = "-"
+
 if ambari_provider_module is not None:
   ambari_provider_module_option = "-Dprovider.module.class=" +\
                                   ambari_provider_module + " "
@@ -96,6 +100,8 @@ AMBARI_PROPERTIES_FILE="ambari.propertie
 
 SETUP_DB_CMD = ['su', 'postgres',
         '--command=psql -f {0} -v username=\'"{1}"\' -v password="\'{2}\'"']
+UPGRADE_STACK_CMD = ['su', 'postgres',
+        '--command=psql -f {0} -v stack_name="\'{1}\'"  -v stack_version="\'{2}\'"']
 PG_ST_CMD = "/sbin/service postgresql status"
 PG_START_CMD = "/sbin/service postgresql start"
 PG_RESTART_CMD = "/sbin/service postgresql restart"
@@ -262,6 +268,19 @@ def upgrade_db(args):
     print errdata
   return retcode
 
+def upgrade_stack(args, stack_id):
+  #password access to ambari-server and mapred
+  configure_postgres_username_password(args)
+  dbname = args.postgredbname
+  file = args.upgrade_stack_script_file
+  stack_name, stack_version = stack_id.split(STACK_NAME_VER_SEP)
+  command = UPGRADE_STACK_CMD[:]
+  command[-1] = command[-1].format(file, stack_name, stack_version)
+  retcode, outdata, errdata = run_os_command(command)
+  if not retcode == 0:
+    print errdata
+  return retcode
+
 #
 # Checks SELinux
 #
@@ -908,7 +927,7 @@ def configure_postgres_username_password
   try:
     properties.load(open(conf_file))
   except Exception, e:
-    print 'Could not read "%s": %s' % (conf_file, e)
+    print 'Could not read ambari config file "%s": %s' % (conf_file, e)
     return -1
 
   username = properties[JDBC_USER_NAME_PROPERTY]
@@ -959,7 +978,7 @@ def configure_postgres_username_password
 # Main.
 #
 def main():
-  parser = optparse.OptionParser(usage="usage: %prog [options] action",)
+  parser = optparse.OptionParser(usage="usage: %prog [options] action [stack_id]",)
   parser.add_option('-d', '--postgredbname', default='ambari',
                       help="Database name in postgresql")
   parser.add_option('-f', '--init-script-file',
@@ -974,6 +993,10 @@ def main():
                               "ambari-server/resources/upgrade/ddl/"
                               "Ambari-DDL-Postgres-UPGRADE-1.2.1.sql",
                       help="File with upgrade script")
+  parser.add_option('-t', '--upgrade-stack-script-file', default="/var/lib/"
+                              "ambari-server/resources/upgrade/dml/"
+                              "Ambari-DML-Postgres-UPGRADE_STACK.sql",
+                      help="File with stack upgrade script")
   parser.add_option('-j', '--java-home', default=None,
                   help="Use specified java_home.  Must be valid on all hosts")
   parser.add_option("-v", "--verbose",
@@ -993,12 +1016,23 @@ def main():
   global SILENT
   SILENT = options.silent
 
-  if not len(args) == 1:
+
+  
+  if len(args) == 0:
     print parser.print_help()
-    parser.error("Invalid number of arguments")
+    parser.error("No action entered")
 	
   action = args[0]
-
+  
+  if action == UPGRADE_STACK_ACTION:
+    args_number_required = 2
+  else:
+    args_number_required = 1
+	
+  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))
+ 
   if action == SETUP_ACTION:
     setup(options)
   elif action == START_ACTION:
@@ -1009,6 +1043,9 @@ def main():
     reset(options)
   elif action == UPGRADE_ACTION:
     upgrade(options)
+  elif action == UPGRADE_STACK_ACTION:
+    stack_id = args[1]
+    upgrade_stack(options, stack_id)
   else:
     parser.error("Invalid action")
 
@@ -1128,4 +1165,4 @@ class Properties(object):
 
 
 if __name__ == "__main__":
-  main()
\ No newline at end of file
+  main()

Added: incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Postgres-UPGRADE_STACK.sql
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Postgres-UPGRADE_STACK.sql?rev=1447983&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Postgres-UPGRADE_STACK.sql
(added)
+++ incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Postgres-UPGRADE_STACK.sql
Wed Feb 20 00:54:01 2013
@@ -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 ambari;
+
+PREPARE clusters (text, text) AS
+  UPDATE ambari.clusters
+    SET desired_stack_version = '{"stackName":"' || $1 || '","stackVersion":"' || $2 || '"}';
+
+PREPARE hostcomponentdesiredstate (text, text) AS
+  UPDATE ambari.hostcomponentdesiredstate
+    SET desired_stack_version = '{"stackName":"' || $1 || '","stackVersion":"' || $2 || '"}';
+
+PREPARE hostcomponentstate (text, text) AS
+  UPDATE ambari.hostcomponentstate
+    SET current_stack_version = '{"stackName":"' || $1 || '","stackVersion":"' || $2 || '"}';
+
+PREPARE servicecomponentdesiredstate (text, text) AS
+  UPDATE ambari.servicecomponentdesiredstate
+    SET desired_stack_version = '{"stackName":"' || $1  || '","stackVersion":"' || $2 ||
'"}';
+
+PREPARE servicedesiredstate (text, text) AS
+  UPDATE ambari.servicedesiredstate
+    SET desired_stack_version = '{"stackName":"' || $1 || '","stackVersion":"' || $2 || '"}';
+
+EXECUTE clusters(:stack_name, :stack_version);
+EXECUTE hostcomponentdesiredstate(:stack_name, :stack_version);
+EXECUTE hostcomponentstate(:stack_name, :stack_version);
+EXECUTE servicecomponentdesiredstate(:stack_name, :stack_version);
+EXECUTE servicedesiredstate(:stack_name, :stack_version);
\ No newline at end of file



Mime
View raw message