Commit 4b96a7b5 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Don't import the whole protocol module.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2198 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent d48572dc
......@@ -17,8 +17,9 @@
from neo import logging
from neo import protocol
from neo.protocol import NodeTypes, Packets
from neo.protocol import NotReadyError, ProtocolError, UnexpectedPacketError
from neo.protocol import BrokenNodeDisallowedError
from neo.master.handlers import MasterHandler
from neo.exception import ElectionFailure
from neo.util import dump
......@@ -28,7 +29,6 @@ class ClientElectionHandler(MasterHandler):
# FIXME: this packet is not allowed here, but handled in MasterHandler
# a global handler review is required.
def askPrimary(self, conn):
from neo.protocol import UnexpectedPacketError
raise UnexpectedPacketError, "askPrimary on server connection"
def packetReceived(self, conn, packet):
......@@ -204,15 +204,15 @@ class ServerElectionHandler(MasterHandler):
app = self.app
if node_type != NodeTypes.MASTER:
logging.info('reject a connection from a non-master')
raise protocol.NotReadyError
raise NotReadyError
node = app.nm.getByAddress(address)
if node is None:
logging.error('unknown master node: %s' % (address, ))
raise protocol.ProtocolError('unknown master node')
raise ProtocolError('unknown master node')
# If this node is broken, reject it.
if node.getUUID() == uuid:
if node.isBroken():
raise protocol.BrokenNodeDisallowedError
raise BrokenNodeDisallowedError
# supplied another uuid in case of conflict
while not app.isValidUUID(uuid, address):
......@@ -233,7 +233,7 @@ class ServerElectionHandler(MasterHandler):
def announcePrimary(self, conn):
uuid = conn.getUUID()
if uuid is None:
raise protocol.ProtocolError('Not identified')
raise ProtocolError('Not identified')
app = self.app
if app.primary:
# I am also the primary... So restart the election.
......
......@@ -17,8 +17,8 @@
from neo import logging
from neo import protocol
from neo.protocol import NodeTypes, Packets
from neo.protocol import BrokenNodeDisallowedError, ProtocolError
from neo.master.handlers import MasterHandler
class IdentificationHandler(MasterHandler):
......@@ -40,20 +40,20 @@ class IdentificationHandler(MasterHandler):
if node.getAddress() == address:
# the node is still alive
if node.isBroken():
raise protocol.BrokenNodeDisallowedError
raise BrokenNodeDisallowedError
if node.getAddress() != address:
# this node has changed its address
if node.isRunning():
# still running, reject this new node
raise protocol.ProtocolError('invalid server address')
raise ProtocolError('invalid server address')
if node_by_uuid is None and node_by_addr is not None:
if node.isRunning():
# still running, reject this new node
raise protocol.ProtocolError('invalid server address')
raise ProtocolError('invalid server address')
if node is not None:
if node.isConnected():
# more than one connection from this node
raise protocol.ProtocolError('already connected')
raise ProtocolError('already connected')
node.setAddress(address)
node.setRunning()
......
......@@ -18,8 +18,8 @@
from neo import logging
from neo.handler import EventHandler
from neo.protocol import NodeTypes, Packets
from neo import protocol
from neo.protocol import NodeTypes, Packets, NotReadyError
from neo.protocol import ProtocolError, BrokenNodeDisallowedError
from neo.util import dump
class IdentificationHandler(EventHandler):
......@@ -33,12 +33,12 @@ class IdentificationHandler(EventHandler):
self.checkClusterName(name)
# reject any incoming connections if not ready
if not self.app.ready:
raise protocol.NotReadyError
raise NotReadyError
app = self.app
node = app.nm.getByUUID(uuid)
# If this node is broken, reject it.
if node is not None and node.isBroken():
raise protocol.BrokenNodeDisallowedError
raise BrokenNodeDisallowedError
# choose the handler according to the node type
if node_type == NodeTypes.CLIENT:
from neo.storage.handlers.client import ClientOperationHandler
......@@ -55,9 +55,9 @@ class IdentificationHandler(EventHandler):
handler = StorageOperationHandler
if node is None:
logging.error('reject an unknown storage node %s', dump(uuid))
raise protocol.NotReadyError
raise NotReadyError
else:
raise protocol.ProtocolError('reject non-client-or-storage node')
raise ProtocolError('reject non-client-or-storage node')
# apply the handler and set up the connection
handler = handler(self.app)
conn.setUUID(uuid)
......
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