You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by rl...@apache.org on 2015/11/20 09:46:06 UTC

incubator-hawq git commit: HAWQ-172. Add gpoperation.py back for gppkg use.

Repository: incubator-hawq
Updated Branches:
  refs/heads/master e1bd6c6c3 -> 4dbb3479f


HAWQ-172. Add gpoperation.py back for gppkg use.


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

Branch: refs/heads/master
Commit: 4dbb3479f3c6a44ef23efb3d72b76625ca27b212
Parents: e1bd6c6
Author: rlei <rl...@pivotal.io>
Authored: Wed Nov 18 13:52:56 2015 +0800
Committer: rlei <rl...@pivotal.io>
Committed: Fri Nov 20 16:43:42 2015 +0800

----------------------------------------------------------------------
 tools/sbin/gpoperation.py | 62 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/4dbb3479/tools/sbin/gpoperation.py
----------------------------------------------------------------------
diff --git a/tools/sbin/gpoperation.py b/tools/sbin/gpoperation.py
new file mode 100755
index 0000000..9fcb99f
--- /dev/null
+++ b/tools/sbin/gpoperation.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+import sys
+import pickle
+import traceback 
+
+class NullDevice():
+    def write(self, s):
+        pass
+
+# Prevent use of stdout, as it disrupts pickling mechanism
+old_stdout = sys.stdout
+sys.stdout = NullDevice()
+
+# log initialization must be done only AFTER rerouting stdout
+from gppylib import gplog
+from gppylib.mainUtils import getProgramName
+from gppylib.commands import unix
+hostname = unix.getLocalHostname()
+username = unix.getUserName()
+execname = pickle.load(sys.stdin)
+gplog.setup_tool_logging(execname, hostname, username)
+logger = gplog.get_default_logger()
+
+operation = pickle.load(sys.stdin)
+
+from gppylib.gpcoverage import GpCoverage
+coverage = GpCoverage()
+coverage.start()
+
+try:
+    ret = operation.run()
+except Exception, e:
+    exc_type, exc_value, exc_traceback = sys.exc_info()
+    tb_list = traceback.extract_tb(exc_traceback)
+    try:
+        # TODO: Build an ExceptionCapsule that can return the traceback
+        # to RemoteOperation as well. See Pyro.
+
+        # logger.exception(e)               # logging 'e' could be necessary for traceback
+
+        pickled_ret = pickle.dumps(e)       # Pickle exception for stdout transmission
+    except Exception, f:
+        # logger.exception(f)               # 'f' is not important to us, except for debugging perhaps
+
+        # No hope of pickling a precise Exception back to RemoteOperation.
+        # So, provide meaningful trace as text and provide a non-zero return code
+        # to signal to RemoteOperation that its Command invocation of gpoperation.py has failed.
+        pretty_trace = str(e) + "\n"
+        pretty_trace += 'Traceback (most recent call last):\n'
+        pretty_trace += ''.join(traceback.format_list(tb_list))
+        logger.critical(pretty_trace)
+        print >> sys.stderr, pretty_trace
+        sys.exit(2)                         # signal that gpoperation.py has hit unexpected error
+else:
+    pickled_ret = pickle.dumps(ret)         # Pickle return data for stdout transmission
+finally:
+    coverage.stop()
+    coverage.generate_report()
+
+sys.stdout = old_stdout
+print pickled_ret
+sys.exit(0)