Commit 64215aef authored by Grégory Wisniewski's avatar Grégory Wisniewski

Use is* methods from Node class, suppress some imports by using protocol.*.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@965 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 62e025e3
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
import logging import logging
from neo.config import ConfigurationManager from neo.config import ConfigurationManager
from neo.protocol import MASTER_NODE_TYPE
from neo.node import NodeManager, MasterNode from neo.node import NodeManager, MasterNode
from neo.event import EventManager from neo.event import EventManager
from neo.connection import ListeningConnection from neo.connection import ListeningConnection
...@@ -103,7 +102,7 @@ class Application(object): ...@@ -103,7 +102,7 @@ class Application(object):
logging.error('primary master is down') logging.error('primary master is down')
# do not trust any longer our informations # do not trust any longer our informations
self.pt.clear() self.pt.clear()
self.nm.clear(filter = lambda node: node.getNodeType() != MASTER_NODE_TYPE) self.nm.clear(filter = lambda node: not node.isMaster())
def connectToPrimaryMaster(self): def connectToPrimaryMaster(self):
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
import logging import logging
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import STORAGE_NODE_TYPE, TEMPORARILY_DOWN_STATE
from neo.node import StorageNode from neo.node import StorageNode
from neo import protocol from neo import protocol
from neo.exception import PrimaryFailure from neo.exception import PrimaryFailure
...@@ -228,7 +227,7 @@ class MasterMonitoringEventHandler(MasterBaseEventHandler): ...@@ -228,7 +227,7 @@ class MasterMonitoringEventHandler(MasterBaseEventHandler):
node = nm.getNodeByUUID(uuid) node = nm.getNodeByUUID(uuid)
if node is None: if node is None:
node = StorageNode(uuid = uuid) node = StorageNode(uuid = uuid)
node.setState(TEMPORARILY_DOWN_STATE) node.setState(protocol.TEMPORARILY_DOWN_STATE)
nm.add(node) nm.add(node)
pt.setCell(offset, node, state) pt.setCell(offset, node, state)
pt.log() pt.log()
......
...@@ -287,7 +287,7 @@ class Application(object): ...@@ -287,7 +287,7 @@ class Application(object):
def notifyDeadNode(self, conn): def notifyDeadNode(self, conn):
""" Notify a storage failure to the primary master """ """ Notify a storage failure to the primary master """
s_node = self.nm.getNodeByServer(conn.getAddress()) s_node = self.nm.getNodeByServer(conn.getAddress())
if s_node is None or s_node.getNodeType() != protocol.STORAGE_NODE_TYPE: if s_node is None or not s_node.isStorage():
return return
s_uuid = s_node.getUUID() s_uuid = s_node.getUUID()
m_conn = self._getMasterConnection() m_conn = self._getMasterConnection()
...@@ -323,10 +323,9 @@ class Application(object): ...@@ -323,10 +323,9 @@ class Application(object):
raise ValueError, 'Expecting an answer from a node ' \ raise ValueError, 'Expecting an answer from a node ' \
'which type is not known... Is this right ?' 'which type is not known... Is this right ?'
else: else:
node_type = node.getType() if node.isStorage():
if node_type == protocol.STORAGE_NODE_TYPE:
handler = self.storage_handler handler = self.storage_handler
elif node_type == protocol.MASTER_NODE_TYPE: elif node.isMaster():
handler = self.primary_handler handler = self.primary_handler
else: else:
raise ValueError, 'Unknown node type: %r' % ( raise ValueError, 'Unknown node type: %r' % (
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging import logging
from ZODB.TimeStamp import TimeStamp
from neo.client.handlers import BaseHandler, AnswerBaseHandler from neo.client.handlers import BaseHandler, AnswerBaseHandler
from neo.protocol import STORAGE_NODE_TYPE from neo import protocol
from ZODB.TimeStamp import TimeStamp
class StorageEventHandler(BaseHandler): class StorageEventHandler(BaseHandler):
...@@ -75,7 +75,7 @@ class StorageBootstrapHandler(AnswerBaseHandler): ...@@ -75,7 +75,7 @@ class StorageBootstrapHandler(AnswerBaseHandler):
app = self.app app = self.app
node = app.nm.getNodeByServer(conn.getAddress()) node = app.nm.getNodeByServer(conn.getAddress())
# It can be eiter a master node or a storage node # It can be eiter a master node or a storage node
if node_type != STORAGE_NODE_TYPE: if node_type != protocol.STORAGE_NODE_TYPE:
conn.close() conn.close()
return return
if conn.getAddress() != address: if conn.getAddress() != address:
......
...@@ -20,7 +20,7 @@ import logging ...@@ -20,7 +20,7 @@ import logging
from neo import protocol from neo import protocol
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
STORAGE_NODE_TYPE, HIDDEN_STATE, PENDING_STATE, RUNNING HIDDEN_STATE, PENDING_STATE, RUNNING
from neo.util import dump from neo.util import dump
class AdministrationHandler(MasterHandler): class AdministrationHandler(MasterHandler):
...@@ -92,13 +92,13 @@ class AdministrationHandler(MasterHandler): ...@@ -92,13 +92,13 @@ class AdministrationHandler(MasterHandler):
conn.answer(p, packet) conn.answer(p, packet)
app.broadcastNodeInformation(node) app.broadcastNodeInformation(node)
# If this is a storage node, ask it to start. # If this is a storage node, ask it to start.
if node.getNodeType() == STORAGE_NODE_TYPE and state == RUNNING_STATE \ if node.isStorage() and state == RUNNING_STATE \
and self.app.cluster_state == RUNNING: and self.app.cluster_state == RUNNING:
logging.info("asking sn to start operation") logging.info("asking sn to start operation")
node_conn.notify(protocol.startOperation()) node_conn.notify(protocol.startOperation())
# modify the partition table if required # modify the partition table if required
if modify_partition_table and node.getNodeType() == STORAGE_NODE_TYPE: if modify_partition_table and node.isStorage():
if state in (DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE): if state in (DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE):
# remove from pt # remove from pt
cell_list = app.pt.dropNode(node) cell_list = app.pt.dropNode(node)
......
...@@ -19,8 +19,7 @@ import logging ...@@ -19,8 +19,7 @@ import logging
from neo.handler import EventHandler from neo.handler import EventHandler
from neo import protocol from neo import protocol
from neo.protocol import RUNNING_STATE, BROKEN_STATE, \ from neo.protocol import RUNNING_STATE, BROKEN_STATE, CLIENT_NODE_TYPE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, \
DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE
from neo.util import dump from neo.util import dump
from neo.node import MasterNode, StorageNode, ClientNode from neo.node import MasterNode, StorageNode, ClientNode
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
import logging import logging
from neo.storage.handlers import BaseStorageHandler from neo.storage.handlers import BaseStorageHandler
from neo.protocol import BROKEN_STATE, STORAGE_NODE_TYPE
from neo import protocol from neo import protocol
from neo.util import dump from neo.util import dump
from neo.node import ClientNode from neo.node import ClientNode
...@@ -59,14 +58,14 @@ class IdentificationHandler(BaseStorageHandler): ...@@ -59,14 +58,14 @@ class IdentificationHandler(BaseStorageHandler):
logging.error('reject an unknown node %s', dump(uuid)) logging.error('reject an unknown node %s', dump(uuid))
raise protocol.NotReadyError raise protocol.NotReadyError
# If this node is broken, reject it. # If this node is broken, reject it.
if node.getState() == BROKEN_STATE: if node.getState() == protocol.BROKEN_STATE:
raise protocol.BrokenNodeDisallowedError raise protocol.BrokenNodeDisallowedError
# apply the handler and set up the connection # apply the handler and set up the connection
handler = handler(self.app) handler = handler(self.app)
conn.setHandler(handler) conn.setHandler(handler)
conn.setUUID(uuid) conn.setUUID(uuid)
node.setUUID(uuid) node.setUUID(uuid)
args = (STORAGE_NODE_TYPE, app.uuid, app.server, args = (protocol.STORAGE_NODE_TYPE, app.uuid, app.server,
app.pt.getPartitions(), app.pt.getReplicas(), uuid) app.pt.getPartitions(), app.pt.getReplicas(), uuid)
# accept the identification and trigger an event # accept the identification and trigger an event
conn.answer(protocol.acceptNodeIdentification(*args), packet) conn.answer(protocol.acceptNodeIdentification(*args), packet)
......
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