   hue_ini['desktop']['http_port'] ?= '8000'
   hue_ini['desktop']['secret_key'] ?= 'jFE93j;2[290-eiwMYSECRTEKEYy#e=+Iei*@Mn<qW5o'
   hue_ini['desktop']['smtp'] ?= {}
-  hue_ini['desktop']['smtp']['host'] ?= hue_smtp_host if hue_smtp_host
+  ctx.log "WARING: property 'hdp.hue_ini.desktop.smtp.host' isnt set" unless hue_ini['desktop']['smtp']['host']
+  # Desktop database
+  hue_ini['desktop']['database'] ?= {}
+  hue_ini['desktop']['database']['engine'] ?= 'mysql'
+  hue_ini['desktop']['database']['host'] ?= ctx.host_with_module 'phyla/tools/mysql_server'
+  hue_ini['desktop']['database']['port'] ?= ctx.config.mysql_server.port
+  hue_ini['desktop']['database']['user'] ?= 'hue'
+  hue_ini['desktop']['database']['password'] ?= 'hue123'
+  hue_ini['desktop']['database']['name'] ?= 'hue'
+
+module.exports.push name: 'HDP Hue # Packages', timeout: -1, callback: (ctx, next) ->
+  ctx.service [
+    name: 'extjs-2.2-1'
+  ,
+    name: 'hue'
+  ], (err, serviced) ->
+    next err, if serviced then ctx.OK else ctx.PASS
+
+module.exports.push name: 'HDP Hue # Core', callback: (ctx, next) ->
+  {hadoop_conf_dir, hadoop_user, hadoop_group} = ctx.config.hdp
+  properties = 
+    'hadoop.proxyuser.hue.hosts': '*'
+    'hadoop.proxyuser.hue.groups': '*'
+    'hadoop.proxyuser.hcat.groups': '*'
+    'hadoop.proxyuser.hcat.hosts': '*'
+  ctx.hconfigure
+    destination: "#{hadoop_conf_dir}/core-site.xml"
+    properties: properties
+    merge: true
+  , (err, configured) ->
+    return next err if err
+    next err, if configured then ctx.OK else ctx.PASS
+
+module.exports.push name: 'HDP Hue # WebHCat', callback: (ctx, next) ->
+  {webhcat_conf_dir} = ctx.config.hdp
+  webhcat_server = ctx.host_with_module 'phyla/hdp/webhcat'
+  hconfigure = (ssh) ->
+    properties = 
+      'webhcat.proxyuser.hue.hosts': '*'
+      'webhcat.proxyuser.hue.groups': '*'
+    ctx.hconfigure
+      destination: "#{webhcat_conf_dir}/webhcat-site.xml"
+      properties: properties
+      merge: true
+    , (err, configured) ->
+      return next err if err
+      next err, if configured then ctx.OK else ctx.PASS
+  if ctx.config.host is webhcat_server
+    hconfigure ctx.ssh
+  else
+    ctx.connect webhcat_server, (err, ssh) ->
+      return next err if err
+      hconfigure ssh
+
+module.exports.push name: 'HDP Hue # Oozie', callback: (ctx, next) ->
+  {oozie_conf_dir} = ctx.config.hdp
+  oozie_server = ctx.host_with_module 'phyla/hdp/oozie_server'
+  hconfigure = (ssh) ->
+    properties = 
+      'oozie.service.ProxyUserService.proxyuser.hue.hosts': '*'
+      'oozie.service.ProxyUserService.proxyuser.hue.groups': '*'
+    ctx.hconfigure
+      ssh: ssh
+      destination: "#{oozie_conf_dir}/oozie-site.xml"
+      properties: properties
+      merge: true
+    , (err, configured) ->
+      return next err if err
+      next err, if configured then ctx.OK else ctx.PASS
+  if ctx.config.host is oozie_server
+    hconfigure ctx.ssh
+  else
+    ctx.connect oozie_server, (err, ssh) ->
+      return next err if err
+      hconfigure ssh
+
+# # http://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.0.8.0/bk_installing_manually_book/content/rpm-chap-hue-5-2.html
+module.exports.push name: 'HDP Hue # Configure', callback: (ctx, next) ->
+  {hue_conf_dir, hue_ini} = ctx.config.hdp
   ctx.ini
     destination: "#{hue_conf_dir}/hue.ini"
     content: hue_ini

  , (err, written) ->
    next err, if written then ctx.OK else ctx.PASS

