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