Commit c91fc122 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Check cluster transitions in administration handler.

Remove the related TODO.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1745 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 35b7c286
...@@ -22,6 +22,13 @@ from neo.master.handlers import MasterHandler ...@@ -22,6 +22,13 @@ from neo.master.handlers import MasterHandler
from neo.protocol import ClusterStates, NodeStates, Packets, ProtocolError from neo.protocol import ClusterStates, NodeStates, Packets, ProtocolError
from neo.util import dump from neo.util import dump
CLUSTER_STATE_WORKFLOW = {
# destination: sources
ClusterStates.VERIFYING: set([ClusterStates.RECOVERING]),
ClusterStates.STOPPING: set([ClusterStates.RECOVERING,
ClusterStates.VERIFYING, ClusterStates.RUNNING]),
}
class AdministrationHandler(MasterHandler): class AdministrationHandler(MasterHandler):
"""This class deals with messages from the admin node only""" """This class deals with messages from the admin node only"""
...@@ -35,14 +42,22 @@ class AdministrationHandler(MasterHandler): ...@@ -35,14 +42,22 @@ class AdministrationHandler(MasterHandler):
conn.answer(Packets.AnswerPrimary(app.uuid, [])) conn.answer(Packets.AnswerPrimary(app.uuid, []))
def setClusterState(self, conn, state): def setClusterState(self, conn, state):
# TODO: check which cluster state transition we are told to follow, # check request
# and refuse to follow meaningless ones. if not state in CLUSTER_STATE_WORKFLOW.keys():
raise ProtocolError('Invalid state requested')
valid_current_states = CLUSTER_STATE_WORKFLOW[state]
if self.app.cluster_state not in valid_current_states:
raise ProtocolError('Cannot switch to this state')
# change state
if state == ClusterStates.VERIFYING: if state == ClusterStates.VERIFYING:
# XXX: /!\ this allow leave the first phase of recovery
self.app._startup_allowed = True self.app._startup_allowed = True
else: else:
self.app.changeClusterState(state) self.app.changeClusterState(state)
p = protocol.ack('cluster state changed')
conn.answer(p) # answer
conn.answer(protocol.ack('cluster state changed'))
if state == ClusterStates.STOPPING: if state == ClusterStates.STOPPING:
self.app.cluster_state = state self.app.cluster_state = state
self.app.shutdown() self.app.shutdown()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment