Skip to content

Commit

Permalink
enable maintenance in reset-all
Browse files Browse the repository at this point in the history
  • Loading branch information
munakoiso committed Nov 8, 2024
1 parent 860b0e9 commit a82b7ba
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,20 @@ def _wait_maintenance_disabled(zk, timeout):
logging.info('Success')


def enable_maintenance(zk, timeout, wait_all):
zk.ensure_path(zk.MAINTENANCE_PATH)
zk.noexcept_write(zk.MAINTENANCE_PATH, 'enable', need_lock=False)
if wait_all:
_wait_maintenance_enabled(zk, timeout)


def maintenance(opts, conf):
"""
Enable or disable maintenance mode.
"""
zk = zookeeper.Zookeeper(config=conf, plugins=None)
if opts.mode == 'enable':
zk.ensure_path(zk.MAINTENANCE_PATH)
zk.noexcept_write(zk.MAINTENANCE_PATH, 'enable', need_lock=False)
if opts.wait_all:
_wait_maintenance_enabled(zk, opts.timeout)
enable_maintenance(zk, opts.timeout, opts.wait_all)
elif opts.mode == 'disable':
zk.write(zk.MAINTENANCE_PATH, 'disable', need_lock=False)
if opts.wait_all:
Expand Down Expand Up @@ -189,7 +193,7 @@ def reset_all(opts, conf):
if all_nodes is None:
logging.error("Could not get nodes to reset")
all_nodes = []
nodes_to_delete = [x for x in all_nodes if x != zk.MEMBERS_PATH]
nodes_to_delete = [x for x in all_nodes if x not in (zk.MEMBERS_PATH, zk.MAINTENANCE_PATH)] + [zk.MAINTENANCE_PATH]
if not opts.force:
prompt = f'Nodes to delete: {", ".join(nodes_to_delete)}\n' \
f'This is a potentially dangerous action. Proceed [y/n]?\n'
Expand All @@ -199,10 +203,13 @@ def reset_all(opts, conf):
elif ans != 'y':
print('Incorrect value, please type "y" or "n"')
return
enable_maintenance(zk, opts.timeout, True)
for node in nodes_to_delete:
logging.debug(f'resetting path "{node}"')
if not zk.delete(node, recursive=True):
raise ResetException(f'Could not reset node "{node}" in ZK')
if not zk.delete(zk.MAINTENANCE_PATH, recursive=True):
raise ResetException(f'Could not reset node "{zk.MAINTENANCE_PATH}" in ZK')
logging.debug("ZK structures are reset")


Expand Down

0 comments on commit a82b7ba

Please sign in to comment.