You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2014/01/02 19:01:18 UTC

[2/2] git commit: AMBARI-4212. Ambari should handle available JDK 6 vs 7 correctly (Vitaly Brodetskyi via aonishuk)

AMBARI-4212. Ambari should handle available JDK 6 vs 7 correctly (Vitaly
Brodetskyi via aonishuk)


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

Branch: refs/heads/trunk
Commit: 72d92b88922bf267ac1a60cd6864b1b463c59251
Parents: e66947e
Author: Andrew Onischuk <ao...@hortonworks.com>
Authored: Thu Jan 2 09:56:02 2014 -0800
Committer: Andrew Onischuk <ao...@hortonworks.com>
Committed: Thu Jan 2 10:01:02 2014 -0800

----------------------------------------------------------------------
 .../hdp-hadoop/templates/hadoop-env.sh.erb      |   2 +-
 .../hdp-hbase/templates/hbase-env.sh.erb        |   2 +-
 .../modules/hdp-hcat/templates/hcat-env.sh.erb  |   2 +-
 .../hdp-oozie/templates/oozie-env.sh.erb        |   2 +-
 .../modules/hdp-pig/templates/pig-env.sh.erb    |   2 +-
 .../modules/hdp-yarn/templates/yarn-env.sh.erb  |   2 +-
 .../templates/zookeeper-env.sh.erb              |   2 +-
 .../puppet/parser/functions/hdp_java_home.rb    |  29 ---
 .../main/puppet/modules/hdp/manifests/init.pp   |   6 +-
 .../modules/hdp/manifests/java/package.pp       |  81 +++----
 .../puppet/modules/hdp/manifests/package.pp     |   4 +-
 .../main/puppet/modules/hdp/manifests/params.pp |  10 +-
 .../main/python/ambari_agent/PuppetExecutor.py  |   6 +-
 ambari-server/conf/unix/ambari.properties       |   6 +-
 .../ambari/server/agent/ExecutionCommand.java   |   3 +
 .../server/configuration/Configuration.java     |  20 +-
 .../AmbariCustomCommandExecutionHelperImpl.java |   9 +
 .../controller/AmbariManagementController.java  |  15 ++
 .../AmbariManagementControllerImpl.java         |  28 ++-
 ambari-server/src/main/python/ambari-server.py  | 234 +++++++++++++------
 .../1.3.4/hooks/before-START/scripts/params.py  |   7 +-
 .../scripts/shared_initialization.py            |  32 ++-
 .../services/HBASE/package/scripts/params.py    |   2 +-
 .../services/HIVE/package/scripts/params.py     |   2 +-
 .../services/NAGIOS/package/scripts/params.py   |   2 +-
 .../services/OOZIE/package/scripts/params.py    |   2 +-
 .../services/PIG/package/scripts/params.py      |   2 +-
 .../ZOOKEEPER/package/scripts/params.py         |   2 +-
 .../2.0.8/hooks/before-START/scripts/params.py  |   7 +-
 .../scripts/shared_initialization.py            |  32 ++-
 .../services/HBASE/package/scripts/params.py    |   2 +-
 .../services/HIVE/package/scripts/params.py     |   2 +-
 .../services/NAGIOS/package/scripts/params.py   |   2 +-
 .../services/OOZIE/package/scripts/params.py    |   2 +-
 .../services/PIG/package/scripts/params.py      |   2 +-
 .../services/YARN/package/scripts/params.py     |   2 +-
 .../ZOOKEEPER/package/scripts/params.py         |   2 +-
 .../src/test/python/TestAmbariServer.py         |  56 ++++-
 38 files changed, 399 insertions(+), 226 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp-hadoop/templates/hadoop-env.sh.erb
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-hadoop/templates/hadoop-env.sh.erb b/ambari-agent/src/main/puppet/modules/hdp-hadoop/templates/hadoop-env.sh.erb
index 049f369..ef0d3d4 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-hadoop/templates/hadoop-env.sh.erb
+++ b/ambari-agent/src/main/puppet/modules/hdp-hadoop/templates/hadoop-env.sh.erb
@@ -24,7 +24,7 @@
 # remote nodes.
 
 # The java implementation to use.  Required.
-export JAVA_HOME=<%=scope.function_hdp_java_home()%>
+export JAVA_HOME=<%=scope.function_hdp_template_var("::hdp::params::java64_home")%>
 export HADOOP_HOME_WARN_SUPPRESS=1
 
 # Hadoop Configuration Directory

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp-hbase/templates/hbase-env.sh.erb
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-hbase/templates/hbase-env.sh.erb b/ambari-agent/src/main/puppet/modules/hdp-hbase/templates/hbase-env.sh.erb
index 93d30fd..ea19d23 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-hbase/templates/hbase-env.sh.erb
+++ b/ambari-agent/src/main/puppet/modules/hdp-hbase/templates/hbase-env.sh.erb
@@ -19,7 +19,7 @@
 # Set environment variables here.
 
 # The java implementation to use. Java 1.6 required.
-export JAVA_HOME=<%=scope.function_hdp_java_home()%>
+export JAVA_HOME=<%=scope.function_hdp_template_var("::hdp::params::java64_home")%>
 
 # HBase Configuration directory
 export HBASE_CONF_DIR=${HBASE_CONF_DIR:-<%=scope.function_hdp_template_var("hbase_conf_dir")%>}

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp-hcat/templates/hcat-env.sh.erb
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-hcat/templates/hcat-env.sh.erb b/ambari-agent/src/main/puppet/modules/hdp-hcat/templates/hcat-env.sh.erb
index d808446..cf46b5c 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-hcat/templates/hcat-env.sh.erb
+++ b/ambari-agent/src/main/puppet/modules/hdp-hcat/templates/hcat-env.sh.erb
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-JAVA_HOME=<%=scope.function_hdp_java_home()%>
+JAVA_HOME=<%=scope.function_hdp_template_var("::hdp::params::java64_home")%>
 HCAT_PID_DIR=<%=scope.function_hdp_template_var("::hcat_pid_dir")%>/
 HCAT_LOG_DIR=<%=scope.function_hdp_template_var("::hcat_log_dir")%>/
 HCAT_CONF_DIR=<%=scope.function_hdp_template_var("hcat_conf_dir")%>

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp-oozie/templates/oozie-env.sh.erb
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-oozie/templates/oozie-env.sh.erb b/ambari-agent/src/main/puppet/modules/hdp-oozie/templates/oozie-env.sh.erb
index 431f26f..bb2ba72 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-oozie/templates/oozie-env.sh.erb
+++ b/ambari-agent/src/main/puppet/modules/hdp-oozie/templates/oozie-env.sh.erb
@@ -18,7 +18,7 @@
 #
 
 #Set JAVA HOME
-export JAVA_HOME=<%=scope.function_hdp_java_home()%>
+export JAVA_HOME=<%=scope.function_hdp_template_var("::hdp::params::java64_home")%>
 
 # Set Oozie specific environment variables here.
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp-pig/templates/pig-env.sh.erb
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-pig/templates/pig-env.sh.erb b/ambari-agent/src/main/puppet/modules/hdp-pig/templates/pig-env.sh.erb
index 883ba0a..a69f817 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-pig/templates/pig-env.sh.erb
+++ b/ambari-agent/src/main/puppet/modules/hdp-pig/templates/pig-env.sh.erb
@@ -13,5 +13,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-JAVA_HOME=<%=scope.function_hdp_java_home()%>
+JAVA_HOME=<%=scope.function_hdp_template_var("::hdp::params::java64_home")%>
 HADOOP_HOME=${HADOOP_HOME:-<%=scope.function_hdp_template_var("::hdp::params::hadoop_home")%>}

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp-yarn/templates/yarn-env.sh.erb
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-yarn/templates/yarn-env.sh.erb b/ambari-agent/src/main/puppet/modules/hdp-yarn/templates/yarn-env.sh.erb
index 4bf1779..b9e9398 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-yarn/templates/yarn-env.sh.erb
+++ b/ambari-agent/src/main/puppet/modules/hdp-yarn/templates/yarn-env.sh.erb
@@ -20,7 +20,7 @@ export HADOOP_YARN_HOME=<%=scope.function_hdp_template_var("hadoop_yarn_home")%>
 export YARN_LOG_DIR=<%=scope.function_hdp_template_var("yarn_log_dir_prefix")%>/$USER
 export YARN_PID_DIR=<%=scope.function_hdp_template_var("yarn_pid_dir_prefix")%>/$USER
 export HADOOP_LIBEXEC_DIR=<%=scope.function_hdp_template_var("hadoop_libexec_dir")%>
