Merge "Change and move the workers options to corresponding service section"

This commit is contained in:
Jenkins 2015-08-19 22:52:27 +00:00 committed by Gerrit Code Review
commit a92e9c4026
7 changed files with 41 additions and 45 deletions

View File

@ -27,7 +27,6 @@ from ceilometer.api import hooks
from ceilometer.api import middleware
from ceilometer.i18n import _
from ceilometer.i18n import _LW
from ceilometer import service
LOG = log.getLogger(__name__)
@ -38,8 +37,6 @@ OPTS = [
default="api_paste.ini",
help="Configuration file for WSGI definition of API."
),
cfg.IntOpt('api_workers', default=1,
help='Number of workers for Ceilometer API server.'),
]
API_OPTS = [
@ -78,7 +75,7 @@ def setup_app(pecan_config=None, extra_hooks=None):
# NOTE(sileht): pecan debug won't work in multi-process environment
pecan_debug = CONF.api.pecan_debug
if service.get_workers('api') != 1 and pecan_debug:
if CONF.api.workers and CONF.api.workers != 1 and pecan_debug:
pecan_debug = False
LOG.warning(_LW('pecan_debug cannot be enabled, if workers is > 1, '
'the value is overrided with False'))
@ -144,9 +141,8 @@ def build_server():
LOG.info(_("serving on http://%(host)s:%(port)s") % (
{'host': host, 'port': port}))
workers = service.get_workers('api')
serving.run_simple(cfg.CONF.api.host, cfg.CONF.api.port,
app, processes=workers)
app, processes=CONF.api.workers)
def app_factory(global_config, **local_conf):

View File

@ -26,4 +26,4 @@ CONF = cfg.CONF
def main():
service.prepare_service()
os_service.launch(CONF, notification.NotificationService(),
workers=service.get_workers('notification')).wait()
workers=CONF.notification.workers).wait()

View File

@ -26,4 +26,4 @@ CONF = cfg.CONF
def main():
service.prepare_service()
os_service.launch(CONF, collector.CollectorService(),
workers=service.get_workers('collector')).wait()
workers=CONF.collector.workers).wait()

View File

@ -87,10 +87,13 @@ def list_opts():
ceilometer.api.controllers.v2.alarms.ALARM_API_OPTS)),
('api',
itertools.chain(ceilometer.api.OPTS,
ceilometer.api.app.API_OPTS,)),
ceilometer.api.app.API_OPTS,
[ceilometer.service.API_OPT])),
# deprecated path, new one is 'polling'
('central', ceilometer.agent.manager.OPTS),
('collector', ceilometer.collector.OPTS),
('collector',
itertools.chain(ceilometer.collector.OPTS,
[ceilometer.service.COLL_OPT])),
('compute', ceilometer.compute.discovery.OPTS),
('coordination', ceilometer.coordination.OPTS),
('database', ceilometer.storage.OPTS),
@ -100,7 +103,9 @@ def list_opts():
('ipmi',
itertools.chain(ceilometer.ipmi.platform.intel_node_manager.OPTS,
ceilometer.ipmi.pollsters.OPTS)),
('notification', ceilometer.notification.OPTS),
('notification',
itertools.chain(ceilometer.notification.OPTS,
[ceilometer.service.NOTI_OPT])),
('polling', ceilometer.agent.manager.OPTS),
('publisher', ceilometer.publisher.utils.OPTS),
('publisher_notifier', ceilometer.publisher.messaging.NOTIFIER_OPTS),

View File

@ -22,9 +22,7 @@ from oslo_config import cfg
import oslo_i18n
from oslo_log import log
from ceilometer.i18n import _
from ceilometer import messaging
from ceilometer import utils
OPTS = [
@ -33,14 +31,6 @@ OPTS = [
help='Name of this node, which must be valid in an AMQP '
'key. Can be an opaque identifier. For ZeroMQ only, must '
'be a valid host name, FQDN, or IP address.'),
cfg.IntOpt('collector_workers',
default=1,
help='Number of workers for collector service. A single '
'collector is enabled by default.'),
cfg.IntOpt('notification_workers',
default=1,
help='Number of workers for notification service. A single '
'notification agent is enabled by default.'),
cfg.IntOpt('http_timeout',
default=600,
help='Timeout seconds for HTTP requests. Set it to None to '
@ -87,26 +77,39 @@ CLI_OPTS = [
help='Disables X.509 certificate validation when an '
'SSL connection to Identity Service is established.'),
]
cfg.CONF.register_cli_opts(CLI_OPTS, group="service_credentials")
API_OPT = cfg.IntOpt('workers',
default=1,
min=1,
deprecated_group='DEFAULT',
deprecated_name='api_workers',
help='Number of workers for api, default value is 1.')
cfg.CONF.register_opt(API_OPT, 'api')
NOTI_OPT = cfg.IntOpt('workers',
default=1,
min=1,
deprecated_group='DEFAULT',
deprecated_name='notification_workers',
help='Number of workers for notification service, '
'default value is 1.')
cfg.CONF.register_opt(NOTI_OPT, 'notification')
COLL_OPT = cfg.IntOpt('workers',
default=1,
min=1,
deprecated_group='DEFAULT',
deprecated_name='collector_workers',
help='Number of workers for collector service. '
'default value is 1.')
cfg.CONF.register_opt(COLL_OPT, 'collector')
LOG = log.getLogger(__name__)
class WorkerException(Exception):
"""Exception for errors relating to service workers."""
def get_workers(name):
workers = (cfg.CONF.get('%s_workers' % name) or
utils.cpu_count())
if workers and workers < 1:
msg = (_("%(worker_name)s value of %(workers)s is invalid, "
"must be greater than 0") %
{'worker_name': '%s_workers' % name, 'workers': str(workers)})
raise WorkerException(msg)
return workers
def prepare_service(argv=None):
oslo_i18n.enable_lazy()
log.register_options(cfg.CONF)

View File

@ -45,7 +45,7 @@ class TestApp(base.BaseTestCase):
self.CONF.set_override('debug', g_debug)
if p_debug is not None:
self.CONF.set_override('pecan_debug', p_debug, group='api')
self.CONF.set_override('api_workers', workers)
self.CONF.set_override('workers', workers, group='api')
app.setup_app()
args, kwargs = mocked.call_args
self.assertEqual(expected, kwargs.get('debug'))

View File

@ -24,7 +24,6 @@ import copy
import datetime
import decimal
import hashlib
import multiprocessing
import struct
from oslo_concurrency import processutils
@ -202,13 +201,6 @@ def update_nested(original_dict, updates):
return dict_to_update
def cpu_count():
try:
return multiprocessing.cpu_count() or 1
except NotImplementedError:
return 1
def uniq(dupes, attrs):
"""Exclude elements of dupes with a duplicated set of attribute values."""
key = lambda d: '/'.join([getattr(d, a) or '' for a in attrs])