Skip to content

Commit

Permalink
update ReturnCode
Browse files Browse the repository at this point in the history
Signed-off-by: Jat <[email protected]>
  • Loading branch information
jat001 committed Feb 10, 2023
1 parent 9a39b99 commit 14b7022
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 115 deletions.
6 changes: 3 additions & 3 deletions python/fate_flow/apps/client/data_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
from webargs import fields

from fate_flow.entity.types import Code
from fate_flow.entity.types import ReturnCode
from fate_flow.utils.api_utils import get_json_result, validate_request_json, validate_request_params
from fate_flow.utils.data_upload import Upload, UploadParam

Expand All @@ -30,10 +30,10 @@
def upload_data(file, head, partitions, namespace, name, meta, destroy=False, storage_engine=""):
data = Upload().run(parameters=UploadParam(file=file, head=head, partitions=partitions, namespace=namespace,
name=name, storage_engine=storage_engine, meta=meta, destroy=destroy))
return get_json_result(code=Code.SUCCESS, message="success", data=data)
return get_json_result(code=ReturnCode.Base.SUCCESS, message="success", data=data)


@manager.route('/download', methods=['GET'])
@validate_request_params(name=fields.String(required=True), namespace=fields.String(required=True))
def download(name, namespace):
return get_json_result(code=Code.SUCCESS, message="success")
return get_json_result(code=ReturnCode.Base.SUCCESS, message="success")
10 changes: 5 additions & 5 deletions python/fate_flow/apps/client/job_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def submit_job(dag_schema):
def query_job(job_id=None, role=None, party_id=None, status=None):
jobs = JobController.query_job(job_id=job_id, role=role, party_id=party_id, status=status)
if not jobs:
return get_json_result(code=ReturnCode.JOB.NO_FOUND, message="no found job")
return get_json_result(code=ReturnCode.JOB.SUCCESS, message="success",
return get_json_result(code=ReturnCode.Job.NOT_FOUND, message="job no found")
return get_json_result(code=ReturnCode.Base.SUCCESS, message="success",
data=[job.to_human_model_dict() for job in jobs])


Expand All @@ -47,8 +47,8 @@ def query_task(job_id=None, role=None, party_id=None, status=None, task_name=Non
tasks = JobController.query_tasks(job_id=job_id, role=role, party_id=party_id, status=status, task_name=task_name,
task_id=task_id, task_version=task_version)
if not tasks:
return get_json_result(code=ReturnCode.TASK.NO_FOUND, message="no found task")
return get_json_result(code=ReturnCode.TASK.SUCCESS, message="success",
return get_json_result(code=ReturnCode.Task.NOT_FOUND, message="task no found")
return get_json_result(code=ReturnCode.Base.SUCCESS, message="success",
data=[task.to_human_model_dict() for task in tasks])


Expand All @@ -64,6 +64,6 @@ def request_stop_job(job_id=None):
def request_rerun_job(job_id=None):
jobs = JobController.query_job(job_id=job_id)
if not jobs:
return get_json_result(code=ReturnCode.JOB.NO_FOUND, message="no found job")
return get_json_result(code=ReturnCode.Job.NOT_FOUND, message="job not found")
rerun_result = JobController.request_rerun_job(job=jobs[0])
return get_json_result(**rerun_result)
16 changes: 8 additions & 8 deletions python/fate_flow/apps/client/output_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#
from webargs import fields

from fate_flow.entity.types import ReturnCode, Code
from fate_flow.entity.types import ReturnCode
from fate_flow.manager.model_manager import PipelinedModel
from fate_flow.manager.output_manager import OutputMetric
from fate_flow.operation.job_saver import JobSaver
from fate_flow.utils.api_utils import get_json_result, validate_request_json, validate_request_params
from fate_flow.utils.api_utils import get_json_result, validate_request_params


@manager.route('/metric/key/query', methods=['GET'])
Expand All @@ -28,10 +28,10 @@
def query_metric_key(job_id, role, party_id, task_name):
tasks = JobSaver.query_task(job_id=job_id, role=role, party_id=party_id, task_name=task_name)
if not tasks:
return get_json_result(code=ReturnCode.TASK.NO_FOUND, message="no found task")
return get_json_result(code=ReturnCode.Task.NOT_FOUND, message="task not found")
metric_keys = OutputMetric(job_id=job_id, role=role, party_id=party_id, task_name=task_name,
task_id=tasks[0].f_task_id, task_version=tasks[0].f_task_version).query_metric_keys()
return get_json_result(code=Code.SUCCESS, message='success', data=metric_keys)
return get_json_result(code=ReturnCode.Base.SUCCESS, message='success', data=metric_keys)


@manager.route('/metric/query', methods=['GET'])
Expand All @@ -41,10 +41,10 @@ def query_metric_key(job_id, role, party_id, task_name):
def query_metric(job_id, role, party_id, task_name, filters=None):
tasks = JobSaver.query_task(job_id=job_id, role=role, party_id=party_id, task_name=task_name)
if not tasks:
return get_json_result(code=ReturnCode.TASK.NO_FOUND, message="no found task")
return get_json_result(code=ReturnCode.Task.NOT_FOUND, message="task not found")
metrics = OutputMetric(job_id=job_id, role=role, party_id=party_id, task_name=task_name, task_id=tasks[0].f_task_id,
task_version=tasks[0].f_task_version).read_metrics(filters)
return get_json_result(code=Code.SUCCESS, message='success', data=metrics)
return get_json_result(code=ReturnCode.Base.SUCCESS, message='success', data=metrics)


@manager.route('/model/query', methods=['GET'])
Expand All @@ -53,7 +53,7 @@ def query_metric(job_id, role, party_id, task_name, filters=None):
def query_model(job_id, role, party_id, task_name):
tasks = JobSaver.query_task(job_id=job_id, role=role, party_id=party_id, task_name=task_name)
if not tasks:
return get_json_result(code=ReturnCode.TASK.NO_FOUND, message="no found task")
return get_json_result(code=ReturnCode.Task.NOT_FOUND, message="task not found")

model_data, message = PipelinedModel(role=role, party_id=party_id, job_id=job_id).read_model_data(task_name)
return get_json_result(code=Code.SUCCESS, message=message, data=model_data)
return get_json_result(code=ReturnCode.Base.SUCCESS, message=message, data=model_data)
6 changes: 3 additions & 3 deletions python/fate_flow/apps/client/site_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
#
from webargs import fields

from fate_flow.entity.types import Code, SiteCode, ReturnCode
from fate_flow.entity.types import ReturnCode
from fate_flow.settings import PARTY_ID, IS_STANDALONE
from fate_flow.utils.api_utils import get_json_result


@manager.route('/info/query', methods=['GET'])
def query_site_info():
if not IS_STANDALONE:
return get_json_result(code=ReturnCode.SITE.SUCCESS, message="success", data={"party_id": PARTY_ID})
return get_json_result(code=ReturnCode.Base.SUCCESS, message="success", data={"party_id": PARTY_ID})
else:
return get_json_result(code=ReturnCode.SITE.IS_STANDALONE, message="site is standalone")
return get_json_result(code=ReturnCode.Site.IS_STANDALONE, message="site is standalone")
52 changes: 26 additions & 26 deletions python/fate_flow/apps/partner/partner_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
def partner_create_job(dag_schema, job_id, role, party_id):
try:
JobController.create_job(dag_schema, job_id, role, party_id)
return get_json_result(code=ReturnCode.JOB.SUCCESS, message="create job success")
return get_json_result(code=ReturnCode.Base.SUCCESS, message="create job success")
except RuntimeError as e:
return get_json_result(code=ReturnCode.JOB.CREATE_JOB_FAILED, message=str(e), data={"job_id": job_id})
return get_json_result(code=ReturnCode.Job.CREATE_JOB_FAILED, message=str(e), data={"job_id": job_id})


@manager.route('/job/start', methods=['POST'])
@job_request_json(extra_info=fields.Dict(required=False))
def start_job(job_id, role, party_id, extra_info=None):
JobController.start_job(job_id=job_id, role=role, party_id=party_id, extra_info=extra_info)
return get_json_result(code=ReturnCode.JOB.SUCCESS, message="start job success")
return get_json_result(code=ReturnCode.Base.SUCCESS, message="start job success")


@manager.route('/job/status/update', methods=['POST'])
Expand All @@ -53,9 +53,9 @@ def partner_job_status_update(job_id, role, party_id, status):
"status": status
}
if JobController.update_job_status(job_info=job_info):
return get_json_result(code=ReturnCode.JOB.SUCCESS, message='success')
return get_json_result(code=ReturnCode.Base.SUCCESS, message='success')
else:
return get_json_result(code=ReturnCode.JOB.UPDATE_STATUS_FAILED,
return get_json_result(code=ReturnCode.Job.UPDATE_STATUS_FAILED,
message="update job status does not take effect")


Expand All @@ -70,25 +70,25 @@ def partner_job_update(job_id, role, party_id, progress):
if progress:
job_info.update({"progress": progress})
if JobController.update_job(job_info=job_info):
return get_json_result(code=ReturnCode.JOB.SUCCESS, message='success')
return get_json_result(code=ReturnCode.Base.SUCCESS, message='success')
else:
return get_json_result(code=ReturnCode.JOB.UPDATE_FAILED, message="update job does not take effect")
return get_json_result(code=ReturnCode.Job.UPDATE_FAILED, message="update job does not take effect")


@manager.route('/job/pipeline/save', methods=['POST'])
@job_request_json()
def save_pipeline(job_id, role, party_id):
return get_json_result(code=ReturnCode.JOB.SUCCESS, message='success')
return get_json_result(code=ReturnCode.Base.SUCCESS, message='success')


@manager.route('/job/resource/apply', methods=['POST'])
@job_request_json()
def apply_resource(job_id, role, party_id):
status = ResourceManager.apply_for_job_resource(job_id, role, party_id)
if status:
return get_json_result(code=ReturnCode.JOB.SUCCESS, message='success')
return get_json_result(code=ReturnCode.Base.SUCCESS, message='success')
else:
return get_json_result(code=ReturnCode.JOB.APPLY_RESOURCE_FAILED,
return get_json_result(code=ReturnCode.Job.APPLY_RESOURCE_FAILED,
message=f'apply for job {job_id} resource failed')


Expand All @@ -97,17 +97,17 @@ def apply_resource(job_id, role, party_id):
def return_resource(job_id, role, party_id):
status = ResourceManager.return_job_resource(job_id=job_id, role=role, party_id=party_id)
if status:
return get_json_result(ReturnCode.JOB.SUCCESS, message='success')
return get_json_result(ReturnCode.Base.SUCCESS, message='success')
else:
return get_json_result(code=ReturnCode.JOB.APPLY_RESOURCE_FAILED,
return get_json_result(code=ReturnCode.Job.APPLY_RESOURCE_FAILED,
message=f'return for job {job_id} resource failed')


@manager.route('/job/stop', methods=['POST'])
@job_request_json()
def stop_job(job_id, role, party_id):
kill_status, kill_details = JobController.stop_jobs(job_id=job_id, role=role, party_id=party_id)
return get_json_result(code=ReturnCode.JOB.SUCCESS if kill_status else ReturnCode.JOB.KILL_FAILED,
return get_json_result(code=ReturnCode.Base.SUCCESS if kill_status else ReturnCode.Job.KILL_FAILED,
message='success' if kill_status else 'failed',
data=kill_details)

Expand All @@ -118,9 +118,9 @@ def apply_task_resource(job_id, role, party_id, task_id, task_version):
status = ResourceManager.apply_for_task_resource(job_id=job_id, role=role, party_id=party_id,
task_id=task_id, task_version=task_version)
if status:
return get_json_result(code=ReturnCode.TASK.SUCCESS, message='success')
return get_json_result(code=ReturnCode.Base.SUCCESS, message='success')
else:
return get_json_result(code=ReturnCode.TASK.APPLY_RESOURCE_FAILED,
return get_json_result(code=ReturnCode.Task.APPLY_RESOURCE_FAILED,
message=f'apply for task {job_id} resource failed')


Expand All @@ -130,19 +130,19 @@ def return_task_resource(job_id, role, party_id, task_id, task_version):
status = ResourceManager.return_task_resource(job_id=job_id, role=role, party_id=party_id,
task_id=task_id, task_version=task_version)
if status:
return get_json_result(ReturnCode.TASK.SUCCESS, message='success')
return get_json_result(ReturnCode.Base.SUCCESS, message='success')
else:
return get_json_result(code=ReturnCode.TASK.APPLY_RESOURCE_FAILED,
return get_json_result(code=ReturnCode.Task.APPLY_RESOURCE_FAILED,
message=f'return for task {job_id} resource failed')


@manager.route('/task/start', methods=['POST'])
@task_request_json()
def start_task(job_id, role, party_id, task_id, task_version):
if TaskController.start_task(job_id, role, party_id, task_id, task_version):
return get_json_result(code=ReturnCode.TASK.SUCCESS, message='success')
return get_json_result(code=ReturnCode.Base.SUCCESS, message='success')
else:
return get_json_result(code=ReturnCode.TASK.START_FAILED, message='start task failed')
return get_json_result(code=ReturnCode.Task.START_FAILED, message='start task failed')


@manager.route('/task/collect', methods=['POST'])
Expand All @@ -151,9 +151,9 @@ def collect_task(job_id, role, party_id, task_id, task_version):
task_info = TaskController.collect_task(job_id=job_id, task_id=task_id, task_version=task_version, role=role,
party_id=party_id)
if task_info:
return get_json_result(code=ReturnCode.TASK.SUCCESS, message="success", data=task_info)
return get_json_result(code=ReturnCode.Base.SUCCESS, message="success", data=task_info)
else:
return get_json_result(code=ReturnCode.TASK.NO_FOUND, message="no found task")
return get_json_result(code=ReturnCode.Task.NOT_FOUND, message="task not found")


@manager.route('/task/status/update', methods=['POST'])
Expand All @@ -169,10 +169,10 @@ def task_status_update(job_id, role, party_id, task_id, task_version, status):
"status": status
})
if TaskController.update_task_status(task_info=task_info):
return get_json_result(code=ReturnCode.TASK.SUCCESS, message='success')
return get_json_result(code=ReturnCode.Base.SUCCESS, message='success')
else:
return get_json_result(
code=ReturnCode.TASK.UPDATE_STATUS_FAILED,
code=ReturnCode.Task.UPDATE_STATUS_FAILED,
message="update job status does not take effect"
)

Expand All @@ -186,7 +186,7 @@ def stop_task(job_id, role, party_id, task_id, task_version, status=None):
kill_status = True
for task in tasks:
kill_status = kill_status & TaskController.stop_task(task=task, stop_status=status)
return get_json_result(code=ReturnCode.TASK.SUCCESS if kill_status else ReturnCode.TASK.KILL_FAILED,
return get_json_result(code=ReturnCode.Base.SUCCESS if kill_status else ReturnCode.Task.KILL_FAILED,
message='success' if kill_status else 'failed')


Expand All @@ -196,8 +196,8 @@ def rerun_task(job_id, role, party_id, task_id, task_version, new_version):
tasks = JobSaver.query_task(job_id=job_id, task_id=task_id, role=role, party_id=party_id)
if not tasks:
return get_json_result(
code=ReturnCode.TASK.NO_FOUND,
message="no found task"
code=ReturnCode.Task.NOT_FOUND,
message="task not found"
)
TaskController.create_new_version_task(task=tasks[0], new_version=new_version)
return get_json_result()
10 changes: 5 additions & 5 deletions python/fate_flow/apps/worker/worker_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def report_task_status(status, execution_id, error=None):
task_info.update({"error_report": error})
TaskController.update_task(task_info)
return get_json_result()
return get_json_result(code=ReturnCode.TASK.NO_FOUND, message="no found task")
return get_json_result(code=ReturnCode.Task.NOT_FOUND, message="task not found")


@manager.route('/task/status', methods=['GET'])
Expand All @@ -56,8 +56,8 @@ def query_task_status(execution_id):
task_info = {
"status": tasks[0].f_status,
}
return get_json_result(code=ReturnCode.TASK.SUCCESS, message="success", data=task_info)
return get_json_result(code=ReturnCode.TASK.NO_FOUND, message="no found task")
return get_json_result(code=ReturnCode.Base.SUCCESS, message="success", data=task_info)
return get_json_result(code=ReturnCode.Task.NOT_FOUND, message="task not found")


@manager.route('/task/output/tracking', methods=['POST'])
Expand All @@ -81,8 +81,8 @@ def log_output_artifacts(execution_id, meta_data, type, uri, output_key):
"task_name": task.f_task_name
}
OutputDataTracking.create(data_info)
return get_json_result(code=ReturnCode.TASK.SUCCESS, message="success")
return get_json_result(code=ReturnCode.TASK.NO_FOUND, message="no found task")
return get_json_result(code=ReturnCode.Base.SUCCESS, message="success")
return get_json_result(code=ReturnCode.Task.NOT_FOUND, message="task not found")


@manager.route('/task/model/<job_id>/<role>/<party_id>/<model_id>/<model_version>/<component>/<task_name>/<model_name>', methods=['POST'])
Expand Down
2 changes: 1 addition & 1 deletion python/fate_flow/controller/job_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def request_stop_job(cls, job_id):
schedule_logger(job_id).info(f"stop job on this party")
jobs = JobSaver.query_job(job_id=job_id)
if not jobs:
return {"code": ReturnCode.JOB.NO_FOUND, "message": "no found job"}
return {"code": ReturnCode.Job.NOT_FOUND, "message": "job not found"}
status = JobStatus.CANCELED
kill_status, kill_details = JobController.stop_jobs(job_id=job_id, stop_status=status)
schedule_logger(job_id).info(f"stop job on this party status {kill_status}")
Expand Down
1 change: 0 additions & 1 deletion python/fate_flow/entity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@
# limitations under the License.
#
from ._base import BaseEntity, BaseModel
from .types import RetCode
Loading

0 comments on commit 14b7022

Please sign in to comment.