-export JAVA_HOME=<%=scope.function_hdp_java_home()%>
+export JAVA_HOME=<%=scope.function_hdp_template_var("::hdp::params::java64_home")%>
 
 # User for YARN daemons
 export HADOOP_YARN_USER=${HADOOP_YARN_USER:-yarn}

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp-zookeeper/templates/zookeeper-env.sh.erb
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-zookeeper/templates/zookeeper-env.sh.erb b/ambari-agent/src/main/puppet/modules/hdp-zookeeper/templates/zookeeper-env.sh.erb
index 03cf969..f0c18f7 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-zookeeper/templates/zookeeper-env.sh.erb
+++ b/ambari-agent/src/main/puppet/modules/hdp-zookeeper/templates/zookeeper-env.sh.erb
@@ -12,7 +12,7 @@
 # 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.
-export JAVA_HOME=<%=scope.function_hdp_java_home()%>
+export JAVA_HOME=<%=scope.function_hdp_template_var("::hdp::params::java64_home")%>
 export ZOO_LOG_DIR=<%=scope.function_hdp_template_var("zk_log_dir")%>
 export ZOOPIDFILE=<%=scope.function_hdp_template_var("zk_pid_file")%>
 export SERVER_JVMFLAGS=<%=scope.function_hdp_template_var("zk_server_heapsize")%>

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp/lib/puppet/parser/functions/hdp_java_home.rb
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp/lib/puppet/parser/functions/hdp_java_home.rb b/ambari-agent/src/main/puppet/modules/hdp/lib/puppet/parser/functions/hdp_java_home.rb
deleted file mode 100644
index f82ee37..0000000
--- a/ambari-agent/src/main/puppet/modules/hdp/lib/puppet/parser/functions/hdp_java_home.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-#
-# 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.
-#
-#
-module Puppet::Parser::Functions
-  newfunction(:hdp_java_home, :type => :rvalue) do 
-    size = lookupvar("size")
-    if size.nil? or size == :undefined
-      size = "64"
-    end
-    lookupvar("::hdp::params::java#{size.to_s}_home")
-  end
-end

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp/manifests/init.pp
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp/manifests/init.pp b/ambari-agent/src/main/puppet/modules/hdp/manifests/init.pp
index 256610d..d907130 100644
--- a/ambari-agent/src/main/puppet/modules/hdp/manifests/init.pp
+++ b/ambari-agent/src/main/puppet/modules/hdp/manifests/init.pp
@@ -485,10 +485,12 @@ define hdp::exec(
     logoutput   => $logoutput,
     cwd         => $cwd
   }
+
+  hdp::java::package{ $name:}
   
-  anchor{ "hdp::exec::${name}::begin":} -> Exec[$name] -> anchor{ "hdp::exec::${name}::end":} 
+  anchor{ "hdp::exec::${name}::begin":} -> Hdp::Java::Package[$name] -> Exec[$name] -> anchor{ "hdp::exec::${name}::end":}
   if (($initial_wait != undef) and ($initial_wait != "undef")) {
-    Anchor["hdp::exec::${name}::begin"] -> Hdp::Wait["service ${name}"] -> Exec[$name]
+    Anchor["hdp::exec::${name}::begin"] -> Hdp::Wait["service ${name}"] -> Hdp::Java::Package[$name] -> Exec[$name]
   }
 }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp/manifests/java/package.pp
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp/manifests/java/package.pp b/ambari-agent/src/main/puppet/modules/hdp/manifests/java/package.pp
index 40f9217..1b748f6 100644
--- a/ambari-agent/src/main/puppet/modules/hdp/manifests/java/package.pp
+++ b/ambari-agent/src/main/puppet/modules/hdp/manifests/java/package.pp
@@ -18,57 +18,60 @@
 # under the License.
 #
 #
