constant.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 enum import IntEnum
  17. """
  18. class WorkMode(IntEnum):
  19. STANDALONE = 0
  20. CLUSTER = 1
  21. class Backend(IntEnum):
  22. EGGROLL = 0
  23. SPARK_RABBITMQ = 1
  24. SPARK_PULSAR = 2
  25. def is_eggroll(self):
  26. return self.value == self.EGGROLL
  27. def is_spark_rabbitmq(self):
  28. return self.value == self.SPARK_RABBITMQ
  29. def is_spark_pulsar(self):
  30. return self.value == self.SPARK_PULSAR
  31. """
  32. class StoreEngine(IntEnum):
  33. EGGROLL = 0
  34. HDFS = 1
  35. def is_hdfs(self):
  36. return self.value == self.HDFS
  37. def is_eggroll(self):
  38. return self.value == self.EGGROLL
  39. class RetCode(IntEnum):
  40. SUCCESS = 0
  41. EXCEPTION_ERROR = 100
  42. PARAMETER_ERROR = 101
  43. DATA_ERROR = 102
  44. OPERATING_ERROR = 103
  45. FEDERATED_ERROR = 104
  46. CONNECTION_ERROR = 105
  47. SERVER_ERROR = 500
  48. class SchedulingStatusCode(object):
  49. SUCCESS = 0
  50. NO_RESOURCE = 1
  51. PASS = 1
  52. NO_NEXT = 2
  53. HAVE_NEXT = 3
  54. FAILED = 4
  55. class FederatedSchedulingStatusCode(object):
  56. SUCCESS = 0
  57. PARTIAL = 1
  58. FAILED = 2
  59. class BaseStatus(object):
  60. @classmethod
  61. def status_list(cls):
  62. return [cls.__dict__[k] for k in cls.__dict__.keys() if not callable(getattr(cls, k))
  63. and not k.startswith("__")]
  64. @classmethod
  65. def contains(cls, status):
  66. return status in cls.status_list()
  67. class StatusSet(BaseStatus):
  68. WAITING = 'waiting'
  69. START = 'start'
  70. RUNNING = "running"
  71. CANCELED = "canceled"
  72. TIMEOUT = "timeout"
  73. FAILED = "failed"
  74. SUCCESS = "success"
  75. @classmethod
  76. def get_level(cls, status):
  77. return dict(zip(cls.status_list(), range(len(cls.status_list())))).get(status, None)
  78. class JobStatus(BaseStatus):
  79. WAITING = StatusSet.WAITING
  80. RUNNING = StatusSet.RUNNING
  81. CANCELED = StatusSet.CANCELED
  82. TIMEOUT = StatusSet.TIMEOUT
  83. FAILED = StatusSet.FAILED
  84. SUCCESS = StatusSet.SUCCESS
  85. class TaskSetStatus(BaseStatus):
  86. WAITING = StatusSet.WAITING
  87. RUNNING = StatusSet.RUNNING
  88. CANCELED = StatusSet.CANCELED
  89. TIMEOUT = StatusSet.TIMEOUT
  90. FAILED = StatusSet.FAILED
  91. SUCCESS = StatusSet.SUCCESS
  92. class TaskStatus(BaseStatus):
  93. WAITING = StatusSet.WAITING
  94. RUNNING = StatusSet.RUNNING
  95. CANCELED = StatusSet.CANCELED
  96. TIMEOUT = StatusSet.TIMEOUT
  97. FAILED = StatusSet.FAILED
  98. SUCCESS = StatusSet.SUCCESS
  99. class OngoingStatus(BaseStatus):
  100. WAITING = StatusSet.WAITING
  101. RUNNING = StatusSet.RUNNING
  102. class InterruptStatus(BaseStatus):
  103. CANCELED = StatusSet.CANCELED
  104. TIMEOUT = StatusSet.TIMEOUT
  105. FAILED = StatusSet.FAILED
  106. class EndStatus(BaseStatus):
  107. CANCELED = StatusSet.CANCELED
  108. TIMEOUT = StatusSet.TIMEOUT
  109. FAILED = StatusSet.FAILED
  110. SUCCESS = StatusSet.SUCCESS
  111. @staticmethod
  112. def is_end_status(status):
  113. return status in EndStatus.__dict__.keys()
  114. class ModelStorage(object):
  115. REDIS = "redis"
  116. MYSQL = "mysql"
  117. class ModelOperation(object):
  118. STORE = "store"
  119. RESTORE = "restore"
  120. EXPORT = "export"
  121. IMPORT = "import"
  122. LOAD = "load"
  123. BIND = "bind"
  124. class ProcessRole(object):
  125. SERVER = "server"
  126. EXECUTOR = "executor"
  127. class TagOperation(object):
  128. CREATE = "create"
  129. RETRIEVE = "retrieve"
  130. UPDATE = "update"
  131. DESTROY = "destroy"
  132. LIST = "list"
  133. class ProviderType(object):
  134. FATE = "fate"
  135. FATE_FLOW = "fate_flow"
  136. FATE_SQL = "fate_sql"