You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vb...@apache.org on 2017/06/12 11:00:45 UTC

ambari git commit: AMBARI-21167. mpack install fails when using https links.(vbrodetskyi)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 4b87ad4ea -> e1ca8d7ca


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/e1ca8d7c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e1ca8d7c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e1ca8d7c

Branch: refs/heads/branch-2.5
Commit: e1ca8d7ca0b3a4b3c65e17a51cc72dd7d36ec11a
Parents: 4b87ad4
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Mon Jun 12 13:55:15 2017 +0300
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Mon Jun 12 13:55:15 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/e1ca8d7c/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 66f6544..0da7f32 100644
--- a/ambari-common/src/main/python/ambari_commons/inet_utils.py
+++ b/ambari-common/src/main/python/ambari_commons/inet_utils.py
@@ -22,10 +22,18 @@ import os
 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
 
@@ -58,6 +66,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/e1ca8d7c/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 917dd9c..6f048d1 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):