def thread_test_EM_running(task_type): """this is the implementation for testing new execution manager """ if task_type == "false": with open( os.path.join(os.path.dirname(__file__), '../../tests/sample_output/input_wrong.json'), 'r') as f: json_data = json.load(f) job = Job.from_json(json_data) job.job_id = "thisisafalseinputcmdtaskjob6" task = job.tasks[0] task.task_id = "thisisafalseinputcmdtask" else: with open( os.path.join(os.path.dirname(__file__), '../../tests/sample_output/input.json'), 'r') as f: json_data = json.load(f) job = Job.from_json(json_data) job.job_id = "thisisatrueinputcmd_job6" task = job.tasks[0] task.task_id = "thisisatrueinputcmd_task" file_dict = {} folder_path = os.path.join("/tmp/Felucca", f"{task.task_id}") if not os.path.exists(folder_path): os.makedirs(folder_path) for input_flag, content in json_data["Tasks"][0]["Files"].items(): filename = json_data["Tasks"][0]["Input_File_Args"][ input_flag] #oo.exe file_path = os.path.join("/tmp/Felucca", f"{task.task_id}/{filename}") with open(file_path, "wb") as f: byte_stream = base64.b64decode(content.encode('utf-8')) f.write(byte_stream) #this is the simulation for RM changing the task.files from task.files = {"-f":exe_str } to task.files = {"-f": path } file_dict[filename] = file_path print(f"file_path: {file_path}") task.files = file_dict ExecutionManager().submit_task(task)
def save_new_job_and_tasks(self, new_job_dict): """Turn the newly submitted job with its tasks from dict to objects and save them The input files will be saved to a temporary directory named by task_id Args: new_job_dict (dict): the json file from Front-end Return: job (Job): built job instance with its tasks """ logger = Logger().get() logger.debug("start save_new_job_and_tasks") # Build the job & task from json job = Job.from_json(new_job_dict) job.created_time = datetime.now().replace(microsecond=0) # Save the job & tasks # job_id, tasks_id = self.insert_new_job(job) job_id, tasks_id = self.db_manager.insert_new_job(job) job.job_id = job_id for i in range(len(job.tasks)): job.tasks[i].job_id = job_id job.tasks[i].task_id = tasks_id[i] # Save the input files of tasks for i in range(len(new_job_dict["Tasks"])): task = job.tasks[i] file_dict = {} # Create the unique directory for each task task_file_path = os.path.join("/tmp/Felucca", f"{task.task_id}") if not os.path.exists(task_file_path): try: os.makedirs(task_file_path) except OSError as e: logger.error(f"Failed to create directory {task_file_path}" f" with exception {e}") for param, content in new_job_dict["Tasks"][i]["Files"].items(): filename = new_job_dict["Tasks"][i]["Input_File_Args"][param] file_path = os.path.join("/tmp/Felucca", f"{task.task_id}" f"/{filename}") with open(file_path, "wb") as f: f.write(base64.b64decode(content.encode('utf-8'))) file_dict[param] = file_path task.files = file_dict return job