Make local manager work

Change-Id: I3d084fed2442ec435a0ced85945f43d28af98fe9
This commit is contained in:
LingxianKong 2015-05-12 21:28:06 +08:00
parent e7a701446b
commit a090881fbf
6 changed files with 62 additions and 41 deletions

View File

@ -1,4 +1,8 @@
[DEFAULT] [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 # The name of the host running the global manager
global_manager_host = controller global_manager_host = controller
@ -35,6 +39,24 @@ network_migration_bandwidth = 10
# collector in seconds # collector in seconds
data_collector_interval = 300 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] [api]
# Terracotta API server host # Terracotta API server host
host = 0.0.0.0 host = 0.0.0.0
@ -42,20 +64,6 @@ host = 0.0.0.0
# Terracotta API server port # Terracotta API server port
port = 9090 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] [global_manager]
# The message topic that the global_manager listens on. (string value) # The message topic that the global_manager listens on. (string value)
#topic=global_manager #topic=global_manager
@ -169,4 +177,18 @@ host_cpu_overload_threshold = 0.8
[database] [database]
# The host name and credentials for connecting to the MySQL database # The host name and credentials for connecting to the MySQL database
# specified in the format supported by SQLAlchemy # specified in the format supported by SQLAlchemy
sql_connection = mysql://terracotta:terracottapassword@controller/terracotta 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

View File

@ -42,6 +42,7 @@ from terracotta import rpc
from terracotta.locals import collector from terracotta.locals import collector
from terracotta.locals import manager as local_mgr from terracotta.locals import manager as local_mgr
from terracotta.globals import manager as global_mgr from terracotta.globals import manager as global_mgr
from terracotta.openstack.common import threadgroup
from terracotta import version from terracotta import version
@ -74,12 +75,19 @@ def launch_lm(transport):
local_manager = local_mgr.LocalManager() local_manager = local_mgr.LocalManager()
endpoints = [rpc.LocalManagerServer(local_manager)] 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( server = messaging.get_rpc_server(
transport, transport,
target, target,
endpoints, endpoints,
executor='eventlet', executor='eventlet'
serializer=ctx.RpcContextSerializer(ctx.JsonPayloadSerializer())
) )
server.start() server.start()
@ -100,7 +108,6 @@ def launch_gm(transport):
target, target,
endpoints, endpoints,
executor='eventlet', executor='eventlet',
serializer=ctx.RpcContextSerializer(ctx.JsonPayloadSerializer())
) )
server.start() server.start()
@ -113,8 +120,16 @@ def launch_collector(transport):
server=cfg.CONF.collector.host server=cfg.CONF.collector.host
) )
global_manager = collector.Collector() launch_collector = collector.Collector()
endpoints = [rpc.GlobalManagerServer(global_manager)] 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( server = messaging.get_rpc_server(
transport, transport,

View File

@ -101,7 +101,6 @@ from oslo_log import log as logging
from terracotta import common from terracotta import common
from terracotta.openstack.common import periodic_task from terracotta.openstack.common import periodic_task
from terracotta.openstack.common import threadgroup
from terracotta.utils import db_utils from terracotta.utils import db_utils
@ -123,13 +122,6 @@ class Collector(periodic_task.PeriodicTasks):
CONF.local_data_directory) CONF.local_data_directory)
self.state = self.init_state() 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): def init_state(self):
""" Initialize a dict for storing the state of the data collector.""" """ 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, 'physical_core_mhz': host_cpu_mhz / physical_cpus,
'db': db} 'db': db}
@periodic_task.periodic_task @periodic_task.periodic_task(spacing=10, run_immediately=True)
def execute(self): def execute(self, ctx=None):
""" Execute a data collection iteration. """ Execute a data collection iteration.
1. Read the names of the files from the <local_data_directory>/vm 1. Read the names of the files from the <local_data_directory>/vm

View File

@ -110,7 +110,6 @@ from oslo_log import log as logging
from terracotta import common from terracotta import common
from terracotta.openstack.common import periodic_task from terracotta.openstack.common import periodic_task
from terracotta.openstack.common import threadgroup
from terracotta.utils import db_utils from terracotta.utils import db_utils
@ -122,13 +121,6 @@ class LocalManager(periodic_task.PeriodicTasks):
def __init__(self): def __init__(self):
super(LocalManager, self).__init__() super(LocalManager, self).__init__()
self.state = self.init_state() 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): def init_state(self):
""" Initialize a dict for storing the state of the local manager. """ 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_username': sha1(CONF.os_admin_user).hexdigest(),
'hashed_password': sha1(CONF.os_admin_password).hexdigest()} 'hashed_password': sha1(CONF.os_admin_password).hexdigest()}
@periodic_task.periodic_task @periodic_task.periodic_task(spacing=10, run_immediately=True)
def execute(self): def execute(self, ctx=None):
""" Execute an iteration of the local manager. """ Execute an iteration of the local manager.
1. Read the data on resource usage by the VMs running on the host from 1. Read the data on resource usage by the VMs running on the host from

View File

@ -19,7 +19,7 @@ from sqlalchemy.sql import func
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from terracotta import db as database from terracotta import db_temp as database
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)