ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject [1/2] ambari git commit: AMBARI-12563. Ambari return fail upon service check (aonishuk)
Date Tue, 28 Jul 2015 12:09:37 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 46e04ec5e -> 3a32f836c
  refs/heads/trunk c2f10d57c -> 0144f793c


AMBARI-12563. Ambari return fail upon service check  (aonishuk)


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

Branch: refs/heads/trunk
Commit: 0144f793c5dfc1fac54a8bcb39e787b605e676fe
Parents: c2f10d5
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Tue Jul 28 15:09:27 2015 +0300
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Tue Jul 28 15:09:27 2015 +0300

----------------------------------------------------------------------
 .../libraries/functions/get_user_call_output.py | 60 ++++++++++++++++++++
 .../libraries/functions/jmx.py                  |  3 +-
 .../libraries/providers/hdfs_resource.py        |  3 +-
 3 files changed, 64 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0144f793/ambari-common/src/main/python/resource_management/libraries/functions/get_user_call_output.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/get_user_call_output.py
b/ambari-common/src/main/python/resource_management/libraries/functions/get_user_call_output.py
new file mode 100644
index 0000000..b254372
--- /dev/null
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/get_user_call_output.py
@@ -0,0 +1,60 @@
+#!/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.
+
+Ambari Agent
+
+"""
+
+import os
+import tempfile
+from resource_management.core import shell
+
+def get_user_call_output(command, user, is_checked_call=True, **call_kwargs):
+  """
+  This function eliminates only output of command inside the su, ignoring the su ouput itself.
+  This is useful since some users have motd messages setup by default on su -l. 
+  
+  @return: code, stdout, stderr
+  """
+  command_string = shell.string_cmd_from_args_list(command) if isinstance(command, (list,
tuple)) else command
+  out_files = []
+  
+  try:
+    out_files.append(tempfile.NamedTemporaryFile())
+    out_files.append(tempfile.NamedTemporaryFile())
+    
+    # other user should be able to write to it
+    for f in out_files:
+      os.chmod(f.name, 0666)
+    
+    command_string += " 1>" + out_files[0].name
+    command_string += " 2>" + out_files[1].name
+    
+    func = shell.checked_call if is_checked_call else shell.call
+    func_result = func(shell.as_user(command_string, user), **call_kwargs)
+    
+    files_output = []
+    for f in out_files:
+      files_output.append(f.read())
+    
+    return func_result[0], files_output[0], files_output[1]
+  finally:
+    for f in out_files:
+      f.close()
+      
+  
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/0144f793/ambari-common/src/main/python/resource_management/libraries/functions/jmx.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/jmx.py
b/ambari-common/src/main/python/resource_management/libraries/functions/jmx.py
index 39d6bee..9a4ff5f 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/jmx.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/jmx.py
@@ -21,6 +21,7 @@ import urllib2
 import ambari_simplejson as json # simplejson is much faster comparing to Python 2.6 json
module and has the same functions set.
 from resource_management.core import shell
 from resource_management.core.logger import Logger
+from resource_management.libraries.functions.get_user_call_output import get_user_call_output
 
 def get_value_from_jmx(qry, property, security_enabled, run_user, is_https_enabled):
   try:
@@ -34,7 +35,7 @@ def get_value_from_jmx(qry, property, security_enabled, run_user, is_https_enabl
 
     cmd.append(qry)
 
-    _, data = shell.checked_call(cmd, user=run_user, quiet=False)
+    _, data, _ = get_user_call_output(cmd, user=run_user, quiet=False)
 
     if data:
       data_dict = json.loads(data)

http://git-wip-us.apache.org/repos/asf/ambari/blob/0144f793/ambari-common/src/main/python/resource_management/libraries/providers/hdfs_resource.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/providers/hdfs_resource.py
b/ambari-common/src/main/python/resource_management/libraries/providers/hdfs_resource.py
index 994846f..cb6fb21 100644
--- a/ambari-common/src/main/python/resource_management/libraries/providers/hdfs_resource.py
+++ b/ambari-common/src/main/python/resource_management/libraries/providers/hdfs_resource.py
@@ -30,6 +30,7 @@ from resource_management.core.logger import Logger
 from resource_management.core import shell
 from resource_management.libraries.script import Script
 from resource_management.libraries.functions import format
+from resource_management.libraries.functions.get_user_call_output import get_user_call_output
 from resource_management.libraries.functions import is_empty
 from resource_management.libraries.functions import namenode_ha_utils
 
@@ -185,7 +186,7 @@ class WebHDFSUtil:
       cmd += ["-k"]
       
     cmd.append(url)
-    _, out, err = shell.checked_call(cmd, user=self.run_user, logoutput=self.logoutput, quiet=False,
stderr=subprocess.PIPE)
+    _, out, err = get_user_call_output(cmd, user=self.run_user, logoutput=self.logoutput,
quiet=False)
     status_code = out[-3:]
     out = out[:-3] # remove last line from output which is status code
     


Mime
View raw message