def really_start_cron(args, options): api, job_key, config_file = LiveJobDisambiguator.disambiguate_args_or_die( args, options, make_client_factory()) config = get_job_config(job_key.to_path(), config_file, options) if config_file else None resp = api.start_cronjob(job_key, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name)
def really_killall(args, options): """Helper for testing purposes: make it easier to mock out the actual kill process, while testing hooks in the command dispatch process. """ maybe_disable_hooks(options) job_key = AuroraJobKey.from_path(args[0]) config_file = args[1] if len(args) > 1 else None # the config for hooks new_cmd = ["job", "killall", args[0]] if config_file is not None: new_cmd.append("--config=%s" % config_file) if options.open_browser: new_cmd.append("--open-browser") if options.batch_size is not None: new_cmd.append("--batch-size=%s" % options.batch_size) if options.max_total_failures is not None: new_cmd.append("--max-total-failures=%s" % options.max_total_failures) v1_deprecation_warning("killall", new_cmd) config = get_job_config(job_key.to_path(), config_file, options) if config_file else None api = make_client(job_key.cluster) if options.batch_size is not None: kill_in_batches(api, job_key, None, options.batch_size, options.max_failures_option) else: resp = api.kill_job(job_key, None, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name) wait_kill_tasks(api.scheduler_proxy, job_key)
def really_kill(args, options): if options.shards is None: print( 'Shards option is required for kill; use killall to kill all shards', file=sys.stderr) exit(1) api, job_key, config_file = LiveJobDisambiguator.disambiguate_args_or_die( args, options, make_client_factory()) instance_key = str(job_key) if options.shards is not None: instance_key = "%s/%s" % (instance_key, ",".join( map(str, options.shards))) new_cmd = ["job", "kill", instance_key] if config_file is not None: new_cmd.append("--config=%s" % config_file) if options.open_browser: new_cmd.append("--open-browser") if options.batch_size is not None: new_cmd.append("--batch-size=%s" % options.batch_size) if options.max_total_failures is not None: new_cmd.append("--max-total-failures=%s" % options.max_total_failures) v1_deprecation_warning("kill", new_cmd) config = get_job_config(job_key.to_path(), config_file, options) if config_file else None if options.batch_size is not None: kill_in_batches(api, job_key, options.shards, options.batch_size, options.max_failures_option) else: resp = api.kill_job(job_key, options.shards, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name) wait_kill_tasks(api.scheduler_proxy, job_key, options.shards)
def really_kill(args, options): if options.shards is None: print('Shards option is required for kill; use killall to kill all shards', file=sys.stderr) exit(1) api, job_key, config_file = LiveJobDisambiguator.disambiguate_args_or_die( args, options, make_client_factory()) instance_key = str(job_key) if options.shards is not None: instance_key = "%s/%s" % (instance_key, ",".join(map(str, options.shards))) new_cmd = ["job", "kill", instance_key] if config_file is not None: new_cmd.append("--config=%s" % config_file) if options.open_browser: new_cmd.append("--open-browser") if options.batch_size is not None: new_cmd.append("--batch-size=%s" % options.batch_size) if options.max_total_failures is not None: new_cmd.append("--max-total-failures=%s" % options.max_total_failures) v1_deprecation_warning("kill", new_cmd) config = get_job_config(job_key.to_path(), config_file, options) if config_file else None if options.batch_size is not None: kill_in_batches(api, job_key, options.shards, options.batch_size, options.max_failures_option) else: resp = api.kill_job(job_key, options.shards, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name) wait_kill_tasks(api.scheduler_proxy, job_key, options.shards)
def restart(args, options): """usage: restart cluster/role/env/job [--shards=SHARDS] [--batch_size=INT] [--updater_health_check_interval_seconds=SECONDS] [--max_per_shard_failures=INT] [--max_total_failures=INT] [--restart_threshold=INT] [--watch_secs=SECONDS] Performs a rolling restart of shards within a job. Restarts are fully controlled client-side, so aborting halts the restart. """ api, job_key, config_file = LiveJobDisambiguator.disambiguate_args_or_die( args, options, make_client_factory()) config = get_job_config(job_key.to_path(), config_file, options) if config_file else None updater_config = UpdaterConfig( options.batch_size, options.restart_threshold, options.watch_secs, options.max_per_shard_failures, options.max_total_failures) resp = api.restart(job_key, options.shards, updater_config, options.health_check_interval_seconds, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name)
def killall(args, options): """usage: killall cluster/role/env/job Kills all tasks in a running job, blocking until all specified tasks have been terminated. """ job_key = AuroraJobKey.from_path(args[0]) config_file = args[1] if len(args) > 1 else None # the config for hooks config = get_job_config(job_key.to_path(), config_file, options) if config_file else None api = make_client(job_key.cluster) resp = api.kill_job(job_key, None, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name)
def start_cron(args, options): """usage: start_cron cluster/role/env/job Invokes a cron job immediately, out of its normal cron cycle. This does not affect the cron cycle in any way. """ api, job_key, config_file = LiveJobDisambiguator.disambiguate_args_or_die( args, options, make_client_factory()) config = get_job_config(job_key.to_path(), config_file, options) if config_file else None resp = api.start_cronjob(job_key, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name)
def really_create(job_spec, config_file, options): try: config = get_job_config(job_spec, config_file, options) except ValueError as v: print("Error: %s" % v) sys.exit(1) api = make_client(config.cluster()) resp = api.create_job(config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, config.role(), config.environment(), config.name()) if options.wait_until == 'RUNNING': JobMonitor(api.scheduler_proxy, config.job_key()).wait_until(JobMonitor.running_or_finished) elif options.wait_until == 'FINISHED': JobMonitor(api.scheduler_proxy, config.job_key()).wait_until(JobMonitor.terminal)
def kill(args, options): """usage: kill cluster/role/env/job Kills a running job, blocking until all tasks have terminated. Default behaviour is to kill all shards in the job, but the kill can be limited to specific shards with the --shards option """ api, job_key, config_file = LiveJobDisambiguator.disambiguate_args_or_die( args, options, make_client_factory()) options = app.get_options() config = get_job_config(job_key.to_path(), config_file, options) if config_file else None resp = api.kill_job(job_key, options.shards, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name)
def kill(args, options): """usage: kill --shards=shardspec cluster/role/env/job Kills a group of tasks in a running job, blocking until all specified tasks have terminated. """ if options.shards is None: print('Shards option is required for kill; use killall to kill all shards', file=sys.stderr) exit(1) api, job_key, config_file = LiveJobDisambiguator.disambiguate_args_or_die( args, options, make_client_factory()) options = app.get_options() config = get_job_config(job_key.to_path(), config_file, options) if config_file else None resp = api.kill_job(job_key, options.shards, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name)
def killall(args, options): """usage: killall cluster/role/env/job Kills all tasks in a running job, blocking until all specified tasks have been terminated. """ maybe_disable_hooks(options) job_key = AuroraJobKey.from_path(args[0]) config_file = args[1] if len(args) > 1 else None # the config for hooks config = get_job_config(job_key.to_path(), config_file, options) if config_file else None api = make_client(job_key.cluster) if options.batch_size is not None: kill_in_batches(api, job_key, None, options.batch_size, options.max_failures_option) else: resp = api.kill_job(job_key, None, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name) wait_kill_tasks(api.scheduler_proxy, job_key)
def really_restart(args, options): if options.max_total_failures < 0: print("max_total_failures option must be >0, but you specified %s" % options.max_total_failures, file=sys.stderr) exit(1) maybe_disable_hooks(options) api, job_key, config_file = LiveJobDisambiguator.disambiguate_args_or_die( args, options, make_client_factory()) config = get_job_config(job_key.to_path(), config_file, options) if config_file else None updater_config = UpdaterConfig( options.batch_size, options.restart_threshold, options.watch_secs, options.max_per_shard_failures, options.max_total_failures) resp = api.restart(job_key, options.shards, updater_config, options.health_check_interval_seconds, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name)
def create(job_spec, config_file): """usage: create cluster/role/env/job config Creates a job based on a configuration file. """ options = app.get_options() try: config = get_job_config(job_spec, config_file, options) except ValueError as v: print("Error: %s" % v) sys.exit(1) api = make_client(config.cluster()) monitor = JobMonitor(api, config.role(), config.environment(), config.name()) resp = api.create_job(config) check_and_log_response(resp) handle_open(api.scheduler.scheduler().url, config.role(), config.environment(), config.name()) if options.wait_until == 'RUNNING': monitor.wait_until(monitor.running_or_finished) elif options.wait_until == 'FINISHED': monitor.wait_until(monitor.terminal)
def kill(args, options): """usage: kill --shards=shardspec cluster/role/env/job Kills a group of tasks in a running job, blocking until all specified tasks have terminated. """ CoreCommandHook.run_hooks("kill", options, *args) maybe_disable_hooks(options) if options.shards is None: print('Shards option is required for kill; use killall to kill all shards', file=sys.stderr) exit(1) api, job_key, config_file = LiveJobDisambiguator.disambiguate_args_or_die( args, options, make_client_factory()) options = app.get_options() config = get_job_config(job_key.to_path(), config_file, options) if config_file else None if options.batch_size is not None: kill_in_batches(api, job_key, options.shards, options.batch_size, options.max_failures_option) else: resp = api.kill_job(job_key, options.shards, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name) wait_kill_tasks(api.scheduler_proxy, job_key, options.shards)
def really_restart(args, options): if options.max_total_failures < 0: print("max_total_failures option must be >0, but you specified %s" % options.max_total_failures, file=sys.stderr) exit(1) maybe_disable_hooks(options) api, job_key, config_file = LiveJobDisambiguator.disambiguate_args_or_die( args, options, make_client_factory()) config = get_job_config(job_key.to_path(), config_file, options) if config_file else None updater_config = UpdaterConfig(options.batch_size, options.restart_threshold, options.watch_secs, options.max_per_shard_failures, options.max_total_failures) resp = api.restart(job_key, options.shards, updater_config, options.health_check_interval_seconds, config=config) check_and_log_response(resp) handle_open(api.scheduler_proxy.scheduler_client().url, job_key.role, job_key.env, job_key.name)