ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [47/50] [abbrv] ambari git commit: AMBARI-21167. mpack install fails when using https links.(vbrodetskyi)
Date Mon, 12 Jun 2017 16:45:54 GMT
AMBARI-21167. mpack install fails when using https links.(vbrodetskyi)


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

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: c7b77436477117050103b35d1e579d02a096d341
Parents: 219f223
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Mon Jun 12 14:05:12 2017 +0300
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Mon Jun 12 14:05:12 2017 +0300

----------------------------------------------------------------------
 .../main/python/ambari_commons/inet_utils.py    | 32 ++++++++++++++++++++
 .../main/python/ambari_server/setupMpacks.py    |  4 +--
 2 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c7b77436/ambari-common/src/main/python/ambari_commons/inet_utils.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/inet_utils.py b/ambari-common/src/main/python/ambari_commons/inet_utils.py
index 22eaaf5..5fd3e88 100644
--- a/ambari-common/src/main/python/ambari_commons/inet_utils.py
+++ b/ambari-common/src/main/python/ambari_commons/inet_utils.py
@@ -23,10 +23,18 @@ import time
 import sys
 import urllib2
 import socket
+from ambari_commons import OSCheck
 from functools import wraps
 
 from exceptions import FatalException, NonFatalException, TimeoutError
 
+if OSCheck.is_windows_family():
+  from ambari_commons.os_windows import os_run_os_command
+else:
+  # MacOS not supported
+  from ambari_commons.os_linux import os_run_os_command
+  pass
+
 from logging_utils import *
 from os_check import OSCheck
 
@@ -59,6 +67,30 @@ def download_file(link, destination, chunk_size=16 * 1024, progress_func
= None)
   force_download_file(link, destination, chunk_size, progress_func = progress_func)
 
 
+def download_file_anyway(link, destination, chunk_size=16 * 1024, progress_func = None):
+  print_info_msg("Trying to download {0} to {1} with python lib [urllib2].".format(link,
destination))
+  if os.path.exists(destination):
+    print_warning_msg("File {0} already exists, assuming it was downloaded before".format(destination))
+    return
+  try:
+    force_download_file(link, destination, chunk_size, progress_func = progress_func)
+  except:
+    print_error_msg("Download {0} with python lib [urllib2] failed with error: {1}".format(link,
str(sys.exc_info())))
+
+  if not os.path.exists(destination):
+    print "Trying to download {0} to {1} with [curl] command.".format(link, destination)
+    #print_info_msg("Trying to download {0} to {1} with [curl] command.".format(link, destination))
+    curl_command = "curl --fail -k -o %s %s" % (destination, link)
+    retcode, out, err = os_run_os_command(curl_command)
+    if retcode != 0:
+      print_error_msg("Download file {0} with [curl] command failed with error: {1}".format(link,
out + err))
+
+
+  if not os.path.exists(destination):
+    print_error_msg("Unable to download file {0}!".format(link))
+    print "ERROR: unable to donwload file %s!" % (link)
+
+
 def download_progress(file_name, downloaded_size, blockSize, totalSize):
   percent = int(downloaded_size * 100 / totalSize)
   status = "\r" + file_name

http://git-wip-us.apache.org/repos/asf/ambari/blob/c7b77436/ambari-server/src/main/python/ambari_server/setupMpacks.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/setupMpacks.py b/ambari-server/src/main/python/ambari_server/setupMpacks.py
index 625e428..6f232f4 100755
--- a/ambari-server/src/main/python/ambari_server/setupMpacks.py
+++ b/ambari-server/src/main/python/ambari_server/setupMpacks.py
@@ -27,7 +27,7 @@ import logging
 from ambari_server.serverClassPath import ServerClassPath
 
 from ambari_commons.exceptions import FatalException
-from ambari_commons.inet_utils import download_file
+from ambari_commons.inet_utils import download_file, download_file_anyway
 from ambari_commons.logging_utils import print_info_msg, print_error_msg, print_warning_msg
 from ambari_commons.os_utils import copy_file, run_os_command, change_owner, set_file_permissions
 from ambari_server.serverConfiguration import get_ambari_properties, get_ambari_version,
get_stack_location, \
@@ -137,7 +137,7 @@ def download_mpack(mpack_path):
     copy_file(mpack_path, tmp_archive_path)
   else:
     # remote path
-    download_file(mpack_path, tmp_archive_path)
+    download_file_anyway(mpack_path, tmp_archive_path)
   return tmp_archive_path
 
 def expand_mpack(archive_path):


Mime
View raw message