Skip to content

Commit

Permalink
Use constants for repeated suite params DB keys
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewrmshin committed Jun 5, 2019
1 parent e8067b6 commit b7c0f0a
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 28 deletions.
43 changes: 20 additions & 23 deletions cylc/flow/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,7 @@ def command_set_stop_after_point(self, point_string):
stop_point = self.get_standardised_point(point_string)
if self.pool.set_stop_point(stop_point):
self.options.stopcp = str(stop_point)
self.suite_db_mgr.put_suite_params_1(
'stopcp', self.options.stopcp)
self.suite_db_mgr.put_suite_stop_cycle_point(self.options.stopcp)

def command_set_stop_after_clock_time(self, arg):
"""Set stop after clock time.
Expand Down Expand Up @@ -968,50 +967,50 @@ def _load_suite_params(self, row_idx, row):
if row_idx == 0:
LOG.info('LOADING suite parameters')
key, value = row
if key in ['icp', 'initial_point']:
if key in self.suite_db_mgr.KEY_INITIAL_CYCLE_POINT_COMPATS:
if self.options.ignore_icp:
LOG.debug('- initial point = %s (ignored)' % value)
elif self.options.icp is None:
self.options.icp = value
LOG.info('+ initial point = %s' % value)
elif key in ['startcp', 'start_point', 'warm_point']:
elif key in self.suite_db_mgr.KEY_START_CYCLE_POINT_COMPATS:
# 'warm_point' for back compat <= 7.6.X
if self.options.ignore_startcp:
LOG.debug('- start point = %s (ignored)' % value)
elif self.options.startcp is None:
self.options.startcp = value
LOG.info('+ start point = %s' % value)
elif key in ['fcp', 'final_point']:
elif key in self.suite_db_mgr.KEY_FINAL_CYCLE_POINT_COMPATS:
if self.options.ignore_fcp:
LOG.debug('- override final point = %s (ignored)' % value)
elif self.options.fcp is None:
self.options.fcp = value
LOG.info('+ override final point = %s' % value)
elif key == 'stopcp':
elif key == self.suite_db_mgr.KEY_STOP_CYCLE_POINT:
if self.options.ignore_stopcp:
LOG.debug('- stop point = %s (ignored)' % value)
elif self.options.stopcp is None:
self.options.stopcp = value
LOG.info('+ stop point = %s' % value)
elif key == 'uuid_str':
elif key == self.suite_db_mgr.KEY_UUID_STR:
self.uuid_str.value = value
LOG.info('+ suite UUID = %s', value)
elif key == 'is_held':
elif key == self.suite_db_mgr.KEY_HOLD:
if self.options.hold_start is None:
self.options.hold_start = bool(value)
LOG.info('+ hold suite = %s', bool(value))
elif key == 'holdcp':
elif key == self.suite_db_mgr.KEY_HOLD_CYCLE_POINT:
if self.options.holdcp is None:
self.options.holdcp = value
LOG.info('+ hold point = %s', value)
elif key == 'no_auto_shutdown':
elif key == self.suite_db_mgr.KEY_NO_AUTO_SHUTDOWN:
value = bool(int(value))
if self.options.no_auto_shutdown is None:
self.options.no_auto_shutdown = value
LOG.info('+ no auto shutdown = %s', value)
else:
LOG.debug('- no auto shutdown = %s (ignored)', value)
elif key == 'stop_clock_time':
elif key == self.suite_db_mgr.KEY_STOP_CLOCK_TIME:
value = int(value)
if time() <= value:
self.stop_clock_time = value
Expand All @@ -1021,7 +1020,7 @@ def _load_suite_params(self, row_idx, row):
'- stop clock time = %d (%s) (ignored)',
value,
time2str(value))
elif key == 'stop_task':
elif key == self.suite_db_mgr.KEY_STOP_TASK:
self.stop_task = value
LOG.info('+ stop task = %s', value)

Expand Down Expand Up @@ -1732,8 +1731,7 @@ def set_stop_clock(self, unix_time):
time2str(unix_time),
unix_time)
self.stop_clock_time = unix_time
self.suite_db_mgr.put_suite_params_1(
'stop_clock_time', self.stop_clock_time)
self.suite_db_mgr.put_suite_stop_clock_time(self.stop_clock_time)

def set_stop_task(self, task_id):
"""Set stop after a task."""
Expand All @@ -1742,8 +1740,7 @@ def set_stop_task(self, task_id):
task_id = self.get_standardised_taskid(task_id)
LOG.info("Setting stop task: " + task_id)
self.stop_task = task_id
self.suite_db_mgr.put_suite_params_1(
'stop_task', self.stop_task)
self.suite_db_mgr.put_suite_stop_task(self.stop_task)
else:
LOG.warning("Requested stop task name does not exist: %s" % name)

Expand All @@ -1756,7 +1753,7 @@ def stop_clock_done(self):
LOG.info("Wall clock stop time reached: %s", time2str(
self.stop_clock_time))
self.stop_clock_time = None
self.suite_db_mgr.delete_suite_params("stop_clock_time")
self.suite_db_mgr.delete_suite_stop_clock_time()
return True
else:
LOG.debug(
Expand All @@ -1768,7 +1765,7 @@ def stop_task_done(self):
if self.stop_task and self.pool.task_succeeded(self.stop_task):
LOG.info("Stop task %s finished" % self.stop_task)
self.stop_task = None
self.suite_db_mgr.delete_suite_params("stop_task")
self.suite_db_mgr.delete_suite_stop_task()
return True
else:
return False
Expand Down Expand Up @@ -1796,27 +1793,27 @@ def check_auto_shutdown(self):
if can_shutdown and self.pool.stop_point:
self.options.stopcp = None
self.pool.stop_point = None
self.suite_db_mgr.delete_suite_params("stopcp")
self.suite_db_mgr.delete_suite_stop_cycle_point()
return can_shutdown

def hold_suite(self, point=None):
"""Hold all tasks in suite."""
if point is None:
self.pool.hold_all_tasks()
self.task_events_mgr.pflag = True
self.suite_db_mgr.put_suite_params_1("is_held", 1)
self.suite_db_mgr.put_suite_hold()
else:
LOG.info("Setting suite hold cycle point: " + str(point))
LOG.info("Setting suite hold cycle point: %s", point)
self.pool.set_hold_point(point)
self.suite_db_mgr.put_suite_params_1("holdcp", str(point))
self.suite_db_mgr.put_suite_hold_cycle_point(point)

def release_suite(self):
"""Release (un-hold) all tasks in suite."""
if self.pool.is_held:
LOG.info("RELEASE: new tasks will be queued when ready")
self.pool.set_hold_point(None)
self.pool.release_all_tasks()
self.suite_db_mgr.delete_suite_params("is_held", "holdcp")
self.suite_db_mgr.delete_suite_hold()

def paused(self):
"""Is the suite paused?"""
Expand Down
69 changes: 65 additions & 4 deletions cylc/flow/suite_db_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@
class SuiteDatabaseManager(object):
"""Manage the suite runtime private and public databases."""

KEY_INITIAL_CYCLE_POINT = 'icp'
KEY_INITIAL_CYCLE_POINT_COMPATS = (
KEY_INITIAL_CYCLE_POINT, 'initial_point')
KEY_START_CYCLE_POINT = 'startcp'
KEY_START_CYCLE_POINT_COMPATS = (
KEY_START_CYCLE_POINT, 'start_point', 'warm_point')
KEY_FINAL_CYCLE_POINT = 'fcp'
KEY_FINAL_CYCLE_POINT_COMPATS = (KEY_FINAL_CYCLE_POINT, 'final_point')
KEY_STOP_CYCLE_POINT = 'stopcp'
KEY_UUID_STR = 'uuid_str'
KEY_HOLD = 'is_held'
KEY_HOLD_CYCLE_POINT = 'holdcp'
KEY_NO_AUTO_SHUTDOWN = 'no_auto_shutdown'
KEY_STOP_CLOCK_TIME = 'stop_clock_time'
KEY_STOP_TASK = 'stop_task'

TABLE_BROADCAST_EVENTS = CylcSuiteDAO.TABLE_BROADCAST_EVENTS
TABLE_BROADCAST_STATES = CylcSuiteDAO.TABLE_BROADCAST_STATES
TABLE_CHECKPOINT_ID = CylcSuiteDAO.TABLE_CHECKPOINT_ID
Expand Down Expand Up @@ -118,6 +134,22 @@ def delete_suite_params(self, *keys):
for key in keys:
self.db_deletes_map[self.TABLE_SUITE_PARAMS].append({'key': key})

def delete_suite_hold(self):
"""Delete suite hold flag and hold cycle point."""
self.delete_suite_params(self.KEY_HOLD, self.KEY_HOLD_CYCLE_POINT)

def delete_suite_stop_clock_time(self):
"""Delete suite stop clock time from suite_params table."""
self.delete_suite_params(self.KEY_STOP_CLOCK_TIME)

def delete_suite_stop_cycle_point(self):
"""Delete suite stop cycle point from suite_params table."""
self.delete_suite_params(self.KEY_STOP_CYCLE_POINT)

def delete_suite_stop_task(self):
"""Delete suite stop task from suite_params table."""
self.delete_suite_params(self.KEY_STOP_TASK)

def get_pri_dao(self):
"""Return the primary DAO."""
return CylcSuiteDAO(self.pri_path)
Expand Down Expand Up @@ -262,7 +294,7 @@ def put_suite_params(self, schd):
else:
final_point_str = str(schd.config.final_point)
self.db_inserts_map[self.TABLE_SUITE_PARAMS].extend([
{"key": "uuid_str", "value": str(schd.uuid_str)},
{"key": self.KEY_UUID_STR, "value": str(schd.uuid_str)},
{"key": "run_mode", "value": schd.config.run_mode()},
{"key": "cylc_version", "value": CYLC_VERSION},
{"key": "UTC_mode", "value": get_utc_mode()},
Expand All @@ -273,13 +305,22 @@ def put_suite_params(self, schd):
"value": schd.config.cfg['cylc']['cycle point format']})
if schd.pool.is_held:
self.db_inserts_map[self.TABLE_SUITE_PARAMS].append({
"key": "is_held", "value": 1})
for key in ('icp', 'fcp', 'startcp', 'stopcp', 'no_auto_shutdown'):
"key": self.KEY_HOLD, "value": 1})
for key in (
self.KEY_INITIAL_CYCLE_POINT,
self.KEY_FINAL_CYCLE_POINT,
self.KEY_START_CYCLE_POINT,
self.KEY_STOP_CYCLE_POINT,
):
value = getattr(schd.options, key, None)
if value is not None:
self.db_inserts_map[self.TABLE_SUITE_PARAMS].append({
"key": key, "value": value})
for key in ('stop_clock_time', 'stop_task'):
if schd.options.no_auto_shutdown is not None:
self.db_inserts_map[self.TABLE_SUITE_PARAMS].append({
"key": self.KEY_NO_AUTO_SHUTDOWN,
"value": int(schd.options.no_auto_shutdown)})
for key in (self.KEY_STOP_CLOCK_TIME, self.KEY_STOP_TASK):
value = getattr(schd, key, None)
if value is not None:
self.db_inserts_map[self.TABLE_SUITE_PARAMS].append({
Expand All @@ -290,6 +331,26 @@ def put_suite_params_1(self, key, value):
self.db_inserts_map[self.TABLE_SUITE_PARAMS].append(
{"key": key, "value": value})

def put_suite_hold(self):
"""Put suite hold flag to suite_params table."""
self.put_suite_params_1(self.KEY_HOLD, 1)

def put_suite_hold_cycle_point(self, value):
"""Put suite hold cycle point to suite_params table."""
self.put_suite_params_1(self.KEY_HOLD_CYCLE_POINT, str(value))

def put_suite_stop_clock_time(self, value):
"""Put suite stop clock time to suite_params table."""
self.put_suite_params_1(self.KEY_STOP_CLOCK_TIME, value)

def put_suite_stop_cycle_point(self, value):
"""Put suite stop cycle point to suite_params table."""
self.put_suite_params_1(self.KEY_STOP_CYCLE_POINT, value)

def put_suite_stop_task(self, value):
"""Put suite stop task to suite_params table."""
self.put_suite_params_1(self.KEY_STOP_TASK, value)

def put_suite_template_vars(self, template_vars):
"""Put template_vars in runtime database.
Expand Down
2 changes: 1 addition & 1 deletion tests/restart/47-no-auto-stop.t
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cmp_ok 'noautoshutdown.out' <<<'no_auto_shutdown|1'
cut -d ' ' -f 4- "${SUITE_RUN_DIR}/log/suite/log" >'log.edited'
contains_ok 'log.edited' <<__LOG__
+ no auto shutdown = True
Suite shutting down - 'Abort on suite inactivity is set'
Suite shutting down - Abort on suite inactivity is set
__LOG__
cmp_ok 'taskpool.out' <<'__OUT__'
1|t_i01|1|succeeded|
Expand Down

0 comments on commit b7c0f0a

Please sign in to comment.