initiator_app.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from flask import request
  17. from fate_flow.db.db_models import Task
  18. from fate_flow.operation.job_saver import JobSaver
  19. from fate_flow.scheduler.dag_scheduler import DAGScheduler
  20. from fate_flow.utils.api_utils import get_json_result
  21. # apply initiator for control operation
  22. @manager.route('/<job_id>/<role>/<party_id>/stop/<stop_status>', methods=['POST'])
  23. def stop_job(job_id, role, party_id, stop_status):
  24. retcode, retmsg = DAGScheduler.stop_job(job_id=job_id, role=role, party_id=party_id, stop_status=stop_status)
  25. return get_json_result(retcode=retcode, retmsg=retmsg)
  26. @manager.route('/<job_id>/<role>/<party_id>/rerun', methods=['POST'])
  27. def rerun_job(job_id, role, party_id):
  28. DAGScheduler.set_job_rerun(job_id=job_id, initiator_role=role, initiator_party_id=party_id,
  29. component_name=request.json.get("component_name"),
  30. force=request.json.get("force", False),
  31. auto=False)
  32. #todo: 判断状态
  33. return get_json_result(retcode=0, retmsg='success')
  34. @manager.route('/<job_id>/<component_name>/<task_id>/<task_version>/<role>/<party_id>/report', methods=['POST'])
  35. def report_task(job_id, component_name, task_id, task_version, role, party_id):
  36. task_info = {}
  37. task_info.update(request.json)
  38. task_info.update({
  39. "job_id": job_id,
  40. "task_id": task_id,
  41. "task_version": task_version,
  42. "role": role,
  43. "party_id": party_id,
  44. })
  45. JobSaver.update_task(task_info=task_info, report=True)
  46. if task_info.get("party_status"):
  47. JobSaver.update_status(Task, task_info)
  48. return get_json_result(retcode=0, retmsg='success')