def list_tasks(pattern): ltask = [] prefix = pattern suffix = '' if prefix.endswith('*'): prefix = prefix[:-1] suffix = '*' p = has_ability(flask.g, '', prefix) if p is False: abort(make_response(jsonify(message="insufficient credentials for " "list tasks starting with %s" % prefix[0:2]), 403)) elif p is not True: prefix = p for task_key in task.scan_iter(redis, prefix + suffix): task_id = task.id(task_key) info = task.info( redis, taskfile_dir, task_id, ["launched_time", "alloc_resource", "alloc_lgpu", "resource", "content", "status", "message", "type", "iterations", "priority"]) if info["content"] is not None and info["content"] != "": content = json.loads(info["content"]) info["image"] = content['docker']['image'] del info['content'] else: info["image"] = '-' info['task_id'] = task_id ltask.append(info) return flask.jsonify(ltask)
def list_tasks(pattern): """ Goal: return tasks list based on prefix/pattern Arguments: pattern: if not empty, the first two characters will be used to search the entity. """ ltask = [] prefix = "*" if pattern == '-*' else pattern suffix = '' if prefix.endswith('*'): prefix = prefix[:-1] suffix = '*' task_where_clauses = [] if has_ability(flask.g, '', ''): # super admin so no control on the prefix of searching criteria task_where_clauses.append(prefix) else: search_entity_expression = to_regex_format(prefix[:2]) # empty == all entities search_user_expression = prefix[2:5] search_remaining_expression = prefix[5:] filtered_entities = [ent for ent in flask.g.entities if is_regex_matched(ent, search_entity_expression)] for entity in filtered_entities: if has_ability(flask.g, 'train', entity): task_where_clauses.append(entity + search_user_expression + search_remaining_expression) else: continue if not task_where_clauses: abort(make_response(jsonify(message="insufficient credentials for tasks %s" % pattern), 403)) for clause in task_where_clauses: for task_key in task.scan_iter(redis, clause + suffix): task_id = task.id(task_key) info = task.info( redis, taskfile_dir, task_id, ["launched_time", "alloc_resource", "alloc_lgpu", "alloc_lcpu", "resource", "content", "status", "message", "type", "iterations", "priority"]) if info["alloc_lgpu"]: info["alloc_lgpu"] = info["alloc_lgpu"].split(",") if info["alloc_lcpu"]: info["alloc_lcpu"] = info["alloc_lcpu"].split(",") info["image"] = '-' info["model"] = '-' if info["content"]: content = json.loads(info["content"]) info["image"] = content["docker"]["image"] + ':' + content["docker"]["tag"] j = 0 while j < len(content["docker"]["command"]) - 1: if content["docker"]["command"][j] == "-m" or content["docker"]["command"][j] == "--model": info["model"] = content["docker"]["command"][j+1] break j = j+1 del info['content'] info['task_id'] = task_id ltask.append(info) return flask.jsonify(ltask)
def status(task_id): fields = flask.request.args.get('fields', None) if fields is not None and fields != '': fields = fields.split(',') else: fields = None response = task.info(redis, taskfile_dir, task_id, fields) return flask.jsonify(response)
def terminate(task_id): with redis.acquire_lock(task_id): current_status = task.info(redis, task_id, "status") if current_status is None: flask.abort(flask.make_response(flask.jsonify(message="task %s unknown" % task_id), 404)) elif current_status == "stopped": return flask.jsonify(message="%s already stopped" % task_id) phase = flask.request.args.get('phase') task.terminate(redis, task_id, phase=phase) return flask.jsonify(message="terminating %s" % task_id)
def list_tasks(pattern): ltask = [] for task_key in task.scan_iter(redis, pattern): task_id = task.id(task_key) info = task.info(redis, task_id, ["queued_time", "service", "content", "status", "message"]) content = json.loads(info["content"]) info["image"] = content['docker']['image'] del info['content'] info['task_id'] = task_id ltask.append(info) return flask.jsonify(ltask)
def status(task_id): fields = flask.request.args.get('fields', None) if fields is not None and fields != '': fields = fields.split(',') else: fields = None response = task.info(redis, taskfile_dir, task_id, fields) if response.get("alloc_lgpu"): response["alloc_lgpu"] = response["alloc_lgpu"].split(",") if response.get("alloc_lcpu"): response["alloc_lcpu"] = response["alloc_lcpu"].split(",") return flask.jsonify(response)
def terminate(task_id): with redis.acquire_lock(task_id): current_status = task.info(redis, taskfile_dir, task_id, "status") if current_status is None: abort(flask.make_response(flask.jsonify(message="task %s unknown" % task_id), 404)) elif current_status == "stopped": return flask.jsonify(message="%s already stopped" % task_id) phase = flask.request.args.get('phase') res = post_function('GET/task/terminate', task_id, phase) if res: task.terminate(redis, task_id, phase="publish_error") return flask.jsonify(message="problem while posting model: %s" % res) task.terminate(redis, task_id, phase=phase) return flask.jsonify(message="terminating %s" % task_id)
def list_tasks(pattern): ltask = [] for task_key in task.scan_iter(redis, pattern): task_id = task.id(task_key) info = task.info(redis, task_id, [ "queued_time", "alloc_resource", "alloc_lgpu", "resource", "content", "status", "message", "type", "iterations", "priority" ]) if info["content"] is not None and info["content"] != "": content = json.loads(info["content"]) info["image"] = content['docker']['image'] del info['content'] else: info["image"] = '-' info['task_id'] = task_id ltask.append(info) return flask.jsonify(ltask)
def list_tasks(pattern): ltask = [] prefix = pattern suffix = '' if prefix.endswith('*'): prefix = prefix[:-1] suffix = '*' p = has_ability(flask.g, '', prefix) if p is False: abort( make_response( jsonify(message="insufficient credentials for " "list tasks starting with %s" % prefix[0:2]), 403)) elif p is not True: prefix = p for task_key in task.scan_iter(redis, prefix + suffix): task_id = task.id(task_key) info = task.info(redis, taskfile_dir, task_id, [ "launched_time", "alloc_resource", "alloc_lgpu", "alloc_lcpu", "resource", "content", "status", "message", "type", "iterations", "priority" ]) if info["alloc_lgpu"]: info["alloc_lgpu"] = info["alloc_lgpu"].split(",") if info["alloc_lcpu"]: info["alloc_lcpu"] = info["alloc_lcpu"].split(",") info["image"] = '-' info["model"] = '-' if info["content"]: content = json.loads(info["content"]) info["image"] = content["docker"]["image"] + ':' + content[ "docker"]["tag"] j = 0 while j < len(content["docker"]["command"]) - 1: if content["docker"]["command"][j] == "-m" or content[ "docker"]["command"][j] == "--model": info["model"] = content["docker"]["command"][j + 1] break j = j + 1 del info['content'] info['task_id'] = task_id ltask.append(info) return flask.jsonify(ltask)
def status(task_id): if not task.exists(redis, task_id): flask.abort(flask.make_response(flask.jsonify(message="task %s unknown" % task_id), 404)) response = task.info(redis, task_id, []) return flask.jsonify(response)
def status(task_id): response = task.info(redis, task_id, []) return flask.jsonify(response)