Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize status flow validation #1408

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion dlrover/python/master/node/status_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,39 @@
]


ALLOWED_TRANSITIONS = {
NodeStatus.INITIAL: [
NodeStatus.INITIAL,
NodeStatus.PENDING,
NodeStatus.RUNNING,
NodeStatus.SUCCEEDED,
NodeStatus.FAILED,
NodeStatus.DELETED,
],
NodeStatus.PENDING: [
NodeStatus.PENDING,
NodeStatus.RUNNING,
NodeStatus.SUCCEEDED,
NodeStatus.FAILED,
NodeStatus.DELETED,
],
NodeStatus.RUNNING: [
NodeStatus.RUNNING,
NodeStatus.SUCCEEDED,
NodeStatus.FAILED,
NodeStatus.DELETED,
],
NodeStatus.SUCCEEDED: [NodeStatus.SUCCEEDED, NodeStatus.DELETED],
NodeStatus.FAILED: [NodeStatus.FAILED, NodeStatus.DELETED],
NodeStatus.DELETED: [NodeStatus.DELETED],
}


def get_node_state_flow(from_status, event_type, phase):
if event_type == "DELETED" and from_status == NodeStatus.PENDING:
# The phase if pending if the pending node is deleted.
phase = NodeStatus.DELETED
if from_status == phase:
if from_status == phase or phase not in ALLOWED_TRANSITIONS[from_status]:
return None
for flow in NODE_STATE_FLOWS:
if (
Expand Down
9 changes: 9 additions & 0 deletions dlrover/python/tests/test_job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from dlrover.python.master.node.job_context import get_job_context
from dlrover.python.master.node.local_job_manager import LocalJobManager
from dlrover.python.master.node.status_flow import (
ALLOWED_TRANSITIONS,
NODE_STATE_FLOWS,
NodeStateFlow,
get_node_state_flow,
Expand Down Expand Up @@ -123,6 +124,14 @@ def test_get_node_state_flow(self):
self.assertEqual(flow, NODE_STATE_FLOWS[9])
self.assertTrue(flow.should_relaunch)

def test_allowed_transitions(self):
self.assertTrue(
NodeStatus.RUNNING in ALLOWED_TRANSITIONS[NodeStatus.RUNNING]
)
self.assertFalse(
NodeStatus.PENDING in ALLOWED_TRANSITIONS[NodeStatus.RUNNING]
)


class DistributedJobManagerTest(unittest.TestCase):
def setUp(self) -> None:
Expand Down
Loading