Commit 692b271f authored by Grégory Wisniewski's avatar Grégory Wisniewski

No more use a configuration file, all neo applications use command line

arguments. This allow easily start new nodes over a network.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1276 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent abfcfad6
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
from neo import logging from neo import logging
from neo.config import ConfigurationManager
from neo.node import NodeManager, MasterNode from neo.node import NodeManager, MasterNode
from neo.event import EventManager from neo.event import EventManager
from neo.connection import ListeningConnection from neo.connection import ListeningConnection
...@@ -50,17 +49,28 @@ class Dispatcher: ...@@ -50,17 +49,28 @@ class Dispatcher:
class Application(object): class Application(object):
"""The storage node application.""" """The storage node application."""
def __init__(self, filename, section, uuid=None): def __init__(self, cluster, bind, masters, uuid=None):
config = ConfigurationManager(filename, section)
self.name = config.getName() # always use default connector for now
logging.debug('the name is %s', self.name) self.connector_handler = getConnectorHandler()
self.connector_handler = getConnectorHandler(config.getConnector())
self.server = config.getServer() # set the cluster name
if cluster is None:
raise RuntimeError, 'cluster name must be non-empty'
self.name = cluster
# set the bind address
ip_address, port = bind.split(':')
self.server = (ip_address, int(port))
logging.debug('IP address is %s, port is %d', *(self.server)) logging.debug('IP address is %s, port is %d', *(self.server))
self.master_node_list = config.getMasterNodeList() # 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)
logging.debug('master nodes are %s', self.master_node_list) logging.debug('master nodes are %s', self.master_node_list)
# Internal attributes. # Internal attributes.
......
...@@ -20,7 +20,6 @@ import os, sys ...@@ -20,7 +20,6 @@ import os, sys
from time import time, gmtime from time import time, gmtime
from struct import pack, unpack from struct import pack, unpack
from neo.config import ConfigurationManager
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
...@@ -41,20 +40,28 @@ REQUIRED_NODE_NUMBER = 1 ...@@ -41,20 +40,28 @@ REQUIRED_NODE_NUMBER = 1
class Application(object): class Application(object):
"""The master node application.""" """The master node application."""
def __init__(self, filename, section, uuid=None): def __init__(self, cluster, bind, masters, replicas, partitions, uuid):
config = ConfigurationManager(filename, section) # always use default connector for now
self.connector_handler = getConnectorHandler(config.getConnector()) self.connector_handler = getConnectorHandler()
self.name = config.getName() # set the cluster name
if len(self.name) == 0: if cluster is None:
raise RuntimeError, 'cluster name must be non-empty' raise RuntimeError, 'cluster name must be non-empty'
self.name = cluster
self.server = config.getServer() # set the bind address
ip_address, port = bind.split(':')
self.server = (ip_address, int(port))
logging.debug('IP address is %s, port is %d', *(self.server)) logging.debug('IP address is %s, port is %d', *(self.server))
# Exclude itself from the list. # load master node list
self.master_node_list = [n for n in config.getMasterNodeList() if n != self.server] 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)
logging.debug('master nodes are %s', self.master_node_list) logging.debug('master nodes are %s', self.master_node_list)
# Internal attributes. # Internal attributes.
...@@ -62,7 +69,6 @@ class Application(object): ...@@ -62,7 +69,6 @@ class Application(object):
self.nm = NodeManager() self.nm = NodeManager()
# Partition table # Partition table
replicas, partitions = config.getReplicas(), config.getPartitions()
if replicas < 0: if replicas < 0:
raise RuntimeError, 'replicas must be a positive integer' raise RuntimeError, 'replicas must be a positive integer'
if partitions <= 0: if partitions <= 0:
......
...@@ -19,7 +19,6 @@ from neo import logging ...@@ -19,7 +19,6 @@ from neo import logging
import sys import sys
from collections import deque from collections import deque
from neo.config import ConfigurationManager
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
...@@ -39,29 +38,46 @@ from neo.bootstrap import BootstrapManager ...@@ -39,29 +38,46 @@ from neo.bootstrap import BootstrapManager
class Application(object): class Application(object):
"""The storage node application.""" """The storage node application."""
def __init__(self, filename, section, reset=False, uuid=None): def __init__(self, cluster, bind, masters, database, uuid, reset):
config = ConfigurationManager(filename, section)
self.name = config.getName() # always use default connector for now
logging.debug('the name is %s', self.name) self.connector_handler = getConnectorHandler()
self.connector_handler = getConnectorHandler(config.getConnector())
self.server = config.getServer() # set the cluster name
if cluster is None:
raise RuntimeError, 'cluster name must be non-empty'
self.name = cluster
# set the bind address
ip_address, port = bind.split(':')
self.server = (ip_address, int(port))
logging.debug('IP address is %s, port is %d', *(self.server)) logging.debug('IP address is %s, port is %d', *(self.server))
self.master_node_list = config.getMasterNodeList() # 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)
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
if database is None:
raise RuntimeError, 'database connection required'
(ident, dbname) = database.split('@')
(username, password) = ident.split(':')
# Internal attributes. # Internal attributes.
self.em = EventManager() self.em = EventManager()
self.nm = NodeManager() self.nm = NodeManager()
self.dm = MySQLDatabaseManager(database = config.getDatabase(), self.dm = MySQLDatabaseManager(database=dbname, user=username,
user = config.getUser(), password=password)
password = config.getPassword())
self.loid = None
# The partition table is initialized after getting the number of # The partition table is initialized after getting the number of
# partitions. # partitions.
self.pt = None self.pt = None
self.loid = None
self.replicator = None self.replicator = None
self.listening_conn = None self.listening_conn = None
......
...@@ -27,20 +27,26 @@ parser.add_option('-u', '--uuid', help='specify an UUID to use for this ' \ ...@@ -27,20 +27,26 @@ parser.add_option('-u', '--uuid', help='specify an UUID to use for this ' \
'process') 'process')
parser.add_option('-v', '--verbose', action = 'store_true', parser.add_option('-v', '--verbose', action = 'store_true',
help = 'print verbose messages') help = 'print verbose messages')
parser.add_option('-c', '--config', help = 'specify a configuration file')
parser.add_option('-s', '--section', help = 'specify a configuration section')
parser.add_option('-l', '--logfile', help = 'specify a logging file') parser.add_option('-l', '--logfile', help = 'specify a logging file')
parser.add_option('-c', '--cluster', help = 'the cluster name')
parser.add_option('-m', '--masters', help = 'master node list')
parser.add_option('-b', '--bind', help = 'the local address to bind to')
parser.add_option('-n', '--name', help = 'the node name (impove logging)')
# build configuration dict from command line options
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
config = options.config or 'neo.conf' config = {
section = options.section or 'admin' 'uuid': options.uuid,
uuid = options.uuid 'cluster': options.cluster,
if uuid is not None: 'masters': options.masters or '127.0.0.1:10000',
uuid = bin(uuid) 'bind': options.bind or '127.0.0.1:9999',
}
config['uuid'] = bin(config['uuid'])
logfile = options.logfile or None # setup custom logging
setupLog(section, logfile, options.verbose) setupLog(options.name or 'admin', options.logfile or None, options.verbose)
# and then, load and run the application
from neo.admin.app import Application from neo.admin.app import Application
app = Application(config, section, uuid) app = Application(**config)
app.run() app.run()
...@@ -23,24 +23,35 @@ from neo import setupLog ...@@ -23,24 +23,35 @@ from neo import setupLog
from neo.util import bin from neo.util import bin
parser = OptionParser() parser = OptionParser()
parser.add_option('-u', '--uuid', help='specify an UUID to use for this ' \
'process')
parser.add_option('-v', '--verbose', action = 'store_true', parser.add_option('-v', '--verbose', action = 'store_true',
help = 'print verbose messages') help = 'print verbose messages')
parser.add_option('-c', '--config', help = 'specify a configuration file') parser.add_option('-u', '--uuid', help='the node UUID (testing purpose)')
parser.add_option('-s', '--section', help = 'specify a configuration section') parser.add_option('-n', '--name', help = 'the node name (impove logging)')
parser.add_option('-b', '--bind', help = 'the local address to bind to')
parser.add_option('-c', '--cluster', help = 'the cluster name')
parser.add_option('-m', '--masters', help = 'master node list')
parser.add_option('-r', '--replicas', help = 'replicas number')
parser.add_option('-p', '--partitions', help = 'partitions number')
parser.add_option('-l', '--logfile', help = 'specify a logging file') parser.add_option('-l', '--logfile', help = 'specify a logging file')
# build configuration dict from command line options
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
config = options.config or 'neo.conf' config = {
section = options.section or 'master' 'uuid': options.uuid,
uuid = options.uuid 'bind': options.bind or '127.0.0.1:10000',
if uuid is not None: 'cluster': options.cluster,
uuid = bin(uuid) 'masters': options.masters or '',
'replicas': options.replicas or 0,
'partitions': options.partitions or 100,
}
config['uuid'] = bin(config['uuid'])
config['replicas'] = int(config['replicas'])
config['partitions'] = int(config['partitions'])
logfile = options.logfile or None # setup custom logging
setupLog(section, logfile, options.verbose) setupLog(options.name or 'master', options.logfile or None, options.verbose)
# and then, load and run the application
from neo.master.app import Application from neo.master.app import Application
app = Application(config, section, uuid) app = Application(**config)
app.run() app.run()
...@@ -24,27 +24,36 @@ from neo.util import bin ...@@ -24,27 +24,36 @@ from neo.util import bin
parser = OptionParser() parser = OptionParser()
parser.add_option('-v', '--verbose', action = 'store_true',
help = 'print verbose messages')
parser.add_option('-u', '--uuid', help='specify an UUID to use for this ' \ parser.add_option('-u', '--uuid', help='specify an UUID to use for this ' \
'process. Previously assigned UUID takes precedence (ie ' \ 'process. Previously assigned UUID takes precedence (ie ' \
'you should always use -R with this switch)') 'you should always use -R with this switch)')
parser.add_option('-v', '--verbose', action = 'store_true',
help = 'print verbose messages')
parser.add_option('-c', '--config', help = 'specify a configuration file')
parser.add_option('-s', '--section', help = 'specify a configuration section')
parser.add_option('-l', '--logfile', help = 'specify a logging file') parser.add_option('-l', '--logfile', help = 'specify a logging file')
parser.add_option('-R', '--reset', action = 'store_true', parser.add_option('-R', '--reset', action = 'store_true',
help = 'remove an existing database if any') help = 'remove an existing database if any')
parser.add_option('-n', '--name', help = 'the node name (impove logging)')
parser.add_option('-b', '--bind', help = 'the local address to bind to')
parser.add_option('-c', '--cluster', help = 'the cluster name')
parser.add_option('-m', '--masters', help = 'master node list')
parser.add_option('-d', '--database', help = 'database connections string')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
config = options.config or 'neo.conf' config = {
section = options.section or 'storage' 'uuid': options.uuid,
uuid = options.uuid 'bind': options.bind or '127.0.0.1:20000',
if uuid is not None: 'cluster': options.cluster,
uuid = bin(uuid) 'masters': options.masters or '127.0.0.1:10000',
'database': options.database,
'reset': options.reset,
}
config['uuid'] = bin(config['uuid'])
logfile = options.logfile or None # setup custom logging
setupLog(section, logfile, options.verbose) setupLog(options.name or 'storage', options.logfile or None, options.verbose)
# and then, load and run the application
from neo.storage.app import Application from neo.storage.app import Application
app = Application(config, section, options.reset, uuid=uuid) app = Application(**config)
app.run() app.run()
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