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

Add create<NodeType> methods on the NodeManager, now node creation is only done

through those methods and node registration is automatic. There is no more need
to import Node classes directly, so remove all related imports.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1312 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 76671a6f
......@@ -17,7 +17,7 @@
from neo import logging
from neo.node import NodeManager, MasterNode
from neo.node import NodeManager
from neo.event import EventManager
from neo.connection import ListeningConnection
from neo.exception import PrimaryFailure
......@@ -120,7 +120,7 @@ class Application(object):
nm.clear()
self.cluster_state = None
for server in self.master_node_list:
nm.add(MasterNode(server = server))
nm.createMaster(server=server)
# search, find, connect and identify to the primary master
bootstrap = BootstrapManager(self, self.name, protocol.ADMIN_NODE_TYPE,
......
......@@ -18,7 +18,6 @@
from neo import logging
from neo.handler import EventHandler
from neo.node import StorageNode
from neo import protocol
from neo.exception import PrimaryFailure
from neo.util import dump
......@@ -174,9 +173,10 @@ class MasterEventHandler(EventHandler):
for uuid, state in row:
node = nm.getNodeByUUID(uuid)
if node is None:
node = StorageNode(uuid = uuid)
node.setState(protocol.TEMPORARILY_DOWN_STATE)
nm.add(node)
nm.createStorage(
uuid=uuid,
state=protocol.TEMPORARILY_DOWN_STATE
)
pt.setCell(offset, node, state)
pt.log()
......
......@@ -19,7 +19,6 @@ from neo import logging
from time import sleep
from neo.handler import EventHandler
from neo.node import MasterNode
from neo import protocol
from neo.util import dump
from neo.connection import ClientConnection
......@@ -65,8 +64,7 @@ class BootstrapManager(EventHandler):
for address, uuid in known_master_list:
node = nm.getNodeByServer(address)
if node is None:
node = MasterNode(server=address)
nm.add(node)
nm.createMaster(server=address)
node.setUUID(uuid)
self.primary = nm.getNodeByUUID(primary_uuid)
......
......@@ -33,7 +33,7 @@ from neo.event import EventManager
from neo.util import makeChecksum, dump
from neo.locking import RLock, Lock
from neo.connection import MTClientConnection
from neo.node import NodeManager, MasterNode, StorageNode
from neo.node import NodeManager
from neo.connector import getConnectorHandler
from neo.client.exception import NEOStorageError, NEOStorageConflictError
from neo.client.exception import NEOStorageNotFoundError
......@@ -255,7 +255,7 @@ class Application(object):
self.master_node_list = parseMasterList(master_nodes)
logging.debug('master nodes are %s', self.master_node_list)
for server in self.master_node_list:
self.nm.add(MasterNode(server=server))
self.nm.createMaster(server=server)
# no self-assigned UUID, primary master will supply us one
self.uuid = None
......
......@@ -18,7 +18,6 @@
from neo import logging
from neo.client.handlers import BaseHandler, AnswerBaseHandler
from neo.node import MasterNode
from neo.pt import MTPartitionTable as PartitionTable
from neo import protocol
from neo.util import dump
......@@ -65,8 +64,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
for address, uuid in known_master_list:
n = app.nm.getNodeByServer(address)
if n is None:
n = MasterNode(server=address)
app.nm.add(n)
app.nm.createMaster(server=address)
if uuid is not None:
# If I don't know the UUID yet, believe what the peer
# told me at the moment.
......
......@@ -23,7 +23,7 @@ from struct import pack, unpack
from neo import protocol
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UUID_NAMESPACES, BOOTING_CLUSTER_STATE, INVALID_UUID
from neo.node import NodeManager, MasterNode, StorageNode, ClientNode, AdminNode
from neo.node import NodeManager
from neo.event import EventManager
from neo.connection import ListeningConnection, ClientConnection, ServerConnection
from neo.exception import ElectionFailure, PrimaryFailure, VerificationFailure, \
......@@ -106,7 +106,7 @@ class Application(object):
def run(self):
"""Make sure that the status is sane and start a loop."""
for server in self.master_node_list:
self.nm.add(MasterNode(server = server))
self.nm.createMaster(server=server)
# Make a listening port.
self.listening_conn = ListeningConnection(self.em, None,
......@@ -799,7 +799,7 @@ class Application(object):
if node_type == protocol.ADMIN_NODE_TYPE:
# always accept admin nodes
klass = AdminNode
node_ctor = self.nm.createAdmin
handler = administration.AdministrationHandler
logging.info('Accept an admin %s' % dump(uuid))
elif node_type == protocol.MASTER_NODE_TYPE:
......@@ -807,7 +807,7 @@ class Application(object):
# unknown master, rejected
raise protocol.ProtocolError('Reject an unknown master node')
# always put other master in waiting state
klass = MasterNode
node_ctor = self.nm.createMaster
handler = secondary.SecondaryMasterHandler
logging.info('Accept a master %s' % dump(uuid))
elif node_type == protocol.CLIENT_NODE_TYPE:
......@@ -815,13 +815,13 @@ class Application(object):
if self.cluster_state != protocol.RUNNING_CLUSTER_STATE:
logging.info('Reject a connection from a client')
raise protocol.NotReadyError
klass = ClientNode
node_ctor = self.nm.createClient
handler = client.ClientServiceHandler
logging.info('Accept a client %s' % dump(uuid))
elif node_type == protocol.STORAGE_NODE_TYPE:
klass = StorageNode
node_ctor = self.nm.createStorage
(uuid, state, handler) = self.identifyStorageNode(uuid, node)
logging.info('Accept a storage (%s)' % state)
return (uuid, node, state, handler, klass)
return (uuid, node, state, handler, node_ctor)
......@@ -23,7 +23,6 @@ from neo.protocol import MASTER_NODE_TYPE, \
DOWN_STATE
from neo.master.handlers import MasterHandler
from neo.exception import ElectionFailure
from neo.node import MasterNode
class ElectionHandler(MasterHandler):
"""This class deals with events for a primary master election."""
......
......@@ -58,14 +58,13 @@ class IdentificationHandler(MasterHandler):
# ask the app the node identification, if refused, an exception is raised
result = self.app.identifyNode(node_type, uuid, node)
(uuid, node, state, handler, klass) = result
(uuid, node, state, handler, node_ctor) = result
if uuid is None:
# no valid uuid, give it one
uuid = app.getNewUUID(node_type)
if node is None:
# new node
node = klass(uuid=uuid, server=address)
app.nm.add(node)
node = node_ctor(uuid=uuid, server=address)
handler = handler(self.app)
# set up the node
node.setUUID(uuid)
......
......@@ -20,7 +20,6 @@ from neo import logging
from neo import protocol
from neo.master.handlers import MasterHandler
from neo.protocol import UnexpectedPacketError, TEMPORARILY_DOWN_STATE
from neo.node import StorageNode
from neo.util import dump
class RecoveryHandler(MasterHandler):
......@@ -56,9 +55,10 @@ class RecoveryHandler(MasterHandler):
for uuid, state in row:
node = app.nm.getNodeByUUID(uuid)
if node is None:
node = StorageNode(uuid=uuid)
node.setState(protocol.TEMPORARILY_DOWN_STATE)
app.nm.add(node)
app.nm.createStorage(
uuid=uuid,
state=protocol.TEMPORARILY_DOWN_STATE,
)
# load partition in memory
self.app.pt.load(ptid, row_list, self.app.nm)
......@@ -22,7 +22,6 @@ from neo.protocol import MASTER_NODE_TYPE, \
from neo.master.handlers import MasterHandler
from neo.exception import ElectionFailure, PrimaryFailure
from neo.protocol import UnexpectedPacketError
from neo.node import MasterNode
class SecondaryMasterHandler(MasterHandler):
""" Handler used by primary to handle secondary masters"""
......
......@@ -29,8 +29,8 @@ from neo.util import dump
class Node(object):
"""This class represents a node."""
def __init__(self, server = None, uuid = None):
self.state = protocol.UNKNOWN_STATE
def __init__(self, server=None, uuid=None, state=protocol.UNKNOWN_STATE):
self.state = state
self.server = server
self.uuid = uuid
self.manager = None
......@@ -200,6 +200,39 @@ class NodeManager(object):
return None
return self.uuid_dict.get(uuid)
def _createNode(self, klass, *args, **kw):
node = klass(*args, **kw)
self.add(node)
return node
def createMaster(self, *args, **kw):
""" Create and register a new master """
return self._createNode(MasterNode, *args, **kw)
def createStorage(self, *args, **kw):
""" Create and register a new storage """
return self._createNode(StorageNode, *args, **kw)
def createClient(self, *args, **kw):
""" Create and register a new client """
return self._createNode(ClientNode, *args, **kw)
def createAdmin(self, *args, **kw):
""" Create and register a new admin """
return self._createNode(AdminNode, *args, **kw)
def createFromNodeType(self, node_type, *args, **kw):
# XXX: use a static dict or drop this
klass = {
protocol.MASTER_NODE_TYPE: self.createMaster,
protocol.STORAGE_NODE_TYPE: self.createStorage,
protocol.CLIENT_NODE_TYPE: self.createClient,
protocol.ADMIN_NODE_TYPE: self.createAdmin,
}.get(node_type)
if klass is None:
raise RuntimeError('Unknown node type : %s' % node_type)
return self._createNode(klass, *args, **kw)
def clear(self, filter=None):
for node in self.getNodeList():
if filter is None or filter(node):
......
......@@ -22,7 +22,7 @@ from collections import deque
from neo import protocol
from neo.protocol import TEMPORARILY_DOWN_STATE, \
cell_states, HIDDEN_STATE
from neo.node import NodeManager, MasterNode, StorageNode
from neo.node import NodeManager
from neo.event import EventManager
from neo.storage.mysqldb import MySQLDatabaseManager
from neo.connection import ListeningConnection
......@@ -136,9 +136,10 @@ class Application(object):
state = protocol.cell_states[state]
# register unknown nodes
if self.nm.getNodeByUUID(uuid) is None:
node = StorageNode(uuid=uuid)
node.setState(protocol.TEMPORARILY_DOWN_STATE)
self.nm.add(node)
self.nm.createStorage(
uuid=uuid,
state=protocol.TEMPORARILY_DOWN_STATE,
)
new_cell_list.append((offset, uuid, state))
# load the partition table in manager
self.pt.clear()
......@@ -150,7 +151,7 @@ class Application(object):
raise RuntimeError, 'cluster name must be non-empty'
for server in self.master_node_list:
self.nm.add(MasterNode(server = server))
self.nm.createMaster(server=server)
# Make a listening port
handler = identification.IdentificationHandler(self)
......
......@@ -22,7 +22,6 @@ from neo import protocol
from neo.protocol import RUNNING_STATE, BROKEN_STATE, CLIENT_NODE_TYPE, \
DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE
from neo.util import dump
from neo.node import MasterNode, StorageNode, ClientNode
from neo.exception import PrimaryFailure, OperationFailure
class BaseStorageHandler(EventHandler):
......
......@@ -20,7 +20,6 @@ from neo import logging
from neo.storage.handlers import BaseStorageHandler
from neo import protocol
from neo.util import dump
from neo.node import ClientNode
class IdentificationHandler(BaseStorageHandler):
""" Handler used for incoming connections during operation state """
......@@ -41,8 +40,7 @@ class IdentificationHandler(BaseStorageHandler):
from neo.storage.handlers.client import ClientOperationHandler
handler = ClientOperationHandler
if node is None:
node = ClientNode()
app.nm.add(node)
node = app.nm.createClient()
elif node_type == protocol.STORAGE_NODE_TYPE:
from neo.storage.handlers.storage import StorageOperationHandler
handler = StorageOperationHandler
......
......@@ -20,7 +20,6 @@ from neo import logging
from neo.storage.handlers import BaseMasterHandler
from neo.protocol import TEMPORARILY_DOWN_STATE
from neo import protocol
from neo.node import StorageNode
class InitializationHandler(BaseMasterHandler):
......
......@@ -35,7 +35,6 @@ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure
from neo.node import MasterNode, StorageNode, ClientNode
class MasterClientHandlerTests(NeoTestBase):
......@@ -50,7 +49,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.app.ltid = '\0' * 8
self.app.finishing_transaction_dict = {}
for server in self.app.master_node_list:
self.app.nm.add(MasterNode(server = server))
self.app.nm.createMaster(server=server)
self.service = ClientServiceHandler(self.app)
# define some variable to simulate client and storage node
self.client_port = 11022
......@@ -61,7 +60,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.storage_address = ('127.0.0.1', self.storage_port)
# register the storage
kw = {'uuid':self.getNewUUID(), 'server': self.master_address}
self.app.nm.add(StorageNode(**kw))
self.app.nm.createStorage(**kw)
def tearDown(self):
NeoTestBase.tearDown(self)
......@@ -74,15 +73,12 @@ class MasterClientHandlerTests(NeoTestBase):
"""Do first step of identification to MN """
# register the master itself
uuid = self.getNewUUID()
address = (ip, port)
if node_type == MASTER_NODE_TYPE:
node = MasterNode(address, uuid)
elif node_type == CLIENT_NODE_TYPE:
node = ClientNode(address, uuid)
else:
node = StorageNode(address, uuid)
node.setState(protocol.RUNNING_STATE)
self.app.nm.add(node)
self.app.nm.createFromNodeType(
node_type,
server=(ip, port),
uuid=uuid,
state=protocol.RUNNING_STATE,
)
return uuid
# Tests
......@@ -114,7 +110,10 @@ class MasterClientHandlerTests(NeoTestBase):
for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID")
# notify about a known node but with bad address, don't care
self.app.nm.add(StorageNode(("127.0.0.1", 11011), self.getNewUUID()))
self.app.nm.createStorage(
server=("127.0.0.1", 11011),
uuid=self.getNewUUID(),
)
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, ('127.0.0.1', 11012), uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list)
......
......@@ -47,7 +47,6 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure
from neo.node import MasterNode, StorageNode
from neo.tests import DoNothingConnector
from neo.connection import ClientConnection
......@@ -71,7 +70,7 @@ class MasterClientElectionTests(NeoTestBase):
self.app.em = Mock({"getConnectionList" : []})
self.app.finishing_transaction_dict = {}
for server in self.app.master_node_list:
self.app.nm.add(MasterNode(server = server))
self.app.nm.createMaster(server=server)
self.election = ClientElectionHandler(self.app)
self.app.unconnected_master_node_set = set()
self.app.negotiating_master_node_set = set()
......@@ -97,9 +96,8 @@ class MasterClientElectionTests(NeoTestBase):
def identifyToMasterNode(self, port=10000, ip='127.0.0.1'):
uuid = self.getNewUUID()
address = (ip, port)
node = MasterNode(address, uuid)
node.setState(protocol.RUNNING_STATE)
self.app.nm.add(node)
self.app.nm.createMaster(server=address, uuid=uuid,
state=protocol.RUNNING_STATE)
return uuid
def test_01_connectionStarted(self):
......@@ -200,7 +198,7 @@ class MasterClientElectionTests(NeoTestBase):
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = protocol.askPrimaryMaster()
self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid))
self.app.nm.createMaster(server=("127.0.0.1", self.master_port), uuid=uuid)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
......@@ -243,7 +241,7 @@ class MasterClientElectionTests(NeoTestBase):
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = protocol.askPrimaryMaster()
self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid))
self.app.nm.createMaster(server=("127.0.0.1", self.master_port), uuid=uuid)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
......@@ -273,7 +271,7 @@ class MasterServerElectionTests(NeoTestBase):
self.app.em = Mock({"getConnectionList" : []})
self.app.finishing_transaction_dict = {}
for server in self.app.master_node_list:
self.app.nm.add(MasterNode(server = server))
self.app.nm.createMaster(server=server)
self.election = ServerElectionHandler(self.app)
self.app.unconnected_master_node_set = set()
self.app.negotiating_master_node_set = set()
......
......@@ -21,7 +21,6 @@ from neo.tests import NeoTestBase
from neo.master.app import Application
from neo.protocol import INVALID_PTID, INVALID_OID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION
from neo.node import MasterNode, ClientNode, StorageNode
from neo.storage.mysqldb import p64, u64
class MasterAppTests(NeoTestBase):
......@@ -78,12 +77,11 @@ class MasterAppTests(NeoTestBase):
def test_06_broadcastNodeInformation(self):
# defined some nodes to which data will be send
master_uuid = self.getNewUUID()
master = MasterNode(uuid=master_uuid)
self.app.nm.createMaster(uuid=master_uuid)
storage_uuid = self.getNewUUID()
storage = StorageNode(uuid=storage_uuid)
storage = self.app.nm.createStorage(uuid=storage_uuid)
client_uuid = self.getNewUUID()
client = ClientNode(uuid=client_uuid)
self.app.nm.add(master)
client = self.app.nm.createClient(uuid=client_uuid)
self.app.nm.add(storage)
self.app.nm.add(client)
# create conn and patch em
......@@ -93,7 +91,7 @@ class MasterAppTests(NeoTestBase):
self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)})
# no address defined, not send to client node
c_node = ClientNode(uuid = self.getNewUUID())
c_node = self.app.nm.createClient(uuid = self.getNewUUID())
self.app.broadcastNodeInformation(c_node)
# check conn
self.checkNoPacketSent(client_conn)
......@@ -105,7 +103,10 @@ class MasterAppTests(NeoTestBase):
storage_conn = Mock({"getUUID" : storage_uuid})
client_conn = Mock({"getUUID" : client_uuid})
self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)})
s_node = ClientNode(uuid = self.getNewUUID(), server=("127.1.0.1", 3361))
s_node = self.app.nm.createClient(
uuid = self.getNewUUID(),
server=("127.1.0.1", 3361)
)
self.app.broadcastNodeInformation(c_node)
# check conn
self.checkNoPacketSent(client_conn)
......@@ -117,7 +118,11 @@ class MasterAppTests(NeoTestBase):
storage_conn = Mock({"getUUID" : storage_uuid})
client_conn = Mock({"getUUID" : client_uuid})
self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)})
s_node = StorageNode(uuid = self.getNewUUID(), server=("127.0.0.1", 1351))
s_node = self.app.nm.createStorage(
uuid=self.getNewUUID(),
server=("127.0.0.1", 1351)
)
self.app.broadcastNodeInformation(s_node)
# check conn
self.checkNotifyNodeInformation(client_conn)
......
......@@ -47,7 +47,6 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure
from neo.node import MasterNode, StorageNode
from neo.tests import DoNothingConnector
from neo.connection import ClientConnection
......@@ -60,7 +59,7 @@ class MasterRecoveryTests(NeoTestBase):
self.app.pt.clear()
self.app.finishing_transaction_dict = {}
for server in self.app.master_node_list:
self.app.nm.add(MasterNode(server = server))
self.app.nm.createMaster(server=server)
self.recovery = RecoveryHandler(self.app)
self.app.unconnected_master_node_set = set()
self.app.negotiating_master_node_set = set()
......
......@@ -35,7 +35,6 @@ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure
from neo.node import MasterNode, StorageNode
class MasterStorageHandlerTests(NeoTestBase):
......@@ -48,7 +47,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.app.em = Mock({"getConnectionList" : []})
self.app.finishing_transaction_dict = {}
for server in self.app.master_node_list:
self.app.nm.add(MasterNode(server = server))
self.app.nm.createMaster(server=server)
self.service = StorageServiceHandler(self.app)
# define some variable to simulate client and storage node
self.client_port = 11022
......@@ -101,7 +100,10 @@ class MasterStorageHandlerTests(NeoTestBase):
for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID")
# notify about a known node but with bad address, don't care
self.app.nm.add(StorageNode(("127.0.0.1", 11011), self.getNewUUID()))
self.app.nm.createStorage(
server=("127.0.0.1", 11011),
uuid=self.getNewUUID(),
)
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', 11012, uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list)
......
......@@ -34,7 +34,6 @@ from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure, VerificationFailure
from neo.node import MasterNode, StorageNode
from neo.tests import DoNothingConnector
from neo.connection import ClientConnection
......@@ -48,7 +47,7 @@ class MasterVerificationTests(NeoTestBase):
self.app.pt.clear()
self.app.finishing_transaction_dict = {}
for server in self.app.master_node_list:
self.app.nm.add(MasterNode(server = server))
self.app.nm.createMaster(server=server)
self.verification = VerificationHandler(self.app)
self.app.unconnected_master_node_set = set()
self.app.negotiating_master_node_set = set()
......@@ -79,11 +78,11 @@ class MasterVerificationTests(NeoTestBase):
"""Do first step of identification to MN
"""
uuid = self.getNewUUID()
if node_type == STORAGE_NODE_TYPE:
node = StorageNode(uuid=uuid)
else:
node = MasterNode(uuid=uuid)
self.app.nm.add(node)
self.app.nm.createFromNodeType(
node_type,
server=(ip, port),
uuid=uuid,
)
return uuid
# Tests
......
......@@ -22,8 +22,7 @@ from struct import pack, unpack
from mock import Mock
from collections import deque
from neo.tests import NeoTestBase
from neo.master.app import MasterNode
from neo.storage.app import Application, StorageNode
from neo.storage.app import Application
from neo.storage.handlers.client import TransactionInformation
from neo.storage.handlers.client import ClientOperationHandler
from neo.exception import PrimaryFailure, OperationFailure
......@@ -53,8 +52,7 @@ class StorageClientHandlerTests(NeoTestBase):
self.app.load_lock_dict = {}
self.app.event_queue = deque()
for server in self.app.master_node_list:
master = MasterNode(server = server)
self.app.nm.add(master)
self.app.nm.createMaster(server=server)
# handler
self.operation = ClientOperationHandler(self.app)
# set pmn
......@@ -89,12 +87,10 @@ class StorageClientHandlerTests(NeoTestBase):
def test_05_dealWithClientFailure(self):
# check if client's transaction are cleaned
uuid = self.getNewUUID()
from neo.node import ClientNode
manager = Mock()
client = ClientNode(('127.0.0.1', 10010))
client.setManager(manager)
client.setUUID(uuid)
self.app.nm.add(client)
client = self.app.nm.createClient(
uuid=uuid,
server=('127.0.0.1', 10010)
)
self.app.store_lock_dict[0] = object()
transaction = Mock({
'getUUID': uuid,
......
......@@ -21,9 +21,8 @@ from neo import logging
from mock import Mock
from neo.tests import NeoTestBase
from neo import protocol
from neo.node import MasterNode
from neo.pt import PartitionTable
from neo.storage.app import Application, StorageNode
from neo.storage.app import Application
from neo.storage.handlers.initialization import InitializationHandler
from neo.protocol import STORAGE_NODE_TYPE, MASTER_NODE_TYPE, CLIENT_NODE_TYPE
from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \
......@@ -106,9 +105,9 @@ class StorageInitializationHandlerTests(NeoTestBase):
node_2 = self.getNewUUID()
node_3 = self.getNewUUID()
# SN already know all nodes
self.app.nm.add(StorageNode(uuid=node_1))
self.app.nm.add(StorageNode(uuid=node_2))
self.app.nm.add(StorageNode(uuid=node_3))
self.app.nm.createStorage(uuid=node_1)
self.app.nm.createStorage(uuid=node_2)
self.app.nm.createStorage(uuid=node_3)
self.assertEqual(self.app.dm.getPartitionTable(), [])
row_list = [(0, ((node_1, UP_TO_DATE_STATE), (node_2, UP_TO_DATE_STATE))),
(1, ((node_3, UP_TO_DATE_STATE), (node_1, UP_TO_DATE_STATE))),
......
......@@ -22,8 +22,7 @@ from struct import pack, unpack
from mock import Mock
from collections import deque
from neo.tests import NeoTestBase
from neo.master.app import MasterNode
from neo.storage.app import Application, StorageNode
from neo.storage.app import Application
from neo.storage.handlers.master import MasterOperationHandler
from neo.exception import PrimaryFailure, OperationFailure
from neo.pt import PartitionTable
......@@ -52,8 +51,7 @@ class StorageMasterHandlerTests(NeoTestBase):
self.app.load_lock_dict = {}
self.app.event_queue = deque()
for server in self.app.master_node_list:
master = MasterNode(server = server)
self.app.nm.add(master)
self.app.nm.createMaster(server=server)
# handler
self.operation = MasterOperationHandler(self.app)
# set pmn
......@@ -129,9 +127,9 @@ class StorageMasterHandlerTests(NeoTestBase):
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
app = self.app
# register nodes
app.nm.add(StorageNode(uuid=uuid1))
app.nm.add(StorageNode(uuid=uuid2))
app.nm.add(StorageNode(uuid=uuid3))
app.nm.createStorage(uuid=uuid1)
app.nm.createStorage(uuid=uuid2)
app.nm.createStorage(uuid=uuid3)
ptid1, ptid2 = (1, 2)
self.assertNotEquals(ptid1, ptid2)
app.pt = PartitionTable(3, 1)
......
......@@ -21,7 +21,6 @@ from neo.tests import NeoTestBase
from neo.storage.app import Application
from neo.protocol import INVALID_PTID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION, UP_TO_DATE_STATE
from neo.node import MasterNode, ClientNode, StorageNode
from neo.storage.mysqldb import p64, u64, MySQLDatabaseManager
from collections import deque
from neo.pt import PartitionTable
......@@ -59,11 +58,11 @@ class StorageAppTests(NeoTestBase):
# add some node, will be remove when loading table
master_uuid = self.getNewUUID()
master = MasterNode(uuid=master_uuid)
master = self.app.nm.createMaster(uuid=master_uuid)
storage_uuid = self.getNewUUID()
storage = StorageNode(uuid=storage_uuid)
storage = self.app.nm.createStorage(uuid=storage_uuid)
client_uuid = self.getNewUUID()
client = ClientNode(uuid=client_uuid)
client = self.app.nm.createClient(uuid=client_uuid)
self.app.pt.setCell(0, master, UP_TO_DATE_STATE)
self.app.pt.setCell(0, storage, UP_TO_DATE_STATE)
......
......@@ -22,8 +22,7 @@ from struct import pack, unpack
from mock import Mock
from collections import deque
from neo.tests import NeoTestBase
from neo.master.app import MasterNode
from neo.storage.app import Application, StorageNode
from neo.storage.app import Application
from neo.storage.handlers.storage import StorageOperationHandler
from neo import protocol
from neo.protocol import *
......@@ -50,8 +49,7 @@ class StorageStorageHandlerTests(NeoTestBase):
self.app.load_lock_dict = {}
self.app.event_queue = deque()
for server in self.app.master_node_list:
master = MasterNode(server = server)
self.app.nm.add(master)
self.app.nm.createMaster(server=server)
# handler
self.operation = StorageOperationHandler(self.app)
# set pmn
......
......@@ -21,9 +21,8 @@ from neo import logging
from mock import Mock
from neo.tests import NeoTestBase
from neo import protocol
from neo.node import MasterNode
from neo.pt import PartitionTable
from neo.storage.app import Application, StorageNode
from neo.storage.app import Application
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, \
......@@ -162,7 +161,10 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.assertEqual(len(rows), 0)
# try to get known offset
node = StorageNode(("127.7.9.9", 1), self.getNewUUID())
node = self.app.nm.createStorage(
server=("127.7.9.9", 1),
uuid=self.getNewUUID()
)
self.app.pt.setCell(1, node, UP_TO_DATE_STATE)
self.assertTrue(self.app.pt.hasOffset(1))
conn = Mock({"getUUID" : uuid,
......@@ -194,7 +196,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
new_uuid = self.getNewUUID()
cell = (0, new_uuid, UP_TO_DATE_STATE)
self.app.nm.add(StorageNode(uuid=new_uuid))
self.app.nm.createStorage(uuid=new_uuid)
self.app.pt = PartitionTable(1, 1)
self.app.dm = Mock({ })
ptid, self.ptid = self.getTwoIDs()
......
......@@ -20,9 +20,8 @@ import unittest
from neo import logging
from mock import Mock
from neo.tests import NeoTestBase
from neo.master.app import MasterNode
from neo.pt import PartitionTable
from neo.storage.app import Application, StorageNode
from neo.storage.app import Application
from neo.bootstrap import BootstrapManager
from neo import protocol
from neo.protocol import STORAGE_NODE_TYPE, MASTER_NODE_TYPE
......@@ -39,7 +38,7 @@ class BootstrapManagerTests(NeoTestBase):
config = self.getStorageConfiguration()
self.app = Application(**config)
for server in self.app.master_node_list:
self.app.nm.add(MasterNode(server=server))
self.app.nm.createMaster(server=server)
self.bootstrap = BootstrapManager(self.app, 'main', protocol.STORAGE_NODE_TYPE)
# define some variable to simulate client and storage node
self.master_port = 10010
......
......@@ -19,7 +19,6 @@ from mock import Mock
from neo import protocol
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID
from neo.node import Node, MasterNode, StorageNode, ClientNode, NodeManager
from time import time
from neo.connection import BaseConnection, ListeningConnection, Connection, \
ClientConnection, ServerConnection, MTClientConnection, MTServerConnection
......
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