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
from neo.bootstrap import BootstrapManager
from neo.pt import PartitionTable
from neo import protocol
from neo.util import parseMasterList
class Dispatcher:
"""Dispatcher use to redirect master request to handler"""
......@@ -65,12 +66,7 @@ class Application(object):
logging.debug('IP address is %s, port is %d', *(self.server))
# load master node list
self.master_node_list = []
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)
self.master_node_list = parseMasterList(masters)
logging.debug('master nodes are %s', self.master_node_list)
# Internal attributes.
......
......@@ -43,6 +43,7 @@ from neo.dispatcher import Dispatcher
from neo.client.poll import ThreadedPoll
from neo.client.iterator import Iterator
from neo.client.mq import MQ
from neo.util import u64, parseMasterList
class ConnectionClosed(Exception):
......@@ -249,21 +250,13 @@ class Application(object):
self.master_conn = None
self.primary_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,))
self.master_node_list = master_node_list = []
for node in master_nodes.split():
if not node:
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)
# load master node list
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))
# no self-assigned UUID, primary master will supply us one
self.uuid = None
self.mq_cache = MQ()
......@@ -512,7 +505,6 @@ class Application(object):
def getStorageSize(self):
# return the last OID used, this is innacurate
from neo.util import u64
return int(u64(self.last_oid))
def getSerial(self, oid):
......
......@@ -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 administration
from neo.master.pt import PartitionTable
from neo.util import dump
from neo.util import dump, parseMasterList
from neo.connector import getConnectorHandler
REQUIRED_NODE_NUMBER = 1
......@@ -56,12 +56,7 @@ class Application(object):
logging.debug('IP address is %s, port is %d', *(self.server))
# load master node list
self.master_node_list = []
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)
self.master_node_list = parseMasterList(masters, self.server)
logging.debug('master nodes are %s', self.master_node_list)
# Internal attributes.
......
......@@ -32,7 +32,7 @@ from neo.storage.handlers import master, hidden
from neo.storage.replicator import Replicator
from neo.connector import getConnectorHandler
from neo.pt import PartitionTable
from neo.util import dump
from neo.util import dump, parseMasterList
from neo.bootstrap import BootstrapManager
class Application(object):
......@@ -54,12 +54,7 @@ class Application(object):
logging.debug('IP address is %s, port is %d', *(self.server))
# load master node list
self.master_node_list = []
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)
self.master_node_list = parseMasterList(masters)
logging.debug('master nodes are %s', self.master_node_list)
# load database connection credentials, from user:password@database
......
......@@ -87,7 +87,7 @@ class NeoTestBase(unittest.TestCase):
return {
'cluster': cluster,
'bind': masters[0],
'masters': ' '.join(masters),
'masters': '/'.join(masters),
'replicas': replicas,
'partitions': partitions,
'uuid': uuid,
......@@ -105,7 +105,7 @@ class NeoTestBase(unittest.TestCase):
return {
'cluster': cluster,
'bind': '127.0.0.1:1002%d' % (index, ),
'masters': ' '.join(masters),
'masters': '/'.join(masters),
'database': database,
'uuid': uuid,
'reset': False,
......
......@@ -172,7 +172,7 @@ class NEOCluster(object):
self.temp_dir = temp_dir
self.cluster_name = 'neo_%s' % (random.randint(0, 100), )
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
admin_port = self.__allocatePort()
self.__newProcess(NEO_ADMIN, {
......
......@@ -77,3 +77,15 @@ def getNextTID(ltid):
lower += 1
tid = pack('!LL', upper, lower)
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