dependence_registry.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. import os
  17. from fate_flow.db.db_models import DependenciesStorageMeta, DB
  18. from fate_flow.entity.types import FateDependenceStorageEngine
  19. class DependenceRegistry:
  20. @classmethod
  21. @DB.connection_context()
  22. def get_dependencies_storage_meta(cls, get_or_one=False, **kwargs):
  23. kwargs["storage_engine"] = FateDependenceStorageEngine.HDFS.value
  24. dependencies_storage_info = DependenciesStorageMeta.query(**kwargs)
  25. if get_or_one:
  26. return dependencies_storage_info[0] if dependencies_storage_info else None
  27. return dependencies_storage_info
  28. @classmethod
  29. @DB.connection_context()
  30. def save_dependencies_storage_meta(cls, storage_meta, status_check=False):
  31. entity_model, status = DependenciesStorageMeta.get_or_create(
  32. f_storage_engine=storage_meta.get("f_storage_engine"),
  33. f_type=storage_meta.get("f_type"),
  34. f_version=storage_meta.get("f_version"),
  35. defaults=storage_meta)
  36. if status is False:
  37. if status_check:
  38. if "f_upload_status" in storage_meta.keys() and storage_meta["f_upload_status"] \
  39. != entity_model.f_upload_status:
  40. return
  41. for key in storage_meta:
  42. setattr(entity_model, key, storage_meta[key])
  43. entity_model.save(force_insert=False)
  44. @classmethod
  45. def get_modify_time(cls, path):
  46. return int(os.path.getmtime(path)*1000)