Skip to content

Commit

Permalink
replace platform_from_name with get_platform where args!=None
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Aug 19, 2020
1 parent 2a3349e commit 9daf8aa
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cylc/flow/job_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
TASK_STATUS_RUNNING, TASK_STATUS_SUCCEEDED,
TASK_STATUS_FAILED)
from cylc.flow.data_messages_pb2 import PbJob, JDeltas
from cylc.flow.platforms import platform_from_name, get_host_from_platform
from cylc.flow.platforms import get_platform, get_host_from_platform

JOB_STATUSES_ALL = [
TASK_STATUS_READY,
Expand Down Expand Up @@ -139,7 +139,7 @@ def insert_db_job(self, row_idx, row):
j_owner = self.schd.owner
if platform_name:
j_host = get_host_from_platform(
platform_from_name(platform_name)
get_platform(platform_name)
)
else:
j_host = self.schd.host
Expand Down
17 changes: 11 additions & 6 deletions cylc/flow/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,27 @@ def get_platform(task_conf=None):
method decides whether to get platform from name, or Cylc7 config items.
Args:
task_conf (dict or dict-like such as OrderedDictWithDefaults):
A configuration for a task.
task_conf (str, dict or dict-like such as OrderedDictWithDefaults):
If str this is assumed to be the platform name, otherwise this
should be a configuration for a task.
Returns:
platform:
Actually it returns either platform_from_name() or
Actually it returns either get_platform() or
platform_from_job_info(), but to the user these look the same.
Todo: Implement the above.
"""
if task_conf == None
return platform_from_name()
if task_conf == None:
return get_platform_from_name()
elif type(task_conf) is str:
return get_platform_from_name(task_conf)
else:
return get_platform_from_name(task_conf['platform'])



def platform_from_name(platform_name=None, platforms=None):
def get_platform_from_name(platform_name=None, platforms=None):
"""
Find out which job platform to use given a list of possible platforms and
a task platform string.
Expand Down
6 changes: 3 additions & 3 deletions cylc/flow/scripts/cylc_cat_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
from cylc.flow.task_job_logs import (
JOB_LOG_OUT, JOB_LOG_ERR, JOB_LOG_OPTS, NN, JOB_LOG_ACTIVITY)
from cylc.flow.terminal import cli_function
from cylc.flow.platforms import platform_from_name, get_host_from_platform
from cylc.flow.platforms import get_platform, get_host_from_platform


# Immortal tail-follow processes on job hosts can be cleaned up by killing
Expand Down Expand Up @@ -354,7 +354,7 @@ def main(parser, options, *args, color=False):
raise UserInputError(
"max rotation %d" % (len(logs) - 1))
tail_tmpl = os.path.expandvars(
platform_from_name()["tail command template"]
get_platform()["tail command template"]
)
out = view_log(logpath, mode, tail_tmpl, color=color)
if out == 1:
Expand Down Expand Up @@ -389,7 +389,7 @@ def main(parser, options, *args, color=False):
pass
platform_name, batch_sys_name, live_job_id = get_task_job_attrs(
suite_name, point, task, options.submit_num)
platform = platform_from_name(platform_name)
platform = get_platform(platform_name)
batchview_cmd = None
if live_job_id is not None:
# Job is currently running. Get special batch system log view
Expand Down
4 changes: 2 additions & 2 deletions cylc/flow/scripts/cylc_check_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from cylc.flow.cylc_subproc import procopen, PIPE, DEVNULL
from cylc.flow import __version__ as CYLC_VERSION
from cylc.flow.config import SuiteConfig
from cylc.flow.platforms import platform_from_name
from cylc.flow.platforms import get_platform
from cylc.flow.remote import construct_platform_ssh_cmd
from cylc.flow.suite_files import parse_suite_arg
from cylc.flow.templatevars import load_template_vars
Expand Down Expand Up @@ -88,7 +88,7 @@ def main(_, options, *args):
# get the cylc version on each platform
versions = {}
for platform_name in sorted(platforms):
platform = platform_from_name(platform_name)
platform = get_platform(platform_name)
cmd = construct_platform_ssh_cmd(['version'], platform)
if verbose:
print(cmd)
Expand Down
4 changes: 2 additions & 2 deletions cylc/flow/task_events_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from cylc.flow.pathutil import (
get_remote_suite_run_job_dir,
get_suite_run_job_dir)
from cylc.flow.platforms import platform_from_name, get_host_from_platform
from cylc.flow.platforms import get_platform, get_host_from_platform
from cylc.flow.subprocctx import SubProcContext
from cylc.flow.task_action_timer import TaskActionTimer
from cylc.flow.task_job_logs import (
Expand Down Expand Up @@ -619,7 +619,7 @@ def _get_events_conf(self, itask, key, default=None):

def _process_job_logs_retrieval(self, schd_ctx, ctx, id_keys):
"""Process retrieval of task job logs from remote user@host."""
platform = platform_from_name(ctx.platform_n)
platform = get_platform(ctx.platform_n)
ssh_str = str(platform["ssh command"])
rsync_str = str(platform["retrieve job logs command"])

Expand Down
6 changes: 3 additions & 3 deletions cylc/flow/task_job_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from cylc.flow.task_outputs import (
TASK_OUTPUT_SUBMITTED, TASK_OUTPUT_STARTED, TASK_OUTPUT_SUCCEEDED,
TASK_OUTPUT_FAILED)
from cylc.flow.platforms import platform_from_name, get_host_from_platform
from cylc.flow.platforms import get_platform, get_host_from_platform
from cylc.flow.task_remote_mgr import (
REMOTE_INIT_FAILED, TaskRemoteMgr)
from cylc.flow.task_state import (
Expand Down Expand Up @@ -671,7 +671,7 @@ def _run_job_cmd(self, cmd_key, suite, itasks, callback):

# Go through each list of itasks and carry out commands as required.
for platform_n, itasks in sorted(auth_itasks.items()):
platform = platform_from_name(platform_n)
platform = get_platform(platform_n)
if is_remote_platform(platform):
remote_mode = True
cmd = [cmd_key]
Expand Down Expand Up @@ -801,7 +801,7 @@ def _prep_submit_task_job(self, suite, itask, check_syntax=True):
# Determine task host settings now, just before job submission,
# because dynamic host selection may be used.
try:
platform = platform_from_name(rtconfig['platform'])
platform = get_platform(rtconfig)
except PlatformLookupError as exc:
# Submit number not yet incremented
itask.submit_num += 1
Expand Down
4 changes: 2 additions & 2 deletions cylc/flow/task_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
TASK_STATUS_WAITING
)
from cylc.flow.wallclock import get_current_time_string
from cylc.flow.platforms import platform_from_name
from cylc.flow.platforms import get_platform


class FlowLabelMgr:
Expand Down Expand Up @@ -382,7 +382,7 @@ def load_db_task_pool_for_restart(self, row_idx, row):
TASK_STATUS_RUNNING
):
# update the task proxy with user@host
itask.platform = platform_from_name(platform_name)
itask.platform = get_platform(platform_name)

if time_submit:
itask.set_summary_time('submitted', time_submit)
Expand Down
6 changes: 3 additions & 3 deletions cylc/flow/task_remote_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
get_contact_file)
from cylc.flow.task_remote_cmd import (
FILE_BASE_UUID, REMOTE_INIT_DONE, REMOTE_INIT_NOT_REQUIRED)
from cylc.flow.platforms import platform_from_name, get_host_from_platform
from cylc.flow.platforms import get_platform, get_host_from_platform
from cylc.flow.remote import construct_platform_ssh_cmd


Expand Down Expand Up @@ -156,7 +156,7 @@ def remote_init(self, platform_name, curve_auth, client_pub_key_dir):
"""
# get the platform from the platform_name
platform = platform_from_name(platform_name)
platform = get_platform(platform_name)

# If task is running locally we can skip the rest of this function
if self.single_task_mode or not is_remote_platform(platform):
Expand Down Expand Up @@ -239,7 +239,7 @@ def remote_tidy(self):
# Issue all SSH commands in parallel
procs = {}
for platform, init_with_contact in self.remote_init_map.items():
platform = platform_from_name(platform)
platform = get_platform(platform)
host = get_host_from_platform(platform)
owner = platform['owner']
if init_with_contact != REMOTE_INIT_DONE:
Expand Down

0 comments on commit 9daf8aa

Please sign in to comment.