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