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