You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2017/05/12 14:36:42 UTC

[03/26] ambari git commit: AMBARI-20937. Ambari Upgrade to 2.5 fails due to custom service; rpm upgrade does not preserve the custom service directory.(vbrodetskyi)

AMBARI-20937. Ambari Upgrade to 2.5 fails due to custom service; rpm upgrade does not preserve the custom service directory.(vbrodetskyi)


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

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: c12c320f81de6cfed34b5d913384fc3851b71f4a
Parents: 506b847
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Wed May 10 20:55:26 2017 +0300
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Wed May 10 20:55:26 2017 +0300

----------------------------------------------------------------------
 .../main/python/ambari_server/serverUpgrade.py  | 31 ++++++++++++++++----
 1 file changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c12c320f/ambari-server/src/main/python/ambari_server/serverUpgrade.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverUpgrade.py b/ambari-server/src/main/python/ambari_server/serverUpgrade.py
index 6f17900..160c91d 100644
--- a/ambari-server/src/main/python/ambari_server/serverUpgrade.py
+++ b/ambari-server/src/main/python/ambari_server/serverUpgrade.py
@@ -522,7 +522,28 @@ def restore_custom_services():
     print_error_msg(err)
     raise FatalException(1, err)
 
-  services = glob.glob(os.path.join(resources_dir,"stacks","*","*","services","*"))
+  stack_services_search_path = os.path.join("stacks","*","*","services","*")
+  stack_old_dir_name = "stacks_*.old"
+  stack_backup_services_search_path = os.path.join("*","*","services","*")
+  stack_old_dir_mask = r'/stacks.*old/'
+  stack_base_service_dir = '/stacks/'
+
+  find_and_copy_custom_services(resources_dir, stack_services_search_path, stack_old_dir_name,
+                                stack_backup_services_search_path, stack_old_dir_mask, stack_base_service_dir)
+
+  common_services_search_path = os.path.join("common-services","*")
+  common_old_dir_name = "common-services_*.old"
+  common_backup_services_search_path = "*"
+  common_old_dir_mask = r'/common-services.*old'
+  common_base_service_dir = '/common-services/'
+
+  find_and_copy_custom_services(resources_dir, common_services_search_path, common_old_dir_name,
+                                common_backup_services_search_path, common_old_dir_mask, common_base_service_dir)
+
+
+def find_and_copy_custom_services(resources_dir, services_search_path, old_dir_name, backup_services_search_path,
+                                    old_dir_mask, base_service_dir):
+  services = glob.glob(os.path.join(resources_dir, services_search_path))
   managed_services = []
   for service in services:
     if os.path.isdir(service) and not os.path.basename(service) in managed_services:
@@ -530,15 +551,15 @@ def restore_custom_services():
   # add deprecated managed services
   managed_services.extend(["NAGIOS","GANGLIA","MAPREDUCE","WEBHCAT"])
 
-  stack_backup_dirs = glob.glob(os.path.join(resources_dir,"stacks_*.old"))
+  stack_backup_dirs = glob.glob(os.path.join(resources_dir, old_dir_name))
   if stack_backup_dirs:
     last_backup_dir = max(stack_backup_dirs, key=os.path.getctime)
-    backup_services = glob.glob(os.path.join(last_backup_dir,"*","*","services","*"))
+    backup_services = glob.glob(os.path.join(last_backup_dir, backup_services_search_path))
 
-    regex = re.compile(r'/stacks.*old/')
+    regex = re.compile(old_dir_mask)
     for backup_service in backup_services:
       backup_base_service_dir = os.path.dirname(backup_service)
-      current_base_service_dir = regex.sub('/stacks/', backup_base_service_dir)
+      current_base_service_dir = regex.sub(base_service_dir, backup_base_service_dir)
       # if services dir does not exists, we do not manage this stack
       if not os.path.exists(current_base_service_dir):
         continue