hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject incubator-hawq git commit: HAWQ-651. Enhance update property values in xml file
Date Sun, 10 Apr 2016 10:05:33 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/master d10d229df -> 96d926186


HAWQ-651. Enhance update property values in xml file


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/96d92618
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/96d92618
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/96d92618

Branch: refs/heads/master
Commit: 96d9261860583fa4b3d080ac5702a8a087267e9b
Parents: d10d229
Author: rlei <rlei@pivotal.io>
Authored: Sat Apr 9 17:46:09 2016 +0800
Committer: rlei <rlei@pivotal.io>
Committed: Sun Apr 10 17:57:07 2016 +0800

----------------------------------------------------------------------
 tools/bin/hawq_ctl             |   2 +-
 tools/bin/hawqconfig           |   9 +--
 tools/bin/hawqpylib/hawqlib.py | 150 +++++++++++++++++++++++++-----------
 tools/doc/gpssh-exkeys_help    |   8 +-
 4 files changed, 113 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/96d92618/tools/bin/hawq_ctl
----------------------------------------------------------------------
diff --git a/tools/bin/hawq_ctl b/tools/bin/hawq_ctl
index ed9436b..f79e3a9 100755
--- a/tools/bin/hawq_ctl
+++ b/tools/bin/hawq_ctl
@@ -212,7 +212,7 @@ class HawqInit:
                 update_xml_property(xml_file, property_name, property_value)
             else:
                 logger.debug("Add output.replace-datanode-on-failure as %s" % property_value)
-                append_xml_property(xml_file, property_name, property_value)
+                update_xml_property(xml_file, property_name, property_value)
 
             self.sync_hdfs_client()
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/96d92618/tools/bin/hawqconfig
----------------------------------------------------------------------
diff --git a/tools/bin/hawqconfig b/tools/bin/hawqconfig
index 4a1e3c7..791176a 100755
--- a/tools/bin/hawqconfig
+++ b/tools/bin/hawqconfig
@@ -18,7 +18,7 @@
 try:
     import os, sys, re
     from optparse import Option, OptionParser
-    from hawqpylib.hawqlib import HawqXMLParser, parse_hosts_file, remove_property_xml, update_xml_property,
append_xml_property, local_ssh
+    from hawqpylib.hawqlib import HawqXMLParser, parse_hosts_file, remove_property_xml, update_xml_property,
local_ssh
     from gppylib.commands.unix import getLocalHostname, getUserName
     from gppylib.db import dbconn
     from pg import DatabaseError
@@ -170,10 +170,7 @@ def show_property(hawq_site, property_name):
 
 def update_hawq_site(org_config_file, hawq_site, property_name, property_value):
     result = check_property(hawq_site, property_name, property_value)
-    if result:
-        update_xml_property(org_config_file, property_name, property_value)
-    else:
-        append_xml_property(org_config_file, property_name, property_value)
+    update_xml_property(org_config_file, property_name, property_value)
 
 
 def sync_hawq_site(config_dir, host_list, ignore_bad_hosts):
@@ -202,8 +199,6 @@ if __name__ == '__main__':
         standby_host = hawq_site.hawq_dict['hawq_standby_address_host']
         if standby_host not in ('None', 'none', ''):
             host_list = host_list + [standby_host]
-    else:
-        print "No standby host configured, skip it."
 
     # Update hawq-site.xml
     if options.change:

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/96d92618/tools/bin/hawqpylib/hawqlib.py
----------------------------------------------------------------------
diff --git a/tools/bin/hawqpylib/hawqlib.py b/tools/bin/hawqpylib/hawqlib.py
index 85174e5..ae0d852 100755
--- a/tools/bin/hawqpylib/hawqlib.py
+++ b/tools/bin/hawqpylib/hawqlib.py
@@ -142,8 +142,12 @@ class HawqXMLParser:
         with open(self.xml_file) as f:
             xmldoc = minidom.parse(f)
         for node in xmldoc.getElementsByTagName('property'):
-            name, value = (node.getElementsByTagName('name')[0].childNodes[0].data,
-                           node.getElementsByTagName('value')[0].childNodes[0].data)
+            name = node.getElementsByTagName('name')[0].childNodes[0].data.encode('ascii')
+            try:
+                value = node.getElementsByTagName('value')[0].childNodes[0].data.encode('ascii')
+            except:
+                value = ''
+
             if name == property_name:
                 self.propertyValue = value
         return self.propertyValue
