Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions cli/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ def unpack_comp(p_app, p_old_ver, p_new_ver):
tar = tarfile.open(fileobj=tarFileObj, mode="r")

new_comp_dir = p_app + "_new"
old_comp_dir = p_app + "_old"

try:
tar.extractall(path=new_comp_dir)
Expand Down Expand Up @@ -687,39 +688,44 @@ def unpack_comp(p_app, p_old_ver, p_new_ver):
os.mkdir(backup_target_dir)
if not os.path.exists(os.path.join(backup_target_dir, p_app)):
my_logger.info("backing up the old version of %s " % p_app)
util.copytree(
f"{os.path.join(MY_HOME, p_app)} {os.path.join(backup_target_dir, p_app)}"
)
util.copytree(f"{os.path.join(MY_HOME, p_app)} {os.path.join(backup_target_dir, p_app)}")

msg = p_app + " upgrade staged for completion."
my_logger.info(msg)
if p_app in ('hub'):
copy2(os.path.join(MY_HOME, MY_CMD), backup_target_dir)
os.rename(new_comp_dir, "hub_new")
## run the update_hub script in the _new directory
upd_hub_cmd = sys.executable + " hub_new" + os.sep + "hub" + os.sep + "scripts" + os.sep + "update_hub.py "
os.system(upd_hub_cmd + p_old_ver + " " + p_new_ver)
else:
my_logger.info("renaming the existing folder %s" % p_app)
os.rename(p_app, p_app+"_old")
my_logger.info("copying the new files to folder %s" % p_app)

my_logger.info("copying the new files over folder %s" % p_app)

util.copytree(
f"{os.path.join(MY_HOME, new_comp_dir, p_app, '.')} {os.path.join(MY_HOME, p_app)}"
)

my_logger.info(p_app + " upgrade completed.")
util.copytree(f"{os.path.join(MY_HOME, new_comp_dir, p_app)} {os.path.join(MY_HOME, p_app)}")

my_logger.info("Restoring the conf and extension files if any")
util.restore_conf_ext_files(os.path.join(MY_HOME, p_app+"_old"), os.path.join(MY_HOME, p_app))
my_logger.info(p_app + " upgrade completed.")
except Exception as upgrade_exception:
error_msg = (
"Error while upgrading the " + p_app + " : " + str(upgrade_exception)
)
error_msg = "Error while upgrading the " + p_app + " : " + str(upgrade_exception)
my_logger.error(error_msg)
my_logger.error(traceback.format_exc())
if isJSON:
json_dict = {}
json_dict["state"] = "error"
json_dict["component"] = p_app
json_dict["msg"] = str(upgrade_exception)
json_dict['state'] = "error"
json_dict['component'] = p_app
json_dict['msg'] = str(upgrade_exception)
error_msg = json.dumps([json_dict])
if not isSILENT:
print(error_msg)
return_value = 1
return_value = 1

if os.path.exists(os.path.join(MY_HOME, new_comp_dir)):
util.delete_dir(os.path.join(MY_HOME, new_comp_dir))
if os.path.exists(os.path.join(MY_HOME, old_comp_dir)):
util.delete_dir(os.path.join(MY_HOME, old_comp_dir))

return return_value

Expand Down Expand Up @@ -1879,4 +1885,4 @@ def cli_lock():
print("ERROR: The TUNE command must have 1 parameter (pgver).")
exit_cleanly(1)

util.exit_cleanly(0,connL)
util.exit_cleanly(0,connL)
44 changes: 37 additions & 7 deletions cli/scripts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3795,6 +3795,35 @@ def process_time(amount, units):
return buf


# recursively check and restore all env / extension files during upgrade
def recursively_copy_old_files(dcmp, diff_files=[], ignore=None):
for name in dcmp.left_only:
if ignore and name in ignore:
continue
try:
source_file = os.path.join(dcmp.left, name)
shutil.move(source_file, dcmp.right)
except Exception as e:
my_logger.error(
"Failed to restore the file %s due to %s"
% (os.path.join(dcmp.right, name), str(e))
)
my_logger.error(traceback.format_exc())
diff_files.append([name, dcmp.left, dcmp.right])
for sub_dcmp in dcmp.subdirs.values():
allfiles = diff_files
recursively_copy_old_files(sub_dcmp, allfiles)
return diff_files


# restore any extensions or env/conf files during upgrade
def restore_conf_ext_files(src, dst, ignore=None):
if os.path.isdir(dst):
diff = filecmp.dircmp(src, dst)
extension_files_list = recursively_copy_old_files(diff, ignore=ignore)
return True


def exit_cleanly(p_rc, conn=None):
if conn:
try:
Expand Down Expand Up @@ -4303,13 +4332,6 @@ def process_nodes(group, group_name):
node
)

BASE_DIR = "cluster"
# MAINLINE ################################################################
cL = sqlite3.connect(MY_LITE, check_same_thread=False)
REPO = get_value("GLOBAL", "REPO")



def check_directory_status(directory):
"""
Check if the directory exists and is writable.
Expand All @@ -4326,3 +4348,11 @@ def check_directory_status(directory):
else:
message = f"Directory {directory} does not exist."
return {"exists": False, "writable": False, "message": message}

BASE_DIR = "cluster"
# MAINLINE ################################################################
cL = sqlite3.connect(MY_LITE, check_same_thread=False)
REPO = get_value("GLOBAL", "REPO")