_session.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. import shutil
  18. import traceback
  19. from fate_arch.common import file_utils
  20. from fate_arch.storage import StorageSessionBase, StorageEngine
  21. from fate_arch.abc import AddressABC
  22. from fate_arch.common.address import ApiAddress
  23. class StorageSession(StorageSessionBase):
  24. def __init__(self, session_id, options=None):
  25. super(StorageSession, self).__init__(session_id=session_id, engine=StorageEngine.PATH)
  26. self.base_dir = os.path.join(file_utils.get_project_base_directory(), "api_data", session_id)
  27. def table(self, address: AddressABC, name, namespace, partitions, store_type=None, options=None, **kwargs):
  28. if isinstance(address, ApiAddress):
  29. from fate_arch.storage.api._table import StorageTable
  30. return StorageTable(path=os.path.join(self.base_dir, namespace, name),
  31. address=address,
  32. name=name,
  33. namespace=namespace,
  34. partitions=partitions, store_type=store_type, options=options)
  35. raise NotImplementedError(f"address type {type(address)} not supported with api storage")
  36. def cleanup(self, name, namespace):
  37. # path = os.path.join(self.base_dir, namespace, name)
  38. # try:
  39. # os.remove(path)
  40. # except Exception as e:
  41. # traceback.print_exc()
  42. pass
  43. def stop(self):
  44. # try:
  45. # shutil.rmtree(self.base_dir)
  46. # except Exception as e:
  47. # traceback.print_exc()
  48. pass
  49. def kill(self):
  50. # try:
  51. # shutil.rmtree(self.base_dir)
  52. # except Exception as e:
  53. # traceback.print_exc()
  54. pass