From a090881fbf721a8afa320e969297177a02faa234 Mon Sep 17 00:00:00 2001 From: LingxianKong Date: Tue, 12 May 2015 21:28:06 +0800 Subject: [PATCH] Make local manager work Change-Id: I3d084fed2442ec435a0ced85945f43d28af98fe9 --- etc/terracotta.conf.sample | 52 +++++++++++++++++++++++--------- terracotta/cmd/launch.py | 25 ++++++++++++--- terracotta/{db.py => db_temp.py} | 0 terracotta/locals/collector.py | 12 ++------ terracotta/locals/manager.py | 12 ++------ terracotta/utils/db_utils.py | 2 +- 6 files changed, 62 insertions(+), 41 deletions(-) rename terracotta/{db.py => db_temp.py} (100%) diff --git a/etc/terracotta.conf.sample b/etc/terracotta.conf.sample index ea863dc..0a44424 100644 --- a/etc/terracotta.conf.sample +++ b/etc/terracotta.conf.sample @@ -1,4 +1,8 @@ [DEFAULT] +# Print debugging output (set logging level to DEBUG instead +# of default WARNING level). (boolean value) +#debug=True + # The name of the host running the global manager global_manager_host = controller @@ -35,6 +39,24 @@ network_migration_bandwidth = 10 # collector in seconds data_collector_interval = 300 +[oslo_messaging_rabbit] +# The RabbitMQ broker address where a single node is used. +# (string value) +#rabbit_host=localhost + +# The RabbitMQ broker port where a single node is used. +# (integer value) +#rabbit_port=5672 + +# RabbitMQ HA cluster host:port pairs. (list value) +#rabbit_hosts=$rabbit_host:$rabbit_port + +# The RabbitMQ userid. (string value) +#rabbit_userid=guest + +# The RabbitMQ password. (string value) +#rabbit_password=guest + [api] # Terracotta API server host host = 0.0.0.0 @@ -42,20 +64,6 @@ host = 0.0.0.0 # Terracotta API server port port = 9090 -[pecan] -# Pecan root controller -root = terracotta.api.controllers.root.RootController - -# A list of modules where pecan will search for applications. -modules = terracotta.api - -# Enables the ability to display tracebacks in the -# browser and interactively debug during development. -debug = False - -# Enables user authentication in pecan. -auth_enable = True - [global_manager] # The message topic that the global_manager listens on. (string value) #topic=global_manager @@ -169,4 +177,18 @@ host_cpu_overload_threshold = 0.8 [database] # The host name and credentials for connecting to the MySQL database # specified in the format supported by SQLAlchemy -sql_connection = mysql://terracotta:terracottapassword@controller/terracotta \ No newline at end of file +sql_connection = mysql://terracotta:password@localhost:3306/terracotta + +[pecan] +# Pecan root controller +root = terracotta.api.controllers.root.RootController + +# A list of modules where pecan will search for applications. +modules = terracotta.api + +# Enables the ability to display tracebacks in the +# browser and interactively debug during development. +debug = False + +# Enables user authentication in pecan. +auth_enable = True \ No newline at end of file diff --git a/terracotta/cmd/launch.py b/terracotta/cmd/launch.py index 554ef29..6e38735 100644 --- a/terracotta/cmd/launch.py +++ b/terracotta/cmd/launch.py @@ -42,6 +42,7 @@ from terracotta import rpc from terracotta.locals import collector from terracotta.locals import manager as local_mgr from terracotta.globals import manager as global_mgr +from terracotta.openstack.common import threadgroup from terracotta import version @@ -74,12 +75,19 @@ def launch_lm(transport): local_manager = local_mgr.LocalManager() endpoints = [rpc.LocalManagerServer(local_manager)] + tg = threadgroup.ThreadGroup() + tg.add_dynamic_timer( + local_manager.run_periodic_tasks, + initial_delay=None, + periodic_interval_max=None, + context=None + ) + server = messaging.get_rpc_server( transport, target, endpoints, - executor='eventlet', - serializer=ctx.RpcContextSerializer(ctx.JsonPayloadSerializer()) + executor='eventlet' ) server.start() @@ -100,7 +108,6 @@ def launch_gm(transport): target, endpoints, executor='eventlet', - serializer=ctx.RpcContextSerializer(ctx.JsonPayloadSerializer()) ) server.start() @@ -113,8 +120,16 @@ def launch_collector(transport): server=cfg.CONF.collector.host ) - global_manager = collector.Collector() - endpoints = [rpc.GlobalManagerServer(global_manager)] + launch_collector = collector.Collector() + endpoints = [rpc.GlobalManagerServer(launch_collector)] + + tg = threadgroup.ThreadGroup() + tg.add_dynamic_timer( + launch_collector.run_periodic_tasks, + initial_delay=None, + periodic_interval_max=None, + context=None + ) server = messaging.get_rpc_server( transport, diff --git a/terracotta/db.py b/terracotta/db_temp.py similarity index 100% rename from terracotta/db.py rename to terracotta/db_temp.py diff --git a/terracotta/locals/collector.py b/terracotta/locals/collector.py index 9cd6171..2335548 100644 --- a/terracotta/locals/collector.py +++ b/terracotta/locals/collector.py @@ -101,7 +101,6 @@ from oslo_log import log as logging from terracotta import common from terracotta.openstack.common import periodic_task -from terracotta.openstack.common import threadgroup from terracotta.utils import db_utils @@ -123,13 +122,6 @@ class Collector(periodic_task.PeriodicTasks): CONF.local_data_directory) self.state = self.init_state() - self.tg = threadgroup.ThreadGroup() - self.tg.add_dynamic_timer( - self.run_periodic_tasks, - initial_delay=None, - periodic_interval_max=1, - context=None - ) def init_state(self): """ Initialize a dict for storing the state of the data collector.""" @@ -166,8 +158,8 @@ class Collector(periodic_task.PeriodicTasks): 'physical_core_mhz': host_cpu_mhz / physical_cpus, 'db': db} - @periodic_task.periodic_task - def execute(self): + @periodic_task.periodic_task(spacing=10, run_immediately=True) + def execute(self, ctx=None): """ Execute a data collection iteration. 1. Read the names of the files from the /vm diff --git a/terracotta/locals/manager.py b/terracotta/locals/manager.py index 6ee5ef3..75e7c98 100644 --- a/terracotta/locals/manager.py +++ b/terracotta/locals/manager.py @@ -110,7 +110,6 @@ from oslo_log import log as logging from terracotta import common from terracotta.openstack.common import periodic_task -from terracotta.openstack.common import threadgroup from terracotta.utils import db_utils @@ -122,13 +121,6 @@ class LocalManager(periodic_task.PeriodicTasks): def __init__(self): super(LocalManager, self).__init__() self.state = self.init_state() - self.tg = threadgroup.ThreadGroup() - self.tg.add_dynamic_timer( - self.run_periodic_tasks, - initial_delay=None, - periodic_interval_max=1, - context=None - ) def init_state(self): """ Initialize a dict for storing the state of the local manager. @@ -156,8 +148,8 @@ class LocalManager(periodic_task.PeriodicTasks): 'hashed_username': sha1(CONF.os_admin_user).hexdigest(), 'hashed_password': sha1(CONF.os_admin_password).hexdigest()} - @periodic_task.periodic_task - def execute(self): + @periodic_task.periodic_task(spacing=10, run_immediately=True) + def execute(self, ctx=None): """ Execute an iteration of the local manager. 1. Read the data on resource usage by the VMs running on the host from diff --git a/terracotta/utils/db_utils.py b/terracotta/utils/db_utils.py index 01679c4..5d1ccbf 100644 --- a/terracotta/utils/db_utils.py +++ b/terracotta/utils/db_utils.py @@ -19,7 +19,7 @@ from sqlalchemy.sql import func from oslo_config import cfg from oslo_log import log as logging -from terracotta import db as database +from terracotta import db_temp as database LOG = logging.getLogger(__name__)