def test__get_problem_path(): tar_gz_url = "https://github.com/mesos-magellan/traveling-sailor/" \ "archive/0.1.0.tar.gz" package = get_package(tar_gz_url) assert os.path.split(package.problem_path)[-1] == \ 'traveling-sailor-0.1.0' package.remove()
def run_task(): try: print "Running task %s" % task.task_id.value update = mesos_pb2.TaskStatus() update.task_id.value = task.task_id.value update.state = mesos_pb2.TASK_RUNNING update.data = "task running" driver.sendStatusUpdate(update) print task.data task_data = json.loads(task.data) uid = task_data["uid"] problem_name = task_data["name"] task_command = task_data["command"] problem_data = task_data["problem_data"] problem_data_str = json.dumps(problem_data) package = get_package(problem_name) sys.path.append(package.problem_path) pccls_module = import_module("problem") PCCls = getattr(pccls_module, "Problem") pcp = ProblemClassPath("problem", "Problem") if task_command == "divisions": task_divisions = task_data["divisions"] res = list(PCCls.divide(divisions=task_divisions, problem_data=problem_data)) res_data = {"divisions": res} elif task_command == "anneal": minutes_per_division = task_data["minutes_per_division"] sstates = task_data["sstates"] solutions = group_runner((uid, pcp, sstates, minutes_per_division, problem_data_str, None)) winner = sorted((solution for solution in solutions), key=lambda s: s.energy)[0] res_data = {"best_location": winner.state, "fitness_score": winner.energy} else: raise ValueError("Invalid task_command {}".format(task_command)) update = mesos_pb2.TaskStatus() update.task_id.value = task.task_id.value update.state = mesos_pb2.TASK_FINISHED res_dict = dict(uid=uid) res_dict.update(res_data) update.data = json.dumps(res_dict) driver.sendStatusUpdate(update) except: stacktrace = "".join(traceback.format_exception(*sys.exc_info())) sys.stderr.write(stacktrace + "\n") update = mesos_pb2.TaskStatus() update.task_id.value = task.task_id.value update.state = mesos_pb2.TASK_FAILED res_dict = {"error": stacktrace} update.data = json.dumps(res_dict) driver.sendStatusUpdate(update)
def run_task(): try: print "Running task %s" % task.task_id.value update = mesos_pb2.TaskStatus() update.task_id.value = task.task_id.value update.state = mesos_pb2.TASK_RUNNING update.data = 'task running' driver.sendStatusUpdate(update) print task.data task_data = json.loads(task.data) uid = task_data['uid'] problem_name = task_data['name'] task_command = task_data['command'] problem_data = task_data['problem_data'] problem_data_str = json.dumps(problem_data) package = get_package(problem_name) sys.path.append(package.problem_path) pccls_module = import_module("problem") PCCls = getattr(pccls_module, "Problem") pcp = ProblemClassPath("problem", "Problem") if task_command == 'divisions': task_divisions = task_data['divisions'] res = list(PCCls.divide( divisions=task_divisions, problem_data=problem_data )) res_data = { "divisions": res } elif task_command == 'anneal': minutes_per_division = task_data['minutes_per_division'] sstates = task_data['sstates'] solutions = group_runner(( uid, pcp, sstates, minutes_per_division, problem_data_str, None)) winner = sorted( (solution for solution in solutions), key=lambda s: s.energy )[0] res_data = { "best_location": winner.state, "fitness_score": winner.energy } else: raise ValueError("Invalid task_command {}" .format(task_command)) update = mesos_pb2.TaskStatus() update.task_id.value = task.task_id.value update.state = mesos_pb2.TASK_FINISHED res_dict = dict(uid=uid) res_dict.update(res_data) update.data = json.dumps(res_dict) driver.sendStatusUpdate(update) except: stacktrace = "".join( traceback.format_exception(*sys.exc_info()) ) sys.stderr.write(stacktrace+'\n') update = mesos_pb2.TaskStatus() update.task_id.value = task.task_id.value update.state = mesos_pb2.TASK_FAILED res_dict = {"error": stacktrace} update.data = json.dumps(res_dict) driver.sendStatusUpdate(update)