Commit dfee4fcc authored by Vincent Pelletier's avatar Vincent Pelletier

Replace isinstance(node, ...Node) by node.getNodeType() == ..._NODE_TYPE (and...

Replace isinstance(node, ...Node) by node.getNodeType() == ..._NODE_TYPE (and similar). This makes things easier to unit test.
Add missing imports.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@303 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 47d42d56
...@@ -94,7 +94,7 @@ class ClientEventHandler(EventHandler): ...@@ -94,7 +94,7 @@ class ClientEventHandler(EventHandler):
else: else:
# Connection to a storage node failed # Connection to a storage node failed
node = app.nm.getNodeByServer(conn.getAddress()) node = app.nm.getNodeByServer(conn.getAddress())
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
self._dealWithStorageFailure(conn, node, TEMPORARILY_DOWN_STATE) self._dealWithStorageFailure(conn, node, TEMPORARILY_DOWN_STATE)
EventHandler.connectionFailed(self, conn) EventHandler.connectionFailed(self, conn)
...@@ -114,7 +114,7 @@ class ClientEventHandler(EventHandler): ...@@ -114,7 +114,7 @@ class ClientEventHandler(EventHandler):
self.dispatcher.connectToPrimaryMasterNode(app, conn) self.dispatcher.connectToPrimaryMasterNode(app, conn)
else: else:
node = app.nm.getNodeByServer(conn.getAddress()) node = app.nm.getNodeByServer(conn.getAddress())
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
# Notify primary master node that a storage node is temporarily down # Notify primary master node that a storage node is temporarily down
logging.info("connection to storage node %s closed", logging.info("connection to storage node %s closed",
node.getServer()) node.getServer())
...@@ -133,7 +133,7 @@ class ClientEventHandler(EventHandler): ...@@ -133,7 +133,7 @@ class ClientEventHandler(EventHandler):
self.dispatcher.connectToPrimaryMasterNode(app, conn) self.dispatcher.connectToPrimaryMasterNode(app, conn)
else: else:
node = app.nm.getNodeByServer(conn.getAddress()) node = app.nm.getNodeByServer(conn.getAddress())
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
# Notify primary master node that a storage node is # Notify primary master node that a storage node is
# temporarily down. # temporarily down.
self._dealWithStorageFailure(conn, node, TEMPORARILY_DOWN_STATE) self._dealWithStorageFailure(conn, node, TEMPORARILY_DOWN_STATE)
...@@ -151,7 +151,7 @@ class ClientEventHandler(EventHandler): ...@@ -151,7 +151,7 @@ class ClientEventHandler(EventHandler):
self.dispatcher.connectToPrimaryMasterNode(app, conn) self.dispatcher.connectToPrimaryMasterNode(app, conn)
else: else:
node = app.nm.getNodeByServer(conn.getAddress()) node = app.nm.getNodeByServer(conn.getAddress())
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
self._dealWithStorageFailure(conn, node, BROKEN_STATE) self._dealWithStorageFailure(conn, node, BROKEN_STATE)
EventHandler.peerBroken(self, conn) EventHandler.peerBroken(self, conn)
...@@ -222,7 +222,7 @@ class ClientEventHandler(EventHandler): ...@@ -222,7 +222,7 @@ class ClientEventHandler(EventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
# This must be sent only by primary master node # This must be sent only by primary master node
if not isinstance(node, MasterNode): if node.getNodeType() != MASTER_NODE_TYPE:
return return
# Register new master nodes. # Register new master nodes.
for ip_address, port, uuid in known_master_list: for ip_address, port, uuid in known_master_list:
...@@ -268,7 +268,7 @@ class ClientEventHandler(EventHandler): ...@@ -268,7 +268,7 @@ class ClientEventHandler(EventHandler):
pt = app.pt pt = app.pt
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
# This must be sent only by primary master node # This must be sent only by primary master node
if not isinstance(node, MasterNode): if node.getNodeType() != MASTER_NODE_TYPE:
return return
if app.ptid != ptid: if app.ptid != ptid:
...@@ -298,7 +298,7 @@ class ClientEventHandler(EventHandler): ...@@ -298,7 +298,7 @@ class ClientEventHandler(EventHandler):
# This must be sent only by a primary master node. # This must be sent only by a primary master node.
# Note that this may be sent before I know that it is # Note that this may be sent before I know that it is
# a primary master node. # a primary master node.
if not isinstance(node, MasterNode): if node.getNodeType() != MASTER_NODE_TYPE:
logging.warn('ignoring notify node information from %s', logging.warn('ignoring notify node information from %s',
dump(uuid)) dump(uuid))
return return
...@@ -358,7 +358,7 @@ class ClientEventHandler(EventHandler): ...@@ -358,7 +358,7 @@ class ClientEventHandler(EventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
# This must be sent only by primary master node # This must be sent only by primary master node
if not isinstance(node, MasterNode) \ if node.getNodeType() != MASTER_NODE_TYPE \
or app.primary_master_node is None \ or app.primary_master_node is None \
or app.primary_master_node.getUUID() != uuid: or app.primary_master_node.getUUID() != uuid:
return return
......
...@@ -23,7 +23,8 @@ from struct import pack, unpack ...@@ -23,7 +23,8 @@ from struct import pack, unpack
from neo.config import ConfigurationManager from neo.config import ConfigurationManager
from neo.protocol import Packet, \ from neo.protocol import Packet, \
RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \ RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \
INVALID_UUID, INVALID_OID, INVALID_TID, INVALID_PTID, CLIENT_NODE_TYPE INVALID_UUID, INVALID_OID, INVALID_TID, INVALID_PTID, \
CLIENT_NODE_TYPE, MASTER_NODE_TYPE, STORAGE_NODE_TYPE
from neo.node import NodeManager, MasterNode, StorageNode, ClientNode from neo.node import NodeManager, MasterNode, StorageNode, ClientNode
from neo.event import EventManager from neo.event import EventManager
from neo.connection import ListeningConnection, ClientConnection, ServerConnection from neo.connection import ListeningConnection, ClientConnection, ServerConnection
...@@ -295,12 +296,12 @@ class Application(object): ...@@ -295,12 +296,12 @@ class Application(object):
for c in self.em.getConnectionList(): for c in self.em.getConnectionList():
if c.getUUID() is not None: if c.getUUID() is not None:
n = self.nm.getNodeByUUID(c.getUUID()) n = self.nm.getNodeByUUID(c.getUUID())
if isinstance(n, (MasterNode, StorageNode)): if n.getNodeType() in (MASTER_NODE_TYPE, STORAGE_NODE_TYPE):
p = Packet() p = Packet()
node_list = [(node_type, ip_address, port, uuid, state)] node_list = [(node_type, ip_address, port, uuid, state)]
p.notifyNodeInformation(c.getNextId(), node_list) p.notifyNodeInformation(c.getNextId(), node_list)
c.addPacket(p) c.addPacket(p)
elif isinstance(node, (MasterNode, StorageNode)): elif node.getNodeType() in (MASTER_NODE_TYPE, STORAGE_NODE_TYPE):
for c in self.em.getConnectionList(): for c in self.em.getConnectionList():
if c.getUUID() is not None: if c.getUUID() is not None:
p = Packet() p = Packet()
...@@ -316,7 +317,7 @@ class Application(object): ...@@ -316,7 +317,7 @@ class Application(object):
for c in self.em.getConnectionList(): for c in self.em.getConnectionList():
if c.getUUID() is not None: if c.getUUID() is not None:
n = self.nm.getNodeByUUID(c.getUUID()) n = self.nm.getNodeByUUID(c.getUUID())
if isinstance(n, (ClientNode, StorageNode)): if n.getNodeType() in (CLIENT_NODE_TYPE, STORAGE_NODE_TYPE):
# Split the packet if too big. # Split the packet if too big.
size = len(cell_list) size = len(cell_list)
start = 0 start = 0
...@@ -358,7 +359,7 @@ class Application(object): ...@@ -358,7 +359,7 @@ class Application(object):
uuid = conn.getUUID() uuid = conn.getUUID()
if uuid is not None: if uuid is not None:
node = nm.getNodeByUUID(uuid) node = nm.getNodeByUUID(uuid)
if isinstance(node, StorageNode) \ if node.getNodeType() == STORAGE_NODE_TYPE \
and node.getState() == RUNNING_STATE: and node.getState() == RUNNING_STATE:
p = Packet() p = Packet()
msg_id = conn.getNextId() msg_id = conn.getNextId()
...@@ -539,7 +540,7 @@ class Application(object): ...@@ -539,7 +540,7 @@ class Application(object):
uuid = conn.getUUID() uuid = conn.getUUID()
if uuid is not None: if uuid is not None:
node = nm.getNodeByUUID(uuid) node = nm.getNodeByUUID(uuid)
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
# Split the packet if too huge. # Split the packet if too huge.
p = Packet() p = Packet()
row_list = [] row_list = []
...@@ -577,7 +578,7 @@ class Application(object): ...@@ -577,7 +578,7 @@ class Application(object):
uuid = conn.getUUID() uuid = conn.getUUID()
if uuid is not None: if uuid is not None:
node = nm.getNodeByUUID(uuid) node = nm.getNodeByUUID(uuid)
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
self.asking_uuid_dict[uuid] = False self.asking_uuid_dict[uuid] = False
p = Packet() p = Packet()
msg_id = conn.getNextId() msg_id = conn.getNextId()
...@@ -603,7 +604,7 @@ class Application(object): ...@@ -603,7 +604,7 @@ class Application(object):
uuid = conn.getUUID() uuid = conn.getUUID()
if uuid is not None: if uuid is not None:
node = nm.getNodeByUUID(uuid) node = nm.getNodeByUUID(uuid)
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
p = Packet() p = Packet()
p.deleteTransaction(conn.getNextId(), tid) p.deleteTransaction(conn.getNextId(), tid)
conn.addPacket(p) conn.addPacket(p)
...@@ -658,7 +659,7 @@ class Application(object): ...@@ -658,7 +659,7 @@ class Application(object):
uuid = conn.getUUID() uuid = conn.getUUID()
if uuid is not None: if uuid is not None:
node = nm.getNodeByUUID(uuid) node = nm.getNodeByUUID(uuid)
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
conn.addPacket(Packet().startOperation(conn.getNextId())) conn.addPacket(Packet().startOperation(conn.getNextId()))
# Now everything is passive. # Now everything is passive.
...@@ -696,9 +697,9 @@ class Application(object): ...@@ -696,9 +697,9 @@ class Application(object):
uuid = conn.getUUID() uuid = conn.getUUID()
if uuid is not None: if uuid is not None:
node = nm.getNodeByUUID(uuid) node = nm.getNodeByUUID(uuid)
if isinstance(node, (StorageNode, ClientNode)): if node.getNodeType() in (STORAGE_NODE_TYPE, CLIENT_NODE_TYPE):
conn.addPacket(Packet().stopOperation(conn.getNextId())) conn.addPacket(Packet().stopOperation(conn.getNextId()))
if isinstance(node, ClientNode): if node.getNodeType() == CLIENT_NODE_TYPE:
conn.abort() conn.abort()
# Then, go back, and restart. # Then, go back, and restart.
......
...@@ -104,7 +104,7 @@ class RecoveryEventHandler(MasterEventHandler): ...@@ -104,7 +104,7 @@ class RecoveryEventHandler(MasterEventHandler):
# address but with a different UUID. # address but with a different UUID.
if node.getUUID() is None: if node.getUUID() is None:
# This must be a master node. # This must be a master node.
if not isinstance(node, MasterNode) or node_type != MASTER_NODE_TYPE: if node.getNodeType() != MASTER_NODE_TYPE or node_type != MASTER_NODE_TYPE:
# Error. This node uses the same server address as a master # Error. This node uses the same server address as a master
# node. # node.
conn.addPacket(Packet().protocolError(packet.getId(), conn.addPacket(Packet().protocolError(packet.getId(),
...@@ -210,7 +210,7 @@ class RecoveryEventHandler(MasterEventHandler): ...@@ -210,7 +210,7 @@ class RecoveryEventHandler(MasterEventHandler):
# If this is a storage node, ask the last IDs. # If this is a storage node, ask the last IDs.
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
p = Packet() p = Packet()
msg_id = conn.getNextId() msg_id = conn.getNextId()
p.askLastIDs(msg_id) p.askLastIDs(msg_id)
...@@ -292,7 +292,7 @@ class RecoveryEventHandler(MasterEventHandler): ...@@ -292,7 +292,7 @@ class RecoveryEventHandler(MasterEventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, StorageNode): if node.getNodeType() != STORAGE_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -320,7 +320,7 @@ class RecoveryEventHandler(MasterEventHandler): ...@@ -320,7 +320,7 @@ class RecoveryEventHandler(MasterEventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, StorageNode): if node.getNodeType() != STORAGE_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
if uuid != app.target_uuid: if uuid != app.target_uuid:
......
...@@ -20,7 +20,7 @@ from copy import copy ...@@ -20,7 +20,7 @@ from copy import copy
from neo.protocol import MASTER_NODE_TYPE, CLIENT_NODE_TYPE, \ from neo.protocol import MASTER_NODE_TYPE, CLIENT_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, FEEDING_STATE, DISCARDED_STATE, STORAGE_NODE_TYPE
from neo.master.handler import MasterEventHandler from neo.master.handler import MasterEventHandler
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
...@@ -77,13 +77,13 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -77,13 +77,13 @@ class ServiceEventHandler(MasterEventHandler):
node.setState(TEMPORARILY_DOWN_STATE) node.setState(TEMPORARILY_DOWN_STATE)
logging.debug('broadcasting node information') logging.debug('broadcasting node information')
app.broadcastNodeInformation(node) app.broadcastNodeInformation(node)
if isinstance(node, ClientNode): if node.getNodeType() == CLIENT_NODE_TYPE:
# If this node is a client, just forget it. # If this node is a client, just forget it.
app.nm.remove(node) app.nm.remove(node)
for tid, t in app.finishing_transaction_dict.items(): for tid, t in app.finishing_transaction_dict.items():
if t.getConnection() is conn: if t.getConnection() is conn:
del app.finishing_transaction_dict[tid] del app.finishing_transaction_dict[tid]
elif isinstance(node, StorageNode): elif node.getNodeType() == STORAGE_NODE_TYPE:
if not app.pt.operational(): if not app.pt.operational():
# Catastrophic. # Catastrophic.
raise OperationFailure, 'cannot continue operation' raise OperationFailure, 'cannot continue operation'
...@@ -98,13 +98,13 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -98,13 +98,13 @@ class ServiceEventHandler(MasterEventHandler):
node.setState(TEMPORARILY_DOWN_STATE) node.setState(TEMPORARILY_DOWN_STATE)
logging.debug('broadcasting node information') logging.debug('broadcasting node information')
app.broadcastNodeInformation(node) app.broadcastNodeInformation(node)
if isinstance(node, ClientNode): if node.getNodeType() == CLIENT_NODE_TYPE:
# If this node is a client, just forget it. # If this node is a client, just forget it.
app.nm.remove(node) app.nm.remove(node)
for tid, t in app.finishing_transaction_dict.items(): for tid, t in app.finishing_transaction_dict.items():
if t.getConnection() is conn: if t.getConnection() is conn:
del app.finishing_transaction_dict[tid] del app.finishing_transaction_dict[tid]
elif isinstance(node, StorageNode): elif node.getNodeType() == STORAGE_NODE_TYPE:
if not app.pt.operational(): if not app.pt.operational():
# Catastrophic. # Catastrophic.
raise OperationFailure, 'cannot continue operation' raise OperationFailure, 'cannot continue operation'
...@@ -119,13 +119,13 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -119,13 +119,13 @@ class ServiceEventHandler(MasterEventHandler):
node.setState(BROKEN_STATE) node.setState(BROKEN_STATE)
logging.debug('broadcasting node information') logging.debug('broadcasting node information')
app.broadcastNodeInformation(node) app.broadcastNodeInformation(node)
if isinstance(node, ClientNode): if node.getNodeType() == CLIENT_NODE_TYPE:
# If this node is a client, just forget it. # If this node is a client, just forget it.
app.nm.remove(node) app.nm.remove(node)
for tid, t in app.finishing_transaction_dict.items(): for tid, t in app.finishing_transaction_dict.items():
if t.getConnection() is conn: if t.getConnection() is conn:
del app.finishing_transaction_dict[tid] del app.finishing_transaction_dict[tid]
elif isinstance(node, StorageNode): elif node.getNodeType() == STORAGE_NODE_TYPE:
cell_list = app.pt.dropNode(node) cell_list = app.pt.dropNode(node)
ptid = app.getNextPartitionTableID() ptid = app.getNextPartitionTableID()
app.broadcastPartitionChanges(ptid, cell_list) app.broadcastPartitionChanges(ptid, cell_list)
...@@ -179,7 +179,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -179,7 +179,7 @@ class ServiceEventHandler(MasterEventHandler):
# server address but with a different UUID. # server address but with a different UUID.
if node.getUUID() is None: if node.getUUID() is None:
# This must be a master node. XXX Why ?? # This must be a master node. XXX Why ??
if not isinstance(node, MasterNode) \ if node.getNodeType() != MASTER_NODE_TYPE \
or node_type != MASTER_NODE_TYPE: or node_type != MASTER_NODE_TYPE:
# Error. This node uses the same server address as # Error. This node uses the same server address as
# a master node. # a master node.
...@@ -266,7 +266,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -266,7 +266,7 @@ class ServiceEventHandler(MasterEventHandler):
conn.setUUID(uuid) conn.setUUID(uuid)
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
# If this is a storage node, add it into the partition table. # If this is a storage node, add it into the partition table.
# Note that this does no harm, even if the node is not new. # Note that this does no harm, even if the node is not new.
if old_node is not None: if old_node is not None:
...@@ -328,7 +328,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -328,7 +328,7 @@ class ServiceEventHandler(MasterEventHandler):
# If this is a storage node or a client node, send the partition table. # If this is a storage node or a client node, send the partition table.
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if isinstance(node, (StorageNode, ClientNode)): if node.getNodeType() in (STORAGE_NODE_TYPE, CLIENT_NODE_TYPE):
logging.debug('sending send partition table to %s:%d', logging.debug('sending send partition table to %s:%d',
*(conn.getAddress())) *(conn.getAddress()))
# Split the packet if too huge. # Split the packet if too huge.
...@@ -345,7 +345,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -345,7 +345,7 @@ class ServiceEventHandler(MasterEventHandler):
conn.addPacket(p) conn.addPacket(p)
# If this is a storage node, ask it to start. # If this is a storage node, ask it to start.
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
conn.addPacket(Packet().startOperation(conn.getNextId())) conn.addPacket(Packet().startOperation(conn.getNextId()))
def handleAnnouncePrimaryMaster(self, conn, packet): def handleAnnouncePrimaryMaster(self, conn, packet):
...@@ -417,7 +417,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -417,7 +417,7 @@ class ServiceEventHandler(MasterEventHandler):
logging.debug('broadcasting node information') logging.debug('broadcasting node information')
app.broadcastNodeInformation(node) app.broadcastNodeInformation(node)
if isinstance(node, StorageNode) \ if node.getNodeType() == STORAGE_NODE_TYPE \
and state in (DOWN_STATE, BROKEN_STATE): and state in (DOWN_STATE, BROKEN_STATE):
cell_list = app.pt.dropNode(node) cell_list = app.pt.dropNode(node)
if len(cell_list) != 0: if len(cell_list) != 0:
...@@ -433,7 +433,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -433,7 +433,7 @@ class ServiceEventHandler(MasterEventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, StorageNode): if node.getNodeType() != STORAGE_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -451,7 +451,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -451,7 +451,7 @@ class ServiceEventHandler(MasterEventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, ClientNode): if node.getNodeType() != CLIENT_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
tid = app.getNextTID() tid = app.getNextTID()
...@@ -467,7 +467,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -467,7 +467,7 @@ class ServiceEventHandler(MasterEventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, ClientNode): if node.getNodeType() != CLIENT_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -483,7 +483,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -483,7 +483,7 @@ class ServiceEventHandler(MasterEventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, ClientNode): if node.getNodeType() != CLIENT_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -530,7 +530,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -530,7 +530,7 @@ class ServiceEventHandler(MasterEventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, StorageNode): if node.getNodeType() != STORAGE_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -553,7 +553,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -553,7 +553,7 @@ class ServiceEventHandler(MasterEventHandler):
uuid = c.getUUID() uuid = c.getUUID()
if uuid is not None: if uuid is not None:
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if isinstance(node, ClientNode): if node.getNodeType() == CLIENT_NODE_TYPE:
if c is t.getConnection(): if c is t.getConnection():
p.notifyTransactionFinished(t.getMessageId(), p.notifyTransactionFinished(t.getMessageId(),
tid) tid)
...@@ -562,7 +562,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -562,7 +562,7 @@ class ServiceEventHandler(MasterEventHandler):
p.invalidateObjects(c.getNextId(), p.invalidateObjects(c.getNextId(),
t.getOIDList(), tid) t.getOIDList(), tid)
c.addPacket(p) c.addPacket(p)
elif isinstance(node, StorageNode): elif node.getNodeType() == STORAGE_NODE_TYPE:
if uuid in t.getUUIDSet(): if uuid in t.getUUIDSet():
p.unlockInformation(c.getNextId(), tid) p.unlockInformation(c.getNextId(), tid)
c.addPacket(p) c.addPacket(p)
...@@ -580,7 +580,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -580,7 +580,7 @@ class ServiceEventHandler(MasterEventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, ClientNode): if node.getNodeType() != CLIENT_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -627,7 +627,7 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -627,7 +627,7 @@ class ServiceEventHandler(MasterEventHandler):
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
if not isinstance(node, StorageNode): if node.getNodeType() != STORAGE_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
......
...@@ -36,10 +36,10 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -36,10 +36,10 @@ class VerificationEventHandler(MasterEventHandler):
if node.getState() == RUNNING_STATE: if node.getState() == RUNNING_STATE:
node.setState(TEMPORARILY_DOWN_STATE) node.setState(TEMPORARILY_DOWN_STATE)
app.broadcastNodeInformation(node) app.broadcastNodeInformation(node)
if isinstance(node, ClientNode): if node.getNodeType() == CLIENT_NODE_TYPE:
# If this node is a client, just forget it. # If this node is a client, just forget it.
app.nm.remove(node) app.nm.remove(node)
elif isinstance(node, StorageNode): elif node.getNodeType() == STORAGE_NODE_TYPE:
if not app.pt.operational(): if not app.pt.operational():
# Catastrophic. # Catastrophic.
raise VerificationFailure, 'cannot continue verification' raise VerificationFailure, 'cannot continue verification'
...@@ -53,10 +53,10 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -53,10 +53,10 @@ class VerificationEventHandler(MasterEventHandler):
if node.getState() == RUNNING_STATE: if node.getState() == RUNNING_STATE:
node.setState(TEMPORARILY_DOWN_STATE) node.setState(TEMPORARILY_DOWN_STATE)
app.broadcastNodeInformation(node) app.broadcastNodeInformation(node)
if isinstance(node, ClientNode): if node.getNodeType() == CLIENT_NODE_TYPE:
# If this node is a client, just forget it. # If this node is a client, just forget it.
app.nm.remove(node) app.nm.remove(node)
elif isinstance(node, StorageNode): elif node.getNodeType() == STORAGE_NODE_TYPE:
if not app.pt.operational(): if not app.pt.operational():
# Catastrophic. # Catastrophic.
raise VerificationFailure, 'cannot continue verification' raise VerificationFailure, 'cannot continue verification'
...@@ -70,10 +70,10 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -70,10 +70,10 @@ class VerificationEventHandler(MasterEventHandler):
if node.getState() != BROKEN_STATE: if node.getState() != BROKEN_STATE:
node.setState(BROKEN_STATE) node.setState(BROKEN_STATE)
app.broadcastNodeInformation(node) app.broadcastNodeInformation(node)
if isinstance(node, ClientNode): if node.getNodeType() == CLIENT_NODE_TYPE:
# If this node is a client, just forget it. # If this node is a client, just forget it.
app.nm.remove(node) app.nm.remove(node)
elif isinstance(node, StorageNode): elif node.getNodeType() == STORAGE_NODE_TYPE:
cell_list = app.pt.dropNode(node) cell_list = app.pt.dropNode(node)
ptid = app.getNextPartitionTableID() ptid = app.getNextPartitionTableID()
app.broadcastPartitionChanges(ptid, cell_list) app.broadcastPartitionChanges(ptid, cell_list)
...@@ -127,7 +127,7 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -127,7 +127,7 @@ class VerificationEventHandler(MasterEventHandler):
# address but with a different UUID. # address but with a different UUID.
if node.getUUID() is None: if node.getUUID() is None:
# This must be a master node. # This must be a master node.
if not isinstance(node, MasterNode) or node_type != MASTER_NODE_TYPE: if node.getNodeType() != MASTER_NODE_TYPE or node_type != MASTER_NODE_TYPE:
# Error. This node uses the same server address as a master # Error. This node uses the same server address as a master
# node. # node.
conn.addPacket(Packet().protocolError(packet.getId(), conn.addPacket(Packet().protocolError(packet.getId(),
...@@ -233,7 +233,7 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -233,7 +233,7 @@ class VerificationEventHandler(MasterEventHandler):
# If this is a storage node, send the partition table. # If this is a storage node, send the partition table.
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if isinstance(node, StorageNode): if node.getNodeType() == STORAGE_NODE_TYPE:
# Split the packet if too huge. # Split the packet if too huge.
p = Packet() p = Packet()
row_list = [] row_list = []
...@@ -322,7 +322,7 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -322,7 +322,7 @@ class VerificationEventHandler(MasterEventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, StorageNode): if node.getNodeType() != STORAGE_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -345,7 +345,7 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -345,7 +345,7 @@ class VerificationEventHandler(MasterEventHandler):
tid_list, *(conn.getAddress())) tid_list, *(conn.getAddress()))
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, StorageNode): if node.getNodeType() != STORAGE_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -367,7 +367,7 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -367,7 +367,7 @@ class VerificationEventHandler(MasterEventHandler):
oid_list, tid, *(conn.getAddress())) oid_list, tid, *(conn.getAddress()))
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, StorageNode): if node.getNodeType() != STORAGE_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -395,7 +395,7 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -395,7 +395,7 @@ class VerificationEventHandler(MasterEventHandler):
logging.info('TID not found: %s', message) logging.info('TID not found: %s', message)
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, StorageNode): if node.getNodeType() != STORAGE_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -415,7 +415,7 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -415,7 +415,7 @@ class VerificationEventHandler(MasterEventHandler):
logging.info('object %s:%s found', dump(oid), dump(tid)) logging.info('object %s:%s found', dump(oid), dump(tid))
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, StorageNode): if node.getNodeType() != STORAGE_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -434,7 +434,7 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -434,7 +434,7 @@ class VerificationEventHandler(MasterEventHandler):
logging.info('OID not found: %s', message) logging.info('OID not found: %s', message)
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, StorageNode): if node.getNodeType() != STORAGE_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
......
...@@ -133,13 +133,13 @@ class NodeManager(object): ...@@ -133,13 +133,13 @@ class NodeManager(object):
return [n for n in self.node_list if filter(n)] return [n for n in self.node_list if filter(n)]
def getMasterNodeList(self): def getMasterNodeList(self):
return self.getNodeList(filter = lambda node: isinstance(node, MasterNode)) return self.getNodeList(filter = lambda node: node.getNodeType() == MASTER_NODE_TYPE)
def getStorageNodeList(self): def getStorageNodeList(self):
return self.getNodeList(filter = lambda node: isinstance(node, StorageNode)) return self.getNodeList(filter = lambda node: node.getNodeType() == STORAGE_NODE_TYPE)
def getClientNodeList(self): def getClientNodeList(self):
return self.getNodeList(filter = lambda node: isinstance(node, ClientNode)) return self.getNodeList(filter = lambda node: node.getNodeType() == CLIENT_NODE_TYPE)
def getNodeByServer(self, server): def getNodeByServer(self, server):
return self.server_dict.get(server) return self.server_dict.get(server)
......
...@@ -84,7 +84,7 @@ class StorageEventHandler(EventHandler): ...@@ -84,7 +84,7 @@ class StorageEventHandler(EventHandler):
if node is None: if node is None:
raise RuntimeError('I do not know the uuid %r' % dump(uuid)) raise RuntimeError('I do not know the uuid %r' % dump(uuid))
if not isinstance(node, MasterNode): if node.getNodeType() != MASTER_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
return return
...@@ -118,7 +118,7 @@ class StorageEventHandler(EventHandler): ...@@ -118,7 +118,7 @@ class StorageEventHandler(EventHandler):
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, MasterNode) \ if node.getNodeType() != MASTER_NODE_TYPE \
or app.primary_master_node is None \ or app.primary_master_node is None \
or app.primary_master_node.getUUID() != uuid: or app.primary_master_node.getUUID() != uuid:
return return
......
...@@ -73,7 +73,7 @@ class OperationEventHandler(StorageEventHandler): ...@@ -73,7 +73,7 @@ class OperationEventHandler(StorageEventHandler):
if uuid is not None: if uuid is not None:
app = self.app app = self.app
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if isinstance(node, ClientNode): if node.getNodeType() == CLIENT_NODE_TYPE:
for tid, t in app.transaction_dict.items(): for tid, t in app.transaction_dict.items():
if t.getUUID() == uuid: if t.getUUID() == uuid:
for o in t.getObjectList(): for o in t.getObjectList():
......
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