@@ -153,8 +157,13 @@ class HawqXMLParser:
             xmldoc = minidom.parse(f)
 
         for node in xmldoc.getElementsByTagName('property'):
-            name, value = (node.getElementsByTagName('name')[0].childNodes[0].data.encode('ascii'),
-                           node.getElementsByTagName('value')[0].childNodes[0].data.encode('ascii'))
+            name = node.getElementsByTagName('name')[0].childNodes[0].data.encode('ascii')
+
+            try:
+                value = node.getElementsByTagName('value')[0].childNodes[0].data.encode('ascii')
+            except:
+                value = ''
+
             if value == '':
                 value == 'None'
             self.hawq_dict[name] = value
@@ -387,72 +396,125 @@ def update_xml_property(xmlfile, property_name, property_value):
     file_path, filename = os.path.split(xmlfile)
     xmlfile_backup = os.path.join(file_path, '.bak.' + filename)
     xmlfile_swap = os.path.join(file_path, '.swp.' + filename)
+
+    # Backup current xmlfile
     shutil.copyfile(xmlfile, xmlfile_backup)
-    with open(xmlfile_backup) as f:
-        f_tmp = open(xmlfile_swap, 'w')
+
+    f_tmp = open(xmlfile_swap, 'w')
+
+    with open(xmlfile) as f:
+        xmldoc = minidom.parse(f)
+
+    with open(xmlfile) as f:
         while 1:
             line = f.readline()
-
             if not line:
                 break
-
-            m = re.match('\s*<name>%s' % property_name, line)
+            m = re.match('.*<configuration>.*', line)
             if m:
-                while 1:
-                    next_line = f.readline()
-                    m2 = re.match('\s*<value>', next_line)
-                    if m2:
-                        f_tmp.write(line)
-                        p = re.compile('\s*<value>(.*)</value>')
-                        p_value = p.match(next_line).group(1)
-                        next_line_new = re.sub(p_value, property_value, next_line)
-                        f_tmp.write(next_line_new)
-                        break
+                line_1 = line.split('<configuration>')[0] + '<configuration>\n'
+                f_tmp.write(line_1)
+                break
             else:
                 f_tmp.write(line)
-        f_tmp.close()
+
+    count_num = 0
+
+    for node in xmldoc.getElementsByTagName('property'):
+
+        name = node.getElementsByTagName('name')[0].childNodes[0].data.encode('ascii')
+
+        try:
+            value = node.getElementsByTagName('value')[0].childNodes[0].data.encode('ascii')
+        except:
+            value = ''
+
+        try:
+            description = node.getElementsByTagName('description')[0].childNodes[0].data.encode('ascii')
+        except:
+            description = ''
+
+        if name == property_name:
+            value = property_value
+            count_num += 1
+
+        f_tmp.write("        <property>\n")
+        f_tmp.write("                <name>%s</name>\n" % name)
+        f_tmp.write("                <value>%s</value>\n" % value)
+        if description:
+            f_tmp.write("                <description>%s</description>\n" % description)
+        f_tmp.write("        </property>\n\n")
+
+    if count_num == 0:
+        f_tmp.write("        <property>\n")
+        f_tmp.write("                <name>%s</name>\n" % property_name)
+        f_tmp.write("                <value>%s</value>\n" % property_value)
+        f_tmp.write("        </property>\n\n")
+        f_tmp.write("</configuration>\n")
+    else:
+        f_tmp.write("</configuration>\n")
+
+    f_tmp.close
 
     shutil.move(xmlfile_swap, xmlfile)
 
 
-def append_xml_property(xmlfile, property_name, property_value):
+def remove_property_xml(property_name, xmlfile, quiet = False):
     file_path, filename = os.path.split(xmlfile)
     xmlfile_backup = os.path.join(file_path, '.bak.' + filename)
     xmlfile_swap = os.path.join(file_path, '.swp.' + filename)
+
+    # Backup current xmlfile
     shutil.copyfile(xmlfile, xmlfile_backup)
