server_app.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.runtime_config import RuntimeConfig
  18. from fate_flow.utils.api_utils import get_json_result
  19. from fate_flow.settings import API_VERSION
  20. from fate_flow.db.service_registry import ServerRegistry
  21. from fate_flow.db.config_manager import ConfigManager
  22. from fate_flow.db.job_default_config import JobDefaultConfig
  23. from fate_flow.entity import RetCode
  24. @manager.route('/fateflow/info', methods=['POST'])
  25. def fate_flow_server_info():
  26. data = RuntimeConfig.SERVICE_DB.get_servers()
  27. return get_json_result(data=data)
  28. @manager.route('/version/get', methods=['POST'])
  29. def get_fate_version_info():
  30. module = (request.json or {}).get('module', None)
  31. if module:
  32. version = {module: RuntimeConfig.get_env(module)}
  33. else:
  34. version = RuntimeConfig.get_all_env()
  35. version["API"] = API_VERSION
  36. return get_json_result(data=version)
  37. @manager.route('/get', methods=['POST'])
  38. @manager.route('/service/get', methods=['POST'])
  39. def get_server_registry():
  40. return get_json_result(data=ServerRegistry.get_all())
  41. @manager.route('/<server_name>/register', methods=['POST'])
  42. @manager.route('/service/<server_name>/register', methods=['POST'])
  43. def register_server(server_name: str):
  44. ServerRegistry.register(server_name.upper(), request.json)
  45. if ServerRegistry.get(server_name.upper()) is not None:
  46. return get_json_result()
  47. else:
  48. return get_json_result(retcode=RetCode.OPERATING_ERROR)
  49. @manager.route('/<server_name>/get', methods=['POST'])
  50. @manager.route('/service/<server_name>/get', methods=['POST'])
  51. def get_server(server_name: str):
  52. return get_json_result(data=ServerRegistry.get(server_name.upper()))
  53. @manager.route('/reload', methods=['POST'])
  54. def reload():
  55. config = ConfigManager.load()
  56. return get_json_result(data=config)
  57. @manager.route('/config/job/default', methods=['POST'])
  58. def job_default_config():
  59. return get_json_result(data=JobDefaultConfig.get_all())