hadoop hue开发调试环境搭建

    hue系统后台主要使用 python语言,我们需要对 hue进行定制化二次开发。开发机操作系统为ubuntu12.04,使用独立的开发机器,小组其他人可共用。也可在自己平时使用的windows机器上开ubuntu虚拟机(如果机器配置较高),下面是hue开发环境的搭建过程。

  

   1.独立的开发机上不能使用图形环境,需要在自己的windows机器上安装Xming xwindow server软件,下载地址http://sourceforge.net/projects/xming/

     安装后,修改安装目录中的X0.hosts,在其中增加一行,内容为开发机的ip地址。

    启动windows上的Xming,这样开发机器上的eclipse启动后会将图形窗口投射到windows机器上。

     hadoop hue开发调试环境搭建    

  2.在开发机器上安装jdk1.7huehttps://github.com/cloudera/hue,版本3.7.0)、eclipse(4.3/kepler).

   假设hue安装在/home/wanggb/hue目录

   配置好hue后,在/home/wanggb/hue目录下运行build/env/bin/hue     runcherrypyserver命令启动hue,在浏览器中输入hue的ip和端口看是否能访问。

  3.在用户的.profile文件中加入环境变量DISPLAY,如下:

   export DISPLAY=windows机器的ip:0.0

   执行. .profile让环境变量生效。

  4.telnet到开发机上命令行方式启动eclipse,将会在windows机器上弹出eclipse图形窗口,提示设置workspace目录。

    5.安装pydev eclipse插件(http://pydev.org/updates)用于python开发调试。安装完成重启eclipse设置pydev插件,主要是设置python解释器。使用hue自带的python,为/home/wanggb/hue/build/env/bin/python2.7     

    
hadoop hue开发调试环境搭建
 
  

  6.eclipse中创建python django项目

     
hadoop hue开发调试环境搭建
 
     

       

hadoop hue开发调试环境搭建
 
 

 

  设置项目属性:      

hadoop hue开发调试环境搭建
   

   设置项目的debug配置:

    
hadoop hue开发调试环境搭建
 主模块设为buid/env/bin/hue,在有些eclipse中会报找不到该文件的提示,此时可以将hue拷贝为hue.py,刷新项目后再用Main Module右边的Browse按扭选取该hue.py,或直接输入${workspace_loc:hue/build/env/bin/hue.py}做为主模块。
hadoop hue开发调试环境搭建
 
 

   7.打开pyDev透视图

 
hadoop hue开发调试环境搭建
 
 

   8.修改hue的一处代码

  修改文件为:hue/desktop/core/src/desktop/appmanager.py

    改动其中的import_module_or_none方法为如下,在my_file = re.sub(r'\.pyc','.py', __file__)

    语句后面直接return None

 def _import_module_or_none(module):

  """Like import_module, but returns None if the module does not exist.

  This will properly handle nested ImportErrors in such a way that, if the

  module should exist but throws ImportError, we *will* raise through

  that error.

  """

  try:

    __import__(module)

    return sys.modules[module]

  except ImportError, ie:

    # If the exception came from us importing, we want to just

    # return None. We need to inspect the stack, though, so we properly

    # reraise in the case that the module we're importing triggered

    # an import error itself.

    tb = sys.exc_info()[2]

    top_frame = traceback.extract_tb(tb)[-1]

    err_file = re.sub(r'\.pyc','.py', top_frame[0])

    my_file = re.sub(r'\.pyc','.py', __file__)

    return None

    不修改的话在eclispe中调试时,会报错"ImportError: No module named settings"

 

   8 .python代码中设置断点,启动debug配置进行调试。

 

  9.上面的是本机调试,只是使用xwindoweclipse图形窗口投射到windows机器上,也可在自己的windows机器上起ubuntun虚拟机,这样就不需要xwindow了。

 

 

 10.pydev插件也可进行python远程调试,详细说明见http://pydev.org/manual_adv_remote_debugger.html。 

 

 11.图形化的python开发调试工具,除了eclispe+pydev,比较不错的还有pycharm ,可在     https://www.jetbrains.com/pycharm/download/下载。