Commit 04d5bcc6 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Apply new Enum class to node types. Use each time the 'NodeTypes' symbol import

to avoid full module.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1334 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 7358c9bf
...@@ -28,6 +28,7 @@ from neo.bootstrap import BootstrapManager ...@@ -28,6 +28,7 @@ from neo.bootstrap import BootstrapManager
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo import protocol from neo import protocol
from neo.util import parseMasterList from neo.util import parseMasterList
from neo.protocol import NodeTypes
class Dispatcher: class Dispatcher:
"""Dispatcher use to redirect master request to handler""" """Dispatcher use to redirect master request to handler"""
...@@ -123,7 +124,7 @@ class Application(object): ...@@ -123,7 +124,7 @@ class Application(object):
nm.createMaster(address=address) nm.createMaster(address=address)
# search, find, connect and identify to the primary master # search, find, connect and identify to the primary master
bootstrap = BootstrapManager(self, self.name, protocol.ADMIN_NODE_TYPE, bootstrap = BootstrapManager(self, self.name, NodeTypes.ADMIN,
self.uuid, self.server) self.uuid, self.server)
data = bootstrap.getPrimaryConnection(self.connector_handler) data = bootstrap.getPrimaryConnection(self.connector_handler)
(node, conn, uuid, num_partitions, num_replicas) = data (node, conn, uuid, num_partitions, num_replicas) = data
......
...@@ -29,6 +29,7 @@ setupLog('CLIENT', verbose=True) ...@@ -29,6 +29,7 @@ setupLog('CLIENT', verbose=True)
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
from neo.event import EventManager from neo.event import EventManager
from neo.util import makeChecksum, dump from neo.util import makeChecksum, dump
from neo.locking import RLock, Lock from neo.locking import RLock, Lock
...@@ -86,7 +87,7 @@ class ConnectionPool(object): ...@@ -86,7 +87,7 @@ class ConnectionPool(object):
logging.error('Connection to storage node %s failed', node) logging.error('Connection to storage node %s failed', node)
return None return None
p = protocol.requestNodeIdentification(protocol.CLIENT_NODE_TYPE, p = protocol.requestNodeIdentification(NodeTypes.CLIENT,
app.uuid, None, app.name) app.uuid, None, app.name)
msg_id = conn.ask(app.local_var.queue, p) msg_id = conn.ask(app.local_var.queue, p)
finally: finally:
...@@ -438,7 +439,7 @@ class Application(object): ...@@ -438,7 +439,7 @@ class Application(object):
self.trying_master_node) self.trying_master_node)
self.primary_master_node = None self.primary_master_node = None
break break
p = protocol.requestNodeIdentification(protocol.CLIENT_NODE_TYPE, p = protocol.requestNodeIdentification(NodeTypes.CLIENT,
self.uuid, None, self.name) self.uuid, None, self.name)
msg_id = conn.ask(self.local_var.queue, p) msg_id = conn.ask(self.local_var.queue, p)
finally: finally:
......
...@@ -20,6 +20,7 @@ from neo import logging ...@@ -20,6 +20,7 @@ from neo import logging
from neo.client.handlers import BaseHandler, AnswerBaseHandler from neo.client.handlers import BaseHandler, AnswerBaseHandler
from neo.pt import MTPartitionTable as PartitionTable from neo.pt import MTPartitionTable as PartitionTable
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
from neo.util import dump from neo.util import dump
class PrimaryBootstrapHandler(AnswerBaseHandler): class PrimaryBootstrapHandler(AnswerBaseHandler):
...@@ -35,7 +36,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -35,7 +36,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
# this must be a master node # this must be a master node
if node_type != protocol.MASTER_NODE_TYPE: if node_type != NodeTypes.MASTER:
conn.close() conn.close()
return return
if conn.getAddress() != address: if conn.getAddress() != address:
...@@ -163,14 +164,14 @@ class PrimaryNotificationsHandler(BaseHandler): ...@@ -163,14 +164,14 @@ class PrimaryNotificationsHandler(BaseHandler):
app = self.app app = self.app
self.app.nm.update(node_list) self.app.nm.update(node_list)
for node_type, addr, uuid, state in node_list: for node_type, addr, uuid, state in node_list:
if node_type != protocol.STORAGE_NODE_TYPE \ if node_type != NodeTypes.STORAGE \
or state != protocol.RUNNING_STATE: or state != protocol.RUNNING_STATE:
continue continue
# close connection to this storage if no longer running # close connection to this storage if no longer running
conn = self.app.em.getConnectionByUUID(uuid) conn = self.app.em.getConnectionByUUID(uuid)
if conn is not None: if conn is not None:
conn.close() conn.close()
if node_type == protocol.STORAGE_NODE_TYPE: if node_type == NodeTypes.STORAGE:
# Remove from pool connection # Remove from pool connection
app.cp.removeConnection(conn) app.cp.removeConnection(conn)
self.dispatcher.unregister(conn) self.dispatcher.unregister(conn)
......
...@@ -20,6 +20,7 @@ from ZODB.TimeStamp import TimeStamp ...@@ -20,6 +20,7 @@ from ZODB.TimeStamp import TimeStamp
from neo.client.handlers import BaseHandler, AnswerBaseHandler from neo.client.handlers import BaseHandler, AnswerBaseHandler
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
class StorageEventHandler(BaseHandler): class StorageEventHandler(BaseHandler):
...@@ -56,8 +57,8 @@ class StorageBootstrapHandler(AnswerBaseHandler): ...@@ -56,8 +57,8 @@ class StorageBootstrapHandler(AnswerBaseHandler):
uuid, address, num_partitions, num_replicas, your_uuid): uuid, address, num_partitions, num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
# It can be eiter a master node or a storage node # this must be a storage node
if node_type != protocol.STORAGE_NODE_TYPE: if node_type != NodeTypes.STORAGE:
conn.close() conn.close()
return return
if conn.getAddress() != address: if conn.getAddress() != address:
......
...@@ -21,7 +21,7 @@ from time import time ...@@ -21,7 +21,7 @@ from time import time
from struct import pack, unpack from struct import pack, unpack
from neo import protocol from neo import protocol
from neo.protocol import UUID_NAMESPACES, ClusterStates from neo.protocol import UUID_NAMESPACES, ClusterStates, NodeTypes
from neo.node import NodeManager from neo.node import NodeManager
from neo.event import EventManager from neo.event import EventManager
from neo.connection import ListeningConnection, ClientConnection from neo.connection import ListeningConnection, ClientConnection
...@@ -78,7 +78,7 @@ class Application(object): ...@@ -78,7 +78,7 @@ class Application(object):
# Generate an UUID for self # Generate an UUID for self
if uuid is None: if uuid is None:
uuid = self.getNewUUID(protocol.MASTER_NODE_TYPE) uuid = self.getNewUUID(NodeTypes.MASTER)
self.uuid = uuid self.uuid = uuid
# The last OID. # The last OID.
...@@ -770,12 +770,12 @@ class Application(object): ...@@ -770,12 +770,12 @@ class Application(object):
state = protocol.RUNNING_STATE state = protocol.RUNNING_STATE
handler = identification.IdentificationHandler handler = identification.IdentificationHandler
if node_type == protocol.ADMIN_NODE_TYPE: if node_type == NodeTypes.ADMIN:
# always accept admin nodes # always accept admin nodes
node_ctor = self.nm.createAdmin node_ctor = self.nm.createAdmin
handler = administration.AdministrationHandler handler = administration.AdministrationHandler
logging.info('Accept an admin %s' % dump(uuid)) logging.info('Accept an admin %s' % dump(uuid))
elif node_type == protocol.MASTER_NODE_TYPE: elif node_type == NodeTypes.MASTER:
if node is None: if node is None:
# unknown master, rejected # unknown master, rejected
raise protocol.ProtocolError('Reject an unknown master node') raise protocol.ProtocolError('Reject an unknown master node')
...@@ -783,7 +783,7 @@ class Application(object): ...@@ -783,7 +783,7 @@ class Application(object):
node_ctor = self.nm.createMaster node_ctor = self.nm.createMaster
handler = secondary.SecondaryMasterHandler handler = secondary.SecondaryMasterHandler
logging.info('Accept a master %s' % dump(uuid)) logging.info('Accept a master %s' % dump(uuid))
elif node_type == protocol.CLIENT_NODE_TYPE: elif node_type == NodeTypes.CLIENT:
# refuse any client before running # refuse any client before running
if self.cluster_state != ClusterStates.RUNNING: if self.cluster_state != ClusterStates.RUNNING:
logging.info('Reject a connection from a client') logging.info('Reject a connection from a client')
...@@ -791,7 +791,7 @@ class Application(object): ...@@ -791,7 +791,7 @@ class Application(object):
node_ctor = self.nm.createClient node_ctor = self.nm.createClient
handler = client.ClientServiceHandler handler = client.ClientServiceHandler
logging.info('Accept a client %s' % dump(uuid)) logging.info('Accept a client %s' % dump(uuid))
elif node_type == protocol.STORAGE_NODE_TYPE: elif node_type == NodeTypes.STORAGE:
node_ctor = self.nm.createStorage node_ctor = self.nm.createStorage
(uuid, state, handler) = self.identifyStorageNode(uuid, node) (uuid, state, handler) = self.identifyStorageNode(uuid, node)
logging.info('Accept a storage (%s)' % state) logging.info('Accept a storage (%s)' % state)
......
...@@ -19,6 +19,7 @@ from neo import logging ...@@ -19,6 +19,7 @@ from neo import logging
from neo import protocol from neo import protocol
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import NodeTypes
class MasterHandler(EventHandler): class MasterHandler(EventHandler):
"""This class implements a generic part of the event handlers.""" """This class implements a generic part of the event handlers."""
...@@ -71,7 +72,7 @@ class MasterHandler(EventHandler): ...@@ -71,7 +72,7 @@ class MasterHandler(EventHandler):
DISCONNECTED_STATE_DICT = { DISCONNECTED_STATE_DICT = {
protocol.STORAGE_NODE_TYPE: protocol.TEMPORARILY_DOWN_STATE, NodeTypes.STORAGE: protocol.TEMPORARILY_DOWN_STATE,
} }
class BaseServiceHandler(MasterHandler): class BaseServiceHandler(MasterHandler):
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
from neo.exception import ElectionFailure from neo.exception import ElectionFailure
...@@ -30,7 +31,7 @@ class ElectionHandler(MasterHandler): ...@@ -30,7 +31,7 @@ class ElectionHandler(MasterHandler):
raise protocol.UnexpectedPacketError raise protocol.UnexpectedPacketError
app = self.app app = self.app
for node_type, addr, uuid, state in node_list: for node_type, addr, uuid, state in node_list:
if node_type != protocol.MASTER_NODE_TYPE: if node_type != NodeTypes.MASTER:
# No interest. # No interest.
continue continue
...@@ -114,7 +115,7 @@ class ClientElectionHandler(ElectionHandler): ...@@ -114,7 +115,7 @@ class ClientElectionHandler(ElectionHandler):
num_replicas, your_uuid): num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
if node_type != protocol.MASTER_NODE_TYPE: if node_type != NodeTypes.MASTER:
# The peer is not a master node! # The peer is not a master node!
logging.error('%s:%d is not a master node', *address) logging.error('%s:%d is not a master node', *address)
app.nm.remove(node) app.nm.remove(node)
...@@ -198,7 +199,7 @@ class ClientElectionHandler(ElectionHandler): ...@@ -198,7 +199,7 @@ class ClientElectionHandler(ElectionHandler):
# Request a node idenfitication. # Request a node idenfitication.
conn.ask(protocol.requestNodeIdentification( conn.ask(protocol.requestNodeIdentification(
protocol.MASTER_NODE_TYPE, NodeTypes.MASTER,
app.uuid, app.uuid,
app.server, app.server,
app.name app.name
...@@ -230,7 +231,7 @@ class ServerElectionHandler(ElectionHandler): ...@@ -230,7 +231,7 @@ class ServerElectionHandler(ElectionHandler):
return return
self.checkClusterName(name) self.checkClusterName(name)
app = self.app app = self.app
if node_type != protocol.MASTER_NODE_TYPE: if node_type != NodeTypes.MASTER:
logging.info('reject a connection from a non-master') logging.info('reject a connection from a non-master')
raise protocol.NotReadyError raise protocol.NotReadyError
node = app.nm.getByAddress(address) node = app.nm.getByAddress(address)
...@@ -250,7 +251,7 @@ class ServerElectionHandler(ElectionHandler): ...@@ -250,7 +251,7 @@ class ServerElectionHandler(ElectionHandler):
conn.setUUID(uuid) conn.setUUID(uuid)
p = protocol.acceptNodeIdentification( p = protocol.acceptNodeIdentification(
protocol.MASTER_NODE_TYPE, NodeTypes.MASTER,
app.uuid, app.uuid,
app.server, app.server,
app.pt.getPartitions(), app.pt.getPartitions(),
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
class IdentificationHandler(MasterHandler): class IdentificationHandler(MasterHandler):
...@@ -73,7 +74,7 @@ class IdentificationHandler(MasterHandler): ...@@ -73,7 +74,7 @@ class IdentificationHandler(MasterHandler):
conn.setUUID(uuid) conn.setUUID(uuid)
conn.setHandler(handler) conn.setHandler(handler)
# answer # answer
args = (protocol.MASTER_NODE_TYPE, app.uuid, app.server, args = (NodeTypes.MASTER, app.uuid, app.server,
app.pt.getPartitions(), app.pt.getReplicas(), uuid) app.pt.getPartitions(), app.pt.getReplicas(), uuid)
conn.answer(protocol.acceptNodeIdentification(*args), packet.getId()) conn.answer(protocol.acceptNodeIdentification(*args), packet.getId())
# trigger the event # trigger the event
......
...@@ -20,6 +20,7 @@ from neo import logging ...@@ -20,6 +20,7 @@ from neo import logging
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
from neo.exception import ElectionFailure, PrimaryFailure from neo.exception import ElectionFailure, PrimaryFailure
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
class SecondaryMasterHandler(MasterHandler): class SecondaryMasterHandler(MasterHandler):
""" Handler used by primary to handle secondary masters""" """ Handler used by primary to handle secondary masters"""
...@@ -66,7 +67,7 @@ class PrimaryMasterHandler(MasterHandler): ...@@ -66,7 +67,7 @@ class PrimaryMasterHandler(MasterHandler):
def handleNotifyNodeInformation(self, conn, packet, node_list): def handleNotifyNodeInformation(self, conn, packet, node_list):
app = self.app app = self.app
for node_type, addr, uuid, state in node_list: for node_type, addr, uuid, state in node_list:
if node_type != protocol.MASTER_NODE_TYPE: if node_type != NodeTypes.MASTER:
# No interest. # No interest.
continue continue
...@@ -90,7 +91,7 @@ class PrimaryMasterHandler(MasterHandler): ...@@ -90,7 +91,7 @@ class PrimaryMasterHandler(MasterHandler):
num_replicas, your_uuid): num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
assert node_type == protocol.MASTER_NODE_TYPE assert node_type == NodeTypes.MASTER
assert conn.getAddress() == address assert conn.getAddress() == address
if your_uuid != app.uuid: if your_uuid != app.uuid:
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
from neo.neoctl.neoctl import NeoCTL, NotReadyException from neo.neoctl.neoctl import NeoCTL, NotReadyException
from neo.util import bin, dump from neo.util import bin, dump
from neo import protocol from neo import protocol
from neo.protocol import ClusterStates from neo.protocol import ClusterStates, NodeTypes
action_dict = { action_dict = {
'print': { 'print': {
...@@ -49,9 +49,7 @@ class TerminalNeoCTL(object): ...@@ -49,9 +49,7 @@ class TerminalNeoCTL(object):
return protocol.node_states.getFromStr(value) return protocol.node_states.getFromStr(value)
def asNodeType(self, value): def asNodeType(self, value):
if not value.endswith('_NODE_TYPE'): return NodeTypes.getByName(values.upper())
value += '_NODE_TYPE'
return protocol.node_types.getFromStr(value)
def asClusterState(self, value): def asClusterState(self, value):
return ClusterStates.getByName(value.upper()) return ClusterStates.getByName(value.upper())
...@@ -167,8 +165,7 @@ class TerminalNeoCTL(object): ...@@ -167,8 +165,7 @@ class TerminalNeoCTL(object):
otherwise, the list of storage nodes to enable. otherwise, the list of storage nodes to enable.
""" """
if len(params) == 1 and params[0] == 'all': if len(params) == 1 and params[0] == 'all':
node_list = self.neoctl.getNodeList( node_list = self.neoctl.getNodeList(NodeTypes.STORAGE)
node_type=protocol.STORAGE_NODE_TYPE)
uuid_list = [node[2] for node in node_list] uuid_list = [node[2] for node in node_list]
else: else:
uuid_list = [self.asNode(x) for x in params] uuid_list = [self.asNode(x) for x in params]
......
...@@ -20,6 +20,7 @@ from time import time ...@@ -20,6 +20,7 @@ from time import time
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.util import dump from neo.util import dump
from neo.protocol import NodeTypes
class Node(object): class Node(object):
"""This class represents a node.""" """This class represents a node."""
...@@ -158,16 +159,16 @@ class AdminNode(Node): ...@@ -158,16 +159,16 @@ class AdminNode(Node):
NODE_TYPE_MAPPING = { NODE_TYPE_MAPPING = {
protocol.MASTER_NODE_TYPE: MasterNode, NodeTypes.MASTER: MasterNode,
protocol.STORAGE_NODE_TYPE: StorageNode, NodeTypes.STORAGE: StorageNode,
protocol.CLIENT_NODE_TYPE: ClientNode, NodeTypes.CLIENT: ClientNode,
protocol.ADMIN_NODE_TYPE: AdminNode, NodeTypes.ADMIN: AdminNode,
} }
NODE_CLASS_MAPPING = { NODE_CLASS_MAPPING = {
StorageNode: protocol.STORAGE_NODE_TYPE, StorageNode: NodeTypes.STORAGE,
MasterNode: protocol.MASTER_NODE_TYPE, MasterNode: NodeTypes.MASTER,
ClientNode: protocol.CLIENT_NODE_TYPE, ClientNode: NodeTypes.CLIENT,
AdminNode: protocol.ADMIN_NODE_TYPE, AdminNode: NodeTypes.ADMIN,
} }
class NodeManager(object): class NodeManager(object):
......
...@@ -327,13 +327,14 @@ class ClusterStates(Enum): ...@@ -327,13 +327,14 @@ class ClusterStates(Enum):
ClusterStates = ClusterStates() ClusterStates = ClusterStates()
# Node types. class NodeTypes(Enum):
node_types = OldEnum({
'MASTER_NODE_TYPE' : 1, MASTER = Enum.Item(1)
'STORAGE_NODE_TYPE' : 2, STORAGE = Enum.Item(2)
'CLIENT_NODE_TYPE' : 3, CLIENT = Enum.Item(3)
'ADMIN_NODE_TYPE' : 4, ADMIN = Enum.Item(4)
})
NodeTypes = NodeTypes()
# Node states. # Node states.
node_states = OldEnum({ node_states = OldEnum({
...@@ -387,10 +388,10 @@ CLIENT_NS = 'C' ...@@ -387,10 +388,10 @@ CLIENT_NS = 'C'
ADMIN_NS = 'A' ADMIN_NS = 'A'
UUID_NAMESPACES = { UUID_NAMESPACES = {
STORAGE_NODE_TYPE: STORAGE_NS, NodeTypes.STORAGE: STORAGE_NS,
MASTER_NODE_TYPE: MASTER_NS, NodeTypes.MASTER: MASTER_NS,
CLIENT_NODE_TYPE: CLIENT_NS, NodeTypes.CLIENT: CLIENT_NS,
ADMIN_NODE_TYPE: ADMIN_NS, NodeTypes.ADMIN: ADMIN_NS,
} }
class ProtocolError(Exception): class ProtocolError(Exception):
...@@ -510,7 +511,7 @@ def _decodeNodeState(state): ...@@ -510,7 +511,7 @@ def _decodeNodeState(state):
return node_state return node_state
def _decodeNodeType(original_node_type): def _decodeNodeType(original_node_type):
node_type = node_types.get(original_node_type) node_type = NodeTypes.get(original_node_type)
if node_type is None: if node_type is None:
raise PacketMalformedError('invalid node type %d' % original_node_type) raise PacketMalformedError('invalid node type %d' % original_node_type)
return node_type return node_type
......
...@@ -20,6 +20,7 @@ import sys ...@@ -20,6 +20,7 @@ import sys
from collections import deque from collections import deque
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
from neo.node import NodeManager from neo.node import NodeManager
from neo.event import EventManager from neo.event import EventManager
from neo.storage.mysqldb import MySQLDatabaseManager from neo.storage.mysqldb import MySQLDatabaseManager
...@@ -196,7 +197,7 @@ class Application(object): ...@@ -196,7 +197,7 @@ class Application(object):
# search, find, connect and identify to the primary master # search, find, connect and identify to the primary master
bootstrap = BootstrapManager(self, self.name, bootstrap = BootstrapManager(self, self.name,
protocol.STORAGE_NODE_TYPE, self.uuid, self.server) NodeTypes.STORAGE, self.uuid, self.server)
data = bootstrap.getPrimaryConnection(self.connector_handler) data = bootstrap.getPrimaryConnection(self.connector_handler)
(node, conn, uuid, num_partitions, num_replicas) = data (node, conn, uuid, num_partitions, num_replicas) = data
self.master_node = node self.master_node = node
......
...@@ -19,7 +19,7 @@ from neo import logging ...@@ -19,7 +19,7 @@ from neo import logging
from neo.handler import EventHandler from neo.handler import EventHandler
from neo import protocol from neo import protocol
from neo.protocol import BROKEN_STATE, CLIENT_NODE_TYPE, \ from neo.protocol import BROKEN_STATE, \
DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE
from neo.util import dump from neo.util import dump
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
......
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
from neo import logging from neo import logging
from neo.storage.handlers import BaseMasterHandler from neo.storage.handlers import BaseMasterHandler
from neo.protocol import BROKEN_STATE, STORAGE_NODE_TYPE, DOWN_STATE, \ from neo.protocol import BROKEN_STATE, DOWN_STATE, \
TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE
from neo.protocol import NodeTypes
class HiddenHandler(BaseMasterHandler): class HiddenHandler(BaseMasterHandler):
"""This class implements a generic part of the event handlers.""" """This class implements a generic part of the event handlers."""
...@@ -34,7 +35,7 @@ class HiddenHandler(BaseMasterHandler): ...@@ -34,7 +35,7 @@ class HiddenHandler(BaseMasterHandler):
app = self.app app = self.app
self.app.nm.update(node_list) self.app.nm.update(node_list)
for node_type, addr, uuid, state in node_list: for node_type, addr, uuid, state in node_list:
if node_type == STORAGE_NODE_TYPE: if node_type == NodeTypes.STORAGE:
if uuid == self.app.uuid: if uuid == self.app.uuid:
# This is me, do what the master tell me # This is me, do what the master tell me
if state in (DOWN_STATE, TEMPORARILY_DOWN_STATE, BROKEN_STATE): if state in (DOWN_STATE, TEMPORARILY_DOWN_STATE, BROKEN_STATE):
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
from neo import logging from neo import logging
from neo.storage.handlers import BaseStorageHandler from neo.storage.handlers import BaseStorageHandler
from neo.protocol import NodeTypes
from neo import protocol from neo import protocol
from neo.util import dump from neo.util import dump
...@@ -36,12 +37,12 @@ class IdentificationHandler(BaseStorageHandler): ...@@ -36,12 +37,12 @@ class IdentificationHandler(BaseStorageHandler):
app = self.app app = self.app
node = app.nm.getByUUID(uuid) node = app.nm.getByUUID(uuid)
# choose the handler according to the node type # choose the handler according to the node type
if node_type == protocol.CLIENT_NODE_TYPE: if node_type == NodeTypes.CLIENT:
from neo.storage.handlers.client import ClientOperationHandler from neo.storage.handlers.client import ClientOperationHandler
handler = ClientOperationHandler handler = ClientOperationHandler
if node is None: if node is None:
node = app.nm.createClient() node = app.nm.createClient()
elif node_type == protocol.STORAGE_NODE_TYPE: elif node_type == NodeTypes.STORAGE:
from neo.storage.handlers.storage import StorageOperationHandler from neo.storage.handlers.storage import StorageOperationHandler
handler = StorageOperationHandler handler = StorageOperationHandler
else: else:
...@@ -57,7 +58,7 @@ class IdentificationHandler(BaseStorageHandler): ...@@ -57,7 +58,7 @@ class IdentificationHandler(BaseStorageHandler):
conn.setHandler(handler) conn.setHandler(handler)
conn.setUUID(uuid) conn.setUUID(uuid)
node.setUUID(uuid) node.setUUID(uuid)
args = (protocol.STORAGE_NODE_TYPE, app.uuid, app.server, args = (NodeTypes.STORAGE, app.uuid, app.server,
app.pt.getPartitions(), app.pt.getReplicas(), uuid) app.pt.getPartitions(), app.pt.getReplicas(), uuid)
# accept the identification and trigger an event # accept the identification and trigger an event
conn.answer(protocol.acceptNodeIdentification(*args), packet.getId()) conn.answer(protocol.acceptNodeIdentification(*args), packet.getId())
......
...@@ -20,8 +20,8 @@ from random import choice ...@@ -20,8 +20,8 @@ from random import choice
from neo.storage.handlers import replication from neo.storage.handlers import replication
from neo import protocol from neo import protocol
from neo.protocol import STORAGE_NODE_TYPE, UP_TO_DATE_STATE, \ from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, RUNNING_STATE
OUT_OF_DATE_STATE, RUNNING_STATE from neo.protocol import NodeTypes
from neo.connection import ClientConnection from neo.connection import ClientConnection
from neo.util import dump from neo.util import dump
...@@ -180,8 +180,8 @@ class Replicator(object): ...@@ -180,8 +180,8 @@ class Replicator(object):
self.current_connection = ClientConnection(app.em, handler, self.current_connection = ClientConnection(app.em, handler,
addr = addr, addr = addr,
connector_handler = app.connector_handler) connector_handler = app.connector_handler)
p = protocol.requestNodeIdentification(STORAGE_NODE_TYPE, app.uuid, p = protocol.requestNodeIdentification(NodeTypes.STORAGE,
app.server, app.name) app.uuid, app.server, app.name)
self.current_connection.ask(p) self.current_connection.ask(p)
self.tid_offset = 0 self.tid_offset = 0
......
...@@ -334,7 +334,7 @@ class TestElectionConnector(DoNothingConnector): ...@@ -334,7 +334,7 @@ class TestElectionConnector(DoNothingConnector):
p = protocol.Packet() p = protocol.Packet()
self.uuid = getNewUUID() self.uuid = getNewUUID()
p.acceptNodeIdentification(1, p.acceptNodeIdentification(1,
protocol.MASTER_NODE_TYPE, NodeType.MASTER,
self.uuid, self.uuid,
self.getAddress()[0], self.getAddress()[0],
self.getAddress()[1], self.getAddress()[1],
......
This diff is collapsed.
...@@ -28,7 +28,7 @@ import unittest ...@@ -28,7 +28,7 @@ import unittest
import tempfile import tempfile
import traceback import traceback
from neo.protocol import ClusterStates from neo.protocol import ClusterStates, NodeTypes
from neo.client.Storage import Storage from neo.client.Storage import Storage
from neo.tests import getNewUUID from neo.tests import getNewUUID
from neo.util import dump from neo.util import dump
...@@ -245,7 +245,7 @@ class NEOCluster(object): ...@@ -245,7 +245,7 @@ class NEOCluster(object):
if time.time() > end_time: if time.time() > end_time:
raise AssertionError, 'Timeout when starting cluster' raise AssertionError, 'Timeout when starting cluster'
storage_node_list = neoctl.getNodeList( storage_node_list = neoctl.getNodeList(
node_type=protocol.STORAGE_NODE_TYPE) node_type=NodeTypes.STORAGE)
if len(storage_node_list) == target_count: if len(storage_node_list) == target_count:
break break
time.sleep(0.5) time.sleep(0.5)
...@@ -332,10 +332,10 @@ class NEOCluster(object): ...@@ -332,10 +332,10 @@ class NEOCluster(object):
if state is None or x[3] == state] if state is None or x[3] == state]
def getMasterList(self, state=None): def getMasterList(self, state=None):
return self.__getNodeList(protocol.MASTER_NODE_TYPE, state) return self.__getNodeList(NodeTypes.MASTER, state)
def getStorageList(self, state=None): def getStorageList(self, state=None):
return self.__getNodeList(protocol.STORAGE_NODE_TYPE, state) return self.__getNodeList(NodeTypes.STORAGE, state)
def __getNodeState(self, node_type, uuid): def __getNodeState(self, node_type, uuid):
node_list = self.__getNodeList(node_type) node_list = self.__getNodeList(node_type)
...@@ -347,7 +347,7 @@ class NEOCluster(object): ...@@ -347,7 +347,7 @@ class NEOCluster(object):
return state return state
def getMasterNodeState(self, uuid): def getMasterNodeState(self, uuid):
return self.__getNodeState(protocol.MASTER_NODE_TYPE, uuid) return self.__getNodeState(NodeTypes.MASTER, uuid)
def getPrimaryMaster(self): def getPrimaryMaster(self):
try: try:
...@@ -389,11 +389,11 @@ class NEOCluster(object): ...@@ -389,11 +389,11 @@ class NEOCluster(object):
self.expectCondition(callback, timeout, delay) self.expectCondition(callback, timeout, delay)
def expectMasterState(self, uuid, state, timeout=0, delay=1): def expectMasterState(self, uuid, state, timeout=0, delay=1):
self.__expectNodeState(protocol.MASTER_NODE_TYPE, uuid, state, timeout, self.__expectNodeState(NodeTypes.MASTER, uuid, state, timeout,
delay) delay)
def expectStorageState(self, uuid, state, timeout=0, delay=1): def expectStorageState(self, uuid, state, timeout=0, delay=1):
self.__expectNodeState(protocol.STORAGE_NODE_TYPE, uuid, state, self.__expectNodeState(NodeTypes.STORAGE, uuid, state,
timeout,delay) timeout,delay)
def expectPrimaryMaster(self, uuid=None, timeout=0, delay=1): def expectPrimaryMaster(self, uuid=None, timeout=0, delay=1):
......
This diff is collapsed.
This diff is collapsed.
...@@ -22,7 +22,7 @@ from mock import Mock ...@@ -22,7 +22,7 @@ from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, NodeTypes, INVALID_UUID
from neo.master.handlers.recovery import RecoveryHandler from neo.master.handlers.recovery import RecoveryHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
...@@ -43,7 +43,6 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF ...@@ -43,7 +43,6 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \ NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \ PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \
INTERNAL_ERROR_CODE, \ INTERNAL_ERROR_CODE, \
STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
...@@ -81,7 +80,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -81,7 +80,7 @@ class MasterRecoveryTests(NeoTestBase):
def getLastUUID(self): def getLastUUID(self):
return self.uuid return self.uuid
def identifyToMasterNode(self, node_type=STORAGE_NODE_TYPE, ip="127.0.0.1", def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1",
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
...@@ -90,14 +89,14 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -90,14 +89,14 @@ class MasterRecoveryTests(NeoTestBase):
# Tests # Tests
def test_01_connectionClosed(self): def test_01_connectionClosed(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.recovery.connectionClosed(conn) self.recovery.connectionClosed(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
def test_02_timeoutExpired(self): def test_02_timeoutExpired(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.recovery.timeoutExpired(conn) self.recovery.timeoutExpired(conn)
...@@ -105,7 +104,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -105,7 +104,7 @@ class MasterRecoveryTests(NeoTestBase):
def test_03_peerBroken(self): def test_03_peerBroken(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.recovery.peerBroken(conn) self.recovery.peerBroken(conn)
...@@ -113,18 +112,18 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -113,18 +112,18 @@ class MasterRecoveryTests(NeoTestBase):
def test_08_handleNotifyNodeInformation(self): def test_08_handleNotifyNodeInformation(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# tell about a client node, do nothing # tell about a client node, do nothing
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(CLIENT_NODE_TYPE, '127.0.0.1', self.client_port, self.getNewUUID(), DOWN_STATE),] node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port, self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getList()), 0) self.assertEqual(len(self.app.nm.getList()), 0)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getList()), 0) self.assertEqual(len(self.app.nm.getList()), 0)
# tell the master node about itself, if running must do nothing # tell the master node about itself, if running must do nothing
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port-1, self.app.uuid, RUNNING_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port-1, self.app.uuid, RUNNING_STATE),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None) self.assertEqual(node, None)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
...@@ -132,21 +131,21 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -132,21 +131,21 @@ class MasterRecoveryTests(NeoTestBase):
# tell the master node about itself, if down must raise # tell the master node about itself, if down must raise
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port-1, self.app.uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port-1, self.app.uuid, DOWN_STATE),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None) self.assertEqual(node, None)
self.assertRaises(RuntimeError, recovery.handleNotifyNodeInformation, conn, packet, node_list) self.assertRaises(RuntimeError, recovery.handleNotifyNodeInformation, conn, packet, node_list)
# tell about an unknown storage node, do nothing # tell about an unknown storage node, do nothing
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.master_port - 1, self.getNewUUID(), DOWN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.master_port - 1, self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getStorageList()), 0) self.assertEqual(len(self.app.nm.getStorageList()), 0)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getStorageList()), 0) self.assertEqual(len(self.app.nm.getStorageList()), 0)
# tell about a known node but different address # tell about a known node but different address
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.2', self.master_port, uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.2', self.master_port, uuid, DOWN_STATE),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), RUNNING_STATE) self.assertEqual(node.getState(), RUNNING_STATE)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
...@@ -155,7 +154,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -155,7 +154,7 @@ class MasterRecoveryTests(NeoTestBase):
# tell about a known node # tell about a known node
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port, uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port, uuid, DOWN_STATE),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), RUNNING_STATE) self.assertEqual(node.getState(), RUNNING_STATE)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
...@@ -192,10 +191,10 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -192,10 +191,10 @@ class MasterRecoveryTests(NeoTestBase):
def test_10_handleAnswerPartitionTable(self): def test_10_handleAnswerPartitionTable(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
packet = Packet(msg_type=ANSWER_PARTITION_TABLE) packet = Packet(msg_type=ANSWER_PARTITION_TABLE)
# not from target node, ignore # not from target node, ignore
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port) uuid = self.identifyToMasterNode(NodeTypes.STORAGE, port=self.storage_port)
conn = self.getFakeConnection(uuid, self.storage_port) conn = self.getFakeConnection(uuid, self.storage_port)
self.assertNotEquals(self.app.target_uuid, uuid) self.assertNotEquals(self.app.target_uuid, uuid)
offset = 1 offset = 1
......
...@@ -23,7 +23,7 @@ from struct import pack, unpack ...@@ -23,7 +23,7 @@ from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
import neo.master import neo.master
from neo import protocol from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, NodeTypes, INVALID_UUID
from neo.master.handlers.storage import StorageServiceHandler from neo.master.handlers.storage import StorageServiceHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
...@@ -31,7 +31,6 @@ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \ ...@@ -31,7 +31,6 @@ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \ ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \ ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \
NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION, \ NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION, \
STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
...@@ -64,7 +63,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -64,7 +63,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def getLastUUID(self): def getLastUUID(self):
return self.uuid return self.uuid
def identifyToMasterNode(self, node_type=STORAGE_NODE_TYPE, ip="127.0.0.1", def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1",
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
...@@ -78,24 +77,24 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -78,24 +77,24 @@ class MasterStorageHandlerTests(NeoTestBase):
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# tell the master node that is not running any longer, it must raises # tell the master node that is not running any longer, it must raises
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port, self.app.uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port, self.app.uuid, DOWN_STATE),]
self.assertRaises(RuntimeError, service.handleNotifyNodeInformation, conn, packet, node_list) self.assertRaises(RuntimeError, service.handleNotifyNodeInformation, conn, packet, node_list)
# tell the master node that it's running, nothing change # tell the master node that it's running, nothing change
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port, self.app.uuid, RUNNING_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port, self.app.uuid, RUNNING_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about a client node, don't care # notify about a client node, don't care
new_uuid = self.getNewUUID() new_uuid = self.getNewUUID()
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(CLIENT_NODE_TYPE, '127.0.0.1', self.client_port, new_uuid, BROKEN_STATE),] node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port, new_uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about an unknown node, don't care # notify about an unknown node, don't care
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', 11010, new_uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', 11010, new_uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
...@@ -105,20 +104,20 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -105,20 +104,20 @@ class MasterStorageHandlerTests(NeoTestBase):
uuid=self.getNewUUID(), uuid=self.getNewUUID(),
) )
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', 11012, uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', 11012, uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify node is running, as PMN already know it, nothing is done # notify node is running, as PMN already know it, nothing is done
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.storage_port, uuid, RUNNING_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, RUNNING_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify node is temp down, must be taken into account # notify node is temp down, must be taken into account
ptid = self.app.pt.getID() ptid = self.app.pt.getID()
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.storage_port, uuid, TEMPORARILY_DOWN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, TEMPORARILY_DOWN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
...@@ -127,7 +126,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -127,7 +126,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(ptid, self.app.pt.getID()) self.assertEquals(ptid, self.app.pt.getID())
# notify node is broken, must be taken into account and partition must changed # notify node is broken, must be taken into account and partition must changed
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.storage_port, uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
...@@ -169,7 +168,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -169,7 +168,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.app.pt.dropNode(old_node) self.app.pt.dropNode(old_node)
# do the right job # do the right job
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
storage_uuid_1 = self.identifyToMasterNode() storage_uuid_1 = self.identifyToMasterNode()
storage_uuid_2 = self.identifyToMasterNode(port=10022) storage_uuid_2 = self.identifyToMasterNode(port=10022)
storage_conn_1 = self.getFakeConnection(storage_uuid_1, ("127.0.0.1", self.storage_port)) storage_conn_1 = self.getFakeConnection(storage_uuid_1, ("127.0.0.1", self.storage_port))
...@@ -224,7 +223,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -224,7 +223,7 @@ class MasterStorageHandlerTests(NeoTestBase):
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0] tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 0) self.assertEqual(len(tid_list), 0)
# create some transaction # create some transaction
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port=self.client_port) port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
...@@ -242,7 +241,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -242,7 +241,7 @@ class MasterStorageHandlerTests(NeoTestBase):
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
# do not answer if not a storage node # do not answer if not a storage node
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port=self.client_port) port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
self.checkUnexpectedPacketRaised(service.handleNotifyPartitionChanges, self.checkUnexpectedPacketRaised(service.handleNotifyPartitionChanges,
...@@ -330,7 +329,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -330,7 +329,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), BROKEN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), BROKEN_STATE)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port = self.client_port) port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
...@@ -376,7 +375,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -376,7 +375,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port = self.client_port) port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
...@@ -422,7 +421,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -422,7 +421,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port = self.client_port) port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
......
...@@ -22,7 +22,7 @@ from mock import Mock ...@@ -22,7 +22,7 @@ from mock import Mock
from struct import pack, unpack from struct import pack, unpack
import neo import neo
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, NodeTypes, INVALID_UUID
from neo.master.handlers.verification import VerificationHandler from neo.master.handlers.verification import VerificationHandler
from neo.master.app import Application from neo.master.app import Application
from neo import protocol from neo import protocol
...@@ -30,7 +30,6 @@ from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \ ...@@ -30,7 +30,6 @@ from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \
NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \ NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \
ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \ ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \
ANSWER_TRANSACTION_INFORMATION, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \ ANSWER_TRANSACTION_INFORMATION, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure, VerificationFailure from neo.exception import OperationFailure, ElectionFailure, VerificationFailure
...@@ -73,7 +72,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -73,7 +72,7 @@ class MasterVerificationTests(NeoTestBase):
def getLastUUID(self): def getLastUUID(self):
return self.uuid return self.uuid
def identifyToMasterNode(self, node_type=STORAGE_NODE_TYPE, ip="127.0.0.1", def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1",
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
...@@ -87,7 +86,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -87,7 +86,7 @@ class MasterVerificationTests(NeoTestBase):
# Tests # Tests
def test_01_connectionClosed(self): def test_01_connectionClosed(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.verification.connectionClosed(conn) self.verification.connectionClosed(conn)
...@@ -100,7 +99,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -100,7 +99,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
def test_02_timeoutExpired(self): def test_02_timeoutExpired(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.verification.timeoutExpired(conn) self.verification.timeoutExpired(conn)
...@@ -113,7 +112,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -113,7 +112,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
def test_03_peerBroken(self): def test_03_peerBroken(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.verification.peerBroken(conn) self.verification.peerBroken(conn)
......
...@@ -24,7 +24,6 @@ from neo import protocol ...@@ -24,7 +24,6 @@ from neo import protocol
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.storage.app import Application from neo.storage.app import Application
from neo.storage.handlers.verification import VerificationHandler from neo.storage.handlers.verification import VerificationHandler
from neo.protocol import STORAGE_NODE_TYPE, MASTER_NODE_TYPE, CLIENT_NODE_TYPE
from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \ from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \
UP_TO_DATE_STATE, INVALID_OID, INVALID_TID, PROTOCOL_ERROR_CODE UP_TO_DATE_STATE, INVALID_OID, INVALID_TID, PROTOCOL_ERROR_CODE
from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \
...@@ -33,7 +32,7 @@ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION ...@@ -33,7 +32,7 @@ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION
UNLOCK_INFORMATION, TID_NOT_FOUND_CODE, ASK_TRANSACTION_INFORMATION, \ UNLOCK_INFORMATION, TID_NOT_FOUND_CODE, ASK_TRANSACTION_INFORMATION, \
COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS, SEND_PARTITION_TABLE COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS, SEND_PARTITION_TABLE
from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER
from neo.protocol import ANSWER_PRIMARY_MASTER from neo.protocol import ANSWER_PRIMARY_MASTER, NodeTypes
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64 from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
......
...@@ -24,7 +24,7 @@ from neo.pt import PartitionTable ...@@ -24,7 +24,7 @@ from neo.pt import PartitionTable
from neo.storage.app import Application from neo.storage.app import Application
from neo.bootstrap import BootstrapManager from neo.bootstrap import BootstrapManager
from neo import protocol from neo import protocol
from neo.protocol import STORAGE_NODE_TYPE, MASTER_NODE_TYPE from neo.protocol import NodeTypes
from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID
from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION
from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER
...@@ -39,7 +39,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -39,7 +39,7 @@ class BootstrapManagerTests(NeoTestBase):
self.app = Application(**config) self.app = Application(**config)
for address in self.app.master_node_list: for address in self.app.master_node_list:
self.app.nm.createMaster(address=address) self.app.nm.createMaster(address=address)
self.bootstrap = BootstrapManager(self.app, 'main', protocol.STORAGE_NODE_TYPE) self.bootstrap = BootstrapManager(self.app, 'main', NodeTypes.STORAGE)
# define some variable to simulate client and storage node # define some variable to simulate client and storage node
self.master_port = 10010 self.master_port = 10010
self.storage_port = 10020 self.storage_port = 10020
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
import unittest, os import unittest, os
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \ from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID DOWN_STATE, BROKEN_STATE, INVALID_UUID
from time import time from time import time
from neo.connection import BaseConnection, ListeningConnection, Connection, \ from neo.connection import BaseConnection, ListeningConnection, Connection, \
ClientConnection, ServerConnection, MTClientConnection, MTServerConnection ClientConnection, ServerConnection, MTClientConnection, MTServerConnection
......
...@@ -19,8 +19,7 @@ import unittest, os ...@@ -19,8 +19,7 @@ import unittest, os
from mock import Mock, ReturnValues from mock import Mock, ReturnValues
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import UnexpectedPacketError, MASTER_NODE_TYPE, \ from neo.protocol import UnexpectedPacketError
CLIENT_NODE_TYPE, STORAGE_NODE_TYPE, ADMIN_NODE_TYPE
from neo.protocol import PacketMalformedError, UnexpectedPacketError, \ from neo.protocol import PacketMalformedError, UnexpectedPacketError, \
BrokenNodeDisallowedError, NotReadyError, ProtocolError BrokenNodeDisallowedError, NotReadyError, ProtocolError
......
...@@ -18,9 +18,8 @@ ...@@ -18,9 +18,8 @@
import unittest import unittest
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
from neo.protocol import RUNNING_STATE, DOWN_STATE, \ from neo.protocol import RUNNING_STATE, DOWN_STATE, UNKNOWN_STATE
UNKNOWN_STATE, MASTER_NODE_TYPE, STORAGE_NODE_TYPE, \ from neo.protocol import NodeTypes
CLIENT_NODE_TYPE, ADMIN_NODE_TYPE
from neo.node import Node, MasterNode, StorageNode, ClientNode, AdminNode, \ from neo.node import Node, MasterNode, StorageNode, ClientNode, AdminNode, \
NodeManager NodeManager
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
...@@ -90,7 +89,7 @@ class NodesTests(NeoTestBase): ...@@ -90,7 +89,7 @@ class NodesTests(NeoTestBase):
def testMaster(self): def testMaster(self):
""" Check Master sub class """ """ Check Master sub class """
node = MasterNode(self.manager) node = MasterNode(self.manager)
self.assertEqual(node.getType(), protocol.MASTER_NODE_TYPE) self.assertEqual(node.getType(), protocol.NodeTypes.MASTER)
self.assertTrue(node.isMaster()) self.assertTrue(node.isMaster())
self.assertFalse(node.isStorage()) self.assertFalse(node.isStorage())
self.assertFalse(node.isClient()) self.assertFalse(node.isClient())
...@@ -99,7 +98,7 @@ class NodesTests(NeoTestBase): ...@@ -99,7 +98,7 @@ class NodesTests(NeoTestBase):
def testStorage(self): def testStorage(self):
""" Check Storage sub class """ """ Check Storage sub class """
node = StorageNode(self.manager) node = StorageNode(self.manager)
self.assertEqual(node.getType(), protocol.STORAGE_NODE_TYPE) self.assertEqual(node.getType(), protocol.NodeTypes.STORAGE)
self.assertTrue(node.isStorage()) self.assertTrue(node.isStorage())
self.assertFalse(node.isMaster()) self.assertFalse(node.isMaster())
self.assertFalse(node.isClient()) self.assertFalse(node.isClient())
...@@ -108,7 +107,7 @@ class NodesTests(NeoTestBase): ...@@ -108,7 +107,7 @@ class NodesTests(NeoTestBase):
def testClient(self): def testClient(self):
""" Check Client sub class """ """ Check Client sub class """
node = ClientNode(self.manager) node = ClientNode(self.manager)
self.assertEqual(node.getType(), protocol.CLIENT_NODE_TYPE) self.assertEqual(node.getType(), protocol.NodeTypes.CLIENT)
self.assertTrue(node.isClient()) self.assertTrue(node.isClient())
self.assertFalse(node.isMaster()) self.assertFalse(node.isMaster())
self.assertFalse(node.isStorage()) self.assertFalse(node.isStorage())
...@@ -117,7 +116,7 @@ class NodesTests(NeoTestBase): ...@@ -117,7 +116,7 @@ class NodesTests(NeoTestBase):
def testAdmin(self): def testAdmin(self):
""" Check Admin sub class """ """ Check Admin sub class """
node = AdminNode(self.manager) node = AdminNode(self.manager)
self.assertEqual(node.getType(), protocol.ADMIN_NODE_TYPE) self.assertEqual(node.getType(), protocol.NodeTypes.ADMIN)
self.assertTrue(node.isAdmin()) self.assertTrue(node.isAdmin())
self.assertFalse(node.isMaster()) self.assertFalse(node.isMaster())
self.assertFalse(node.isStorage()) self.assertFalse(node.isStorage())
...@@ -249,10 +248,10 @@ class NodeManagerTests(NeoTestBase): ...@@ -249,10 +248,10 @@ class NodeManagerTests(NeoTestBase):
new_address = ('127.0.0.1', 2001) new_address = ('127.0.0.1', 2001)
new_uuid = self.getNewUUID() new_uuid = self.getNewUUID()
node_list = ( node_list = (
(CLIENT_NODE_TYPE, None, self.client.getUUID(), DOWN_STATE), (NodeTypes.CLIENT, None, self.client.getUUID(), DOWN_STATE),
(MASTER_NODE_TYPE, new_address, self.master.getUUID(), RUNNING_STATE), (NodeTypes.MASTER, new_address, self.master.getUUID(), RUNNING_STATE),
(STORAGE_NODE_TYPE, self.storage.getAddress(), new_uuid, RUNNING_STATE), (NodeTypes.STORAGE, self.storage.getAddress(), new_uuid, RUNNING_STATE),
(ADMIN_NODE_TYPE, self.admin.getAddress(), self.admin.getUUID(), UNKNOWN_STATE), (NodeTypes.ADMIN, self.admin.getAddress(), self.admin.getUUID(), UNKNOWN_STATE),
) )
# update manager content # update manager content
manager.update(node_list) manager.update(node_list)
......
...@@ -19,6 +19,7 @@ import unittest, os ...@@ -19,6 +19,7 @@ import unittest, os
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
from neo.protocol import * from neo.protocol import *
from neo.protocol import NodeTypes
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.util import getNextTID from neo.util import getNextTID
from time import time, gmtime from time import time, gmtime
...@@ -91,10 +92,10 @@ class ProtocolTests(NeoTestBase): ...@@ -91,10 +92,10 @@ class ProtocolTests(NeoTestBase):
def test_11_requestNodeIdentification(self): def test_11_requestNodeIdentification(self):
uuid = self.getNewUUID() uuid = self.getNewUUID()
p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE, uuid, p = protocol.requestNodeIdentification(NodeTypes.CLIENT, uuid,
("127.0.0.1", 9080), "unittest") ("127.0.0.1", 9080), "unittest")
node, p_uuid, (ip, port), name = p.decode() node, p_uuid, (ip, port), name = p.decode()
self.assertEqual(node, CLIENT_NODE_TYPE) self.assertEqual(node, NodeTypes.CLIENT)
self.assertEqual(p_uuid, uuid) self.assertEqual(p_uuid, uuid)
self.assertEqual(ip, "127.0.0.1") self.assertEqual(ip, "127.0.0.1")
self.assertEqual(port, 9080) self.assertEqual(port, 9080)
...@@ -102,10 +103,10 @@ class ProtocolTests(NeoTestBase): ...@@ -102,10 +103,10 @@ class ProtocolTests(NeoTestBase):
def test_12_acceptNodeIdentification(self): def test_12_acceptNodeIdentification(self):
uuid1, uuid2 = self.getNewUUID(), self.getNewUUID() uuid1, uuid2 = self.getNewUUID(), self.getNewUUID()
p = protocol.acceptNodeIdentification(CLIENT_NODE_TYPE, uuid1, p = protocol.acceptNodeIdentification(NodeTypes.CLIENT, uuid1,
("127.0.0.1", 9080), 10, 20, uuid2) ("127.0.0.1", 9080), 10, 20, uuid2)
node, p_uuid, (ip, port), nb_partitions, nb_replicas, your_uuid = p.decode() node, p_uuid, (ip, port), nb_partitions, nb_replicas, your_uuid = p.decode()
self.assertEqual(node, CLIENT_NODE_TYPE) self.assertEqual(node, NodeTypes.CLIENT)
self.assertEqual(p_uuid, uuid1) self.assertEqual(p_uuid, uuid1)
self.assertEqual(ip, "127.0.0.1") self.assertEqual(ip, "127.0.0.1")
self.assertEqual(port, 9080) self.assertEqual(port, 9080)
...@@ -143,9 +144,9 @@ class ProtocolTests(NeoTestBase): ...@@ -143,9 +144,9 @@ class ProtocolTests(NeoTestBase):
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
node_list = [(CLIENT_NODE_TYPE, ("127.0.0.1", 1), uuid1, RUNNING_STATE), node_list = [(NodeTypes.CLIENT, ("127.0.0.1", 1), uuid1, RUNNING_STATE),
(CLIENT_NODE_TYPE, ("127.0.0.2", 2), uuid2, DOWN_STATE), (NodeTypes.CLIENT, ("127.0.0.2", 2), uuid2, DOWN_STATE),
(CLIENT_NODE_TYPE, ("127.0.0.3", 3), uuid3, BROKEN_STATE)] (NodeTypes.CLIENT, ("127.0.0.3", 3), uuid3, BROKEN_STATE)]
p = protocol.notifyNodeInformation(node_list) p = protocol.notifyNodeInformation(node_list)
p_node_list = p.decode()[0] p_node_list = p.decode()[0]
self.assertEqual(node_list, p_node_list) self.assertEqual(node_list, p_node_list)
......
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