task_initializer.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 fate_flow.utils.job_utils import get_job_configuration
  17. from fate_flow.utils.log_utils import getLogger
  18. from fate_flow.controller.task_controller import TaskController
  19. from fate_flow.entity import ComponentProvider
  20. from fate_flow.manager.provider_manager import ProviderManager
  21. from fate_flow.utils import schedule_utils
  22. from fate_flow.worker.base_worker import BaseWorker
  23. from fate_flow.utils.log_utils import start_log, successful_log
  24. LOGGER = getLogger()
  25. class TaskInitializer(BaseWorker):
  26. def _run(self):
  27. result = {}
  28. job_configuration = get_job_configuration(
  29. job_id=self.args.job_id,
  30. role=self.args.role,
  31. party_id=self.args.party_id
  32. )
  33. dsl_parser = schedule_utils.get_job_dsl_parser(
  34. dsl=job_configuration.dsl,
  35. runtime_conf=job_configuration.runtime_conf,
  36. train_runtime_conf=job_configuration.train_runtime_conf
  37. )
  38. provider = ComponentProvider(**self.args.config["provider"])
  39. common_task_info = self.args.config["common_task_info"]
  40. log_msg = f"initialize the components: {self.args.config['components']}"
  41. LOGGER.info(start_log(log_msg, role=self.args.role, party_id=self.args.party_id))
  42. for component_name in self.args.config["components"]:
  43. result[component_name] = {}
  44. task_info = {}
  45. task_info.update(common_task_info)
  46. parameters, user_specified_parameters = ProviderManager.get_component_parameters(dsl_parser=dsl_parser,
  47. component_name=component_name,
  48. role=self.args.role,
  49. party_id=self.args.party_id,
  50. provider=provider)
  51. if parameters:
  52. task_info = {}
  53. task_info.update(common_task_info)
  54. task_info["component_name"] = component_name
  55. task_info["component_module"] = parameters["module"]
  56. task_info["provider_info"] = provider.to_dict()
  57. task_info["component_parameters"] = parameters
  58. TaskController.create_task(role=self.args.role, party_id=self.args.party_id,
  59. run_on_this_party=common_task_info["run_on_this_party"],
  60. task_info=task_info)
  61. result[component_name]["need_run"] = True
  62. else:
  63. # The party does not need to run, pass
  64. result[component_name]["need_run"] = False
  65. LOGGER.info(successful_log(log_msg, role=self.args.role, party_id=self.args.party_id))
  66. return result
  67. if __name__ == "__main__":
  68. TaskInitializer().run()