ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vbrodets...@apache.org
Subject ambari git commit: AMBARI-12101. Ambari : upgrading from 2.0.0 to 2.0.1 wipes out the added service folder on the stack.(vbrodetskyi)
Date Tue, 30 Jun 2015 12:13:42 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 abbda5b4b -> b86c5758f


AMBARI-12101. Ambari : upgrading from 2.0.0 to 2.0.1 wipes out the added service folder on
the stack.(vbrodetskyi)


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

Branch: refs/heads/branch-2.1
Commit: b86c5758f8912e066444fe9567eb8585b45524bc
Parents: abbda5b
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Tue Jun 30 15:12:48 2015 +0300
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Tue Jun 30 15:12:48 2015 +0300

----------------------------------------------------------------------
 .../main/python/ambari_server/serverUpgrade.py  | 49 ++++++++++++++++++++
 1 file changed, 49 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b86c5758/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 f446fd6..abd9e84 100644
--- a/ambari-server/src/main/python/ambari_server/serverUpgrade.py
+++ b/ambari-server/src/main/python/ambari_server/serverUpgrade.py
@@ -24,6 +24,8 @@ import sys
 import shutil
 import base64
 import urllib2
+import re
+import glob
 
 from ambari_commons.exceptions import FatalException
 from ambari_commons.logging_utils import print_info_msg, print_warning_msg, print_error_msg,
get_verbose
@@ -292,6 +294,7 @@ def upgrade(args):
     err = AMBARI_KRB_JAAS_LOGIN_FILE + ' file can\'t be updated. Exiting'
     raise FatalException(retcode, err)
 
+  restore_custom_services()
   try:
     update_database_name_property(upgrade=True)
   except FatalException:
@@ -408,6 +411,52 @@ def set_current(options):
   sys.stdout.write('\n')
   sys.stdout.flush()
 
+#
+# Search for folders with custom services and restore them from backup
+#
+def restore_custom_services():
+  properties = get_ambari_properties()
+  if properties == -1:
+    err = "Error getting ambari properties"
+    print_error_msg(err)
+    raise FatalException(-1, err)
+
+  try:
+    resources_dir = properties[RESOURCES_DIR_PROPERTY]
+  except (KeyError), e:
+    conf_file = properties.fileName
+    err = 'Property ' + str(e) + ' is not defined at ' + conf_file
+    print_error_msg(err)
+    raise FatalException(1, err)
+
+  services = glob.glob(os.path.join(resources_dir,"stacks","*","*","services","*"))
+  managed_services = []
+  for service in services:
+    if os.path.isdir(service) and not os.path.basename(service) in managed_services:
+      managed_services.append(os.path.basename(service))
+  # add deprecated managed services
+  managed_services.extend(["NAGIOS","GANGLIA","MAPREDUCE"])
+
+  stack_backup_dirs = glob.glob(os.path.join(resources_dir,"stacks_*.old"))
+  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","*"))
+
+    regex = re.compile(r'/stacks.*old/')
+    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)
+      # if services dir does not exists, we do not manage this stack
+      if not os.path.exists(current_base_service_dir):
+        continue
+
+      # process dirs only
+      if os.path.isdir(backup_service):
+        service_name = os.path.basename(backup_service)
+        if not service_name in managed_services:
+          shutil.copytree(backup_service, os.path.join(current_base_service_dir,service_name))
+
+
 
 class SetCurrentVersionOptions:
   def __init__(self, options):


Mime
View raw message