|
@@ -23,6 +23,7 @@ Ambari Agent
|
|
|
import os
|
|
|
import subprocess
|
|
|
import socket
|
|
|
+import getpass
|
|
|
|
|
|
from resource_management.libraries.functions import packages_analyzer
|
|
|
from ambari_commons import os_utils
|
|
@@ -31,6 +32,8 @@ from ambari_commons.inet_utils import download_file
|
|
|
from resource_management import Script, Execute, format
|
|
|
from ambari_agent.HostInfo import HostInfo
|
|
|
from ambari_agent.HostCheckReportFileHandler import HostCheckReportFileHandler
|
|
|
+from resource_management.core.resources import Directory, File
|
|
|
+from ambari_commons.constants import AMBARI_SUDO_BINARY
|
|
|
|
|
|
CHECK_JAVA_HOME = "java_home_check"
|
|
|
CHECK_DB_CONNECTION = "db_connection_check"
|
|
@@ -170,14 +173,14 @@ class CheckHost(Script):
|
|
|
|
|
|
def execute_java_home_available_check(self, config):
|
|
|
print "Java home check started."
|
|
|
- java64_home = config['commandParams']['java_home']
|
|
|
+ java_home = config['commandParams']['java_home']
|
|
|
|
|
|
- print "Java home to check: " + java64_home
|
|
|
+ print "Java home to check: " + java_home
|
|
|
java_bin = "java"
|
|
|
if OSCheck.is_windows_family():
|
|
|
java_bin = "java.exe"
|
|
|
|
|
|
- if not os.path.isfile(os.path.join(java64_home, "bin", java_bin)):
|
|
|
+ if not os.path.isfile(os.path.join(java_home, "bin", java_bin)):
|
|
|
print "Java home doesn't exist!"
|
|
|
java_home_check_structured_output = {"exit_code" : 1, "message": "Java home doesn't exist!"}
|
|
|
else:
|
|
@@ -195,7 +198,7 @@ class CheckHost(Script):
|
|
|
ambari_server_hostname = config['commandParams']['ambari_server_host']
|
|
|
check_db_connection_jar_name = "DBConnectionVerification.jar"
|
|
|
jdk_location = config['commandParams']['jdk_location']
|
|
|
- java64_home = config['commandParams']['java_home']
|
|
|
+ java_home = config['commandParams']['java_home']
|
|
|
db_name = config['commandParams']['db_name']
|
|
|
|
|
|
if db_name == DB_MYSQL:
|
|
@@ -229,7 +232,7 @@ class CheckHost(Script):
|
|
|
java_bin = "java.exe"
|
|
|
class_path_delimiter = ";"
|
|
|
|
|
|
- java_exec = os.path.join(java64_home, "bin",java_bin)
|
|
|
+ java_exec = os.path.join(java_home, "bin",java_bin)
|
|
|
|
|
|
if ('jdk_name' not in config['commandParams'] or config['commandParams']['jdk_name'] == None \
|
|
|
or config['commandParams']['jdk_name'] == '') and not os.path.isfile(java_exec):
|
|
@@ -245,7 +248,7 @@ class CheckHost(Script):
|
|
|
jdk_name = config['commandParams']['jdk_name']
|
|
|
jdk_url = "{0}/{1}".format(jdk_location, jdk_name)
|
|
|
jdk_download_target = os.path.join(agent_cache_dir, jdk_name)
|
|
|
- java_dir = os.path.dirname(java64_home)
|
|
|
+ java_dir = os.path.dirname(java_home)
|
|
|
try:
|
|
|
download_file(jdk_url, jdk_download_target)
|
|
|
except Exception, e:
|
|
@@ -255,26 +258,38 @@ class CheckHost(Script):
|
|
|
db_connection_check_structured_output = {"exit_code" : 1, "message": message}
|
|
|
return db_connection_check_structured_output
|
|
|
|
|
|
- if jdk_name.endswith(".bin"):
|
|
|
- install_cmd = format("mkdir -p {java_dir} ; chmod +x {jdk_download_target}; cd {java_dir} ; echo A | " \
|
|
|
- "{jdk_curl_target} -noregister > /dev/null 2>&1")
|
|
|
- install_path = ["/bin","/usr/bin/"]
|
|
|
- elif jdk_name.endswith(".gz"):
|
|
|
- install_cmd = format("mkdir -p {java_dir} ; cd {java_dir} ; tar -xf {jdk_download_target} > /dev/null 2>&1")
|
|
|
- install_path = ["/bin","/usr/bin/"]
|
|
|
- elif jdk_name.endswith(".exe"):
|
|
|
+ if jdk_name.endswith(".exe"):
|
|
|
install_cmd = "{0} /s INSTALLDIR={1} STATIC=1 WEB_JAVA=0 /L \\var\\log\\ambari-agent".format(
|
|
|
- os_utils.quote_path(jdk_download_target), os_utils.quote_path(java64_home),
|
|
|
+ os_utils.quote_path(jdk_download_target), os_utils.quote_path(java_home),
|
|
|
)
|
|
|
install_path = [java_dir]
|
|
|
-
|
|
|
- try:
|
|
|
- Execute(install_cmd, path = install_path)
|
|
|
- except Exception, e:
|
|
|
- message = "Error installing java.\n" + str(e)
|
|
|
- print message
|
|
|
- db_connection_check_structured_output = {"exit_code" : 1, "message": message}
|
|
|
- return db_connection_check_structured_output
|
|
|
+ try:
|
|
|
+ Execute(install_cmd, path = install_path)
|
|
|
+ except Exception, e:
|
|
|
+ message = "Error installing java.\n" + str(e)
|
|
|
+ print message
|
|
|
+ db_connection_check_structured_output = {"exit_code" : 1, "message": message}
|
|
|
+ return db_connection_check_structured_output
|
|
|
+ else:
|
|
|
+ tmp_java_dir = format("{tmp_dir}/jdk")
|
|
|
+ sudo = AMBARI_SUDO_BINARY
|
|
|
+ if jdk_name.endswith(".bin"):
|
|
|
+ chmod_cmd = ("chmod", "+x", jdk_download_target)
|
|
|
+ install_cmd = format("mkdir -p {tmp_java_dir} && cd {tmp_java_dir} && echo A | {jdk_download_target} -noregister && {sudo} cp -rp {tmp_java_dir}/* {java_dir}")
|
|
|
+ elif jdk_name.endswith(".gz"):
|
|
|
+ chmod_cmd = ("chmod","a+x", java_dir)
|
|
|
+ install_cmd = format("mkdir -p {tmp_java_dir} && cd {tmp_java_dir} && tar -xf {jdk_download_target} && {sudo} cp -rp {tmp_java_dir}/* {java_dir}")
|
|
|
+ try:
|
|
|
+ Directory(java_dir)
|
|
|
+ Execute(chmod_cmd, not_if = format("test -e {java_exec}"), sudo = True)
|
|
|
+ Execute(install_cmd, not_if = format("test -e {java_exec}"))
|
|
|
+ File(format("{java_home}/bin/java"), mode=0755, cd_access="a")
|
|
|
+ Execute(("chown","-R", getpass.getuser(), java_home), sudo = True)
|
|
|
+ except Exception, e:
|
|
|
+ message = "Error installing java.\n" + str(e)
|
|
|
+ print message
|
|
|
+ db_connection_check_structured_output = {"exit_code" : 1, "message": message}
|
|
|
+ return db_connection_check_structured_output
|
|
|
|
|
|
# download DBConnectionVerification.jar from ambari-server resources
|
|
|
try:
|