address.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. from fate_arch.abc import AddressABC
  2. from fate_arch.metastore.db_utils import StorageConnector
  3. class AddressBase(AddressABC):
  4. def __init__(self, connector_name=None):
  5. self.connector_name = connector_name
  6. if connector_name:
  7. connector = StorageConnector(connector_name=connector_name)
  8. if connector.get_info():
  9. for k, v in connector.get_info().items():
  10. if hasattr(self, k) and v:
  11. self.__setattr__(k, v)
  12. @property
  13. def connector(self):
  14. return {}
  15. @property
  16. def storage_engine(self):
  17. return
  18. class StandaloneAddress(AddressBase):
  19. def __init__(self, home=None, name=None, namespace=None, storage_type=None, connector_name=None):
  20. self.home = home
  21. self.name = name
  22. self.namespace = namespace
  23. self.storage_type = storage_type
  24. super(StandaloneAddress, self).__init__(connector_name=connector_name)
  25. def __hash__(self):
  26. return (self.home, self.name, self.namespace, self.storage_type).__hash__()
  27. def __str__(self):
  28. return f"StandaloneAddress(name={self.name}, namespace={self.namespace})"
  29. def __repr__(self):
  30. return self.__str__()
  31. @property
  32. def connector(self):
  33. return {"home": self.home}
  34. class EggRollAddress(AddressBase):
  35. def __init__(self, home=None, name=None, namespace=None, connector_name=None):
  36. self.name = name
  37. self.namespace = namespace
  38. self.home = home
  39. super(EggRollAddress, self).__init__(connector_name=connector_name)
  40. def __hash__(self):
  41. return (self.home, self.name, self.namespace).__hash__()
  42. def __str__(self):
  43. return f"EggRollAddress(name={self.name}, namespace={self.namespace})"
  44. def __repr__(self):
  45. return self.__str__()
  46. @property
  47. def connector(self):
  48. return {"home": self.home}
  49. class HDFSAddress(AddressBase):
  50. def __init__(self, name_node=None, path=None, connector_name=None):
  51. self.name_node = name_node
  52. self.path = path
  53. super(HDFSAddress, self).__init__(connector_name=connector_name)
  54. def __hash__(self):
  55. return (self.name_node, self.path).__hash__()
  56. def __str__(self):
  57. return f"HDFSAddress(name_node={self.name_node}, path={self.path})"
  58. def __repr__(self):
  59. return self.__str__()
  60. @property
  61. def connector(self):
  62. return {"name_node": self.name_node}
  63. class PathAddress(AddressBase):
  64. def __init__(self, path=None, connector_name=None):
  65. self.path = path
  66. super(PathAddress, self).__init__(connector_name=connector_name)
  67. def __hash__(self):
  68. return self.path.__hash__()
  69. def __str__(self):
  70. return f"PathAddress(path={self.path})"
  71. def __repr__(self):
  72. return self.__str__()
  73. class ApiAddress(AddressBase):
  74. def __init__(self, method="POST", url=None, header=None, body=None, connector_name=None):
  75. self.method = method
  76. self.url = url
  77. self.header = header if header else {}
  78. self.body = body if body else {}
  79. super(ApiAddress, self).__init__(connector_name=connector_name)
  80. def __hash__(self):
  81. return (self.method, self.url).__hash__()
  82. def __str__(self):
  83. return f"ApiAddress(url={self.url})"
  84. def __repr__(self):
  85. return self.__str__()
  86. class MysqlAddress(AddressBase):
  87. def __init__(self, user=None, passwd=None, host=None, port=None, db=None, name=None, connector_name=None):
  88. self.user = user
  89. self.passwd = passwd
  90. self.host = host
  91. self.port = port
  92. self.db = db
  93. self.name = name
  94. self.connector_name = connector_name
  95. super(MysqlAddress, self).__init__(connector_name=connector_name)
  96. def __hash__(self):
  97. return (self.host, self.port, self.db, self.name).__hash__()
  98. def __str__(self):
  99. return f"MysqlAddress(db={self.db}, name={self.name})"
  100. def __repr__(self):
  101. return self.__str__()
  102. @property
  103. def connector(self):
  104. return {"user": self.user, "passwd": self.passwd, "host": self.host, "port": self.port, "db": self.db}
  105. class HiveAddress(AddressBase):
  106. def __init__(self, host=None, name=None, port=10000, username=None, database='default', auth_mechanism='PLAIN',
  107. password=None, connector_name=None):
  108. self.host = host
  109. self.username = username
  110. self.port = port
  111. self.database = database
  112. self.auth_mechanism = auth_mechanism
  113. self.password = password
  114. self.name = name
  115. super(HiveAddress, self).__init__(connector_name=connector_name)
  116. def __hash__(self):
  117. return (self.host, self.port, self.database, self.name).__hash__()
  118. def __str__(self):
  119. return f"HiveAddress(database={self.database}, name={self.name})"
  120. def __repr__(self):
  121. return self.__str__()
  122. @property
  123. def connector(self):
  124. return {
  125. "host": self.host,
  126. "port": self.port,
  127. "username": self.username,
  128. "password": self.password,
  129. "auth_mechanism": self.auth_mechanism,
  130. "database": self.database}
  131. class LinkisHiveAddress(AddressBase):
  132. def __init__(self, host="127.0.0.1", port=9001, username='', database='', name='', run_type='hql',
  133. execute_application_name='hive', source={}, params={}, connector_name=None):
  134. self.host = host
  135. self.port = port
  136. self.username = username
  137. self.database = database if database else f"{username}_ind"
  138. self.name = name
  139. self.run_type = run_type
  140. self.execute_application_name = execute_application_name
  141. self.source = source
  142. self.params = params
  143. super(LinkisHiveAddress, self).__init__(connector_name=connector_name)
  144. def __hash__(self):
  145. return (self.host, self.port, self.database, self.name).__hash__()
  146. def __str__(self):
  147. return f"LinkisHiveAddress(database={self.database}, name={self.name})"
  148. def __repr__(self):
  149. return self.__str__()
  150. class LocalFSAddress(AddressBase):
  151. def __init__(self, path=None, connector_name=None):
  152. self.path = path
  153. super(LocalFSAddress, self).__init__(connector_name=connector_name)
  154. def __hash__(self):
  155. return (self.path).__hash__()
  156. def __str__(self):
  157. return f"LocalFSAddress(path={self.path})"
  158. def __repr__(self):
  159. return self.__str__()