Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 6c2697ad2 -> 96e6fcec3


AMBARI-15852: Changing HAWQ Ports through Ambari prevents HAWQ service from 
restarting


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

Branch: refs/heads/branch-2.2
Commit: 96e6fcec3cd8808bca3cd170e49c0ec5ae81dacf
Parents: 6c2697a
Author: Jun Aoki <ja...@apache.org>
Authored: Fri Apr 15 11:31:26 2016 -0700
Committer: Jun Aoki <ja...@apache.org>
Committed: Fri Apr 15 11:31:26 2016 -0700

----------------------------------------------------------------------
 .../HAWQ/2.0.0/package/scripts/common.py        | 12 +++++---
 .../2.0.0/package/scripts/hawq_constants.py     | 15 ++++++++++
 .../HAWQ/2.0.0/package/scripts/hawqmaster.py    |  4 +--
 .../HAWQ/2.0.0/package/scripts/hawqsegment.py   |  2 +-
 .../HAWQ/2.0.0/package/scripts/hawqstandby.py   |  2 +-
 .../HAWQ/2.0.0/package/scripts/hawqstatus.py    | 25 +++--------------
 .../HAWQ/2.0.0/package/scripts/utils.py         |  8 +++---
 .../python/stacks/2.3/HAWQ/test_hawqmaster.py   |  4 ++-
 .../python/stacks/2.3/HAWQ/test_hawqsegment.py  |  5 ++--
 .../python/stacks/2.3/HAWQ/test_hawqstandby.py  |  4 ++-
 .../test/python/stacks/2.3/HAWQ/test_utils.py   | 29 ++++++++++++++++++++
 11 files changed, 73 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/96e6fcec/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/common.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/common.py
 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/common.py
index 413cf1a..b929430 100644
--- 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/common.py
+++ 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/common.py
@@ -31,6 +31,7 @@ import xml.etree.ElementTree as ET
 import utils
 import hawq_constants
 import custom_params
+import hawqstatus
 
 def setup_user():
   """
@@ -234,7 +235,7 @@ def __update_sysctl_file_suse():
     raise Fail("Failed to update sysctl.conf file ")
 
 
-def get_local_hawq_site_property(property_name):
+def get_local_hawq_site_property_value(property_name):
   """
   Fetches the value of the property specified, from the local hawq-site.xml.
   """
@@ -293,17 +294,20 @@ def start_component(component_name, port, data_dir):
   if os.path.exists(os.path.join(data_dir, 
hawq_constants.postmaster_opts_filename)):
     return utils.exec_hawq_operation(hawq_constants.START,
                                      "{0} -a -v".format(component_name),
-                                     
not_if=utils.chk_hawq_process_status_cmd(port))
+                                     
not_if=utils.generate_hawq_process_status_cmd(component_name, port))
 
   utils.exec_hawq_operation(hawq_constants.INIT, "{0} -a 
-v".format(component_name))
 
-def stop_component(component_name, port, mode):
+def stop_component(component_name, mode):
   """
   Stops the component
+  Unlike start_component, port is obtained from local hawq-site.xml as Ambari 
pontentially have a new value through UI.
   """
+  port_property_name = 
hawq_constants.COMPONENT_ATTRIBUTES_MAP[component_name]['port_property']
+  port_number = get_local_hawq_site_property_value(port_property_name)
   utils.exec_hawq_operation(hawq_constants.STOP,
                             "{0} -M {1} -a -v".format(component_name, mode),
-                            only_if=utils.chk_hawq_process_status_cmd(port, 
component_name))
+                            
only_if=utils.generate_hawq_process_status_cmd(component_name, port_number))
 
 def __check_dfs_truncate_enforced():
   """

http://git-wip-us.apache.org/repos/asf/ambari/blob/96e6fcec/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawq_constants.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawq_constants.py
 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawq_constants.py
index 3f6c371..4ce0c94 100644
--- 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawq_constants.py
+++ 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawq_constants.py
@@ -66,3 +66,18 @@ pxf_hdfs_test_dir = 
"/user/{0}/hawq_pxf_hdfs_service_check".format(hawq_user)
 # Timeouts
 default_exec_timeout = 600
 hawq_operation_exec_timeout = 900