-define hdp::java::package(
-  $size
-)
+define hdp::java::package()
 {
     
   include hdp::params
   
   $security_enabled = $hdp::params::security_enabled
-  $jdk_bin = $hdp::params::jdk_bins[$size]
+  $jdk_bin = $hdp::params::jdk_name
   $artifact_dir = $hdp::params::artifact_dir
   $jdk_location = $hdp::params::jdk_location
   $jdk_curl_target = "${artifact_dir}/${jdk_bin}"
  
-  if ($size == "32") {
-    $java_home = $hdp::params::java32_home
-  } else {
-    $java_home = $hdp::params::java64_home
-  }
+  $java_home = $hdp::params::java64_home
   $java_exec = "${java_home}/bin/java"
   $java_dir = regsubst($java_home,'/[^/]+$','')
 
-  # curl -k - ignoring unverified server ssl sertificate,
-  $curl_cmd = "mkdir -p ${artifact_dir} ; curl -kf --retry 10 ${jdk_location}/${jdk_bin} -o ${jdk_curl_target}"
-  exec{ "${curl_cmd} ${name}":
-    command => $curl_cmd,
-    creates => $jdk_curl_target,
-    path    => ["/bin","/usr/bin/"],
-    unless  => "test -e ${java_exec}"
-  }
- 
-  $install_cmd = "mkdir -p ${java_dir} ; chmod +x ${jdk_curl_target}; cd ${java_dir} ; echo A | ${jdk_curl_target} -noregister > /dev/null 2>&1"
-  exec{ "${install_cmd} ${name}":
-    command => $install_cmd,
-    unless  => "test -e ${java_exec}",
-    path    => ["/bin","/usr/bin/"]
-  }
- 
-  file { "${java_exec} ${name}":
-  ensure => present
-  }   
- 
-  if ($security_enabled == true) {
-    hdp::java::jce::package{ $name:
-      java_home_dir  => $java_home,
-      jdk_location => $jdk_location,
-      jdk_bin => $jdk_bin
+  if ($jdk_bin != "") {
+    # curl -k - ignoring unverified server ssl sertificate,
+    $curl_cmd = "mkdir -p ${artifact_dir} ; curl -kf --retry 10 ${jdk_location}/${jdk_bin} -o ${jdk_curl_target}"
+    exec{ "${curl_cmd} ${name}":
+      command => $curl_cmd,
+      creates => $jdk_curl_target,
+      path    => ["/bin","/usr/bin/"],
+      unless  => "test -e ${java_exec}"
+    }
+
+    if (hdp_str_ends_with($jdk_bin, ".bin")) {
+      $install_cmd = "mkdir -p ${java_dir} ; chmod +x ${jdk_curl_target}; cd ${java_dir} ; echo A | ${jdk_curl_target} -noregister > /dev/null 2>&1"
+    }
+    elsif (hdp_str_ends_with($jdk_bin, ".gz")) {
+      $install_cmd = "mkdir -p ${java_dir} ; cd ${java_dir} ; tar -xf ${jdk_curl_target} > /dev/null 2>&1"
+    }
+
+    exec{ "${install_cmd} ${name}":
+      command => $install_cmd,
+      unless  => "test -e ${java_exec}",
+      path    => ["/bin","/usr/bin/"]
+    }
+
+    exec{ "${java_exec} ${name}":
+      command => "test -e ${java_exec}",
+      path    => ["/bin","/usr/bin/"]
+    }
+
+    if ($security_enabled == true) {
+      hdp::java::jce::package{ $name:
+        java_home_dir  => $java_home,
+        jdk_location => $jdk_location,
+        jdk_bin => $jdk_bin
+      }
     }
-  }
 
-  anchor{"hdp::java::package::${name}::begin":} -> Exec["${curl_cmd} ${name}"] ->  Exec["${install_cmd} ${name}"] -> File["${java_exec} ${name}"] ->  anchor{"hdp::java::package::${name}::end":}
-  if ($security_enabled == true) {
-    File["${java_exec} ${name}"] -> Hdp::Java::Jce::Package[$name] 
-  }
+    anchor{"hdp::java::package::${name}::begin":} -> Exec["${curl_cmd} ${name}"] ->  Exec["${install_cmd} ${name}"] -> Exec["${java_exec} ${name}"] ->  anchor{"hdp::java::package::${name}::end":}
+    if ($security_enabled == true) {
+      Exec["${java_exec} ${name}"] -> Hdp::Java::Jce::Package[$name]
+   }
+ }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp/manifests/package.pp
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp/manifests/package.pp b/ambari-agent/src/main/puppet/modules/hdp/manifests/package.pp
index b6c369e..0ed383e 100644
--- a/ambari-agent/src/main/puppet/modules/hdp/manifests/package.pp
+++ b/ambari-agent/src/main/puppet/modules/hdp/manifests/package.pp
@@ -111,9 +111,7 @@ define hdp::package::process_pkg(
   debug("##Packages list: $packages_list")
 
   if (($java_needed == true) and ($ensure == 'present')){
-    hdp::java::package{ $name:
-      size                 => $size
-    }
+    hdp::java::package{ $name:}
   }
 
   if (($lzo_needed == true) and ($ensure == 'present')){

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/puppet/modules/hdp/manifests/params.pp
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp/manifests/params.pp b/ambari-agent/src/main/puppet/modules/hdp/manifests/params.pp
index 012b559..6e7f7fb 100644
--- a/ambari-agent/src/main/puppet/modules/hdp/manifests/params.pp
+++ b/ambari-agent/src/main/puppet/modules/hdp/manifests/params.pp
@@ -261,18 +261,14 @@ class hdp::params()
   $host_address = undef 
 
   ##### java 
-  $java32_home = hdp_default("java32_home","/usr/jdk32/jdk1.6.0_31")
-  $java64_home = hdp_default("java64_home","/usr/jdk64/jdk1.6.0_31")
+  $java64_home = hdp_default("java_home")
   
   $wipeoff_data =  hdp_default("wipeoff_data",false) 
 
   $jdk_location = hdp_default("jdk_location","http://download.oracle.com/otn-pub/java/jdk/6u31-b03")
-  $jdk_bins = hdp_default("jdk_bins",{
-    32 => "jdk-6u31-linux-i586.bin",
-    64 => "jdk-6u31-linux-x64.bin"
-  })
+  $jdk_name = hdp_default("jdk_name","")
 
-  $jce_policy_zip = "jce_policy-6.zip"
+  $jce_policy_zip = hdp_default("jce_name","")
   $jce_location = hdp_default("jce_location","http://download.oracle.com/otn-pub/java/jce_policy/6")
   $server_db_name = hdp_default("db_name", "postgres")
   $oracle_jdbc_url = hdp_default("oracle_jdbc_url", "")

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-agent/src/main/python/ambari_agent/PuppetExecutor.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/PuppetExecutor.py b/ambari-agent/src/main/python/ambari_agent/PuppetExecutor.py
index d8981c5..b69e8ae 100644
--- a/ambari-agent/src/main/python/ambari_agent/PuppetExecutor.py
+++ b/ambari-agent/src/main/python/ambari_agent/PuppetExecutor.py
@@ -155,11 +155,11 @@ class PuppetExecutor:
     # After installing we must have jdk available for start/stop/smoke
     if command['roleCommand'] != "INSTALL":
       java64_home = None
-      if ('global' in command['configurations']) and ('java64_home' in command['configurations']['global']):
-        java64_home = str(command['configurations']['global']['java64_home']).strip()
+      if 'hostLevelParams' in command and 'java_home' in command['hostLevelParams']:
+        java64_home = str(command['hostLevelParams']['java_home']).strip()
       if java64_home is None or not self.isJavaAvailable(java64_home):
         if java64_home is None:
-          errMsg = "Cannot access JDK! Make sure java64_home is specified in global config"
+          errMsg = "Cannot access JDK! Make sure java_home is specified in global config"
         else:
           errMsg = JAVANOTVALID_MSG.format(java64_home)
         return {'stdout': '', 'stderr': errMsg, 'exitcode': 1}

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/conf/unix/ambari.properties
----------------------------------------------------------------------
diff --git a/ambari-server/conf/unix/ambari.properties b/ambari-server/conf/unix/ambari.properties
index d70612f..ebb5d9c 100644
--- a/ambari-server/conf/unix/ambari.properties
+++ b/ambari-server/conf/unix/ambari.properties
@@ -18,8 +18,10 @@
 
 security.server.keys_dir = /var/lib/ambari-server/keys
 resources.dir = /var/lib/ambari-server/resources
-jdk.url=http://public-repo-1.hortonworks.com/ARTIFACTS/jdk-6u31-linux-x64.bin
-jce_policy.url=http://public-repo-1.hortonworks.com/ARTIFACTS/jce_policy-6.zip
+jdk1.6.url=http://public-repo-1.hortonworks.com/ARTIFACTS/jdk-6u31-linux-x64.bin
+jce_policy1.6.url=http://public-repo-1.hortonworks.com/ARTIFACTS/jce_policy-6.zip
+jdk1.7.url=http://www.reucon.com/cdn/java/jdk-7u45-linux-x64.tar.gz
+jce_policy1.7.url=http://uni-smr.ac.ru/archive/dev/java/SDKs/sun/j2se/7/UnlimitedJCEPolicyJDK7.zip
 metadata.path=/var/lib/ambari-server/resources/stacks
 server.version.file=/var/lib/ambari-server/resources/version
 webapp.dir=/usr/lib/ambari-server/web

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
index dc8d605..7bd2b41 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
@@ -245,6 +245,9 @@ public class ExecutionCommand extends AgentCommand {
     String SERVICE_REPO_INFO = "service_repo_info";
     String PACKAGE_LIST = "package_list";
     String JDK_LOCATION = "jdk_location";
+    String JAVA_HOME = "java_home";
+    String JDK_NAME = "jdk_name";
+    String JCE_NAME = "jce_name";
     String MYSQL_JDBC_URL = "mysql_jdbc_url";
     String ORACLE_JDBC_URL = "oracle_jdbc_url";
     String DB_DRIVER_FILENAME = "db_driver_filename";

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 53a77a8..909e6e1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -79,6 +79,8 @@ public class Configuration {
   public static final String SERVER_VERSION_FILE = "server.version.file";
   public static final String SERVER_VERSION_KEY = "version";
   public static final String JAVA_HOME_KEY = "java.home";
+  public static final String JDK_NAME_KEY = "jdk.name";
+  public static final String JCE_NAME_KEY = "jce.name";
 
   public static final String CLIENT_SECURITY_KEY = "client.security";
   public static final String CLIENT_API_PORT_KEY = "client.api.port";
@@ -208,8 +210,6 @@ public class Configuration {
   private static final String RESOURCES_DIR_DEFAULT =
       "/var/share/ambari/resources/";
   
-  public static final String JAVA_HOME_DEFAULT = "/usr/jdk64/jdk1.6.0_31";
-
   private static final String  ANONYMOUS_AUDIT_NAME_KEY = "anonymous.audit.name";
       
   private static final String CLIENT_SECURITY_DEFAULT = "local";
@@ -339,7 +339,7 @@ public class Configuration {
     configsMap.put(CLIENT_API_SSL_CRT_NAME_KEY, properties.getProperty(
       CLIENT_API_SSL_CRT_NAME_KEY, CLIENT_API_SSL_CRT_NAME_DEFAULT));
     configsMap.put(JAVA_HOME_KEY, properties.getProperty(
-        JAVA_HOME_KEY, JAVA_HOME_DEFAULT));
+        JAVA_HOME_KEY));
 
     File passFile = new File(configsMap.get(SRVR_KSTR_DIR_KEY) + File.separator
         + configsMap.get(SRVR_CRT_PASS_FILE_KEY));
@@ -764,7 +764,19 @@ public class Configuration {
   public String getOjdbcJarName() {
 	return properties.getProperty(OJDBC_JAR_NAME_KEY, OJDBC_JAR_NAME_DEFAULT);
   }
-  
+
+  public String getJavaHome() {
+    return properties.getProperty(JAVA_HOME_KEY);
+  }
+
+  public String getJDKName() {
+    return properties.getProperty(JDK_NAME_KEY);
+  }
+
+  public String getJCEName() {
+    return properties.getProperty(JCE_NAME_KEY);
+  }
+
   public String getServerDBName() {
 	return properties.getProperty(SERVER_DB_NAME_KEY, SERVER_DB_NAME_DEFAULT);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperImpl.java
index f1c7743..8c5d733 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperImpl.java
@@ -185,6 +185,9 @@ public class AmbariCustomCommandExecutionHelperImpl implements AmbariCustomComma
         hostLevelParams = new TreeMap<String, String>();
       }
       hostLevelParams.put(JDK_LOCATION, amc.getJdkResourceUrl());
+      hostLevelParams.put(JAVA_HOME, amc.getJavaHome());
+      hostLevelParams.put(JDK_NAME, amc.getJDKName());
+      hostLevelParams.put(JCE_NAME, amc.getJCEName());
       hostLevelParams.put(STACK_NAME, stackId.getStackName());
       hostLevelParams.put(STACK_VERSION,stackId.getStackVersion());
       hostLevelParams.put(CUSTOM_COMMAND, commandName);
@@ -330,6 +333,9 @@ public class AmbariCustomCommandExecutionHelperImpl implements AmbariCustomComma
       hostLevelParams = new TreeMap<String, String>();
     }
     hostLevelParams.put(JDK_LOCATION, amc.getJdkResourceUrl());
+    hostLevelParams.put(JAVA_HOME, amc.getJavaHome());
+    hostLevelParams.put(JDK_NAME, amc.getJDKName());
+    hostLevelParams.put(JCE_NAME, amc.getJCEName());
     hostLevelParams.put(STACK_NAME, stackId.getStackName());
     hostLevelParams.put(STACK_VERSION,stackId.getStackVersion());
     hostLevelParams.putAll(amc.getRcaParameters());
@@ -534,6 +540,9 @@ public class AmbariCustomCommandExecutionHelperImpl implements AmbariCustomComma
     // TODO: Move parameter population to org.apache.ambari.server.controller.AmbariManagementControllerImpl.createAction()
     hostParams.put(REPO_INFO, repoInfo);
     hostParams.put(JDK_LOCATION, amc.getJdkResourceUrl());
+    hostParams.put(JAVA_HOME, amc.getJavaHome());
+    hostParams.put(JDK_NAME, amc.getJDKName());
+    hostParams.put(JCE_NAME, amc.getJCEName());
     hostParams.put(STACK_NAME, stackId.getStackName());
     hostParams.put(STACK_VERSION, stackId.getStackVersion());
     hostParams.put(DB_NAME, amc.getServerDB());

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
index 18bd98b..c031034 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
@@ -450,6 +450,21 @@ public interface AmbariManagementController {
   public String getJdkResourceUrl();
 
   /**
+   * Getter for the java home, stored in ambari.properties
+   */
+  public String getJavaHome();
+
+  /**
+   * Getter for the jdk name, stored in ambari.properties
+   */
+  public String getJDKName();
+
+  /**
+   * Getter for the jce name, stored in ambari.properties
+   */
+  public String getJCEName();
+
+  /**
    * Getter for the name of server database
    */
   public String getServerDB();

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index c3fdae3..2503b35 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -145,6 +145,9 @@ public class AmbariManagementControllerImpl implements
   final private static int REPO_URL_READ_TIMEOUT = 500;
 
   final private String jdkResourceUrl;
+  final private String javaHome;
+  final private String jdkName;
+  final private String jceName;
   final private String ojdbcUrl;
   final private String serverDB;
   final private String mysqljdbcUrl;
@@ -173,7 +176,10 @@ public class AmbariManagementControllerImpl implements
         this.masterProtocol = "http";
         this.masterPort = configs.getClientApiPort();
       }  
-      this.jdkResourceUrl = getAmbariServerURI(JDK_RESOURCE_LOCATION);    
+      this.jdkResourceUrl = getAmbariServerURI(JDK_RESOURCE_LOCATION);
+      this.javaHome = configs.getJavaHome();
+      this.jdkName = configs.getJDKName();
+      this.jceName = configs.getJCEName();
       this.ojdbcUrl = getAmbariServerURI(JDK_RESOURCE_LOCATION + "/" + configs.getOjdbcJarName());
       this.mysqljdbcUrl = getAmbariServerURI(JDK_RESOURCE_LOCATION + "/" + configs.getMySQLJarName());
      
@@ -182,7 +188,10 @@ public class AmbariManagementControllerImpl implements
       this.masterProtocol = null;
       this.masterPort = null;
       
-      this.jdkResourceUrl = null; 
+      this.jdkResourceUrl = null;
+      this.javaHome = null;
+      this.jdkName = null;
+      this.jceName = null;
       this.ojdbcUrl = null;
       this.mysqljdbcUrl = null;
       this.serverDB = null;
@@ -2533,6 +2542,21 @@ public class AmbariManagementControllerImpl implements
   }
 
   @Override
+  public String getJavaHome() {
+    return javaHome;
+  }
+
+  @Override
+  public String getJDKName() {
+    return jdkName;
+  }
+
+  @Override
+  public String getJCEName() {
+    return jceName;
+  }
+
+  @Override
   public String getServerDB() {
     return serverDB;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index 6482cd5..17a4dfd 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -355,22 +355,28 @@ ORACLE_DB_ID_TYPES = ["Service Name", "SID"]
 
 
 # jdk commands
-JDK_LOCAL_FILENAME = "jdk-6u31-linux-x64.bin"
+JDK_NAMES = ["jdk-7u45-linux-x64.tar.gz" , "jdk-6u31-linux-x64.bin"]
+JDK_URL_PROPERTIES = ["jdk1.7.url", "jdk1.6.url"]
+JCE_URL_PROPERTIES = ["jce_policy1.7.url", "jce_policy1.6.url"]
+JDK_INDEX = 0
+JDK_VERSION_REs = ["(jdk.*)/jre" , "Creating (jdk.*)/jre"]
+CUSTOM_JDK_NUMBER = "3"
 JDK_MIN_FILESIZE = 5000
 JDK_INSTALL_DIR = "/usr/jdk64"
 CREATE_JDK_DIR_CMD = "/bin/mkdir -p " + JDK_INSTALL_DIR
 MAKE_FILE_EXECUTABLE_CMD = "chmod a+x {0}"
 JAVA_HOME_PROPERTY = "java.home"
-JDK_URL_PROPERTY='jdk.url'
-JCE_URL_PROPERTY='jce_policy.url'
+JDK_NAME_PROPERTY = "jdk.name"
+JCE_NAME_PROPERTY = "jce.name"
 OS_TYPE_PROPERTY = "server.os_type"
 GET_FQDN_SERVICE_URL="server.fqdn.service.url"
 
 JDK_DOWNLOAD_CMD = "curl --create-dirs -o {0} {1}"
 JDK_DOWNLOAD_SIZE_CMD = "curl -I {0}"
+UNTAR_JDK_ARVHIVE = "tar -xvf {0}"
 
 #JCE Policy files
-JCE_POLICY_FILENAME = "jce_policy-6.zip"
+JCE_POLICY_FILENAMES = ["UnlimitedJCEPolicyJDK7.zip" , "jce_policy-6.zip"]
 JCE_DOWNLOAD_CMD = "curl -o {0} {1}"
 JCE_MIN_FILESIZE = 5000
 
@@ -912,6 +918,21 @@ def write_property(key, value):
     return -1
   return 0
 
+def remove_property(key):
+  conf_file = find_properties_file()
+  properties = Properties()
+  try:
+    properties.load(open(conf_file))
+  except Exception, e:
+    print_error_msg('Could not read ambari config file "%s": %s' % (conf_file, e))
+    return -1
+  properties.removeOldProp(key)
+  try:
+    properties.store(open(conf_file, "w"))
+  except Exception, e:
+    print_error_msg('Could not write ambari config file "%s": %s' % (conf_file, e))
+    return -1
+  return 0
 
 def setup_db(args):
   #password access to ambari-server and mapred
@@ -1641,7 +1662,7 @@ def install_jce_manualy(args):
       if os.path.isdir(args.jce_policy):
         err = "JCE Policy path is a directory: " + args.jce_policy
         raise FatalException(-1, err)
-      jce_destination = os.path.join(properties[RESOURCES_DIR_PROPERTY], JCE_POLICY_FILENAME)
+      jce_destination = os.path.join(properties[RESOURCES_DIR_PROPERTY], JCE_POLICY_FILENAMES[JDK_INDEX])
       try:
         shutil.copy(args.jce_policy, jce_destination)
       except Exception, e:
@@ -1660,99 +1681,144 @@ def install_jce_manualy(args):
 # Downloads the JDK
 #
 def download_jdk(args):
+  global JDK_INDEX
+  ambari_setup_with_jdk_location = False
   properties = get_ambari_properties()
   if properties == -1:
     err = "Error getting ambari properties"
     raise FatalException(-1, err)
   conf_file = properties.fileName
   ok = False
-  if get_JAVA_HOME() and not args.java_home:
-    pass # do nothing
-  elif args.java_home and os.path.exists(args.java_home):
-    jce_policy_path = os.path.join(properties[RESOURCES_DIR_PROPERTY], JCE_POLICY_FILENAME)
-    if os.path.exists(jce_policy_path):
-      err = "Command failed to execute. Please remove or move " + jce_policy_path + " and retry again"
-      raise FatalException(1, err)
+  jcePolicyWarn = "JCE Policy files are required for configuring Kerberos security. If you plan to use Kerberos," \
+         "please make sure JCE Unlimited Strength Jurisdiction Policy Files are valid on all hosts."
+  if args.java_home and os.path.exists(args.java_home):
+    for jce_file in JCE_POLICY_FILENAMES:
+      jce_policy_path = os.path.join(properties[RESOURCES_DIR_PROPERTY], jce_file)
+      if os.path.exists(jce_policy_path):
+        err = "Command failed to execute. Please remove or move " + jce_policy_path + " and retry again"
+        raise FatalException(1, err)
 
-    print_warning_msg("JAVA_HOME " + args.java_home
-                    + " must be valid on ALL hosts")
+    print_warning_msg("JAVA_HOME " + args.java_home + " must be valid on ALL hosts")
+    print_warning_msg(jcePolicyWarn)
     write_property(JAVA_HOME_PROPERTY, args.java_home)
-    
-    warn = "JCE Policy files are required for configuring Kerberos security. If you plan to use Kerberos," \
-            "please make sure JCE Unlimited Strength Jurisdiction Policy Files are valid on all hosts."
-    print_warning_msg(warn)
-
+    remove_property(JDK_NAME_PROPERTY)
+    remove_property(JCE_NAME_PROPERTY)
     return 0
   else:
+    if get_JAVA_HOME():
+      change_jdk = get_YN_input("Do you want to change Oracle JDK [y/n] (n)? ", False)
+      if not change_jdk:
+        return 0
+
     try:
-      jdk_url = properties[JDK_URL_PROPERTY]
       resources_dir = properties[RESOURCES_DIR_PROPERTY]
     except (KeyError), e:
       err = 'Property ' + str(e) + ' is not defined at ' + conf_file
       raise FatalException(1, err)
-    dest_file = resources_dir + os.sep + JDK_LOCAL_FILENAME
-    if os.path.exists(dest_file):
-      print "JDK already exists, using " + dest_file
-    elif args.jdk_location and os.path.exists(args.jdk_location):
+    ##JDK location was set by user with --jdk-location key
+    if args.jdk_location and os.path.exists(args.jdk_location):
+      path, custom_jdk_name = os.path.split(args.jdk_location)
+      dest_file = resources_dir + os.sep + custom_jdk_name
+      print_warning_msg("JDK must be installed on all agent hosts and JAVA_HOME must be valid on all agent hosts.")
+      print_warning_msg(jcePolicyWarn)
       print "Copying local JDK file {0} to {1}".format(args.jdk_location, dest_file)
       try:
         shutil.copyfile(args.jdk_location, dest_file)
       except Exception, e:
         err = "Can not copy file {0} to {1} due to: {2} . Please check file " \
-              "permissions and free disk space.".format(args.jdk_location,
-                                                        dest_file, e.message)
+              "permissions and free disk space.".format(args.jdk_location, dest_file, e.message)
         raise FatalException(1, err)
+      ambari_setup_with_jdk_location = True
+      remove_property(JDK_NAME_PROPERTY)
+      remove_property(JCE_NAME_PROPERTY)
     else:
-      ok = get_YN_input("To download the Oracle JDK you must accept the "
-                        "license terms found at "
-                        "http://www.oracle.com/technetwork/java/javase/"
-                        "terms/license/index.html and not accepting will "
-                        "cancel the Ambari Server setup.\nDo you accept the "
-                        "Oracle Binary Code License Agreement [y/n] (y)? ", True)
-      if not ok:
-        print 'Exiting...'
-        sys.exit(1)
-
-      print 'Downloading JDK from ' + jdk_url + ' to ' + dest_file
-      jdk_download_fail_msg = " Failed to download JDK: {0}. Please check that Oracle " \
-        "JDK is available at {1}. Also you may specify JDK file " \
-        "location in local filesystem using --jdk-location command " \
-        "line argument.".format("{0}", jdk_url)
-      try:
-        size_command = JDK_DOWNLOAD_SIZE_CMD.format(jdk_url);
-        #Get Header from url,to get file size then
-        retcode, out, err = run_os_command(size_command)
-        if out.find("Content-Length") == -1:
-          err = jdk_download_fail_msg.format("Request header doesn't contain Content-Length")
+      jdk_num = str(JDK_INDEX + 1)
+      jdk_num = get_validated_string_input(
+        "[1] - Oracle JDK 1.7\n[2] - Oracle JDK 1.6\n[3] - Custom JDK\n==============================================================================\nEnter choice (" + jdk_num + "): ",
+        jdk_num,
+        "^[123]$",
+        "Invalid number.",
+        False
+      )
+
+      if jdk_num == CUSTOM_JDK_NUMBER:
+        print_warning_msg("JDK must be installed on all hosts and JAVA_HOME must be valid on all hosts.")
+        print_warning_msg(jcePolicyWarn)
+        args.java_home = get_validated_string_input("Path to JAVA_HOME: ", None, None, None, False, False)
+        if not os.path.exists(args.java_home):
+          err = "Java home path is unavailable. Please put correct path to java home."
           raise FatalException(1, err)
-        start_with = int(out.find("Content-Length") + len("Content-Length") + 2)
-        end_with = out.find("\r\n", start_with)
-        src_size = int(out[start_with:end_with])
-        print 'JDK distribution size is ' + str(src_size) + ' bytes'
-        file_exists = os.path.isfile(dest_file)
-        file_size = -1
-        if file_exists:
-          file_size = os.stat(dest_file).st_size
-        if file_exists and file_size == src_size:
-          print_info_msg("File already exists")
-        else:
-          track_jdk(JDK_LOCAL_FILENAME, jdk_url, dest_file)
-          print 'Successfully downloaded JDK distribution to ' + dest_file
-      except FatalException:
-        raise
-      except Exception, e:
-        err = jdk_download_fail_msg.format(str(e))
-        raise FatalException(1, err)
-      downloaded_size = os.stat(dest_file).st_size
-      if downloaded_size != src_size or downloaded_size < JDK_MIN_FILESIZE:
-        err = 'Size of downloaded JDK distribution file is ' \
-                      + str(downloaded_size) + ' bytes, it is probably \
-                      damaged or incomplete'
+        print "Validating JDK on Ambari Server...done."
+        write_property(JAVA_HOME_PROPERTY, args.java_home)
+        remove_property(JDK_NAME_PROPERTY)
+        remove_property(JCE_NAME_PROPERTY)
+        return 0
+
+      JDK_INDEX = int(jdk_num) -1
+      JDK_FILENAME = JDK_NAMES[JDK_INDEX]
+      JDK_URL_PROPERTY = JDK_URL_PROPERTIES[JDK_INDEX]
+
+      try:
+        jdk_url = properties[JDK_URL_PROPERTY]
+      except (KeyError), e:
+        err = 'Property ' + str(e) + ' is not defined at ' + conf_file
         raise FatalException(1, err)
+      dest_file = resources_dir + os.sep + JDK_FILENAME
+      if os.path.exists(dest_file):
+        print "JDK already exists, using " + dest_file
+      else:
+        ok = get_YN_input("To download the Oracle JDK you must accept the "
+                          "license terms found at "
+                          "http://www.oracle.com/technetwork/java/javase/"
+                          "terms/license/index.html and not accepting will "
+                          "cancel the Ambari Server setup.\nDo you accept the "
+                          "Oracle Binary Code License Agreement [y/n] (y)? ", True)
+        if not ok:
+          print 'Exiting...'
+          sys.exit(1)
+
+        print 'Downloading JDK from ' + jdk_url + ' to ' + dest_file
+        jdk_download_fail_msg = " Failed to download JDK: {0}. Please check that Oracle " \
+          "JDK is available at {1}. Also you may specify JDK file " \
+          "location in local filesystem using --jdk-location command " \
+          "line argument.".format("{0}", jdk_url)
+        try:
+          size_command = JDK_DOWNLOAD_SIZE_CMD.format(jdk_url);
+          #Get Header from url,to get file size then
+          retcode, out, err = run_os_command(size_command)
+          if out.find("Content-Length") == -1:
+            err = jdk_download_fail_msg.format("Request header doesn't contain Content-Length")
+            raise FatalException(1, err)
+          start_with = int(out.find("Content-Length") + len("Content-Length") + 2)
+          end_with = out.find("\r\n", start_with)
+          src_size = int(out[start_with:end_with])
+          print 'JDK distribution size is ' + str(src_size) + ' bytes'
+          file_exists = os.path.isfile(dest_file)
+          file_size = -1
+          if file_exists:
+            file_size = os.stat(dest_file).st_size
+          if file_exists and file_size == src_size:
+            print_info_msg("File already exists")
+          else:
+            track_jdk(JDK_FILENAME, jdk_url, dest_file)
+            print 'Successfully downloaded JDK distribution to ' + dest_file
+        except FatalException:
+          raise
+        except Exception, e:
+          err = jdk_download_fail_msg.format(str(e))
+          raise FatalException(1, err)
+        downloaded_size = os.stat(dest_file).st_size
+        if downloaded_size != src_size or downloaded_size < JDK_MIN_FILESIZE:
+          err = 'Size of downloaded JDK distribution file is ' \
+                        + str(downloaded_size) + ' bytes, it is probably \
+                        damaged or incomplete'
+          raise FatalException(1, err)
 
     try:
        out = install_jdk(dest_file)
-       jdk_version = re.search('Creating (jdk.*)/jre', out).group(1)
+       jdk_version = re.search(JDK_VERSION_REs[JDK_INDEX], out).group(1)
+       if not ambari_setup_with_jdk_location:
+         write_property(JDK_NAME_PROPERTY, JDK_FILENAME)
     except Exception, e:
        print "Installation of JDK has failed: %s\n" % e.message
        file_exists = os.path.isfile(dest_file)
@@ -1764,11 +1830,13 @@ def download_jdk(args):
                    dest_file +" and re-run Ambari Server setup"
              raise FatalException(1, err)
           else:
-             track_jdk(JDK_LOCAL_FILENAME, jdk_url, dest_file)
+             track_jdk(JDK_FILENAME, jdk_url, dest_file)
              print 'Successfully re-downloaded JDK distribution to ' + dest_file
              try:
                  out = install_jdk(dest_file)
-                 jdk_version = re.search('Creating (jdk.*)/jre', out).group(1)
+                 jdk_version = re.search(JDK_VERSION_REs[JDK_INDEX], out).group(1)
+                 if not ambari_setup_with_jdk_location:
+                   write_property(JDK_NAME_PROPERTY, JDK_FILENAME)
              except Exception, e:
                print "Installation of JDK was failed: %s\n" % e.message
                err = "Unable to install JDK. Please remove JDK, file found at "+ \
@@ -1786,7 +1854,8 @@ def download_jdk(args):
         format(JDK_INSTALL_DIR, jdk_version))
 
   try:
-    download_jce_policy(properties, ok)
+    if not ambari_setup_with_jdk_location:
+      download_jce_policy(properties, ok)
   except FatalException as e:
     print "JCE Policy files are required for secure HDP setup. Please ensure " \
             " all hosts have the JCE unlimited strength policy 6, files."
@@ -1798,6 +1867,8 @@ def download_jdk(args):
 
 
 def download_jce_policy(properties, accpeted_bcl):
+  JCE_URL_PROPERTY = JCE_URL_PROPERTIES[JDK_INDEX]
+  JCE_POLICY_FILENAME = JCE_POLICY_FILENAMES[JDK_INDEX]
   try:
     jce_url = properties[JCE_URL_PROPERTY]
     resources_dir = properties[RESOURCES_DIR_PROPERTY]
@@ -1836,6 +1907,7 @@ def download_jce_policy(properties, accpeted_bcl):
         if accpeted_bcl:
           retcode, out, err = run_os_command(jce_download_cmd)
           if retcode == 0:
+            write_property(JCE_NAME_PROPERTY, JCE_POLICY_FILENAME)
             print 'Successfully downloaded JCE Policy archive to ' + dest_file
           else:
             raise FatalException(1, err)
@@ -1850,6 +1922,7 @@ def download_jce_policy(properties, accpeted_bcl):
           if ok:
             retcode, out, err = run_os_command(jce_download_cmd)
             if retcode == 0:
+              write_property(JCE_NAME_PROPERTY, JCE_POLICY_FILENAME)
               print 'Successfully downloaded JCE Policy archive to ' + dest_file
           else:
             raise FatalException(1, None)
@@ -1865,6 +1938,7 @@ def download_jce_policy(properties, accpeted_bcl):
                     damaged or incomplete'
       raise FatalException(1, err)
   else:
+    write_property(JCE_NAME_PROPERTY, JCE_POLICY_FILENAME)
     print "JCE Policy archive already exists, using " + dest_file
 
 class RetCodeException(Exception): pass
@@ -1874,8 +1948,16 @@ def install_jdk(dest_file):
   retcode, out, err = run_os_command(CREATE_JDK_DIR_CMD)
   savedPath = os.getcwd()
   os.chdir(JDK_INSTALL_DIR)
-  retcode, out, err = run_os_command(MAKE_FILE_EXECUTABLE_CMD.format(dest_file))
-  retcode, out, err = run_os_command(dest_file + ' -noregister')
+
+  if dest_file.endswith(".bin"):
+    retcode, out, err = run_os_command(MAKE_FILE_EXECUTABLE_CMD.format(dest_file))
+    retcode, out, err = run_os_command(dest_file + ' -noregister')
+  elif dest_file.endswith(".gz"):
+    retcode, out, err = run_os_command(UNTAR_JDK_ARVHIVE.format(dest_file))
+  else:
+    err = "JDK installation failed.Unknown file mask."
+    raise FatalException(1, err)
+
   os.chdir(savedPath)
   if retcode != 0:
     err = "Installation of JDK returned exit code %s" % retcode

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/1.3.4/hooks/before-START/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.4/hooks/before-START/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/1.3.4/hooks/before-START/scripts/params.py
index f5a90cd..4a15586 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.4/hooks/before-START/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.4/hooks/before-START/scripts/params.py
@@ -24,10 +24,9 @@ import os
 config = Script.get_config()
 
 #java params
-java_home = "/usr/jdk64/jdk1.6.0_31"
 artifact_dir = "/tmp/HDP-artifacts/"
-jdk_bin = "jdk-6u31-linux-x64.bin"
-jce_policy_zip = "jce_policy-6.zip"
+jdk_name = default("/hostLevelParams/jdk_name", None) # None when jdk is already installed by user
+jce_policy_zip = default("/hostLevelParams/jce_name", None) # None when jdk is already installed by user
 jce_location = config['hostLevelParams']['jdk_location']
 jdk_location = config['hostLevelParams']['jdk_location']
 #security params
@@ -124,7 +123,7 @@ else:
   rca_prefix = rca_disabled_prefix
 
 #hadoop-env.sh
-java_home = config['configurations']['global']['java64_home']
+java_home = config['hostLevelParams']['java_home']
 if System.get_instance().platform == "suse":
   jsvc_path = "/usr/lib/bigtop-utils"
 else:

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/1.3.4/hooks/before-START/scripts/shared_initialization.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.4/hooks/before-START/scripts/shared_initialization.py b/ambari-server/src/main/resources/stacks/HDP/1.3.4/hooks/before-START/scripts/shared_initialization.py
index c388e96..6243eca 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.4/hooks/before-START/scripts/shared_initialization.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.4/hooks/before-START/scripts/shared_initialization.py
@@ -27,13 +27,23 @@ def setup_java():
   """
   import params
 
-  jdk_curl_target = format("{artifact_dir}/{jdk_bin}")
+  jdk_curl_target = format("{artifact_dir}/{jdk_name}")
   java_dir = os.path.dirname(params.java_home)
   java_exec = format("{java_home}/bin/java")
-  Execute(format("mkdir -p {artifact_dir} ; curl -kf --retry 10 {jdk_location}/{jdk_bin} -o {jdk_curl_target}"),
+  
+  if not params.jdk_name:
+    return
+  
+  Execute(format("mkdir -p {artifact_dir} ; curl -kf --retry 10 {jdk_location}/{jdk_name} -o {jdk_curl_target}"),
           path = ["/bin","/usr/bin/"],
           not_if = format("test -e {java_exec}"))
-  Execute(format("mkdir -p {java_dir} ; chmod +x {jdk_curl_target}; cd {java_dir} ; echo A | {jdk_curl_target} -noregister > /dev/null 2>&1"),
+
+  if params.jdk_name.endswith(".bin"):
+    install_cmd = format("mkdir -p {java_dir} ; chmod +x {jdk_curl_target}; cd {java_dir} ; echo A | {jdk_curl_target} -noregister > /dev/null 2>&1")
+  elif params.jdk_name.endswith(".gz"):
+    install_cmd = format("mkdir -p {java_dir} ; cd {java_dir} ; tar -xf {jdk_curl_target} > /dev/null 2>&1")
+  
+  Execute(install_cmd,
           path = ["/bin","/usr/bin/"],
           not_if = format("test -e {java_exec}")
   )
@@ -44,13 +54,15 @@ def setup_java():
         not_if =format("test -e {jce_curl_target}"),
         ignore_failures = True
   )
-  security_dir = format("{java_home}/jre/lib/security")
-  extract_cmd = format("rm -f local_policy.jar; rm -f US_export_policy.jar; unzip -o -j -q {jce_curl_target}")
-  Execute(extract_cmd,
-        only_if = format("test -e {security_dir} && test -f {jce_curl_target}"),
-        cwd  = security_dir,
-        path = ['/bin/','/usr/bin']
-  )
+  
+  if params.security_enabled:
+    security_dir = format("{java_home}/jre/lib/security")
+    extract_cmd = format("rm -f local_policy.jar; rm -f US_export_policy.jar; unzip -o -j -q {jce_curl_target}")
+    Execute(extract_cmd,
+          only_if = format("test -e {security_dir} && test -f {jce_curl_target}"),
+          cwd  = security_dir,
+          path = ['/bin/','/usr/bin']
+    )
 
 def setup_hadoop():
   """

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/HBASE/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/HBASE/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/HBASE/package/scripts/params.py
index 6820c19..ca5b171 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/HBASE/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/HBASE/package/scripts/params.py
@@ -37,7 +37,7 @@ user_group = config['configurations']['global']['user_group']
 metric_prop_file_name = "hadoop-metrics.properties" 
 
 # not supporting 32 bit jdk.
-java64_home = config['configurations']['global']['java64_home']
+java64_home = config['hostLevelParams']['java_home']
 
 log_dir = config['configurations']['global']['hbase_log_dir']
 master_heapsize = config['configurations']['global']['hbase_master_heapsize']

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/HIVE/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/HIVE/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/HIVE/package/scripts/params.py
index 38bb517..0cf89be 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/HIVE/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/HIVE/package/scripts/params.py
@@ -94,7 +94,7 @@ start_metastore_path = "/tmp/start_metastore_script"
 
 hive_aux_jars_path = config['configurations']['global']['hive_aux_jars_path']
 hadoop_heapsize = config['configurations']['global']['hadoop_heapsize']
-java64_home = config['configurations']['global']['java64_home']
+java64_home = config['hostLevelParams']['java_home']
 
 ##### MYSQL
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/NAGIOS/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/NAGIOS/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/NAGIOS/package/scripts/params.py
index e915685..0cc6515 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/NAGIOS/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/NAGIOS/package/scripts/params.py
@@ -78,7 +78,7 @@ nn_metrics_property = "FSNamesystemMetrics"
 clientPort = config['configurations']['global']['clientPort'] #ZK 
 
 
-java64_home = config['configurations']['global']['java64_home']
+java64_home = config['hostLevelParams']['java_home']
 security_enabled = config['configurations']['global']['security_enabled']
 
 nagios_keytab_path = default("nagios_keytab_path", "/etc/security/keytabs/nagios.service.keytab")

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/OOZIE/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/OOZIE/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/OOZIE/package/scripts/params.py
index 85e587c..0466ad8 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/OOZIE/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/OOZIE/package/scripts/params.py
@@ -33,7 +33,7 @@ oozie_keytab = config['configurations']['global']['oozie_keytab']
 oracle_driver_jar_name = "ojdbc6.jar"
 java_share_dir = "/usr/share/java"
 
-java_home = config['configurations']['global']['java64_home']
+java_home = config['hostLevelParams']['java_home']
 oozie_metastore_user_name = config['configurations']['oozie-site']['oozie.service.JPAService.jdbc.username']
 oozie_metastore_user_passwd = default("/configurations/oozie-site/oozie.service.JPAService.jdbc.password","")
 oozie_jdbc_connection_url = default("/configurations/oozie-site/oozie.service.JPAService.jdbc.url", "")

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/PIG/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/PIG/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/PIG/package/scripts/params.py
index 9196d80..86e962c 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/PIG/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/PIG/package/scripts/params.py
@@ -32,5 +32,5 @@ smokeuser = config['configurations']['global']['smokeuser']
 user_group = config['configurations']['global']['user_group']
 
 # not supporting 32 bit jdk.
-java64_home = config['configurations']['global']['java64_home']
+java64_home = config['hostLevelParams']['java_home']
 hadoop_home = "/usr"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/ZOOKEEPER/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/ZOOKEEPER/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/ZOOKEEPER/package/scripts/params.py
index 3162cc2..e643c66 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/ZOOKEEPER/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.4/services/ZOOKEEPER/package/scripts/params.py
@@ -49,7 +49,7 @@ zk_primary_name = "zookeeper"
 zk_principal_name = "zookeeper/_HOST@EXAMPLE.COM"
 zk_principal = zk_principal_name.replace('_HOST',hostname)
 
-java64_home = config['configurations']['global']['java64_home']
+java64_home = config['hostLevelParams']['java_home']
 
 zookeeper_hosts = config['clusterHostInfo']['zookeeper_hosts']
 zookeeper_hosts.sort()

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/2.0.8/hooks/before-START/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.8/hooks/before-START/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.0.8/hooks/before-START/scripts/params.py
index a5c5c35..0effa01 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.8/hooks/before-START/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.8/hooks/before-START/scripts/params.py
@@ -24,10 +24,9 @@ import os
 config = Script.get_config()
 
 #java params
-java_home = "/usr/jdk64/jdk1.6.0_31"
 artifact_dir = "/tmp/HDP-artifacts/"
-jdk_bin = "jdk-6u31-linux-x64.bin"
-jce_policy_zip = "jce_policy-6.zip"
+jdk_name = default("/hostLevelParams/jdk_name", None) # None when jdk is already installed by user
+jce_policy_zip = default("/hostLevelParams/jce_name", None) # None when jdk is already installed by user
 jce_location = config['hostLevelParams']['jdk_location']
 jdk_location = config['hostLevelParams']['jdk_location']
 #security params
@@ -124,7 +123,7 @@ else:
   rca_prefix = rca_disabled_prefix
 
 #hadoop-env.sh
-java_home = config['configurations']['global']['java64_home']
+java_home = config['hostLevelParams']['java_home']
 if System.get_instance().platform == "suse":
   jsvc_path = "/usr/lib/bigtop-utils"
 else:

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/2.0.8/hooks/before-START/scripts/shared_initialization.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.8/hooks/before-START/scripts/shared_initialization.py b/ambari-server/src/main/resources/stacks/HDP/2.0.8/hooks/before-START/scripts/shared_initialization.py
index 9de7734..9a1661a 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.8/hooks/before-START/scripts/shared_initialization.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.8/hooks/before-START/scripts/shared_initialization.py
@@ -27,13 +27,23 @@ def setup_java():
   """
   import params
 
-  jdk_curl_target = format("{artifact_dir}/{jdk_bin}")
+  jdk_curl_target = format("{artifact_dir}/{jdk_name}")
   java_dir = os.path.dirname(params.java_home)
   java_exec = format("{java_home}/bin/java")
-  Execute(format("mkdir -p {artifact_dir} ; curl -kf --retry 10 {jdk_location}/{jdk_bin} -o {jdk_curl_target}"),
+  
+  if not params.jdk_name:
+    return
+  
+  Execute(format("mkdir -p {artifact_dir} ; curl -kf --retry 10 {jdk_location}/{jdk_name} -o {jdk_curl_target}"),
           path = ["/bin","/usr/bin/"],
           not_if = format("test -e {java_exec}"))
-  Execute(format("mkdir -p {java_dir} ; chmod +x {jdk_curl_target}; cd {java_dir} ; echo A | {jdk_curl_target} -noregister > /dev/null 2>&1"),
+
+  if params.jdk_name.endswith(".bin"):
+    install_cmd = format("mkdir -p {java_dir} ; chmod +x {jdk_curl_target}; cd {java_dir} ; echo A | {jdk_curl_target} -noregister > /dev/null 2>&1")
+  elif params.jdk_name.endswith(".gz"):
+    install_cmd = format("mkdir -p {java_dir} ; cd {java_dir} ; tar -xf {jdk_curl_target} > /dev/null 2>&1")
+  
+  Execute(install_cmd,
           path = ["/bin","/usr/bin/"],
           not_if = format("test -e {java_exec}")
   )
@@ -44,13 +54,15 @@ def setup_java():
         not_if =format("test -e {jce_curl_target}"),
         ignore_failures = True
   )
-  security_dir = format("{java_home}/jre/lib/security")
-  extract_cmd = format("rm -f local_policy.jar; rm -f US_export_policy.jar; unzip -o -j -q {jce_curl_target}")
-  Execute(extract_cmd,
-        only_if = format("test -e {security_dir} && test -f {jce_curl_target}"),
-        cwd  = security_dir,
-        path = ['/bin/','/usr/bin']
-  )
+  
+  if params.security_enabled:
+    security_dir = format("{java_home}/jre/lib/security")
+    extract_cmd = format("rm -f local_policy.jar; rm -f US_export_policy.jar; unzip -o -j -q {jce_curl_target}")
+    Execute(extract_cmd,
+          only_if = format("test -e {security_dir} && test -f {jce_curl_target}"),
+          cwd  = security_dir,
+          path = ['/bin/','/usr/bin']
+    )
 
 def setup_hadoop():
   """

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/HBASE/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/HBASE/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/HBASE/package/scripts/params.py
index 80400c6..915afea 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/HBASE/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/HBASE/package/scripts/params.py
@@ -37,7 +37,7 @@ user_group = config['configurations']['global']['user_group']
 metric_prop_file_name = "hadoop-metrics2-hbase.properties"
 
 # not supporting 32 bit jdk.
-java64_home = config['configurations']['global']['java64_home']
+java64_home = config['hostLevelParams']['java_home']
 
 log_dir = config['configurations']['global']['hbase_log_dir']
 master_heapsize = config['configurations']['global']['hbase_master_heapsize']

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/HIVE/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/HIVE/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/HIVE/package/scripts/params.py
index 38bb517..0cf89be 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/HIVE/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/HIVE/package/scripts/params.py
@@ -94,7 +94,7 @@ start_metastore_path = "/tmp/start_metastore_script"
 
 hive_aux_jars_path = config['configurations']['global']['hive_aux_jars_path']
 hadoop_heapsize = config['configurations']['global']['hadoop_heapsize']
-java64_home = config['configurations']['global']['java64_home']
+java64_home = config['hostLevelParams']['java_home']
 
 ##### MYSQL
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/NAGIOS/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/NAGIOS/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/NAGIOS/package/scripts/params.py
index 3c3e5ec..bd7135e 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/NAGIOS/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/NAGIOS/package/scripts/params.py
@@ -72,7 +72,7 @@ nn_metrics_property = "FSNamesystem"
 clientPort = config['configurations']['global']['clientPort'] #ZK 
 
 
-java64_home = config['configurations']['global']['java64_home']
+java64_home = config['hostLevelParams']['java_home']
 security_enabled = config['configurations']['global']['security_enabled']
 
 nagios_keytab_path = default("nagios_keytab_path", "/etc/security/keytabs/nagios.service.keytab")

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/OOZIE/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/OOZIE/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/OOZIE/package/scripts/params.py
index 32ffd15..03713a5 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/OOZIE/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/OOZIE/package/scripts/params.py
@@ -33,7 +33,7 @@ oozie_keytab = config['configurations']['global']['oozie_keytab']
 oracle_driver_jar_name = "ojdbc6.jar"
 java_share_dir = "/usr/share/java"
 
-java_home = config['configurations']['global']['java64_home']
+java_home = config['hostLevelParams']['java_home']
 oozie_metastore_user_name = config['configurations']['oozie-site']['oozie.service.JPAService.jdbc.username']
 oozie_metastore_user_passwd = default("/configurations/oozie-site/oozie.service.JPAService.jdbc.password","")
 oozie_jdbc_connection_url = default("/configurations/oozie-site/oozie.service.JPAService.jdbc.url", "")

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/PIG/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/PIG/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/PIG/package/scripts/params.py
index 9196d80..86e962c 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/PIG/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/PIG/package/scripts/params.py
@@ -32,5 +32,5 @@ smokeuser = config['configurations']['global']['smokeuser']
 user_group = config['configurations']['global']['user_group']
 
 # not supporting 32 bit jdk.
-java64_home = config['configurations']['global']['java64_home']
+java64_home = config['hostLevelParams']['java_home']
 hadoop_home = "/usr"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/YARN/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/YARN/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/YARN/package/scripts/params.py
index b5dd926..8f98d77 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/YARN/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/YARN/package/scripts/params.py
@@ -41,7 +41,7 @@ rm_host = config['clusterHostInfo']['rm_host'][0]
 rm_port = config['configurations']['yarn-site']['yarn.resourcemanager.webapp.address'].split(':')[-1]
 rm_https_port = "8090"
 
-java64_home = config['configurations']['global']['java64_home']
+java64_home = config['hostLevelParams']['java_home']
 hadoop_ssl_enabled = default("/configurations/core-site/hadoop.ssl.enabled", False)
 
 hadoop_libexec_dir = '/usr/lib/hadoop/libexec'

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/ZOOKEEPER/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/ZOOKEEPER/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/ZOOKEEPER/package/scripts/params.py
index 3162cc2..e643c66 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/ZOOKEEPER/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.8/services/ZOOKEEPER/package/scripts/params.py
@@ -49,7 +49,7 @@ zk_primary_name = "zookeeper"
 zk_principal_name = "zookeeper/_HOST@EXAMPLE.COM"
 zk_principal = zk_principal_name.replace('_HOST',hostname)
 
-java64_home = config['configurations']['global']['java64_home']
+java64_home = config['hostLevelParams']['java_home']
 
 zookeeper_hosts = config['clusterHostInfo']['zookeeper_hosts']
 zookeeper_hosts.sort()

http://git-wip-us.apache.org/repos/asf/ambari/blob/72d92b88/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index 36fb6df..6daa413 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -1795,13 +1795,15 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch.object(ambari_server, "get_YN_input")
   @patch.object(ambari_server, "run_os_command")
   @patch.object(ambari_server, "write_property")
+  @patch.object(ambari_server, "remove_property")
+  @patch.object(ambari_server, "get_validated_string_input")
   @patch.object(ambari_server, "print_info_msg")
   @patch.object(ambari_server, "get_JAVA_HOME")
   @patch.object(ambari_server, "get_ambari_properties")
   @patch("shutil.copyfile")
   @patch("sys.exit")
   def test_download_jdk(self, exit_mock, copyfile_mock, get_ambari_properties_mock, get_JAVA_HOME_mock, \
-                        print_info_msg_mock, write_property_mock, \
+                        print_info_msg_mock, get_validated_string_input_mock, remove_property_mock, write_property_mock, \
                         run_os_command_mock, get_YN_input_mock, track_jdk_mock,
                         path_existsMock, path_isfileMock, statMock):
     args = MagicMock()
@@ -1817,20 +1819,22 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       # Expected
       self.assertTrue(get_ambari_properties_mock.called)
       pass
-      # Test case: JDK already exists
+    # Test case: JDK already exists
     p = MagicMock()
     get_ambari_properties_mock.return_value = p
     p.__getitem__.return_value = "somewhere"
     get_JAVA_HOME_mock.return_value = True
-    path_existsMock.side_effect = [True,False]
+    get_YN_input_mock.return_value = False
+    path_existsMock.side_effect = [False,False]
     rcode = ambari_server.download_jdk(args)
     self.assertEqual(0, rcode)
     # Test case: java home setup
-    path_existsMock.side_effect = [True,False]
+    path_existsMock.side_effect = [True,False,False]
     get_JAVA_HOME_mock.return_value = False
     rcode = ambari_server.download_jdk(args)
     self.assertEqual(0, rcode)
     self.assertTrue(write_property_mock.called)
+    self.assertTrue(remove_property_mock.call_count == 2)
     # Test case: JDK file does not exist, property not defined
     path_existsMock.side_effect = None
     path_existsMock.return_value = False
@@ -1848,6 +1852,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     p.__getitem__.return_value = "somewhere"
     p.__getitem__.side_effect = None
     path_existsMock.return_value = False
+    get_YN_input_mock.return_value = True
+    get_validated_string_input_mock.return_value = "1"
     run_os_command_mock.return_value = (0, "Wrong out", None)
     try:
       ambari_server.download_jdk(args)
@@ -1875,11 +1881,15 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
 
     # Test case: JDK file does not exist, jdk-location argument passed
     exit_mock.reset_mock()
+    write_property_mock.reset_mock()
+    remove_property_mock.reset_mock()
     get_YN_input_mock.reset_mock()
     get_YN_input_mock.return_value = True
-    args.jdk_location = "/existing/jdk/file"
-    path_existsMock.side_effect = [False, False, True, False, False, False]
+    args.jdk_location = "/existing/jdk/jdk-6u31-linux-x64.bin"
+    path_existsMock.side_effect = [False, True]
     ambari_server.download_jdk(args)
+    self.assertTrue(write_property_mock.call_count == 1)
+    self.assertTrue(remove_property_mock.call_count == 2)
     self.assertTrue(copyfile_mock.called)
 
     copyfile_mock.reset_mock()
@@ -1888,7 +1898,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     p.__getitem__.return_value = "somewhere"
     p.__getitem__.side_effect = None
     args.jdk_location = "/existing/jdk/file"
-    path_existsMock.side_effect = [False, False, True, False, False, False]
+    path_existsMock.side_effect = [False, True]
 
     def copyfile_side_effect(s, d):
       raise Exception("TerribleException")
@@ -1906,19 +1916,22 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     get_ambari_properties_mock.return_value = p
     p.__getitem__.return_value = "somewhere"
     get_JAVA_HOME_mock.return_value = True
-    path_existsMock.return_value = True
+    get_YN_input_mock.return_value = False
+    path_existsMock.side_effect = [False, True]
     with patch.object(ambari_server, "download_jce_policy") as download_jce_policy_mock:
       rcode = ambari_server.download_jdk(args)
-      self.assertTrue(download_jce_policy_mock.called)
+      self.assertFalse(download_jce_policy_mock.called)
 
     # Test case: Update JAVA_HOME location using command: ambari-server setup -j %NEW_LOCATION%
     write_property_mock.reset_mock()
+    remove_property_mock.reset_mock()
     args.java_home = "somewhere"
     path_existsMock.return_value = True
-    path_existsMock.side_effect = [True,False]
+    path_existsMock.side_effect = [True,False,False]
     get_JAVA_HOME_mock.return_value = True
     ambari_server.download_jdk(args)
-    self.assertTrue(write_property_mock.called)
+    self.assertTrue(write_property_mock.call_count == 1)
+    self.assertTrue(remove_property_mock.call_count == 2)
 
     # Test case: Negative test case JAVA_HOME location should not be updated if -j option is supplied and
     # jce_policy file already exists in resources dir.
@@ -1933,6 +1946,27 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     except FatalException as fe:
       # Expected
       self.assertFalse(write_property_mock.called)
+    # Test case: Setup ambari-server first time, Custom JDK selected, JDK exists
+    write_property_mock.reset_mock()
+    remove_property_mock.reset_mock()
+    path_existsMock.side_effect = [False,False,True]
+    get_validated_string_input_mock.return_value = "3"
+    get_JAVA_HOME_mock.return_value = False
+    rcode = ambari_server.download_jdk(args)
+    self.assertEqual(0, rcode)
+    self.assertTrue(write_property_mock.called)
+    self.assertTrue(remove_property_mock.call_count == 2)
+    # Test case: Setup ambari-server first time, Custom JDK selected, JDK not exists
+    write_property_mock.reset_mock()
+    remove_property_mock.reset_mock()
+    path_existsMock.side_effect = [False,False,False]
+    get_validated_string_input_mock.return_value = "3"
+    get_JAVA_HOME_mock.return_value = False
+    try:
+      ambari_server.download_jdk(args)
+      self.fail("Should throw exception")
+    except FatalException as fe:
+      # Expected
       pass