def generate_project(code): """ generate project automatically without project path. :param code: project code. :return: project description. """ project_path = tempfile.mkdtemp() # generate project config file. project_config().dump_to_file(project_path + '/project.yaml') # generate project structure. os.makedirs(project_path + '/python_codes') os.makedirs(project_path + '/jar_dependencies') os.makedirs(project_path + '/resources') open(project_path + '/python_codes/__init__.py', 'w') fd, temp_file = tempfile.mkstemp(suffix='.py', dir=project_path + '/python_codes') with open(temp_file, 'w') as f: f.write(code) # generate project description. project_desc: ProjectDesc = get_project_description_from( project_path) project_desc.project_name = project_config().get_project_name() project_desc.project_config['entry_module_path'] = ( file_path_to_absolute_module(temp_file)).split('.')[-1] return project_desc
def list_workflows() -> List[WorkflowInfo]: """ :return: All workflow information. """ namespace = project_config().get_project_name() return proto_to_workflow_list( get_ai_flow_client().list_workflows(namespace))
def submit_workflow(workflow_name: Text = None, args: Dict = None) -> WorkflowInfo: """ Submit the ai flow workflow to the scheduler. :param workflow_name: The ai flow workflow identify. :param args: The arguments of the submit action. :return: The result of the submit action. """ call_path = os.path.abspath(sys._getframe(1).f_code.co_filename) project_path = os.path.abspath(project_description().project_path) # length /python_codes/ is 14; length .py is 3 entry_module_path = call_path[len(project_path) + 14:-3].replace('/', '.') namespace = project_config().get_project_name() translator = get_default_translator() workflow = translator.translate(graph=default_graph(), project_desc=project_description()) for job in workflow.jobs.values(): _register_job_meta(workflow_id=workflow.workflow_id, job=job) _set_entry_module_path(workflow, entry_module_path) _upload_project_package(workflow) return proto_to_workflow(get_ai_flow_client().submit_workflow_to_scheduler( namespace=namespace, workflow_json=json_utils.dumps(workflow), workflow_name=workflow_name, args=args))
def get_workflow(workflow_name: Text = None) -> WorkflowInfo: """ Return the workflow information. :param workflow_name: The ai flow workflow identify. :return: the workflow information. """ namespace = project_config().get_project_name() return proto_to_workflow(get_ai_flow_client().get_workflow( namespace, workflow_name))
def resume_workflow_scheduling(workflow_name: Text = None) -> WorkflowInfo: """ Resume the ai flow workflow from the scheduler. :param workflow_name: The ai flow workflow identify. :return: The result of the action. """ namespace = project_config().get_project_name() return proto_to_workflow(get_ai_flow_client().resume_workflow_scheduling( namespace, workflow_name))
def get_client(self) -> Optional[AIFlowClient]: """ Get the ai flow client. :return: AIFlowClient. """ if self.client is None: self.client = AIFlowClient( server_uri=project_config().get_master_uri()) return self.client
def list_workflow_executions( workflow_name: Text) -> List[WorkflowExecutionInfo]: """ :param workflow_name: The ai flow workflow identify. :return: All workflow executions of the workflow. """ namespace = project_config().get_project_name() return proto_to_workflow_execution_list( get_ai_flow_client().list_workflow_executions(namespace, workflow_name))
def start_new_workflow_execution(workflow_name: Text) -> WorkflowExecutionInfo: """ Run the project under the current project path. :param workflow_name: The ai flow workflow identify. :return: The result of the run action. """ namespace = project_config().get_project_name() return proto_to_workflow_execution( get_ai_flow_client().start_new_workflow_execution( namespace, workflow_name))
def kill_all_workflow_executions( workflow_name: Text) -> List[WorkflowExecutionInfo]: """ Stop all instances of the workflow. :param workflow_name: The ai flow workflow identify. :return: The result of the action. """ namespace = project_config().get_project_name() return proto_to_workflow_execution_list( get_ai_flow_client().kill_all_workflow_executions( namespace, workflow_name))
def generate_project_desc(project_path: Text = None) -> ProjectDesc: """ Run project under the current project path. :param project_path: The path of the project path. :return: project description. """ if project_path is None: # generate project structure automatically without `project_path` parameter. def generate_project(code): """ generate project automatically without project path. :param code: project code. :return: project description. """ project_path = tempfile.mkdtemp() # generate project config file. project_config().dump_to_file(project_path + '/project.yaml') # generate project structure. os.makedirs(project_path + '/python_codes') os.makedirs(project_path + '/jar_dependencies') os.makedirs(project_path + '/resources') open(project_path + '/python_codes/__init__.py', 'w') fd, temp_file = tempfile.mkstemp(suffix='.py', dir=project_path + '/python_codes') with open(temp_file, 'w') as f: f.write(code) # generate project description. project_desc: ProjectDesc = get_project_description_from( project_path) project_desc.project_name = project_config().get_project_name() project_desc.project_config['entry_module_path'] = ( file_path_to_absolute_module(temp_file)).split('.')[-1] return project_desc return generate_project( inspect.getsource(sys._getframe().f_back.f_back)) else: # parse project description project_desc: ProjectDesc = get_project_description_from(project_path) project_desc.project_name = project_config().get_project_name() return project_desc
def get_client(self): self.client = AIFlowClient( server_uri=project_config().get_master_uri()) return self.client
def set_project_config(main_file): set_project_config_file(get_project_config_file()) project_config()['entry_module_path'] = path_util.get_module_name( main_file)
def test_load_configuration(self): config = project_config() self.assertEqual(config.get_master_uri(), 'localhost:50051')