Make primary watching happen in the daemon not the Node object
This commit is contained in:
parent
d464bf74da
commit
bfd42b5a7b
|
@ -540,6 +540,28 @@ def update_nodes(new_node_list):
|
||||||
# Alias for our local node (passed to network and domain objects)
|
# Alias for our local node (passed to network and domain objects)
|
||||||
this_node = d_node[myhostname]
|
this_node = d_node[myhostname]
|
||||||
|
|
||||||
|
# Primary node
|
||||||
|
@zk_conn.DataWatch('/primary_node')
|
||||||
|
def update_primart(new_primary, stat, event=''):
|
||||||
|
try:
|
||||||
|
new_primary = new_primary.decode('ascii')
|
||||||
|
except AttributeError:
|
||||||
|
new_primary = 'none'
|
||||||
|
|
||||||
|
if new_primary != this_node.primary_node:
|
||||||
|
if config['daemon_mode'] == 'coordinator':
|
||||||
|
# We're a coordinator and there is no primary
|
||||||
|
if new_primary == 'none':
|
||||||
|
if this_node.daemon_state == 'run' and this_node.router_state != 'primary':
|
||||||
|
logger.out('Contending for primary routing state', state='i')
|
||||||
|
zkhandler.writedata(zk_conn, {'/primary_node': myhostname})
|
||||||
|
elif new_primary == myhostname:
|
||||||
|
zkhandler.writedata(zk_conn, {'/nodes/{}/routerstate'.format(myhostname): 'primary'})
|
||||||
|
else:
|
||||||
|
zkhandler.writedata(zk_conn, {'/nodes/{}/routerstate'.format(myhostname): 'secondary'})
|
||||||
|
for node in d_node:
|
||||||
|
d_node[node].primary_node = new_primary
|
||||||
|
|
||||||
# Network objects
|
# Network objects
|
||||||
@zk_conn.ChildrenWatch('/networks')
|
@zk_conn.ChildrenWatch('/networks')
|
||||||
def update_networks(new_network_list):
|
def update_networks(new_network_list):
|
||||||
|
|
|
@ -138,40 +138,6 @@ class NodeInstance(object):
|
||||||
if self.domain_state == 'unflush' and self.inflush == False:
|
if self.domain_state == 'unflush' and self.inflush == False:
|
||||||
self.unflush()
|
self.unflush()
|
||||||
|
|
||||||
@self.zk_conn.DataWatch('/primary_node')
|
|
||||||
def watch_primary_node(data, stat, event=''):
|
|
||||||
if event and event.type == 'DELETED':
|
|
||||||
# The key has been deleted after existing before; terminate this watcher
|
|
||||||
# because this class instance is about to be reaped in Daemon.py
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
|
||||||
data = data.decode('ascii')
|
|
||||||
except AttributeError:
|
|
||||||
data = 'none'
|
|
||||||
|
|
||||||
if data != self.primary_node:
|
|
||||||
if self.daemon_mode == 'coordinator':
|
|
||||||
# We're a coordinator so we care about networking
|
|
||||||
if data == 'none':
|
|
||||||
# Toggle state management of routing functions
|
|
||||||
if self.name == self.this_node:
|
|
||||||
if self.daemon_state == 'run' and self.router_state != 'primary':
|
|
||||||
# Contend for primary
|
|
||||||
self.logger.out('Contending for primary routing state', state='i')
|
|
||||||
zkhandler.writedata(self.zk_conn, {'/primary_node': self.name })
|
|
||||||
elif data == self.this_node:
|
|
||||||
if self.name == self.this_node:
|
|
||||||
zkhandler.writedata(self.zk_conn, { '/nodes/{}/routerstate'.format(self.name): 'primary' })
|
|
||||||
self.primary_node = data
|
|
||||||
else:
|
|
||||||
if self.name == self.this_node:
|
|
||||||
zkhandler.writedata(self.zk_conn, { '/nodes/{}/routerstate'.format(self.name): 'secondary' })
|
|
||||||
self.primary_node = data
|
|
||||||
else:
|
|
||||||
self.primary_node = data
|
|
||||||
|
|
||||||
|
|
||||||
@self.zk_conn.DataWatch('/nodes/{}/memfree'.format(self.name))
|
@self.zk_conn.DataWatch('/nodes/{}/memfree'.format(self.name))
|
||||||
def watch_node_memfree(data, stat, event=''):
|
def watch_node_memfree(data, stat, event=''):
|
||||||
if event and event.type == 'DELETED':
|
if event and event.type == 'DELETED':
|
||||||
|
|
Loading…
Reference in New Issue