run_status.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. class BaseStatus(object):
  17. @classmethod
  18. def status_list(cls):
  19. return [cls.__dict__[k] for k in cls.__dict__.keys() if not callable(getattr(cls, k)) and not k.startswith("__")]
  20. @classmethod
  21. def contains(cls, status):
  22. return status in cls.status_list()
  23. class StatusSet(BaseStatus):
  24. WAITING = 'waiting'
  25. READY = 'ready'
  26. RUNNING = "running"
  27. CANCELED = "canceled"
  28. TIMEOUT = "timeout"
  29. FAILED = "failed"
  30. PASS = "pass"
  31. SUCCESS = "success"
  32. @classmethod
  33. def get_level(cls, status):
  34. return dict(zip(cls.status_list(), range(len(cls.status_list())))).get(status, None)
  35. class BaseStateTransitionRule(object):
  36. RULES = {}
  37. @classmethod
  38. def if_pass(cls, src_status, dest_status):
  39. if src_status not in cls.RULES:
  40. return False
  41. if dest_status not in cls.RULES[src_status]:
  42. return False
  43. else:
  44. return True
  45. class JobStatus(BaseStatus):
  46. READY = StatusSet.READY
  47. WAITING = StatusSet.WAITING
  48. RUNNING = StatusSet.RUNNING
  49. CANCELED = StatusSet.CANCELED
  50. TIMEOUT = StatusSet.TIMEOUT
  51. FAILED = StatusSet.FAILED
  52. SUCCESS = StatusSet.SUCCESS
  53. class StateTransitionRule(BaseStateTransitionRule):
  54. RULES = {
  55. StatusSet.READY: [StatusSet.WAITING, StatusSet.CANCELED, StatusSet.TIMEOUT, StatusSet.FAILED],
  56. StatusSet.WAITING: [StatusSet.RUNNING, StatusSet.CANCELED, StatusSet.TIMEOUT, StatusSet.FAILED, StatusSet.SUCCESS, StatusSet.PASS],
  57. StatusSet.RUNNING: [StatusSet.CANCELED, StatusSet.TIMEOUT, StatusSet.FAILED, StatusSet.SUCCESS],
  58. StatusSet.CANCELED: [StatusSet.WAITING],
  59. StatusSet.TIMEOUT: [StatusSet.FAILED, StatusSet.SUCCESS, StatusSet.WAITING],
  60. StatusSet.FAILED: [StatusSet.WAITING],
  61. StatusSet.SUCCESS: [StatusSet.WAITING],
  62. }
  63. class TaskStatus(BaseStatus):
  64. WAITING = StatusSet.WAITING
  65. RUNNING = StatusSet.RUNNING
  66. CANCELED = StatusSet.CANCELED
  67. TIMEOUT = StatusSet.TIMEOUT
  68. FAILED = StatusSet.FAILED
  69. PASS = StatusSet.PASS
  70. SUCCESS = StatusSet.SUCCESS
  71. class StateTransitionRule(BaseStateTransitionRule):
  72. RULES = {
  73. StatusSet.WAITING: [StatusSet.RUNNING, StatusSet.SUCCESS, StatusSet.PASS],
  74. StatusSet.RUNNING: [StatusSet.CANCELED, StatusSet.TIMEOUT, StatusSet.FAILED, StatusSet.PASS, StatusSet.SUCCESS],
  75. StatusSet.CANCELED: [StatusSet.WAITING],
  76. StatusSet.TIMEOUT: [StatusSet.FAILED, StatusSet.SUCCESS],
  77. StatusSet.FAILED: [],
  78. StatusSet.PASS: [],
  79. StatusSet.SUCCESS: [],
  80. }
  81. class JobInheritanceStatus(BaseStatus):
  82. PASS = StatusSet.PASS
  83. WAITING = StatusSet.WAITING
  84. RUNNING = StatusSet.RUNNING
  85. SUCCESS = StatusSet.SUCCESS
  86. FAILED = StatusSet.FAILED
  87. class OngoingStatus(BaseStatus):
  88. WAITING = StatusSet.WAITING
  89. RUNNING = StatusSet.RUNNING
  90. class InterruptStatus(BaseStatus):
  91. CANCELED = StatusSet.CANCELED
  92. TIMEOUT = StatusSet.TIMEOUT
  93. FAILED = StatusSet.FAILED
  94. class EndStatus(BaseStatus):
  95. CANCELED = StatusSet.CANCELED
  96. TIMEOUT = StatusSet.TIMEOUT
  97. FAILED = StatusSet.FAILED
  98. PASS = StatusSet.PASS
  99. SUCCESS = StatusSet.SUCCESS
  100. class SuccessStatus(BaseStatus):
  101. PASS = StatusSet.PASS
  102. SUCCESS = StatusSet.SUCCESS
  103. class LinkisJobStatus(BaseStatus):
  104. FAILED = "Failed"
  105. SUCCESS = "Success"
  106. RUNNING = "Running"
  107. class AutoRerunStatus(BaseStatus):
  108. TIMEOUT = StatusSet.TIMEOUT
  109. FAILED = StatusSet.FAILED
  110. class SchedulingStatusCode(object):
  111. SUCCESS = 0
  112. NO_RESOURCE = 1
  113. PASS = 1
  114. NO_NEXT = 2
  115. HAVE_NEXT = 3
  116. FAILED = 4
  117. class FederatedSchedulingStatusCode(object):
  118. SUCCESS = 0
  119. PARTIAL = 1
  120. FAILED = 2
  121. ERROR = 3
  122. NOT_EFFECTIVE = 4