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

Factorise split of master node list from command line. Now use '/' as

separator for master addresses list instead of a space to be more shell friendly
(no more need to surround the argument with quotes, easier for remote commands).


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1289 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 60fc3f82
...@@ -27,6 +27,7 @@ from neo.connector import getConnectorHandler ...@@ -27,6 +27,7 @@ from neo.connector import getConnectorHandler
from neo.bootstrap import BootstrapManager 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
class Dispatcher: class Dispatcher:
"""Dispatcher use to redirect master request to handler""" """Dispatcher use to redirect master request to handler"""
...@@ -65,12 +66,7 @@ class Application(object): ...@@ -65,12 +66,7 @@ class Application(object):
logging.debug('IP address is %s, port is %d', *(self.server)) logging.debug('IP address is %s, port is %d', *(self.server))
# load master node list # load master node list
self.master_node_list = [] self.master_node_list = parseMasterList(masters)
for node in masters.split():
ip_address, port = node.split(':')
server = (ip_address, int(port))
if (server != self.server):
self.master_node_list.append(server)
logging.debug('master nodes are %s', self.master_node_list) logging.debug('master nodes are %s', self.master_node_list)
# Internal attributes. # Internal attributes.
......
...@@ -43,6 +43,7 @@ from neo.dispatcher import Dispatcher ...@@ -43,6 +43,7 @@ from neo.dispatcher import Dispatcher
from neo.client.poll import ThreadedPoll from neo.client.poll import ThreadedPoll
from neo.client.iterator import Iterator from neo.client.iterator import Iterator
from neo.client.mq import MQ from neo.client.mq import MQ
from neo.util import u64, parseMasterList
class ConnectionClosed(Exception): class ConnectionClosed(Exception):
...@@ -249,21 +250,13 @@ class Application(object): ...@@ -249,21 +250,13 @@ class Application(object):
self.master_conn = None self.master_conn = None
self.primary_master_node = None self.primary_master_node = None
self.trying_master_node = None self.trying_master_node = None
# XXX: this code duplicates neo.config.ConfigurationManager.getMasterNodeList
logging.debug('master node address are %s' % (master_nodes,)) # load master node list
self.master_node_list = master_node_list = [] self.master_node_list = parseMasterList(master_nodes)
for node in master_nodes.split(): logging.debug('master nodes are %s', self.master_node_list)
if not node: for server in self.master_node_list:
continue
if ':' in node:
ip_address, port = node.split(':')
port = int(port)
else:
ip_address = node
port = 10100 # XXX: default_master_port
server = (ip_address, port)
master_node_list.append(server)
self.nm.add(MasterNode(server=server)) self.nm.add(MasterNode(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
self.mq_cache = MQ() self.mq_cache = MQ()
...@@ -512,7 +505,6 @@ class Application(object): ...@@ -512,7 +505,6 @@ class Application(object):
def getStorageSize(self): def getStorageSize(self):
# return the last OID used, this is innacurate # return the last OID used, this is innacurate
from neo.util import u64
return int(u64(self.last_oid)) return int(u64(self.last_oid))
def getSerial(self, oid): def getSerial(self, oid):
......
...@@ -32,7 +32,7 @@ from neo.master.handlers import election, identification, secondary, recovery ...@@ -32,7 +32,7 @@ from neo.master.handlers import election, identification, secondary, recovery
from neo.master.handlers import verification, storage, client, shutdown from neo.master.handlers import verification, storage, client, shutdown
from neo.master.handlers import administration from neo.master.handlers import administration
from neo.master.pt import PartitionTable from neo.master.pt import PartitionTable
from neo.util import dump from neo.util import dump, parseMasterList
from neo.connector import getConnectorHandler from neo.connector import getConnectorHandler
REQUIRED_NODE_NUMBER = 1 REQUIRED_NODE_NUMBER = 1
...@@ -56,12 +56,7 @@ class Application(object): ...@@ -56,12 +56,7 @@ class Application(object):
logging.debug('IP address is %s, port is %d', *(self.server)) logging.debug('IP address is %s, port is %d', *(self.server))
# load master node list # load master node list
self.master_node_list = [] self.master_node_list = parseMasterList(masters, self.server)
for node in masters.split():
ip_address, port = node.split(':')
server = (ip_address, int(port))
if (server != self.server):
self.master_node_list.append(server)
logging.debug('master nodes are %s', self.master_node_list) logging.debug('master nodes are %s', self.master_node_list)
# Internal attributes. # Internal attributes.
......
...@@ -32,7 +32,7 @@ from neo.storage.handlers import master, hidden ...@@ -32,7 +32,7 @@ from neo.storage.handlers import master, hidden
from neo.storage.replicator import Replicator from neo.storage.replicator import Replicator
from neo.connector import getConnectorHandler from neo.connector import getConnectorHandler
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.util import dump from neo.util import dump, parseMasterList
from neo.bootstrap import BootstrapManager from neo.bootstrap import BootstrapManager
class Application(object): class Application(object):
...@@ -54,12 +54,7 @@ class Application(object): ...@@ -54,12 +54,7 @@ class Application(object):
logging.debug('IP address is %s, port is %d', *(self.server)) logging.debug('IP address is %s, port is %d', *(self.server))
# load master node list # load master node list
self.master_node_list = [] self.master_node_list = parseMasterList(masters)
for node in masters.split():
ip_address, port = node.split(':')
server = (ip_address, int(port))
if (server != self.server):
self.master_node_list.append(server)
logging.debug('master nodes are %s', self.master_node_list) logging.debug('master nodes are %s', self.master_node_list)
# load database connection credentials, from user:password@database # load database connection credentials, from user:password@database
......
...@@ -87,7 +87,7 @@ class NeoTestBase(unittest.TestCase): ...@@ -87,7 +87,7 @@ class NeoTestBase(unittest.TestCase):
return { return {
'cluster': cluster, 'cluster': cluster,
'bind': masters[0], 'bind': masters[0],
'masters': ' '.join(masters), 'masters': '/'.join(masters),
'replicas': replicas, 'replicas': replicas,
'partitions': partitions, 'partitions': partitions,
'uuid': uuid, 'uuid': uuid,
...@@ -105,7 +105,7 @@ class NeoTestBase(unittest.TestCase): ...@@ -105,7 +105,7 @@ class NeoTestBase(unittest.TestCase):
return { return {
'cluster': cluster, 'cluster': cluster,
'bind': '127.0.0.1:1002%d' % (index, ), 'bind': '127.0.0.1:1002%d' % (index, ),
'masters': ' '.join(masters), 'masters': '/'.join(masters),
'database': database, 'database': database,
'uuid': uuid, 'uuid': uuid,
'reset': False, 'reset': False,
......
...@@ -172,7 +172,7 @@ class NEOCluster(object): ...@@ -172,7 +172,7 @@ class NEOCluster(object):
self.temp_dir = temp_dir self.temp_dir = temp_dir
self.cluster_name = 'neo_%s' % (random.randint(0, 100), ) self.cluster_name = 'neo_%s' % (random.randint(0, 100), )
master_node_list = [self.__allocatePort() for i in xrange(master_node_count)] master_node_list = [self.__allocatePort() for i in xrange(master_node_count)]
self.master_nodes = ' '.join('127.0.0.1:%s' % (x, ) for x in master_node_list) self.master_nodes = '/'.join('127.0.0.1:%s' % (x, ) for x in master_node_list)
# create admin node # create admin node
admin_port = self.__allocatePort() admin_port = self.__allocatePort()
self.__newProcess(NEO_ADMIN, { self.__newProcess(NEO_ADMIN, {
......
...@@ -77,3 +77,15 @@ def getNextTID(ltid): ...@@ -77,3 +77,15 @@ def getNextTID(ltid):
lower += 1 lower += 1
tid = pack('!LL', upper, lower) tid = pack('!LL', upper, lower)
return tid return tid
def parseMasterList(masters, except_node=None):
# load master node list
master_node_list = []
for node in masters.split('/'):
ip_address, port = node.split(':')
server = (ip_address, int(port))
if (server != except_node):
master_node_list.append(server)
return master_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