+
+COMPONENT_ATTRIBUTES_MAP = {
+  MASTER: {
+    'port_property': 'hawq_master_address_port',
+    'process_name': 'postgres'
+  },
+  STANDBY: {
+    'port_property': 'hawq_master_address_port',
+    'process_name': 'gpsyncmaster'
+  },
+  SEGMENT: {
+    'port_property': 'hawq_segment_address_port',
+    'process_name': 'postgres'
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/96e6fcec/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqmaster.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqmaster.py
 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqmaster.py
index f2ec914..5e6ca2c 100644
--- 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqmaster.py
+++ 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqmaster.py
@@ -58,7 +58,7 @@ class HawqMaster(Script):
 
   def stop(self, env):
     import params
-    common.stop_component(hawq_constants.MASTER, 
params.hawq_master_address_port, hawq_constants.FAST)
+    common.stop_component(hawq_constants.MASTER, hawq_constants.FAST)
 
   def status(self, env):
     from hawqstatus import assert_component_running
@@ -66,7 +66,7 @@ class HawqMaster(Script):
 
   def immediate_stop_hawq_service(self, env):
     import params
-    common.stop_component(hawq_constants.CLUSTER, 
params.hawq_master_address_port, hawq_constants.IMMEDIATE)
+    common.stop_component(hawq_constants.CLUSTER, hawq_constants.IMMEDIATE)
 
   def hawq_clear_cache(self, env):
     import params

http://git-wip-us.apache.org/repos/asf/ambari/blob/96e6fcec/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqsegment.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqsegment.py
 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqsegment.py
index 636dcad..24e28e4 100644
--- 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqsegment.py
+++ 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqsegment.py
@@ -51,7 +51,7 @@ class HawqSegment(Script):
 
   def stop(self, env, mode=hawq_constants.FAST):
     import params
-    common.stop_component(hawq_constants.SEGMENT, 
params.hawq_segment_address_port, mode)
+    common.stop_component(hawq_constants.SEGMENT, mode)
 
   def status(self, env):
     from hawqstatus import assert_component_running

http://git-wip-us.apache.org/repos/asf/ambari/blob/96e6fcec/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqstandby.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqstandby.py
 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqstandby.py
index 67d1cb0..e2114d8 100644
--- 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqstandby.py
+++ 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqstandby.py
@@ -48,7 +48,7 @@ class HawqStandby(Script):
 
   def stop(self, env):
     import params
-    common.stop_component(hawq_constants.STANDBY, 
params.hawq_master_address_port, hawq_constants.FAST)
+    common.stop_component(hawq_constants.STANDBY, hawq_constants.FAST)
 
   def status(self, env):
     from hawqstatus import assert_component_running

http://git-wip-us.apache.org/repos/asf/ambari/blob/96e6fcec/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqstatus.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqstatus.py
 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqstatus.py
index 92ac0af..92454e6 100644
--- 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqstatus.py
+++ 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/hawqstatus.py
@@ -21,30 +21,13 @@ from resource_management.core.exceptions import 
ComponentIsNotRunning
 
 import common
 import hawq_constants
+import utils
 
-PROCESS_INFO = {
-  hawq_constants.MASTER: {
-    'port_property': 'hawq_master_address_port',
-    'process_name': 'postgres'
-  },
-  hawq_constants.STANDBY: {
-    'port_property': 'hawq_master_address_port',
-    'process_name': 'gpsyncmaster'
-  },
-  hawq_constants.SEGMENT: {
-    'port_property': 'hawq_segment_address_port',
-    'process_name': 'postgres'
-  }
-}
-
-def assert_component_running(component):
+def assert_component_running(component_name):
   """
   Based on the port and process identifies the status of the component
   """
-  port = 
common.get_local_hawq_site_property(PROCESS_INFO[component]['port_property'])
-  process = PROCESS_INFO[component]['process_name']
-
-  netstat_cmd = "netstat -tupln | egrep ':{0}\s' | egrep {1}".format(port, 
process)
-  return_code, _ = call(netstat_cmd)
+  port_number = 
common.get_local_hawq_site_property_value(hawq_constants.COMPONENT_ATTRIBUTES_MAP[component_name]['port_property'])
+  return_code, _ = call(utils.generate_hawq_process_status_cmd(component_name, 
port_number))
   if return_code:
     raise ComponentIsNotRunning()
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/96e6fcec/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/utils.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/utils.py
 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/utils.py
index 0baa4c5..a195fb7 100644
--- 
a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/utils.py
+++ 
b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/utils.py
@@ -23,12 +23,12 @@ from resource_management.core.logger import Logger
 
 import hawq_constants
 
-def chk_hawq_process_status_cmd(port, component_name=None):
+def generate_hawq_process_status_cmd(component_name, port):
   """
-  Check if hawq postgres / gpsyncmaster process is running
+  Generate a string of command to check if hawq postgres / gpsyncmaster 
process is running
   """
-  process = "gpsyncmaster" if component_name == hawq_constants.STANDBY else 
"postgres"
-  return "netstat -tupln | egrep ':{0}\s' | egrep {1}".format(port, process)
+  process_name = 
hawq_constants.COMPONENT_ATTRIBUTES_MAP[component_name]['process_name']
+  return "netstat -tupln | egrep ':{0}\s' | egrep {1}".format(port, 
process_name)
 
 
 def create_dir_as_hawq_user(directory):

http://git-wip-us.apache.org/repos/asf/ambari/blob/96e6fcec/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqmaster.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqmaster.py 
b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqmaster.py
index c18941c..5f7f085 100644
--- a/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqmaster.py
+++ b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqmaster.py
@@ -200,7 +200,9 @@ class TestHawqMaster(RMFTestCase):
 
 
   @patch ('hawqmaster.common.__set_osparams')
-  def test_stop_default(self, set_osparams_mock):
+  @patch ('common.get_local_hawq_site_property_value')
+  def test_stop_default(self, get_local_hawq_site_property_value_mock, 
set_osparams_mock):
+    get_local_hawq_site_property_value_mock.return_value = 5432
 
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + 
'/scripts/hawqmaster.py',
         classname = 'HawqMaster',

http://git-wip-us.apache.org/repos/asf/ambari/blob/96e6fcec/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqsegment.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqsegment.py 
b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqsegment.py
index 17d7473..01e48bb 100644
--- a/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqsegment.py
+++ b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqsegment.py
@@ -154,7 +154,9 @@ class TestHawqSegment(RMFTestCase):
     self.assertNoMoreResources()
 
 
-  def test_stop_default(self):
+  @patch ('common.get_local_hawq_site_property_value')
+  def test_stop_default(self, get_local_hawq_site_property_value_mock):
+    get_local_hawq_site_property_value_mock.return_value = 40000
 
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + 
'/scripts/hawqsegment.py',
         classname = 'HawqSegment',
@@ -173,4 +175,3 @@ class TestHawqSegment(RMFTestCase):
         )
 
     self.assertNoMoreResources()
-

http://git-wip-us.apache.org/repos/asf/ambari/blob/96e6fcec/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqstandby.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqstandby.py 
b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqstandby.py
index 44565b3..59d00de 100644
--- a/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqstandby.py
+++ b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqstandby.py
@@ -170,7 +170,9 @@ class TestHawqStandby(RMFTestCase):
 
 
   @patch ('hawqstandby.common.__set_osparams')
-  def test_stop_default(self, set_osparams_mock):
+  @patch ('common.get_local_hawq_site_property_value')
+  def test_stop_default(self, get_local_hawq_site_property_value_mock, 
set_osparams_mock):
+    get_local_hawq_site_property_value_mock.return_value = 5432
 
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + 
'/scripts/hawqstandby.py',
         classname = 'HawqStandby',

http://git-wip-us.apache.org/repos/asf/ambari/blob/96e6fcec/ambari-server/src/test/python/stacks/2.3/HAWQ/test_utils.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.3/HAWQ/test_utils.py 
b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_utils.py
new file mode 100644
index 0000000..07737eb
--- /dev/null
+++ b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_utils.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+'''
+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.
+'''
+
+from stacks.utils.RMFTestCase import *
+
+import utils
+
+class TestUtils(RMFTestCase):
+
+  def test_generate_hawq_process_status_cmd(self):
+    cmd = utils.generate_hawq_process_status_cmd("master", 12345)
+    self.assertEqual(cmd, "netstat -tupln | egrep ':12345\s' | egrep postgres")

Reply via email to