operation_app.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.utils import job_utils
  18. from fate_flow.utils.api_utils import get_json_result, error_response
  19. from fate_arch.common import file_utils
  20. @manager.route('/job_config/get', methods=['POST'])
  21. def get_config():
  22. kwargs = {}
  23. job_configuration = None
  24. for i in ('job_id', 'role', 'party_id'):
  25. if request.json.get(i) is None:
  26. return error_response(400, f"'{i}' is required.")
  27. kwargs[i] = str(request.json[i])
  28. for i in ('component_name', 'task_id', 'task_version'):
  29. if request.json.get(i) is None:
  30. break
  31. kwargs[i] = str(request.json[i])
  32. else:
  33. try:
  34. job_configuration = job_utils.get_task_using_job_conf(**kwargs)
  35. except Exception:
  36. pass
  37. if job_configuration is None:
  38. job_configuration = job_utils.get_job_configuration(kwargs['job_id'], kwargs['role'], kwargs['party_id'])
  39. if job_configuration is None:
  40. return error_response(404, 'Job not found.')
  41. return get_json_result(data=job_configuration.to_dict())
  42. @manager.route('/json_conf/load', methods=['POST'])
  43. def load_json_conf():
  44. job_conf = file_utils.load_json_conf(request.json.get("config_path"))
  45. return get_json_result(data=job_conf)