Commit 45c34b7b authored by Grégory Wisniewski's avatar Grégory Wisniewski

Clean imports and check node properties in (un)register(Server|UUID).


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1128 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent bb0141e2
...@@ -16,19 +16,16 @@ ...@@ -16,19 +16,16 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from time import time from time import time
from neo import logging
from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
BROKEN_STATE, PENDING_STATE, HIDDEN_STATE, MASTER_NODE_TYPE, \
STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, ADMIN_NODE_TYPE
from neo.util import dump from neo.util import dump
class Node(object): class Node(object):
"""This class represents a node.""" """This class represents a node."""
def __init__(self, server = None, uuid = None): def __init__(self, server = None, uuid = None):
self.state = RUNNING_STATE self.state = protocol.RUNNING_STATE
self.server = server self.server = server
self.uuid = uuid self.uuid = uuid
self.manager = None self.manager = None
...@@ -49,24 +46,16 @@ class Node(object): ...@@ -49,24 +46,16 @@ class Node(object):
self.last_state_change = time() self.last_state_change = time()
def setServer(self, server): def setServer(self, server):
if self.server != server:
if self.server is not None and self.manager is not None:
self.manager.unregisterServer(self) self.manager.unregisterServer(self)
self.server = server self.server = server
if server is not None and self.manager is not None:
self.manager.registerServer(self) self.manager.registerServer(self)
def getServer(self): def getServer(self):
return self.server return self.server
def setUUID(self, uuid): def setUUID(self, uuid):
if self.uuid != uuid:
if self.uuid is not None and self.manager is not None:
self.manager.unregisterUUID(self) self.manager.unregisterUUID(self)
self.uuid = uuid self.uuid = uuid
if uuid is not None and self.manager is not None:
self.manager.registerUUID(self) self.manager.registerUUID(self)
def getUUID(self): def getUUID(self):
...@@ -101,7 +90,7 @@ class MasterNode(Node): ...@@ -101,7 +90,7 @@ class MasterNode(Node):
"""This class represents a master node.""" """This class represents a master node."""
def getType(self): def getType(self):
return MASTER_NODE_TYPE return protocol.MASTER_NODE_TYPE
def isMaster(self): def isMaster(self):
return True return True
...@@ -111,7 +100,7 @@ class StorageNode(Node): ...@@ -111,7 +100,7 @@ class StorageNode(Node):
"""This class represents a storage node.""" """This class represents a storage node."""
def getType(self): def getType(self):
return STORAGE_NODE_TYPE return protocol.STORAGE_NODE_TYPE
def isStorage(self): def isStorage(self):
return True return True
...@@ -121,7 +110,7 @@ class ClientNode(Node): ...@@ -121,7 +110,7 @@ class ClientNode(Node):
"""This class represents a client node.""" """This class represents a client node."""
def getType(self): def getType(self):
return CLIENT_NODE_TYPE return protocol.CLIENT_NODE_TYPE
def isClient(self): def isClient(self):
return True return True
...@@ -131,7 +120,7 @@ class AdminNode(Node): ...@@ -131,7 +120,7 @@ class AdminNode(Node):
"""This class represents an admin node.""" """This class represents an admin node."""
def getType(self): def getType(self):
return ADMIN_NODE_TYPE return protocol.ADMIN_NODE_TYPE
def isAdmin(self): def isAdmin(self):
return True return True
...@@ -168,18 +157,26 @@ class NodeManager(object): ...@@ -168,18 +157,26 @@ class NodeManager(object):
self.unregisterUUID(node) self.unregisterUUID(node)
def registerServer(self, node): def registerServer(self, node):
if node.getServer() is None:
return
self.server_dict[node.getServer()] = node self.server_dict[node.getServer()] = node
def unregisterServer(self, node): def unregisterServer(self, node):
if node.getServer() is None:
return
try: try:
del self.server_dict[node.getServer()] del self.server_dict[node.getServer()]
except KeyError: except KeyError:
pass pass
def registerUUID(self, node): def registerUUID(self, node):
if node.getUUID() is None:
return
self.uuid_dict[node.getUUID()] = node self.uuid_dict[node.getUUID()] = node
def unregisterUUID(self, node): def unregisterUUID(self, node):
if node.getUUID() is None:
return
try: try:
del self.uuid_dict[node.getUUID()] del self.uuid_dict[node.getUUID()]
except KeyError: except KeyError:
......
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