Integrate openstack/common logging and cfg with congress
This patch starts the integration with the common openstack libraries for logging and config management. Other places in the source tree still need to be converted over (datasources/dse/policy/tests) which should be straight forward though I prefer to do these segements in a later commit once I figure out how these seconds work. Part of blueprint integrate-oslo-config-and-logging Change-Id: I24948f157733a3ee0a25b03703ff0e1d87005832
This commit is contained in:
parent
f4b73f7e7f
commit
75ce78e592
|
@ -14,7 +14,6 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
import logging
|
||||
import traceback
|
||||
import webob
|
||||
import webob.dec
|
||||
|
@ -26,9 +25,10 @@ from api.webservice import ElementHandler
|
|||
from api.webservice import INTERNAL_ERROR_RESPONSE
|
||||
from api.webservice import NOT_SUPPORTED_RESPONSE
|
||||
from api.webservice import SimpleDataModel
|
||||
from congress.openstack.common import log as logging
|
||||
|
||||
|
||||
lg = logging.getLogger('api.application')
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ApiApplication(object):
|
||||
|
@ -47,15 +47,15 @@ class ApiApplication(object):
|
|||
handler = self.resource_mgr.get_handler(request)
|
||||
if handler:
|
||||
msg = _("Handling request '%(meth)s %(path)s' with %(hndlr)s")
|
||||
lg.debug(msg % {"meth": request.method, "path": request.path,
|
||||
"hndlr": str(handler)})
|
||||
LOG.debug(msg % {"meth": request.method, "path": request.path,
|
||||
"hndlr": str(handler)})
|
||||
response = handler.handle_request(request)
|
||||
else:
|
||||
response = NOT_SUPPORTED_RESPONSE
|
||||
except Exception as e:
|
||||
msg = _("Exception caught for request: %s")
|
||||
lg.error(msg % (request))
|
||||
lg.error(traceback.format_exc(e))
|
||||
LOG.error(msg % (request))
|
||||
LOG.error(traceback.format_exc(e))
|
||||
response = INTERNAL_ERROR_RESPONSE
|
||||
return response
|
||||
|
||||
|
@ -87,7 +87,7 @@ class ResourceManager(object):
|
|||
else:
|
||||
self.handlers.append(handler)
|
||||
msg = _("Registered API handler: %s") % (handler)
|
||||
lg.info(msg)
|
||||
LOG.info(msg)
|
||||
|
||||
def get_handler(self, request):
|
||||
"""Find a handler for a REST request.
|
||||
|
|
|
@ -16,14 +16,15 @@
|
|||
|
||||
import httplib
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import uuid
|
||||
import webob
|
||||
import webob.dec
|
||||
|
||||
from congress.openstack.common import log as logging
|
||||
|
||||
lg = logging.getLogger("api.webservice")
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def error_response(status, error_code, description, data=None):
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#
|
||||
|
||||
import errno
|
||||
import logging
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
@ -22,8 +21,10 @@ import time
|
|||
import eventlet.wsgi
|
||||
eventlet.patcher.monkey_patch(all=False, socket=True)
|
||||
|
||||
from congress.openstack.common import log as logging
|
||||
|
||||
lg = logging.getLogger('api.wsgi')
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# Number of seconds to keep retrying to listen
|
||||
RETRY_UNTIL_WINDOW = 30
|
||||
|
@ -55,8 +56,8 @@ class Server(object):
|
|||
family = info[0]
|
||||
bind_addr = info[-1]
|
||||
except Exception:
|
||||
lg.error(("Unable to listen on %(host)s:%(port)s") %
|
||||
{'host': host, 'port': port})
|
||||
LOG.error(("Unable to listen on %(host)s:%(port)s") %
|
||||
{'host': host, 'port': port})
|
||||
sys.exit(1)
|
||||
|
||||
sock = None
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
# Copyright 2014 VMware
|
||||
#
|
||||
# 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 congress.openstack.common import log
|
||||
|
||||
core_opts = [
|
||||
cfg.StrOpt('bind_host', default='0.0.0.0',
|
||||
help="The host IP to bind to"),
|
||||
cfg.IntOpt('bind_port', default=8080,
|
||||
help="The port to bind to"),
|
||||
cfg.IntOpt('max_simultaneous_requests', default=1024,
|
||||
help="Thread pool size for eventlet."),
|
||||
|
||||
]
|
||||
|
||||
# Register the configuration options
|
||||
cfg.CONF.register_opts(core_opts)
|
||||
|
||||
|
||||
def init(args, **kwargs):
|
||||
cfg.CONF(args=args, project='congress', **kwargs)
|
||||
|
||||
|
||||
def setup_logging():
|
||||
"""Sets up logging for the congress package."""
|
||||
log.setup('congress')
|
|
@ -18,19 +18,18 @@
|
|||
import eventlet
|
||||
eventlet.monkey_patch()
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os.path
|
||||
from oslo.config import cfg
|
||||
import sys
|
||||
|
||||
import api.application
|
||||
import api.wsgi
|
||||
from congress.common import config
|
||||
from congress.openstack.common import log as logging
|
||||
import dse.d6cage
|
||||
|
||||
|
||||
DEFAULT_POOL_SIZE = 1024
|
||||
DEFAULT_HTTP_ADDR = '0.0.0.0'
|
||||
DEFAULT_HTTP_PORT = 8080
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EventLoop(object):
|
||||
|
@ -76,40 +75,32 @@ class EventLoop(object):
|
|||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Run Congress Server.")
|
||||
parser.add_argument("-v", "--verbose", action="store_true",
|
||||
help="verbose output")
|
||||
parser.add_argument("--max_simultaneous_requests",
|
||||
default=DEFAULT_POOL_SIZE)
|
||||
parser.add_argument("--http_listen_port", default=DEFAULT_HTTP_PORT)
|
||||
parser.add_argument("--http_listen_addr", default=DEFAULT_HTTP_ADDR)
|
||||
args = parser.parse_args()
|
||||
config.init(sys.argv[1:])
|
||||
if not cfg.CONF.config_file:
|
||||
sys.exit("ERROR: Unable to find configuration file via default "
|
||||
"search paths ~/.congress/, ~/, /etc/congress/, /etc/) and "
|
||||
"the '--config-file' option!")
|
||||
config.setup_logging()
|
||||
LOG.info("Starting congress server")
|
||||
|
||||
fmt = "%(asctime)s %(name)s %(levelname)s %(message)s"
|
||||
logging.basicConfig(stream=sys.stdout, format=fmt)
|
||||
if args.verbose:
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
else:
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
|
||||
loop = EventLoop(args.max_simultaneous_requests)
|
||||
#TODO(pballand): Fix the policy enginge registration to work with the
|
||||
loop = EventLoop(cfg.CONF.max_simultaneous_requests)
|
||||
# TODO(pballand): Fix the policy enginge registration to work with the
|
||||
# latest policy changes.
|
||||
#engine = loop.register_service(
|
||||
# engine = loop.register_service(
|
||||
# "engine", "PolicyEngine", "policy/dsepolicy.py",
|
||||
# "Policy Engine (DseRuntime instance)")
|
||||
#engine.initialize_table_subscriptions()
|
||||
# engine.initialize_table_subscriptions()
|
||||
|
||||
# API resource runtime encapsulation:
|
||||
# event loop -> wsgi server -> webapp -> resource manager
|
||||
|
||||
wsgi_server = api.wsgi.Server("Congress API Broker", pool=loop.pool)
|
||||
api_resource_mgr = api.application.ResourceManager()
|
||||
api.application.initialize_resources(api_resource_mgr)
|
||||
api_webapp = api.application.ApiApplication(api_resource_mgr)
|
||||
# TODO(pballand): start this inside d6cage(?)
|
||||
wsgi_server.start(api_webapp, args.http_listen_port,
|
||||
args.http_listen_addr)
|
||||
wsgi_server.start(api_webapp, cfg.CONF.bind_port,
|
||||
cfg.CONF.bind_host)
|
||||
|
||||
loop.wait()
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
# Copyright (c) 2014 VMware
|
||||
#
|
||||
# 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
|
||||
import testtools
|
||||
|
||||
from congress.common import config
|
||||
|
||||
|
||||
class ConfigurationTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ConfigurationTest, self).setUp()
|
||||
config.setup_logging()
|
||||
|
||||
def test_defaults(self):
|
||||
self.assertEqual('0.0.0.0', cfg.CONF.bind_host)
|
||||
self.assertEqual(8080, cfg.CONF.bind_port)
|
|
@ -0,0 +1,31 @@
|
|||
[DEFAULT]
|
||||
# Print more verbose output (set logging level to INFO instead of default WARNING level).
|
||||
# verbose = False
|
||||
|
||||
# Print debugging output (set logging level to DEBUG instead of default WARNING level).
|
||||
# debug = False
|
||||
|
||||
# log_format = %(asctime)s %(levelname)8s [%(name)s] %(message)s
|
||||
# log_date_format = %Y-%m-%d %H:%M:%S
|
||||
|
||||
# use_syslog -> syslog
|
||||
# log_file and log_dir -> log_dir/log_file
|
||||
# (not log_file) and log_dir -> log_dir/{binary_name}.log
|
||||
# use_stderr -> stderr
|
||||
# (not user_stderr) and (not log_file) -> stdout
|
||||
# publish_errors -> notification system
|
||||
|
||||
# use_syslog = False
|
||||
# syslog_log_facility = LOG_USER
|
||||
|
||||
# use_stderr = True
|
||||
# log_file =
|
||||
# log_dir =
|
||||
|
||||
# publish_errors = False
|
||||
|
||||
# Address to bind the API server to
|
||||
# bind_host = 0.0.0.0
|
||||
|
||||
# Port the bind the API server to
|
||||
# bind_port = 9696
|
|
@ -5,3 +5,4 @@ mox<1.0
|
|||
python-neutronclient>=2.3.5,<3
|
||||
argparse
|
||||
six>=1.7.0
|
||||
oslo.config>=1.2.1
|
||||
|
|
|
@ -22,7 +22,7 @@ PYSRCDIR=$ROOTDIR/congress
|
|||
SERVERDIR=$PYSRCDIR/server
|
||||
THIRDPARTYDIR=$ROOTDIR/thirdparty
|
||||
|
||||
export PYTHONPATH=$PYSRCDIR:$THIRDPARTYDIR
|
||||
export PYTHONPATH=$PYSRCDIR:$THIRDPARTYDIR:$ROOTDIR
|
||||
|
||||
ARGS="$@"
|
||||
cd $SERVERDIR
|
||||
|
|
Loading…
Reference in New Issue