# module.exports.push name: 'HDP Hue # Database', callback: (ctx, next) ->
#   modified = false
#   do_db = ->
#     {oozie_db_username, oozie_db_password, oozie_db_host, oozie_site} = ctx.config.hdp
#     username = oozie_site['oozie.service.JPAService.jdbc.username']
#     password = oozie_site['oozie.service.JPAService.jdbc.password']
#     escape = (text) -> text.replace(/[\\"]/g, "\\$&")
#     cmd = "mysql -u#{oozie_db_username} -p#{oozie_db_password} -h#{oozie_db_host} -e "
#     ctx.execute
#       cmd: """
#       if #{cmd} "use oozie"; then exit 2; fi
#       #{cmd} "
#       create database oozie;
#       grant all privileges on oozie.* to '#{username}'@'localhost' identified by '#{password}';
#       grant all privileges on oozie.* to '#{username}'@'%' identified by '#{password}';
#       flush privileges;
#       "
#       """
#       code_skipped: 2
#     , (err, created, stdout, stderr) ->
#       return next err, if created then ctx.OK else ctx.PASS
#   do_config = ->
#     hue_ini = {}
#     hue_ini['desktop'] ?= {}
#     hue_ini['desktop']['database'] ?= {}
#     hue_ini['desktop']['database']['engine'] ?= 'mysql'
#     hue_ini['desktop']['database']['host'] ?= ''
#     hue_ini['desktop']['database']['port'] ?= ''
#     hue_ini['desktop']['database']['user'] ?= ''
#     hue_ini['desktop']['database']['password'] ?= ''
#     hue_ini['desktop']['database']['name'] ?= ''
#     ctx.ini
#       destination: "#{hue_conf_dir}/hue.ini"
#       content: hue_ini
#       merge: true
#       parse: misc.ini.parse_multi_brackets 
#       stringify: misc.ini.stringify_multi_brackets
#       separator: '='
#       comment: '#'
#     , (err, written) ->
#       next err, if written then ctx.OK else ctx.PASS
#   do_end = ->
#     next err, if modified then ctx.OK else ctx.PASS



###
TODO: install Hue over SSL

  require('./oozie_').configure ctx
  # Allow proxy user inside "core-site.xml"
  require('./core').configure ctx
  {nameservice, active_nn_host, hadoop_conf_dir, webhcat_site} = ctx.config.hdp
  webhcat_port = webhcat_site['templeton.port']
  oozie_server = ctx.host_with_module 'phyla/hdp/oozie_server'
  webhcat_server = ctx.host_with_module 'phyla/hdp/webhcat'
  # todo, this might not work as expected after ha migration
  resourcemanager = ctx.host_with_module 'phyla/hdp/yarn_rm'
  # require('./hdfs').configure ctx
  # Webhdfs should be active on the NameNode, Secondary NameNode, and all the DataNodes
  # throw new Error 'WebHDFS not active' if ctx.config.hdp.hdfs_site['dfs.webhdfs.enabled'] isnt 'true'
  ctx.config.hdp.hue_conf_dir ?= '/etc/hue/conf'
  ctx.config.hdp.hue_user ?= 'hue'
  ctx.config.hdp.hue_group ?= 'hue'
  ctx.config.hdp.hue_db_admin_username ?= ctx.config.mysql_server.username
  ctx.config.hdp.hue_db_admin_password ?= ctx.config.mysql_server.password
  hue_ini = ctx.config.hdp.hue_ini ?= {}
  # Configure HDFS Cluster
  hue_ini['hadoop'] ?= {}
  hue_ini['hadoop']['hdfs_clusters'] ?= {}
