api: build the storage connection once and for all

Fixes: bug#1178845

Change-Id: Ic0c639224ba87c3e11f3e1eeba4915e3c8ba0e88
This commit is contained in:
Julien Danjou 2013-07-16 17:51:30 +02:00
parent f7187a4155
commit 1c3c6a6514
2 changed files with 12 additions and 10 deletions

View File

@ -26,6 +26,7 @@ from ceilometer.api import config as api_config
from ceilometer.api import hooks
from ceilometer.api import middleware
from ceilometer import service
from ceilometer import storage
from ceilometer.openstack.common import log
from wsgiref import simple_server
@ -51,9 +52,13 @@ def get_pecan_config():
def setup_app(pecan_config=None, extra_hooks=None):
storage_engine = storage.get_engine(cfg.CONF)
# FIXME: Replace DBHook with a hooks.TransactionHook
app_hooks = [hooks.ConfigHook(),
hooks.DBHook(),
hooks.DBHook(
storage_engine,
storage_engine.get_connection(cfg.CONF),
),
hooks.PipelineHook()]
if extra_hooks:
app_hooks.extend(extra_hooks)

View File

@ -21,7 +21,6 @@ from oslo.config import cfg
from pecan import hooks
from ceilometer import pipeline
from ceilometer import storage
from ceilometer import transformer
@ -36,15 +35,13 @@ class ConfigHook(hooks.PecanHook):
class DBHook(hooks.PecanHook):
def before(self, state):
storage_engine = storage.get_engine(state.request.cfg)
state.request.storage_engine = storage_engine
state.request.storage_conn = storage_engine.get_connection(
state.request.cfg)
def __init__(self, storage_engine, storage_connection):
self.storage_engine = storage_engine
self.storage_connection = storage_connection
# def after(self, state):
# print 'method:', state.request.method
# print 'response:', state.response.status
def before(self, state):
state.request.storage_engine = self.storage_engine
state.request.storage_conn = self.storage_connection
class PipelineHook(hooks.PecanHook):