service_app.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.service_registry import ServiceRegistry, ServerRegistry
  18. from fate_flow.utils.api_utils import get_json_result, validate_request
  19. @manager.route("/registry", methods=['POST'])
  20. def create_service():
  21. service_info = request.json
  22. # compatibility
  23. update_server = {}
  24. if "server_name" not in service_info:
  25. update_server = ServerRegistry.save(request.json)
  26. else:
  27. ServiceRegistry.save_service_info(**request.json)
  28. return get_json_result(data=update_server)
  29. @manager.route('/query', methods=['POST'])
  30. @validate_request("service_name")
  31. def get_service():
  32. service_info = ServiceRegistry.load_service(**request.json)
  33. return get_json_result(data={"service_info": [service.to_json() for service in service_info]})