Commit d256c5b3 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Move handler decorators to their own file to simplify imports.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@667 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent e27a2a69
......@@ -28,7 +28,7 @@ from neo.protocol import Packet, UnexpectedPacketError
from neo.pt import PartitionTable
from neo.exception import PrimaryFailure
from neo.util import dump
from neo.handler import identification_required, restrict_node_types
from neo import decorators
class BaseEventHandler(EventHandler):
......@@ -312,7 +312,7 @@ class MonitoringEventHandler(BaseEventHandler):
conn.close()
@identification_required
@decorators.identification_required
def handleSendPartitionTable(self, conn, packet, ptid, row_list):
logging.warning("handleSendPartitionTable")
uuid = conn.getUUID()
......@@ -338,7 +338,7 @@ class MonitoringEventHandler(BaseEventHandler):
pt.log()
@identification_required
@decorators.identification_required
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
logging.warning("handleNotifyPartitionChanges")
app = self.app
......@@ -368,7 +368,7 @@ class MonitoringEventHandler(BaseEventHandler):
pt.log()
@identification_required
@decorators.identification_required
def handleNotifyNodeInformation(self, conn, packet, node_list):
logging.info("handleNotifyNodeInformation")
uuid = conn.getUUID()
......
......@@ -30,7 +30,7 @@ from neo.pt import MTPartitionTable as PartitionTable
from neo.client.exception import NEOStorageError
from neo.exception import ElectionFailure
from neo.util import dump
from neo.handler import identification_required, restrict_node_types
from neo import decorators
from ZODB.TimeStamp import TimeStamp
from ZODB.utils import p64
......@@ -192,7 +192,7 @@ class PrimaryBootstrapHandler(PrimaryHandler):
finally:
conn.unlock()
@identification_required
@decorators.identification_required
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid, known_master_list):
uuid = conn.getUUID()
app = self.app
......@@ -232,7 +232,7 @@ class PrimaryBootstrapHandler(PrimaryHandler):
# Whatever the situation is, I trust this master.
app.primary_master_node = primary_node
@identification_required
@decorators.identification_required
def handleSendPartitionTable(self, conn, packet, ptid, row_list):
# This handler is in PrimaryBootstrapHandler, since this
# basicaly is an answer to askPrimaryMaster.
......
#
# Copyright (C) 2006-2009 Nexedi SA
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import protocol
# Some decorators useful to avoid duplication of patterns in handlers
def check_cluster_name(handler):
def wrapper(self, conn, packet, name, *args, **kwargs):
if self.app.name != name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError('invalid cluster name')
handler(self, conn, packet, name, *args, **kwargs)
return wrapper
def identification_required(handler):
""" Raise UnexpectedPacketError if the identification has not succeed """
def wrapper(self, conn, packet, *args, **kwargs):
# check if node identification succeed
if conn.getUUID() is None:
raise protocol.UnexpectedPacketError
# identified, call the handler
handler(self, conn, packet, *args, **kwargs)
return wrapper
def restrict_node_types(*node_types):
""" Raise UnexpectedPacketError if the node type is node in the supplied
list, if the uuid is None or if the node is not known. This decorator
should be applied after identification_required """
def inner(handler):
def wrapper(self, conn, packet, *args, **kwargs):
# check if node type is allowed
uuid = conn.getUUID()
if uuid is None:
raise protocol.UnexpectedPacketError
node = self.app.nm.getNodeByUUID(uuid)
if node is None:
raise protocol.UnexpectedPacketError
if node.getNodeType() not in node_types:
raise protocol.UnexpectedPacketError
# all is ok, call the handler
handler(self, conn, packet, *args, **kwargs)
return wrapper
return inner
def client_connection_required(handler):
""" Raise UnexpectedPacketError if the packet comes from a client connection """
def wrapper(self, conn, packet, *args, **kwargs):
if conn.isServerConnection():
raise protocol.UnexpectedPacketError
# it's a client connection, call the handler
handler(self, conn, packet, *args, **kwargs)
return wrapper
def server_connection_required(handler):
""" Raise UnexpectedPacketError if the packet comes from a server connection """
def wrapper(self, conn, packet, *args, **kwargs):
if not conn.isServerConnection():
raise protocol.UnexpectedPacketError
# it's a server connection, call the handler
handler(self, conn, packet, *args, **kwargs)
return wrapper
......@@ -44,57 +44,6 @@ from protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICAT
ANSWER_CLUSTER_STATE, ASK_NODE_INFORMATION, ANSWER_NODE_INFORMATION
# Some decorators useful to avoid duplication of patterns in handlers
# FIXME: they may be applied on generic handler
def identification_required(handler):
""" Raise UnexpectedPacketError if the identification has not succeed """
def wrapper(self, conn, packet, *args, **kwargs):
# check if node identification succeed
if conn.getUUID() is None:
raise UnexpectedPacketError
# identified, call the handler
handler(self, conn, packet, *args, **kwargs)
return wrapper
def restrict_node_types(*node_types):
""" Raise UnexpectedPacketError if the node type is node in the supplied
list, if the uuid is None or if the node is not known. This decorator
should be applied after identification_required """
def inner(handler):
def wrapper(self, conn, packet, *args, **kwargs):
# check if node type is allowed
uuid = conn.getUUID()
if uuid is None:
raise UnexpectedPacketError
node = self.app.nm.getNodeByUUID(uuid)
if node is None:
raise UnexpectedPacketError
if node.getNodeType() not in node_types:
raise UnexpectedPacketError
# all is ok, call the handler
handler(self, conn, packet, *args, **kwargs)
return wrapper
return inner
def client_connection_required(handler):
""" Raise UnexpectedPacketError if the packet comes from a client connection """
def wrapper(self, conn, packet, *args, **kwargs):
if conn.isServerConnection():
raise UnexpectedPacketError
# it's a client connection, call the handler
handler(self, conn, packet, *args, **kwargs)
return wrapper
def server_connection_required(handler):
""" Raise UnexpectedPacketError if the packet comes from a server connection """
def wrapper(self, conn, packet, *args, **kwargs):
if not conn.isServerConnection():
raise UnexpectedPacketError
# it's a server connection, call the handler
handler(self, conn, packet, *args, **kwargs)
return wrapper
class EventHandler(object):
"""This class handles events."""
def __init__(self):
......
......@@ -26,8 +26,7 @@ from neo.connection import ClientConnection
from neo.exception import ElectionFailure
from neo.protocol import Packet, UnexpectedPacketError, INVALID_UUID
from neo.node import MasterNode, StorageNode, ClientNode
from neo.handler import identification_required, restrict_node_types, \
client_connection_required, server_connection_required
from neo import decorators
class ElectionEventHandler(MasterEventHandler):
"""This class deals with events for a primary master election."""
......@@ -89,7 +88,7 @@ class ElectionEventHandler(MasterEventHandler):
node.setState(RUNNING_STATE)
MasterEventHandler.packetReceived(self, conn, packet)
@client_connection_required
@decorators.client_connection_required
def handleAcceptNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, num_partitions,
num_replicas, your_uuid):
......@@ -123,7 +122,7 @@ class ElectionEventHandler(MasterEventHandler):
# Ask a primary master.
conn.ask(protocol.askPrimaryMaster())
@client_connection_required
@decorators.client_connection_required
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid, known_master_list):
app = self.app
# Register new master nodes.
......@@ -169,7 +168,7 @@ class ElectionEventHandler(MasterEventHandler):
app.negotiating_master_node_set.discard(conn.getAddress())
@server_connection_required
@decorators.server_connection_required
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
app = self.app
......@@ -205,8 +204,8 @@ class ElectionEventHandler(MasterEventHandler):
# Next, the peer should ask a primary master node.
conn.answer(p, packet)
@identification_required
@server_connection_required
@decorators.identification_required
@decorators.server_connection_required
def handleAskPrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
app = self.app
......@@ -226,8 +225,8 @@ class ElectionEventHandler(MasterEventHandler):
p = protocol.answerPrimaryMaster(primary_uuid, known_master_list)
conn.answer(p, packet)
@identification_required
@server_connection_required
@decorators.identification_required
@decorators.server_connection_required
def handleAnnouncePrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
app = self.app
......@@ -243,7 +242,7 @@ class ElectionEventHandler(MasterEventHandler):
def handleReelectPrimaryMaster(self, conn, packet):
raise ElectionFailure, 'reelection requested'
@identification_required
@decorators.identification_required
def handleNotifyNodeInformation(self, conn, packet, node_list):
uuid = conn.getUUID()
app = self.app
......
......@@ -26,7 +26,7 @@ from neo.exception import ElectionFailure
from neo.protocol import Packet, UnexpectedPacketError, INVALID_UUID, INVALID_PTID
from neo.node import ClientNode, StorageNode, MasterNode, AdminNode
from neo.util import dump
from neo.handler import identification_required, restrict_node_types
from neo import decorators
class RecoveryEventHandler(MasterEventHandler):
"""This class deals with events for a recovery phase."""
......@@ -169,7 +169,7 @@ class RecoveryEventHandler(MasterEventHandler):
# Next, the peer should ask a primary master node.
conn.answer(p, packet)
@identification_required
@decorators.identification_required
def handleAskPrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
app = self.app
......@@ -193,7 +193,7 @@ class RecoveryEventHandler(MasterEventHandler):
(dump(app.pt.getID()), conn.getAddress()))
app.sendPartitionTable(conn)
@identification_required
@decorators.identification_required
def handleAnnouncePrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
# I am also the primary... So restart the election.
......@@ -202,7 +202,7 @@ class RecoveryEventHandler(MasterEventHandler):
def handleReelectPrimaryMaster(self, conn, packet):
raise ElectionFailure, 'reelection requested'
@identification_required
@decorators.identification_required
def handleNotifyNodeInformation(self, conn, packet, node_list):
uuid = conn.getUUID()
app = self.app
......@@ -253,8 +253,8 @@ class RecoveryEventHandler(MasterEventHandler):
node.setState(state)
app.broadcastNodeInformation(node)
@identification_required
@restrict_node_types(STORAGE_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(STORAGE_NODE_TYPE)
def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid):
uuid = conn.getUUID()
app = self.app
......@@ -275,8 +275,8 @@ class RecoveryEventHandler(MasterEventHandler):
elif app.pt.getID() == lptid and app.target_uuid is None:
app.target_uuid = uuid
@identification_required
@restrict_node_types(STORAGE_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(STORAGE_NODE_TYPE)
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list):
uuid = conn.getUUID()
app = self.app
......
......@@ -26,8 +26,7 @@ from neo.connection import ClientConnection
from neo.exception import ElectionFailure, PrimaryFailure
from neo.protocol import Packet, UnexpectedPacketError, INVALID_UUID
from neo.node import MasterNode
from neo.handler import identification_required, restrict_node_types, \
client_connection_required, server_connection_required
from neo import decorators
class SecondaryEventHandler(MasterEventHandler):
"""This class deals with events for a secondary master."""
......@@ -57,7 +56,7 @@ class SecondaryEventHandler(MasterEventHandler):
node.setState(RUNNING_STATE)
MasterEventHandler.packetReceived(self, conn, packet)
@server_connection_required
@decorators.server_connection_required
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
app = self.app
......@@ -85,8 +84,8 @@ class SecondaryEventHandler(MasterEventHandler):
# Next, the peer should ask a primary master node.
conn.answer(p, packet)
@identification_required
@server_connection_required
@decorators.identification_required
@decorators.server_connection_required
def handleAskPrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
app = self.app
......
......@@ -28,9 +28,9 @@ from neo.master.handler import MasterEventHandler
from neo.protocol import Packet, UnexpectedPacketError, INVALID_UUID
from neo.exception import OperationFailure, ElectionFailure
from neo.node import ClientNode, StorageNode, MasterNode, AdminNode
from neo.handler import identification_required, restrict_node_types
from neo.util import dump
from neo.master import ENABLE_PENDING_NODES
from neo import decorators
class FinishingTransaction(object):
"""This class describes a finishing transaction."""
......@@ -274,7 +274,7 @@ class ServiceEventHandler(MasterEventHandler):
# Next, the peer should ask a primary master node.
conn.answer(p, packet)
@identification_required
@decorators.identification_required
def handleAskPrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
app = self.app
......@@ -298,7 +298,7 @@ class ServiceEventHandler(MasterEventHandler):
if node.getNodeType() == STORAGE_NODE_TYPE and node.getState() != PENDING_STATE:
conn.notify(protocol.startOperation())
@identification_required
@decorators.identification_required
def handleAnnouncePrimaryMaster(self, conn, packet):
# I am also the primary... So restart the election.
raise ElectionFailure, 'another primary arises'
......@@ -306,7 +306,7 @@ class ServiceEventHandler(MasterEventHandler):
def handleReelectPrimaryMaster(self, conn, packet):
raise ElectionFailure, 'reelection requested'
@identification_required
@decorators.identification_required
def handleNotifyNodeInformation(self, conn, packet, node_list):
app = self.app
uuid = conn.getUUID()
......@@ -378,8 +378,8 @@ class ServiceEventHandler(MasterEventHandler):
ptid = app.getNextPartitionTableID()
app.broadcastPartitionChanges(ptid, cell_list)
@identification_required
@restrict_node_types(STORAGE_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(STORAGE_NODE_TYPE)
def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid):
uuid = conn.getUUID()
app = self.app
......@@ -389,8 +389,8 @@ class ServiceEventHandler(MasterEventHandler):
logging.critical('got later information in service')
raise OperationFailure
@identification_required
@restrict_node_types(CLIENT_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(CLIENT_NODE_TYPE)
def handleAskNewTID(self, conn, packet):
uuid = conn.getUUID()
app = self.app
......@@ -399,8 +399,8 @@ class ServiceEventHandler(MasterEventHandler):
app.finishing_transaction_dict[tid] = FinishingTransaction(conn)
conn.answer(protocol.answerNewTID(tid), packet)
@identification_required
@restrict_node_types(CLIENT_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(CLIENT_NODE_TYPE)
def handleAskNewOIDs(self, conn, packet, num_oids):
uuid = conn.getUUID()
app = self.app
......@@ -408,8 +408,8 @@ class ServiceEventHandler(MasterEventHandler):
oid_list = app.getNewOIDList(num_oids)
conn.answer(protocol.answerNewOIDs(oid_list), packet)
@identification_required
@restrict_node_types(CLIENT_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(CLIENT_NODE_TYPE)
def handleFinishTransaction(self, conn, packet, oid_list, tid):
uuid = conn.getUUID()
app = self.app
......@@ -449,8 +449,8 @@ class ServiceEventHandler(MasterEventHandler):
logging.warn('finishing transaction %s does not exist', dump(tid))
pass
@identification_required
@restrict_node_types(STORAGE_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(STORAGE_NODE_TYPE)
def handleNotifyInformationLocked(self, conn, packet, tid):
uuid = conn.getUUID()
app = self.app
......@@ -489,8 +489,8 @@ class ServiceEventHandler(MasterEventHandler):
# What is this?
pass
@identification_required
@restrict_node_types(CLIENT_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(CLIENT_NODE_TYPE)
def handleAbortTransaction(self, conn, packet, tid):
uuid = conn.getUUID()
node = self.app.nm.getNodeByUUID(uuid)
......@@ -500,19 +500,19 @@ class ServiceEventHandler(MasterEventHandler):
logging.warn('aborting transaction %s does not exist', dump(tid))
pass
@identification_required
@decorators.identification_required
def handleAskLastIDs(self, conn, packet):
app = self.app
conn.answer(protocol.answerLastIDs(app.loid, app.ltid, app.pt.getID()), packet)
@identification_required
@decorators.identification_required
def handleAskUnfinishedTransactions(self, conn, packet):
app = self.app
p = protocol.answerUnfinishedTransactions(app.finishing_transaction_dict.keys())
conn.answer(p, packet)
@identification_required
@restrict_node_types(STORAGE_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(STORAGE_NODE_TYPE)
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
# This should be sent when a cell becomes up-to-date because
# a replication has finished.
......@@ -560,8 +560,8 @@ class ServiceEventHandler(MasterEventHandler):
app.broadcastPartitionChanges(ptid, new_cell_list)
@identification_required
@restrict_node_types(ADMIN_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(ADMIN_NODE_TYPE)
def handleSetNodeState(self, conn, packet, uuid, state, modify_partition_table):
logging.info("set node state for %s-%s : %s" %(dump(uuid), state, modify_partition_table))
app = self.app
......@@ -624,6 +624,8 @@ class ServiceEventHandler(MasterEventHandler):
ptid = app.getNextPartitionTableID()
app.broadcastPartitionChanges(ptid, cell_list)
@decorators.identification_required
@decorators.restrict_node_types(ADMIN_NODE_TYPE)
def handleAddPendingNodes(self, conn, packet, uuid_list):
uuids = ', '.join([dump(uuid) for uuid in uuid_list])
logging.debug('Add nodes %s' % uuids)
......
......@@ -26,7 +26,7 @@ from neo.exception import VerificationFailure, ElectionFailure
from neo.protocol import Packet, UnexpectedPacketError, INVALID_UUID
from neo.util import dump
from neo.node import ClientNode, StorageNode, MasterNode, AdminNode
from neo.handler import identification_required, restrict_node_types
from neo import decorators
class VerificationEventHandler(MasterEventHandler):
"""This class deals with events for a verification phase."""
......@@ -192,7 +192,7 @@ class VerificationEventHandler(MasterEventHandler):
# Next, the peer should ask a primary master node.
conn.answer(p, packet)
@identification_required
@decorators.identification_required
def handleAskPrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
app = self.app
......@@ -210,7 +210,7 @@ class VerificationEventHandler(MasterEventHandler):
if node.getNodeType() in (STORAGE_NODE_TYPE, ADMIN_NODE_TYPE):
app.sendPartitionTable(conn)
@identification_required
@decorators.identification_required
def handleAnnouncePrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
# I am also the primary... So restart the election.
......@@ -219,7 +219,7 @@ class VerificationEventHandler(MasterEventHandler):
def handleReelectPrimaryMaster(self, conn, packet):
raise ElectionFailure, 'reelection requested'
@identification_required
@decorators.identification_required
def handleNotifyNodeInformation(self, conn, packet, node_list):
uuid = conn.getUUID()
app = self.app
......@@ -270,8 +270,8 @@ class VerificationEventHandler(MasterEventHandler):
node.setState(state)
app.broadcastNodeInformation(node)
@identification_required
@restrict_node_types(STORAGE_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(STORAGE_NODE_TYPE)
def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid):
uuid = conn.getUUID()
app = self.app
......@@ -285,8 +285,8 @@ class VerificationEventHandler(MasterEventHandler):
# Ignore this packet.
pass
@identification_required
@restrict_node_types(STORAGE_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(STORAGE_NODE_TYPE)
def handleAnswerUnfinishedTransactions(self, conn, packet, tid_list):
uuid = conn.getUUID()
logging.info('got unfinished transactions %s from %s:%d',
......@@ -299,8 +299,8 @@ class VerificationEventHandler(MasterEventHandler):
app.unfinished_tid_set.update(tid_list)
app.asking_uuid_dict[uuid] = True
@identification_required
@restrict_node_types(STORAGE_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(STORAGE_NODE_TYPE)
def handleAnswerTransactionInformation(self, conn, packet, tid,
user, desc, ext, oid_list):
uuid = conn.getUUID()
......@@ -322,8 +322,8 @@ class VerificationEventHandler(MasterEventHandler):
app.unfinished_oid_set = None
app.asking_uuid_dict[uuid] = True
@identification_required
@restrict_node_types(STORAGE_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(STORAGE_NODE_TYPE)
def handleTidNotFound(self, conn, packet, message):
uuid = conn.getUUID()
logging.info('TID not found: %s', message)
......@@ -335,8 +335,8 @@ class VerificationEventHandler(MasterEventHandler):
app.unfinished_oid_set = None
app.asking_uuid_dict[uuid] = True
@identification_required
@restrict_node_types(STORAGE_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(STORAGE_NODE_TYPE)
def handleAnswerObjectPresent(self, conn, packet, oid, tid):
uuid = conn.getUUID()
logging.info('object %s:%s found', dump(oid), dump(tid))
......@@ -347,8 +347,8 @@ class VerificationEventHandler(MasterEventHandler):
return
app.asking_uuid_dict[uuid] = True
@identification_required
@restrict_node_types(STORAGE_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(STORAGE_NODE_TYPE)
def handleOidNotFound(self, conn, packet, message):
uuid = conn.getUUID()
logging.info('OID not found: %s', message)
......
......@@ -28,7 +28,7 @@ from neo.protocol import Packet, UnexpectedPacketError
from neo.pt import PartitionTable
from neo.exception import OperationFailure
from neo.util import dump
from neo.handler import identification_required, restrict_node_types
from neo import decorators
class CommandEventHandler(EventHandler):
""" Base handler for command """
......
......@@ -27,8 +27,7 @@ from neo.protocol import Packet, UnexpectedPacketError
from neo.pt import PartitionTable
from neo.storage.verification import VerificationEventHandler
from neo.util import dump
from neo.handler import identification_required, restrict_node_types, \
server_connection_required, client_connection_required
from neo import decorators
class BootstrapEventHandler(StorageEventHandler):
"""This class deals with events for a bootstrap phase."""
......@@ -107,7 +106,7 @@ class BootstrapEventHandler(StorageEventHandler):
conn.close()
@server_connection_required
@decorators.server_connection_required
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
app = self.app
......@@ -140,7 +139,7 @@ class BootstrapEventHandler(StorageEventHandler):
# Now the master node should know that I am not the right one.
conn.abort()
@client_connection_required
@decorators.client_connection_required
def handleAcceptNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port,
num_partitions, num_replicas, your_uuid):
......@@ -188,7 +187,7 @@ class BootstrapEventHandler(StorageEventHandler):
# Ask a primary master.
conn.ask(protocol.askPrimaryMaster())
@client_connection_required
@decorators.client_connection_required
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid,
known_master_list):
app = self.app
......
......@@ -27,7 +27,7 @@ from neo.util import dump
from neo.node import MasterNode, StorageNode, ClientNode
from neo.connection import ClientConnection
from neo.exception import PrimaryFailure, OperationFailure
from neo.handler import identification_required, restrict_node_types
from neo import decorators
class StorageEventHandler(EventHandler):
"""This class implements a generic part of the event handlers."""
......@@ -72,8 +72,8 @@ class StorageEventHandler(EventHandler):
known_master_list):
raise NotImplementedError('this method must be overridden')
@identification_required
@restrict_node_types(MASTER_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(MASTER_NODE_TYPE)
def handleAnnouncePrimaryMaster(self, conn, packet):
"""Theoretically speaking, I should not get this message,
because the primary master election must happen when I am
......@@ -102,8 +102,8 @@ class StorageEventHandler(EventHandler):
def handleReelectPrimaryMaster(self, conn, packet):
raise PrimaryFailure('re-election occurs')
@identification_required
@restrict_node_types(MASTER_NODE_TYPE)
@decorators.identification_required
@decorators.restrict_node_types(MASTER_NODE_TYPE)
def handleNotifyNodeInformation(self, conn, packet, node_list):
"""Store information on nodes, only if this is sent by a primary
master node."""
......
......@@ -28,8 +28,7 @@ from neo.util import dump
from neo.node import MasterNode, StorageNode, ClientNode
from neo.connection import ClientConnection
from neo.exception import PrimaryFailure
from neo.handler import identification_required, restrict_node_types, \
server_connection_required, client_connection_required
from neo import decorators
class HiddenEventHandler(EventHandler):
......@@ -134,7 +133,7 @@ class HiddenEventHandler(EventHandler):
app.dm.changePartitionTable(ptid, cell_list)
app.pt.log()
@client_connection_required
@decorators.client_connection_required
def handleStartOperation(self, conn, packet):
self.app.operational = True
......
......@@ -29,8 +29,7 @@ from neo.node import MasterNode, StorageNode, ClientNode
from neo.connection import ClientConnection
from neo.protocol import Packet, UnexpectedPacketError
from neo.exception import PrimaryFailure, OperationFailure
from neo.handler import identification_required, restrict_node_types, \
server_connection_required, client_connection_required
from neo import decorators
class TransactionInformation(object):
"""This class represents information on a transaction."""
......@@ -133,7 +132,7 @@ class OperationEventHandler(StorageEventHandler):
StorageEventHandler.peerBroken(self, conn)
@server_connection_required
@decorators.server_connection_required
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
app = self.app
......@@ -171,7 +170,7 @@ class OperationEventHandler(StorageEventHandler):
if node_type == MASTER_NODE_TYPE:
conn.abort()
@client_connection_required
@decorators.client_connection_required
def handleAcceptNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port,
num_partitions, num_replicas, your_uuid):
......@@ -190,7 +189,7 @@ class OperationEventHandler(StorageEventHandler):
def handleSendPartitionTable(self, conn, packet, ptid, row_list):
raise UnexpectedPacketError
@client_connection_required
@decorators.client_connection_required
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
"""This is very similar to Send Partition Table, except that
the information is only about changes from the previous."""
......@@ -226,7 +225,7 @@ class OperationEventHandler(StorageEventHandler):
def handleStartOperation(self, conn, packet):
raise UnexpectedPacketError
@client_connection_required
@decorators.client_connection_required
def handleStopOperation(self, conn, packet):
raise OperationFailure('operation stopped')
......@@ -252,7 +251,7 @@ class OperationEventHandler(StorageEventHandler):
def handleCommitTransaction(self, conn, packet, tid):
raise UnexpectedPacketError
@client_connection_required
@decorators.client_connection_required
def handleLockInformation(self, conn, packet, tid):
app = self.app
try:
......@@ -266,7 +265,7 @@ class OperationEventHandler(StorageEventHandler):
pass
conn.answer(protocol.notifyInformationLocked(tid), packet)
@client_connection_required
@decorators.client_connection_required
def handleUnlockInformation(self, conn, packet, tid):
app = self.app
try:
......@@ -346,7 +345,7 @@ class OperationEventHandler(StorageEventHandler):
p = protocol.answerObjectHistory(oid, history_list)
conn.answer(p, packet)
@identification_required
@decorators.identification_required
def handleAskStoreTransaction(self, conn, packet, tid, user, desc,
ext, oid_list):
uuid = conn.getUUID()
......@@ -355,7 +354,7 @@ class OperationEventHandler(StorageEventHandler):
t.addTransaction(oid_list, user, desc, ext)
conn.answer(protocol.answerStoreTransaction(tid), packet)
@identification_required
@decorators.identification_required
def handleAskStoreObject(self, conn, packet, oid, serial,
compression, checksum, data, tid):
uuid = conn.getUUID()
......@@ -392,7 +391,7 @@ class OperationEventHandler(StorageEventHandler):
conn.answer(p, packet)
app.store_lock_dict[oid] = tid
@identification_required
@decorators.identification_required
def handleAbortTransaction(self, conn, packet, tid):
uuid = conn.getUUID()
app = self.app
......@@ -414,11 +413,11 @@ class OperationEventHandler(StorageEventHandler):
except KeyError:
pass
@client_connection_required
@decorators.client_connection_required
def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid):
self.app.replicator.setCriticalTID(packet, ltid)
@client_connection_required
@decorators.client_connection_required
def handleAnswerUnfinishedTransactions(self, conn, packet, tid_list):
self.app.replicator.setUnfinishedTIDList(tid_list)
......
......@@ -27,8 +27,7 @@ from neo.util import dump
from neo.node import MasterNode, StorageNode, ClientNode
from neo.connection import ClientConnection
from neo.exception import PrimaryFailure, OperationFailure
from neo.handler import identification_required, restrict_node_types, \
server_connection_required, client_connection_required
from neo import decorators
class VerificationEventHandler(StorageEventHandler):
"""This class deals with events for a verification phase."""
......@@ -63,7 +62,7 @@ class VerificationEventHandler(StorageEventHandler):
StorageEventHandler.peerBroken(self, conn)
@server_connection_required
@decorators.server_connection_required
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
app = self.app
......@@ -102,7 +101,7 @@ class VerificationEventHandler(StorageEventHandler):
num_partitions, num_replicas, your_uuid):
raise UnexpectedPacketError
@client_connection_required
@decorators.client_connection_required
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid,
known_master_list):
app = self.app
......@@ -112,7 +111,7 @@ class VerificationEventHandler(StorageEventHandler):
# But a primary master node is supposed not to send any info
# with this packet, so it would be useless.
@client_connection_required
@decorators.client_connection_required
def handleAskLastIDs(self, conn, packet):
app = self.app
oid = app.dm.getLastOID() or INVALID_OID
......@@ -120,7 +119,7 @@ class VerificationEventHandler(StorageEventHandler):
p = protocol.answerLastIDs(oid, tid, app.ptid)
conn.answer(p, packet)
@client_connection_required
@decorators.client_connection_required
def handleAskPartitionTable(self, conn, packet, offset_list):
app = self.app
row_list = []
......@@ -139,7 +138,7 @@ class VerificationEventHandler(StorageEventHandler):
p = protocol.answerPartitionTable(app.ptid, row_list)
conn.answer(p, packet)
@client_connection_required
@decorators.client_connection_required
def handleSendPartitionTable(self, conn, packet, ptid, row_list):
"""A primary master node sends this packet to synchronize a partition
table. Note that the message can be split into multiple packets."""
......@@ -171,7 +170,7 @@ class VerificationEventHandler(StorageEventHandler):
cell.getState()))
app.dm.setPartitionTable(ptid, cell_list)
@client_connection_required
@decorators.client_connection_required
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
"""This is very similar to Send Partition Table, except that
the information is only about changes from the previous."""
......@@ -198,15 +197,15 @@ class VerificationEventHandler(StorageEventHandler):
# Then, the database.
app.dm.changePartitionTable(ptid, cell_list)
@client_connection_required
@decorators.client_connection_required
def handleStartOperation(self, conn, packet):
self.app.operational = True
@client_connection_required
@decorators.client_connection_required
def handleStopOperation(self, conn, packet):
raise OperationFailure('operation stopped')
@client_connection_required
@decorators.client_connection_required
def handleAskUnfinishedTransactions(self, conn, packet):
tid_list = self.app.dm.getUnfinishedTIDList()
p = protocol.answerUnfinishedTransactions(tid_list)
......@@ -228,7 +227,7 @@ class VerificationEventHandler(StorageEventHandler):
p = protocol.answerTransactionInformation(tid, t[1], t[2], t[3], t[0])
conn.answer(p, packet)
@client_connection_required
@decorators.client_connection_required
def handleAskObjectPresent(self, conn, packet, oid, tid):
if self.app.dm.objectPresent(oid, tid):
p = protocol.answerObjectPresent(oid, tid)
......@@ -237,11 +236,11 @@ class VerificationEventHandler(StorageEventHandler):
'%s:%s do not exist' % (dump(oid), dump(tid)))
conn.answer(p, packet)
@client_connection_required
@decorators.client_connection_required
def handleDeleteTransaction(self, conn, packet, tid):
self.app.dm.deleteTransaction(tid, all = True)
@client_connection_required
@decorators.client_connection_required
def handleCommitTransaction(self, conn, packet, tid):
self.app.dm.finishTransaction(tid)
......
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