-    with open(xmlfile_backup) as f:
-        f_tmp = open(xmlfile_swap, 'w')
+
+    f_tmp = open(xmlfile_swap, 'w')
+
+    with open(xmlfile) as f:
+        xmldoc = minidom.parse(f)
+
+    with open(xmlfile) as f:
         while 1:
             line = f.readline()
-
             if not line:
                 break
-
-            m = re.match('\s*</configuration>', line)
+            m = re.match('.*<configuration>.*', line)
             if m:
-                f_tmp.write('    <property>\n')
-                f_tmp.write('        <name>%s</name>\n' % property_name)
-                f_tmp.write('       <value>%s</value>\n' % property_value)
-                f_tmp.write('    </property>\n')
-                f_tmp.write('</configuration>\n')
+                line_1 = line.split('<configuration>')[0] + '<configuration>\n'
+                f_tmp.write(line_1)
+                break
             else:
                 f_tmp.write(line)
-        f_tmp.close()
 
-    shutil.move(xmlfile_swap, xmlfile)
+    for node in xmldoc.getElementsByTagName('property'):
 
+        name = node.getElementsByTagName('name')[0].childNodes[0].data.encode('ascii')
 
-def remove_property_xml(property_name, org_config_file, quiet = False):
-    tree = ElementTree()
-    tree.parse(org_config_file)
-    root = tree.getroot()
-    for child in root:
-        for subet in child:
-            if subet.text == property_name:
-                if not quiet:
-                    print "Remove property %s." % subet.text
-                root.remove(child)
-    tree.write(org_config_file, encoding="utf-8")
+        try:
+            value = node.getElementsByTagName('value')[0].childNodes[0].data.encode('ascii')
+        except:
+            value = ''
+
+        try:
+            description = node.getElementsByTagName('description')[0].childNodes[0].data.encode('ascii')
+        except:
+            description = ''
+
+        if name == property_name:
+            if not quiet:
+                print "Remove property %s" % property_name
+        else:
+            f_tmp.write("        <property>\n")
+            f_tmp.write("                <name>%s</name>\n" % name)
+            f_tmp.write("                <value>%s</value>\n" % value)
+            if description:
+                f_tmp.write("                <description>%s</description>\n"
% description)
+            f_tmp.write("        </property>\n\n")
+
+    f_tmp.write("</configuration>\n")
+
+    f_tmp.close
+
+    shutil.move(xmlfile_swap, xmlfile)
 
 
 def sync_hawq_site(GPHOME, host_list):

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/96d92618/tools/doc/gpssh-exkeys_help
----------------------------------------------------------------------
diff --git a/tools/doc/gpssh-exkeys_help b/tools/doc/gpssh-exkeys_help
index cee249c..95999ae 100755
--- a/tools/doc/gpssh-exkeys_help
+++ b/tools/doc/gpssh-exkeys_help
@@ -10,7 +10,7 @@ SYNOPSIS
 hawq ssh-exkeys -f <hostfile_exkeys> [-p <password>] | -h <hostname> 
 [-h <hostname> ...] [-p <password>]
 
-hawq ssh-exkeys -e <hostfile_exkeys> -x <hostfile_gpexpand>
+hawq ssh-exkeys -e <hostfile_exkeys> -x <hostfile_hawq_expand>
 
 hawq ssh-exkeys -? 
 
@@ -104,7 +104,7 @@ OPTIONS
  Displays the version of this utility.
 
 
--x <hostfile_gpexpand>
+-x <hostfile_hawq_expand>
 
  When doing a system expansion, this is the name and location of a file 
  containing all configured host names and host addresses (interface names) 
@@ -153,7 +153,7 @@ hosts sdw4 and sdw5 as part of a system expansion operation:
     sdw3-1
     sdw3-2
 
-  $ cat hostfile_gpexpand
+  $ cat hostfile_hawq_expand
     sdw4
     sdw4-1
     sdw4-2
@@ -161,7 +161,7 @@ hosts sdw4 and sdw5 as part of a system expansion operation:
     sdw5-1
     sdw5-2
 
- $ hawq ssh-exkeys -e hostfile_exkeys -x hostfile_gpexpand
+ $ hawq ssh-exkeys -e hostfile_exkeys -x hostfile_hawq_expand
 
 *****************************************************
 SEE ALSO


Mime
View raw message