From ab0c18e5d4074085e2006e3daec902c018a23b8a Mon Sep 17 00:00:00 2001 From: Nejc Saje Date: Mon, 21 Jul 2014 09:06:36 +0200 Subject: [PATCH] Separate the console scripts Having all the console scripts in one file means that we always pull in all the dependencies. This presents a problem in downstream packaging, for example, a distro alarm subpackage required pymongo dependencies installed, even if not used. This patch separates the console scripts into a 'cmd' module, the way Nova does it. Eventlet monkey patching is done in the module's __init__.py file. Co-Authored-By: Mehdi Abaakouk Closes-bug: #1317210 Change-Id: I83020b13670928fd0d3046d2d2a493b11fe81d61 --- ceilometer/cli.py | 83 ---------------------------- ceilometer/cmd/__init__.py | 22 ++++++++ ceilometer/cmd/agent_central.py | 24 ++++++++ ceilometer/cmd/agent_compute.py | 24 ++++++++ ceilometer/cmd/agent_notification.py | 28 ++++++++++ ceilometer/cmd/alarm.py | 42 ++++++++++++++ ceilometer/cmd/api.py | 24 ++++++++ ceilometer/cmd/collector.py | 28 ++++++++++ ceilometer/cmd/storage.py | 43 ++++++++++++++ setup.cfg | 18 +++--- 10 files changed, 244 insertions(+), 92 deletions(-) create mode 100644 ceilometer/cmd/__init__.py create mode 100644 ceilometer/cmd/agent_central.py create mode 100644 ceilometer/cmd/agent_compute.py create mode 100644 ceilometer/cmd/agent_notification.py create mode 100644 ceilometer/cmd/alarm.py create mode 100644 ceilometer/cmd/api.py create mode 100644 ceilometer/cmd/collector.py create mode 100644 ceilometer/cmd/storage.py diff --git a/ceilometer/cli.py b/ceilometer/cli.py index b0ac118ee..541bebb6e 100644 --- a/ceilometer/cli.py +++ b/ceilometer/cli.py @@ -30,97 +30,14 @@ import eventlet eventlet.monkey_patch(socket=True, select=True, thread=True) from oslo.config import cfg -from ceilometer.alarm import service as alarm_service -from ceilometer.api import app -from ceilometer.central import manager as central_manager -from ceilometer import collector -from ceilometer.compute import manager as compute_manager -from ceilometer import notification from ceilometer.openstack.common import context -from ceilometer.openstack.common import importutils -from ceilometer.openstack.common import service as os_service from ceilometer.openstack.common import timeutils from ceilometer import pipeline from ceilometer import sample from ceilometer import service -from ceilometer import storage from ceilometer import transformer -OPTS = [ - cfg.StrOpt('evaluation_service', - default='ceilometer.alarm.service.SingletonAlarmService', - help='Class to launch as alarm evaluation service.'), -] - -cfg.CONF.register_opts(OPTS, group='alarm') -cfg.CONF.import_opt('time_to_live', 'ceilometer.storage', - group='database') - -LOG = logging.getLogger(__name__) - - -def alarm_notifier(): - service.prepare_service() - os_service.launch(alarm_service.AlarmNotifierService()).wait() - - -def alarm_evaluator(): - service.prepare_service() - eval_service = importutils.import_object(cfg.CONF.alarm.evaluation_service) - os_service.launch(eval_service).wait() - - -def agent_central(): - service.prepare_service() - os_service.launch(central_manager.AgentManager()).wait() - - -def agent_compute(): - service.prepare_service() - os_service.launch(compute_manager.AgentManager()).wait() - - -def agent_notification(): - service.prepare_service() - launcher = os_service.ProcessLauncher() - launcher.launch_service( - notification.NotificationService(), - workers=service.get_workers('notification')) - launcher.wait() - - -def api(): - service.prepare_service() - srv = app.build_server() - srv.serve_forever() - - -def collector_service(): - service.prepare_service() - launcher = os_service.ProcessLauncher() - launcher.launch_service( - collector.CollectorService(), - workers=service.get_workers('collector')) - launcher.wait() - - -def storage_dbsync(): - service.prepare_service() - storage.get_connection_from_config(cfg.CONF).upgrade() - - -def storage_expirer(): - service.prepare_service() - if cfg.CONF.database.time_to_live > 0: - LOG.debug(_("Clearing expired metering data")) - storage_conn = storage.get_connection_from_config(cfg.CONF) - storage_conn.clear_expired_metering_data( - cfg.CONF.database.time_to_live) - else: - LOG.info(_("Nothing to clean, database time to live is disabled")) - - def send_sample(): cfg.CONF.register_cli_opts([ cfg.StrOpt('sample-name', diff --git a/ceilometer/cmd/__init__.py b/ceilometer/cmd/__init__.py new file mode 100644 index 000000000..0f74ba241 --- /dev/null +++ b/ceilometer/cmd/__init__.py @@ -0,0 +1,22 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import eventlet +# NOTE(jd) We need to monkey patch the socket and select module for, +# at least, oslo.messaging, otherwise everything's blocked on its +# first read() or select(), thread need to be patched too, because +# oslo.messaging use threading.local +eventlet.monkey_patch(socket=True, select=True, thread=True) diff --git a/ceilometer/cmd/agent_central.py b/ceilometer/cmd/agent_central.py new file mode 100644 index 000000000..d0317cfed --- /dev/null +++ b/ceilometer/cmd/agent_central.py @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from ceilometer.central import manager +from ceilometer.openstack.common import service as os_service +from ceilometer import service + + +def main(): + service.prepare_service() + os_service.launch(manager.AgentManager()).wait() diff --git a/ceilometer/cmd/agent_compute.py b/ceilometer/cmd/agent_compute.py new file mode 100644 index 000000000..d23f2b0d3 --- /dev/null +++ b/ceilometer/cmd/agent_compute.py @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from ceilometer.compute import manager +from ceilometer.openstack.common import service as os_service +from ceilometer import service + + +def main(): + service.prepare_service() + os_service.launch(manager.AgentManager()).wait() diff --git a/ceilometer/cmd/agent_notification.py b/ceilometer/cmd/agent_notification.py new file mode 100644 index 000000000..ba924d295 --- /dev/null +++ b/ceilometer/cmd/agent_notification.py @@ -0,0 +1,28 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from ceilometer import notification +from ceilometer.openstack.common import service as os_service +from ceilometer import service + + +def main(): + service.prepare_service() + launcher = os_service.ProcessLauncher() + launcher.launch_service( + notification.NotificationService(), + workers=service.get_workers('notification')) + launcher.wait() diff --git a/ceilometer/cmd/alarm.py b/ceilometer/cmd/alarm.py new file mode 100644 index 000000000..63def1c7f --- /dev/null +++ b/ceilometer/cmd/alarm.py @@ -0,0 +1,42 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo.config import cfg + +from ceilometer.alarm import service as alarm_service +from ceilometer.openstack.common import importutils +from ceilometer.openstack.common import service as os_service +from ceilometer import service + + +OPTS = [ + cfg.StrOpt('evaluation_service', + default='ceilometer.alarm.service.SingletonAlarmService', + help='Class to launch as alarm evaluation service.'), +] + +cfg.CONF.register_opts(OPTS, group='alarm') + + +def notifier(): + service.prepare_service() + os_service.launch(alarm_service.AlarmNotifierService()).wait() + + +def evaluator(): + service.prepare_service() + eval_service = importutils.import_object(cfg.CONF.alarm.evaluation_service) + os_service.launch(eval_service).wait() diff --git a/ceilometer/cmd/api.py b/ceilometer/cmd/api.py new file mode 100644 index 000000000..464f97078 --- /dev/null +++ b/ceilometer/cmd/api.py @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from ceilometer.api import app +from ceilometer import service + + +def main(): + service.prepare_service() + srv = app.build_server() + srv.serve_forever() diff --git a/ceilometer/cmd/collector.py b/ceilometer/cmd/collector.py new file mode 100644 index 000000000..2a1d9ffb0 --- /dev/null +++ b/ceilometer/cmd/collector.py @@ -0,0 +1,28 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from ceilometer import collector +from ceilometer.openstack.common import service as os_service +from ceilometer import service + + +def main(): + service.prepare_service() + launcher = os_service.ProcessLauncher() + launcher.launch_service( + collector.CollectorService(), + workers=service.get_workers('collector')) + launcher.wait() diff --git a/ceilometer/cmd/storage.py b/ceilometer/cmd/storage.py new file mode 100644 index 000000000..c5e9efa39 --- /dev/null +++ b/ceilometer/cmd/storage.py @@ -0,0 +1,43 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import logging + +from oslo.config import cfg + +from ceilometer import service +from ceilometer import storage + +cfg.CONF.import_opt('time_to_live', 'ceilometer.storage', + group='database') + +LOG = logging.getLogger(__name__) + + +def dbsync(): + service.prepare_service() + storage.get_connection_from_config(cfg.CONF).upgrade() + + +def expirer(): + service.prepare_service() + if cfg.CONF.database.time_to_live > 0: + LOG.debug(_("Clearing expired metering data")) + storage_conn = storage.get_connection_from_config(cfg.CONF) + storage_conn.clear_expired_metering_data( + cfg.CONF.database.time_to_live) + else: + LOG.info(_("Nothing to clean, database time to live is disabled")) diff --git a/setup.cfg b/setup.cfg index b9d45d1d0..1a89f09c1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -195,16 +195,16 @@ paste.filter_factory = swift = ceilometer.objectstore.swift_middleware:filter_factory console_scripts = - ceilometer-api = ceilometer.cli:api - ceilometer-agent-central = ceilometer.cli:agent_central - ceilometer-agent-compute = ceilometer.cli:agent_compute - ceilometer-agent-notification = ceilometer.cli:agent_notification + ceilometer-api = ceilometer.cmd.api:main + ceilometer-agent-central = ceilometer.cmd.agent_central:main + ceilometer-agent-compute = ceilometer.cmd.agent_compute:main + ceilometer-agent-notification = ceilometer.cmd.agent_notification:main ceilometer-send-sample = ceilometer.cli:send_sample - ceilometer-dbsync = ceilometer.cli:storage_dbsync - ceilometer-expirer = ceilometer.cli:storage_expirer - ceilometer-collector = ceilometer.cli:collector_service - ceilometer-alarm-evaluator = ceilometer.cli:alarm_evaluator - ceilometer-alarm-notifier = ceilometer.cli:alarm_notifier + ceilometer-dbsync = ceilometer.cmd.storage:dbsync + ceilometer-expirer = ceilometer.cmd.storage:expirer + ceilometer-collector = ceilometer.cmd.collector:main + ceilometer-alarm-evaluator = ceilometer.cmd.alarm:evaluator + ceilometer-alarm-notifier = ceilometer.cmd.alarm:notifier ceilometer.dispatcher = database = ceilometer.dispatcher.database:DatabaseDispatcher