You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ab...@apache.org on 2014/11/25 19:26:30 UTC

ambari git commit: AMBARI-8318 - Fix PYTHONPATH for ambari_agent.alerts and ambari_agents.apscheduler (Florian Barca via abaranchuk)

Repository: ambari
Updated Branches:
  refs/heads/trunk 6a6705188 -> d4f9cb13d


AMBARI-8318 - Fix PYTHONPATH for ambari_agent.alerts and ambari_agents.apscheduler (Florian Barca via abaranchuk)


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

Branch: refs/heads/trunk
Commit: d4f9cb13d687b8a85a1db944dcc77f7bb81567b2
Parents: 6a67051
Author: Artem Baranchuk <ab...@hortonworks.com>
Authored: Tue Nov 25 20:25:27 2014 +0200
Committer: Artem Baranchuk <ab...@hortonworks.com>
Committed: Tue Nov 25 20:25:27 2014 +0200

----------------------------------------------------------------------
 ambari-agent/conf/windows/service_wrapper.py    | 23 +++++++++++++++-----
 .../python/ambari_commons/ambari_service.py     | 12 +++++-----
 .../src/main/python/ambari-server-windows.py    |  7 +++++-
 3 files changed, 30 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d4f9cb13/ambari-agent/conf/windows/service_wrapper.py
----------------------------------------------------------------------
diff --git a/ambari-agent/conf/windows/service_wrapper.py b/ambari-agent/conf/windows/service_wrapper.py
index aaf32ca..1d11202 100644
--- a/ambari-agent/conf/windows/service_wrapper.py
+++ b/ambari-agent/conf/windows/service_wrapper.py
@@ -24,18 +24,15 @@ import win32api
 import win32event
 import win32service
 
-from ambari_commons.ambari_service import AmbariService
+from ambari_commons.ambari_service import AmbariService, ENV_PYTHON_PATH
 from ambari_commons.exceptions import *
 from ambari_commons.logging_utils import *
 from ambari_commons.os_windows import WinServiceController
-from ambari_agent.AmbariConfig import *
+from ambari_agent.AmbariConfig import AmbariConfig, SETUP_ACTION, START_ACTION, DEBUG_ACTION, STOP_ACTION, STATUS_ACTION
 from ambari_agent.HeartbeatHandlers_windows import HeartbeatStopHandler
 
 AMBARI_VERSION_VAR = "AMBARI_VERSION_VAR"
 
-ENV_PYTHONPATH = "PYTHONPATH"
-
-
 def parse_options():
   # parse env cmd
   with open(os.path.join(os.getcwd(), "ambari-env.cmd"), "r") as env_cmd:
@@ -62,6 +59,22 @@ class AmbariAgentService(AmbariService):
 
   heartbeat_stop_handler = None
 
+  # Adds the necessary script dir to the Python's modules path
+  def _adjustPythonPath(self, current_dir):
+    iPos = 0
+    python_path = os.path.join(current_dir, "sbin")
+    sys.path.insert(iPos, python_path)
+
+    # Add the alerts and apscheduler subdirs to the path, for the imports to work correctly without
+    #  having to modify the files in these 2 subdirectories
+    agent_path = os.path.join(current_dir, "sbin", "ambari_agent")
+    iPos += 1
+    sys.path.insert(iPos, agent_path)
+    for subdir in os.listdir(agent_path):
+      full_subdir = os.path.join(agent_path, subdir)
+      iPos += 1
+      sys.path.insert(iPos, full_subdir)
+
   def SvcDoRun(self):
     parse_options()
     self.redirect_output_streams()

http://git-wip-us.apache.org/repos/asf/ambari/blob/d4f9cb13/ambari-common/src/main/python/ambari_commons/ambari_service.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/ambari_service.py b/ambari-common/src/main/python/ambari_commons/ambari_service.py
index 8418e74..391ddc3 100644
--- a/ambari-common/src/main/python/ambari_commons/ambari_service.py
+++ b/ambari-common/src/main/python/ambari_commons/ambari_service.py
@@ -33,6 +33,9 @@ class AmbariService(WinService):
   _svc_display_name_ = "Ambari Service"
   _svc_description_ = "Ambari Service"
 
+  def _adjustPythonPath(self, current_dir):
+    pass
+
   # Sets the current dir and adjusts the PYTHONPATH env variable before calling SvcDoRun()
   def SvcRun(self):
     self.ReportServiceStatus(win32service.SERVICE_START_PENDING)
@@ -53,13 +56,10 @@ class AmbariService(WinService):
       # the script resides in the sbin/ambari_commons subdir
       self.options.current_dir = os.path.normpath(script_path + "\\..\\..")
       os.chdir(self.options.current_dir)
+    else:
+      self.options.current_dir = os.getcwd()
 
-      python_path = os.path.normpath(script_path + "\\..")
-
-      #update the environment vars: set PYTHONPATH = $script_dir\sbin;%PYTHONPATH%
-      if os.environ.has_key(ENV_PYTHON_PATH):
-        python_path += os.pathsep + os.environ[ENV_PYTHON_PATH]
-      os.environ[ENV_PYTHON_PATH] = python_path
+    self._adjustPythonPath(self.options.current_dir)
 
     self.SvcDoRun()
     pass

http://git-wip-us.apache.org/repos/asf/ambari/blob/d4f9cb13/ambari-server/src/main/python/ambari-server-windows.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server-windows.py b/ambari-server/src/main/python/ambari-server-windows.py
index 039069c..6c4f894 100644
--- a/ambari-server/src/main/python/ambari-server-windows.py
+++ b/ambari-server/src/main/python/ambari-server-windows.py
@@ -20,7 +20,7 @@ limitations under the License.
 
 import optparse
 
-from ambari_commons.ambari_service import AmbariService
+from ambari_commons.ambari_service import AmbariService, ENV_PYTHON_PATH
 from ambari_commons.logging_utils import *
 from ambari_commons.os_utils import remove_file
 from ambari_commons.os_windows import SvcStatusCallback
@@ -90,6 +90,11 @@ class AmbariServerService(AmbariService):
 
   AmbariService._AdjustServiceVersion()
 
+  # Adds the necessary script dir to the Python's modules path
+  def _adjustPythonPath(self, current_dir):
+    python_path = os.path.join(current_dir, "sbin")
+    sys.path.insert(0, python_path)
+
   def SvcDoRun(self):
     scmStatus = SvcStatusCallback(self)