Commit 3cbc4ef7 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove cyclic imports found by pylint.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@953 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 203fb855
...@@ -26,10 +26,7 @@ from neo.client.mq import MQ ...@@ -26,10 +26,7 @@ from neo.client.mq import MQ
from neo.node import NodeManager, MasterNode, StorageNode from neo.node import NodeManager, MasterNode, StorageNode
from neo.connection import MTClientConnection from neo.connection import MTClientConnection
from neo import protocol from neo import protocol
from neo.client.handlers.master import PrimaryBootstrapHandler, \ from neo.client.handlers import storage, master
PrimaryNotificationsHandler, PrimaryAnswersHandler
from neo.client.handlers.storage import StorageBootstrapHandler, \
StorageAnswersHandler, StorageEventHandler
from neo.client.exception import NEOStorageError, NEOStorageConflictError, \ from neo.client.exception import NEOStorageError, NEOStorageConflictError, \
NEOStorageNotFoundError NEOStorageNotFoundError
from neo.exception import NeoException from neo.exception import NeoException
...@@ -253,12 +250,13 @@ class Application(object): ...@@ -253,12 +250,13 @@ class Application(object):
self.mq_cache = MQ() self.mq_cache = MQ()
self.new_oid_list = [] self.new_oid_list = []
self.ptid = None self.ptid = None
self.storage_event_handler = StorageEventHandler(self, self.dispatcher) self.storage_event_handler = storage.StorageEventHandler(self, self.dispatcher)
self.storage_bootstrap_handler = StorageBootstrapHandler(self) self.storage_bootstrap_handler = storage.StorageBootstrapHandler(self)
self.storage_handler = StorageAnswersHandler(self) self.storage_handler = handler.storage.StorageAnswersHandler(self)
self.primary_handler = PrimaryAnswersHandler(self) self.primary_handler = master.PrimaryAnswersHandler(self)
self.primary_bootstrap_handler = PrimaryBootstrapHandler(self) self.primary_bootstrap_handler = master.PrimaryBootstrapHandler(self)
self.notifications_handler = PrimaryNotificationsHandler(self, self.dispatcher) self.notifications_handler = master.PrimaryNotificationsHandler(
self, self.dispatcher)
# Internal attribute distinct between thread # Internal attribute distinct between thread
self.local_var = ThreadContext() self.local_var = ThreadContext()
# Lock definition : # Lock definition :
......
...@@ -91,11 +91,3 @@ class AnswerBaseHandler(EventHandler): ...@@ -91,11 +91,3 @@ class AnswerBaseHandler(EventHandler):
packetReceived = unexpectedInAnswerHandler packetReceived = unexpectedInAnswerHandler
peerBroken = unexpectedInAnswerHandler peerBroken = unexpectedInAnswerHandler
from neo.client.handlers.master import PrimaryBootstrapHandler
from neo.client.handlers.master import PrimaryNotificationsHandler
from neo.client.handlers.master import PrimaryAnswersHandler
from neo.client.handlers.storage import StorageEventHandler
from neo.client.handlers.storage import StorageBootstrapHandler
from neo.client.handlers.storage import StorageAnswersHandler
...@@ -31,7 +31,9 @@ from neo.event import EventManager ...@@ -31,7 +31,9 @@ from neo.event import EventManager
from neo.connection import ListeningConnection, ClientConnection, ServerConnection from neo.connection import ListeningConnection, ClientConnection, ServerConnection
from neo.exception import ElectionFailure, PrimaryFailure, VerificationFailure, \ from neo.exception import ElectionFailure, PrimaryFailure, VerificationFailure, \
OperationFailure OperationFailure
from neo.master import handlers from neo.master.handlers import election, identification, secondary, recovery
from neo.master.handlers import verification, storage, client, shutdown
from neo.master.handlers import administration
from neo.master.pt import PartitionTable from neo.master.pt import PartitionTable
from neo.util import dump from neo.util import dump
from neo.connector import getConnectorHandler from neo.connector import getConnectorHandler
...@@ -123,8 +125,8 @@ class Application(object): ...@@ -123,8 +125,8 @@ class Application(object):
self.unconnected_master_node_set = set() self.unconnected_master_node_set = set()
self.negotiating_master_node_set = set() self.negotiating_master_node_set = set()
self.listening_conn.setHandler(handlers.ServerElectionHandler(self)) self.listening_conn.setHandler(election.ServerElectionHandler(self))
client_handler = handlers.ClientElectionHandler(self) client_handler = election.ClientElectionHandler(self)
em = self.em em = self.em
nm = self.nm nm = self.nm
...@@ -586,7 +588,7 @@ class Application(object): ...@@ -586,7 +588,7 @@ class Application(object):
dump(self.uuid), *(self.server)) dump(self.uuid), *(self.server))
# all incoming connections identify through this handler # all incoming connections identify through this handler
self.listening_conn.setHandler(handlers.IdentificationHandler(self)) self.listening_conn.setHandler(identification.IdentificationHandler(self))
# If I know any storage node, make sure that they are not in the running state, # If I know any storage node, make sure that they are not in the running state,
# because they are not connected at this stage. # because they are not connected at this stage.
...@@ -609,7 +611,7 @@ class Application(object): ...@@ -609,7 +611,7 @@ class Application(object):
logging.info('play the secondary role with %s (%s:%d)', logging.info('play the secondary role with %s (%s:%d)',
dump(self.uuid), *(self.server)) dump(self.uuid), *(self.server))
handler = handlers.PrimaryMasterHandler(self) handler = secondary.PrimaryMasterHandler(self)
em = self.em em = self.em
# Make sure that every connection has the secondary event handler. # Make sure that every connection has the secondary event handler.
...@@ -627,13 +629,13 @@ class Application(object): ...@@ -627,13 +629,13 @@ class Application(object):
# select the storage handler # select the storage handler
if state == protocol.BOOTING: if state == protocol.BOOTING:
storage_handler = handlers.RecoveryHandler storage_handler = recovery.RecoveryHandler
elif state == protocol.RECOVERING: elif state == protocol.RECOVERING:
storage_handler = handlers.RecoveryHandler storage_handler = recovery.RecoveryHandler
elif state == protocol.VERIFYING: elif state == protocol.VERIFYING:
storage_handler = handlers.VerificationHandler storage_handler = verification.VerificationHandler
elif state == protocol.RUNNING: elif state == protocol.RUNNING:
storage_handler = handlers.StorageServiceHandler storage_handler = storage.StorageServiceHandler
else: else:
RuntimeError('Unexpected node type') RuntimeError('Unexpected node type')
...@@ -652,7 +654,7 @@ class Application(object): ...@@ -652,7 +654,7 @@ class Application(object):
if node_type == CLIENT_NODE_TYPE: if node_type == CLIENT_NODE_TYPE:
if state != protocol.RUNNING: if state != protocol.RUNNING:
conn.close() conn.close()
handler = handlers.ClientServiceHandler handler = client.ClientServiceHandler
elif node_type == STORAGE_NODE_TYPE: elif node_type == STORAGE_NODE_TYPE:
handler = storage_handler handler = storage_handler
handler = handler(self) handler = handler(self)
...@@ -722,7 +724,7 @@ class Application(object): ...@@ -722,7 +724,7 @@ class Application(object):
def shutdown(self): def shutdown(self):
"""Close all connections and exit""" """Close all connections and exit"""
# change handler # change handler
handler = handlers.ShutdownHandler(self) handler = shutdown.ShutdownHandler(self)
for c in self.em.getConnectionList(): for c in self.em.getConnectionList():
c.setHandler(handler) c.setHandler(handler)
...@@ -763,20 +765,20 @@ class Application(object): ...@@ -763,20 +765,20 @@ class Application(object):
if uuid is None: if uuid is None:
logging.info('reject empty storage node') logging.info('reject empty storage node')
raise protocol.NotReadyError raise protocol.NotReadyError
handler = handlers.RecoveryHandler handler = recovery.RecoveryHandler
elif self.cluster_state == protocol.VERIFYING: elif self.cluster_state == protocol.VERIFYING:
if uuid is None or node is None: if uuid is None or node is None:
# if node is unknown, it has been forget when the current # if node is unknown, it has been forget when the current
# partition was validated by the admin # partition was validated by the admin
uuid = None uuid = None
state = protocol.PENDING_STATE state = protocol.PENDING_STATE
handler = handlers.VerificationHandler handler = verification.VerificationHandler
elif self.cluster_state == protocol.RUNNING: elif self.cluster_state == protocol.RUNNING:
if uuid is None or node is None: if uuid is None or node is None:
# same as for verification # same as for verification
uuid = None uuid = None
state = protocol.PENDING_STATE state = protocol.PENDING_STATE
handler = handlers.StorageServiceHandler handler = storage.StorageServiceHandler
elif self.cluster_state == protocol.STOPPING: elif self.cluster_state == protocol.STOPPING:
# FIXME: raise a ShutdowningError ? # FIXME: raise a ShutdowningError ?
raise protocol.NotReadyError raise protocol.NotReadyError
...@@ -787,17 +789,17 @@ class Application(object): ...@@ -787,17 +789,17 @@ class Application(object):
def identifyNode(self, node_type, uuid, node): def identifyNode(self, node_type, uuid, node):
state = protocol.RUNNING_STATE state = protocol.RUNNING_STATE
handler = handlers.IdentificationHandler handler = identification.IdentificationHandler
if node_type == protocol.ADMIN_NODE_TYPE: if node_type == protocol.ADMIN_NODE_TYPE:
# always accept admin nodes # always accept admin nodes
klass = AdminNode klass = AdminNode
handler = handlers.AdministrationHandler handler = administration.AdministrationHandler
logging.info('Accept an admin %s' % dump(uuid)) logging.info('Accept an admin %s' % dump(uuid))
elif node_type == protocol.MASTER_NODE_TYPE: elif node_type == protocol.MASTER_NODE_TYPE:
# always put other master in waiting state # always put other master in waiting state
klass = MasterNode klass = MasterNode
handler = handlers.SecondaryMasterHandler handler = secondary.SecondaryMasterHandler
logging.info('Accept a master %s' % dump(uuid)) logging.info('Accept a master %s' % dump(uuid))
elif node_type == protocol.CLIENT_NODE_TYPE: elif node_type == protocol.CLIENT_NODE_TYPE:
# refuse any client before running # refuse any client before running
...@@ -805,7 +807,7 @@ class Application(object): ...@@ -805,7 +807,7 @@ class Application(object):
logging.info('reject a connection from a client') logging.info('reject a connection from a client')
raise protocol.NotReadyError raise protocol.NotReadyError
klass = ClientNode klass = ClientNode
handler = handlers.ClientServiceHandler handler = client.ClientServiceHandler
logging.info('Accept a client %s' % dump(uuid)) logging.info('Accept a client %s' % dump(uuid))
elif node_type == protocol.STORAGE_NODE_TYPE: elif node_type == protocol.STORAGE_NODE_TYPE:
klass = StorageNode klass = StorageNode
......
...@@ -159,14 +159,3 @@ class BaseServiceHandler(MasterHandler): ...@@ -159,14 +159,3 @@ class BaseServiceHandler(MasterHandler):
p = protocol.answerUnfinishedTransactions(app.finishing_transaction_dict.keys()) p = protocol.answerUnfinishedTransactions(app.finishing_transaction_dict.keys())
conn.answer(p, packet) conn.answer(p, packet)
# Import all master handlers in the current namespace
from neo.master.handlers.administration import AdministrationHandler
from neo.master.handlers.election import ClientElectionHandler, ServerElectionHandler
from neo.master.handlers.identification import IdentificationHandler
from neo.master.handlers.recovery import RecoveryHandler
from neo.master.handlers.secondary import SecondaryMasterHandler, PrimaryMasterHandler
from neo.master.handlers.shutdown import ShutdownHandler
from neo.master.handlers.verification import VerificationHandler
from neo.master.handlers.storage import StorageServiceHandler
from neo.master.handlers.client import ClientServiceHandler
...@@ -28,7 +28,8 @@ from neo.event import EventManager ...@@ -28,7 +28,8 @@ from neo.event import EventManager
from neo.storage.mysqldb import MySQLDatabaseManager from neo.storage.mysqldb import MySQLDatabaseManager
from neo.connection import ListeningConnection from neo.connection import ListeningConnection
from neo.exception import OperationFailure, PrimaryFailure from neo.exception import OperationFailure, PrimaryFailure
from neo.storage import handlers from neo.storage.handlers import identification, verification, initialization
from neo.storage.handlers import master, hidden
from neo.storage.replicator import Replicator from neo.storage.replicator import Replicator
from neo.connector import getConnectorHandler from neo.connector import getConnectorHandler
from neo.pt import PartitionTable from neo.pt import PartitionTable
...@@ -125,7 +126,7 @@ class Application(object): ...@@ -125,7 +126,7 @@ class Application(object):
self.nm.add(MasterNode(server = server)) self.nm.add(MasterNode(server = server))
# Make a listening port # Make a listening port
handler = handlers.IdentificationHandler(self) handler = identification.IdentificationHandler(self)
self.listening_conn = ListeningConnection(self.em, handler, self.listening_conn = ListeningConnection(self.em, handler,
addr=self.server, connector_handler=self.connector_handler) addr=self.server, connector_handler=self.connector_handler)
...@@ -202,7 +203,7 @@ class Application(object): ...@@ -202,7 +203,7 @@ class Application(object):
Connections from client nodes may not be accepted at this stage.""" Connections from client nodes may not be accepted at this stage."""
logging.info('verifying data') logging.info('verifying data')
handler = handlers.VerificationHandler(self) handler = verification.VerificationHandler(self)
self.master_conn.setHandler(handler) self.master_conn.setHandler(handler)
em = self.em em = self.em
...@@ -212,7 +213,7 @@ class Application(object): ...@@ -212,7 +213,7 @@ class Application(object):
def initialize(self): def initialize(self):
""" Retreive partition table and node informations from the primary """ """ Retreive partition table and node informations from the primary """
logging.debug('initializing...') logging.debug('initializing...')
handler = handlers.InitializationHandler(self) handler = initialization.InitializationHandler(self)
self.master_conn.setHandler(handler) self.master_conn.setHandler(handler)
# ask node list and partition table # ask node list and partition table
...@@ -233,7 +234,7 @@ class Application(object): ...@@ -233,7 +234,7 @@ class Application(object):
em = self.em em = self.em
handler = handlers.MasterOperationHandler(self) handler = master.MasterOperationHandler(self)
self.master_conn.setHandler(handler) self.master_conn.setHandler(handler)
# Forget all unfinished data. # Forget all unfinished data.
...@@ -266,7 +267,7 @@ class Application(object): ...@@ -266,7 +267,7 @@ class Application(object):
def wait(self): def wait(self):
# change handler # change handler
logging.info("waiting in hidden state") logging.info("waiting in hidden state")
handler = handlers.HiddenHandler(self) handler = hidden.HiddenHandler(self)
for conn in self.em.getConnectionList(): for conn in self.em.getConnectionList():
conn.setHandler(handler) conn.setHandler(handler)
......
...@@ -137,13 +137,3 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler): ...@@ -137,13 +137,3 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler):
p = protocol.oidNotFound('%s does not exist' % dump(oid)) p = protocol.oidNotFound('%s does not exist' % dump(oid))
conn.answer(p, packet) conn.answer(p, packet)
# import all handlers in the current namespace
from neo.storage.handlers.identification import IdentificationHandler
from neo.storage.handlers.initialization import InitializationHandler
from neo.storage.handlers.verification import VerificationHandler
from neo.storage.handlers.replication import ReplicationHandler
from neo.storage.handlers.storage import StorageOperationHandler
from neo.storage.handlers.master import MasterOperationHandler
from neo.storage.handlers.client import ClientOperationHandler
from neo.storage.handlers.hidden import HiddenHandler
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