Commit f5e3d4b5 authored by Vincent Pelletier's avatar Vincent Pelletier

Store process' listening port and add an accessor to retrieve it.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1165 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 5f0fe1dd
...@@ -71,10 +71,11 @@ class AlreadyStopped(Exception): ...@@ -71,10 +71,11 @@ class AlreadyStopped(Exception):
class NEOProcess: class NEOProcess:
pid = 0 pid = 0
def __init__(self, command, uuid, arg_dict): def __init__(self, command, uuid, port, arg_dict):
self.command = command self.command = command
self.arg_dict = arg_dict self.arg_dict = arg_dict
self.setUUID(uuid) self.setUUID(uuid)
self.port = port
def start(self): def start(self):
# Prevent starting when already forked and wait wasn't called. # Prevent starting when already forked and wait wasn't called.
...@@ -139,6 +140,9 @@ class NEOProcess: ...@@ -139,6 +140,9 @@ class NEOProcess:
self.uuid = uuid self.uuid = uuid
self.arg_dict['-u'] = dump(uuid) self.arg_dict['-u'] = dump(uuid)
def getPort(self):
return self.port
class NEOCluster(object): class NEOCluster(object):
def __init__(self, db_list, master_node_count=1, def __init__(self, db_list, master_node_count=1,
partitions=1, replicas=0, port_base=10000, partitions=1, replicas=0, port_base=10000,
...@@ -175,29 +179,30 @@ class NEOCluster(object): ...@@ -175,29 +179,30 @@ class NEOCluster(object):
'password': db_password, 'password': db_password,
'port': neo_admin_port, 'port': neo_admin_port,
}) })
self.__newProcess(NEO_ADMIN, 'admin') self.__newProcess(NEO_ADMIN, 'admin', neo_admin_port)
for config_id, port in master_node_dict.iteritems(): for config_id, port in master_node_dict.iteritems():
config_file.write(NEO_CONFIG_MASTER % { config_file.write(NEO_CONFIG_MASTER % {
'id': config_id, 'id': config_id,
'port': port, 'port': port,
}) })
self.__newProcess(NEO_MASTER, config_id) self.__newProcess(NEO_MASTER, config_id, port)
for storage, db in enumerate(db_list): for storage, db in enumerate(db_list):
config_id = NEO_STORAGE_ID % (storage, ) config_id = NEO_STORAGE_ID % (storage, )
port = self.__allocatePort()
config_file.write(NEO_CONFIG_STORAGE % { config_file.write(NEO_CONFIG_STORAGE % {
'id': config_id, 'id': config_id,
'db': db, 'db': db,
'port': self.__allocatePort(), 'port': port,
}) })
self.__newProcess(NEO_STORAGE, config_id) self.__newProcess(NEO_STORAGE, config_id, port)
config_file.close() config_file.close()
self.neoctl = NeoCTL('127.0.0.1', neo_admin_port, self.neoctl = NeoCTL('127.0.0.1', neo_admin_port,
'SocketConnector') 'SocketConnector')
def __newProcess(self, command, section): def __newProcess(self, command, section, port):
uuid = self.__allocateUUID() uuid = self.__allocateUUID()
self.process_dict.setdefault(command, []).append( self.process_dict.setdefault(command, []).append(
NEOProcess(command, uuid, { NEOProcess(command, uuid, port, {
'-v': None, '-v': None,
'-c': self.config_file_path, '-c': self.config_file_path,
'-s': section, '-s': section,
......
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