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 @@
from neo import logging
from neo.config import ConfigurationManager
from neo.node import NodeManager, MasterNode
from neo.event import EventManager
from neo.connection import ListeningConnection
......@@ -50,17 +49,28 @@ class Dispatcher:
class Application(object):
"""The storage node application."""
def __init__(self, filename, section, uuid=None):
config = ConfigurationManager(filename, section)
def __init__(self, cluster, bind, masters, uuid=None):
self.name = config.getName()
logging.debug('the name is %s', self.name)
self.connector_handler = getConnectorHandler(config.getConnector())
# always use default connector for now
self.connector_handler = getConnectorHandler()
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))
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)
# Internal attributes.
......
......@@ -20,7 +20,6 @@ import os, sys
from time import time, gmtime
from struct import pack, unpack
from neo.config import ConfigurationManager
from neo import protocol
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UUID_NAMESPACES, BOOTING_CLUSTER_STATE, INVALID_UUID
......@@ -41,20 +40,28 @@ REQUIRED_NODE_NUMBER = 1
class Application(object):
"""The master node application."""
def __init__(self, filename, section, uuid=None):
def __init__(self, cluster, bind, masters, replicas, partitions, uuid):
config = ConfigurationManager(filename, section)
self.connector_handler = getConnectorHandler(config.getConnector())
# always use default connector for now
self.connector_handler = getConnectorHandler()
self.name = config.getName()
if len(self.name) == 0:
# set the cluster name
if cluster is None:
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))
# Exclude itself from the list.
self.master_node_list = [n for n in config.getMasterNodeList() if n != 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)
logging.debug('master nodes are %s', self.master_node_list)
# Internal attributes.
......@@ -62,7 +69,6 @@ class Application(object):
self.nm = NodeManager()
# Partition table
replicas, partitions = config.getReplicas(), config.getPartitions()
if replicas < 0:
raise RuntimeError, 'replicas must be a positive integer'
if partitions <= 0:
......
......@@ -19,7 +19,6 @@ from neo import logging
import sys
from collections import deque
from neo.config import ConfigurationManager
from neo import protocol
from neo.protocol import TEMPORARILY_DOWN_STATE, \
cell_states, HIDDEN_STATE
......@@ -39,29 +38,46 @@ from neo.bootstrap import BootstrapManager
class Application(object):
"""The storage node application."""
def __init__(self, filename, section, reset=False, uuid=None):
config = ConfigurationManager(filename, section)
def __init__(self, cluster, bind, masters, database, uuid, reset):
self.name = config.getName()
logging.debug('the name is %s', self.name)
self.connector_handler = getConnectorHandler(config.getConnector())
# always use default connector for now
self.connector_handler = getConnectorHandler()
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))
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)
# 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.
self.em = EventManager()
self.nm = NodeManager()
self.dm = MySQLDatabaseManager(database = config.getDatabase(),
user = config.getUser(),
password = config.getPassword())
self.loid = None
self.dm = MySQLDatabaseManager(database=dbname, user=username,
password=password)
# The partition table is initialized after getting the number of
# partitions.
self.pt = None
self.loid = None
self.replicator = None
self.listening_conn = None
......
......@@ -27,20 +27,26 @@ parser.add_option('-u', '--uuid', help='specify an UUID to use for this ' \
'process')
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('-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()
config = options.config or 'neo.conf'
section = options.section or 'admin'
uuid = options.uuid
if uuid is not None:
uuid = bin(uuid)
config = {
'uuid': options.uuid,
'cluster': options.cluster,
'masters': options.masters or '127.0.0.1:10000',
'bind': options.bind or '127.0.0.1:9999',
}
config['uuid'] = bin(config['uuid'])
logfile = options.logfile or None
setupLog(section, logfile, options.verbose)
# setup custom logging
setupLog(options.name or 'admin', options.logfile or None, options.verbose)
# and then, load and run the application
from neo.admin.app import Application
app = Application(config, section, uuid)
app = Application(**config)
app.run()
......@@ -23,24 +23,35 @@ from neo import setupLog
from neo.util import bin
parser = OptionParser()
parser.add_option('-u', '--uuid', help='specify an UUID to use for this ' \
'process')
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('-u', '--uuid', help='the node UUID (testing purpose)')
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')
# build configuration dict from command line options
(options, args) = parser.parse_args()
config = options.config or 'neo.conf'
section = options.section or 'master'
uuid = options.uuid
if uuid is not None:
uuid = bin(uuid)
config = {
'uuid': options.uuid,
'bind': options.bind or '127.0.0.1:10000',
'cluster': options.cluster,
'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
setupLog(section, logfile, options.verbose)
# setup custom logging
setupLog(options.name or 'master', options.logfile or None, options.verbose)
# and then, load and run the application
from neo.master.app import Application
app = Application(config, section, uuid)
app = Application(**config)
app.run()
......@@ -24,27 +24,36 @@ from neo.util import bin
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 ' \
'process. Previously assigned UUID takes precedence (ie ' \
'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('-R', '--reset', action = 'store_true',
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()
config = options.config or 'neo.conf'
section = options.section or 'storage'
uuid = options.uuid
if uuid is not None:
uuid = bin(uuid)
config = {
'uuid': options.uuid,
'bind': options.bind or '127.0.0.1:20000',
'cluster': options.cluster,
'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
setupLog(section, logfile, options.verbose)
# setup custom logging
setupLog(options.name or 'storage', options.logfile or None, options.verbose)
# and then, load and run the application
from neo.storage.app import Application
app = Application(config, section, options.reset, uuid=uuid)
app = Application(**config)
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