Implement wait for node coordinator transition

References #72
This commit is contained in:
2020-02-19 10:33:22 -05:00
parent 6db4df51c0
commit 0aefafa7f7
5 changed files with 48 additions and 15 deletions

View File

@ -618,7 +618,8 @@ class API_Node_CoordinatorState(Resource):
return api_helper.node_coordinator_state(node)
@RequestParser([
{ 'name': 'state', 'choices': ('primary', 'secondary'), 'helptext': "A valid state must be specified", 'required': True }
{ 'name': 'state', 'choices': ('primary', 'secondary'), 'helptext': "A valid state must be specified", 'required': True },
{ 'name': 'wait' }
])
@Authenticator
def post(self, node, reqargs):
@ -636,6 +637,10 @@ class API_Node_CoordinatorState(Resource):
enum:
- primary
- secondary
- in: query
name: wait
type: boolean
description: Whether to block waiting for the full state transition
responses:
200:
description: OK
@ -648,10 +653,11 @@ class API_Node_CoordinatorState(Resource):
type: object
id: Message
"""
wait = bool(strtobool(reqargs.get('wait', 'false')))
if reqargs['state'] == 'primary':
return api_helper.node_primary(node)
return api_helper.node_primary(node, wait)
if reqargs['state'] == 'secondary':
return api_helper.node_secondary(node)
return api_helper.node_secondary(node, wait)
abort(400)
api.add_resource(API_Node_CoordinatorState, '/node/<node>/coordinator-state')

View File

@ -213,12 +213,12 @@ def node_domain_state(node):
return retdata, retcode
def node_secondary(node):
def node_secondary(node, wait):
"""
Take NODE out of primary router mode.
"""
zk_conn = pvc_common.startZKConnection(config['coordinators'])
retflag, retdata = pvc_node.secondary_node(zk_conn, node)
retflag, retdata = pvc_node.secondary_node(zk_conn, node, wait)
pvc_common.stopZKConnection(zk_conn)
if retflag:
@ -231,12 +231,12 @@ def node_secondary(node):
}
return output, retcode
def node_primary(node):
def node_primary(node, wait):
"""
Set NODE to primary router mode.
"""
zk_conn = pvc_common.startZKConnection(config['coordinators'])
retflag, retdata = pvc_node.primary_node(zk_conn, node)
retflag, retdata = pvc_node.primary_node(zk_conn, node, wait)
pvc_common.stopZKConnection(zk_conn)
if retflag: