From ec0b1c51507e322dc195cdc94fe020771a56e62e Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Wed, 15 Jul 2015 16:17:10 +0200 Subject: [PATCH] Add configuration to run service using uwsgi Add a sample configuration for running the wsgi transport using uwsgi, and make devstack uses it, while running zaqar-server with websocket transport. This allows running both websockets and wsgi transports on devstack. Change-Id: Ifac7461ec6b0501b1b9021030d9c173cf368a59b --- devstack/gate/gate_hook.sh | 2 +- devstack/plugin.sh | 40 +++++++++++++++++++--------- devstack/settings | 3 +-- etc/uwsgi.conf | 7 +++++ zaqar/common/configs.py | 2 +- zaqar/transport/websocket/driver.py | 8 ++++-- zaqar/transport/websocket/factory.py | 5 ++-- zaqar/transport/wsgi/app.py | 4 ++- 8 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 etc/uwsgi.conf diff --git a/devstack/gate/gate_hook.sh b/devstack/gate/gate_hook.sh index bca16d43d..ff741194f 100755 --- a/devstack/gate/gate_hook.sh +++ b/devstack/gate/gate_hook.sh @@ -14,7 +14,7 @@ # This script is executed inside gate_hook function in devstack gate. -ENABLED_SERVICES="mysql,key,tempest,zaqar-server," +ENABLED_SERVICES="mysql,key,tempest,zaqar-websocket,zaqar-wsgi" export DEVSTACK_GATE_ZAQAR=1 export DEVSTACK_GATE_INSTALL_TESTONLY=1 diff --git a/devstack/plugin.sh b/devstack/plugin.sh index fe50344f2..89f2d2278 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -5,7 +5,7 @@ # To enable a minimal set of Zaqar services, add the following to localrc: # -# enable_service zaqar-server +# enable_service zaqar-websocket zaqar-wsgi # # Dependencies: # - functions @@ -37,6 +37,7 @@ ZAQAR_DIR=$DEST/zaqar ZAQARCLIENT_DIR=$DEST/python-zaqarclient ZAQAR_CONF_DIR=/etc/zaqar ZAQAR_CONF=$ZAQAR_CONF_DIR/zaqar.conf +ZAQAR_UWSGI_CONF=$ZAQAR_CONF_DIR/uwsgi.conf ZAQAR_API_LOG_DIR=/var/log/zaqar ZAQAR_API_LOG_FILE=$ZAQAR_API_LOG_DIR/queues.log ZAQAR_AUTH_CACHE_DIR=${ZAQAR_AUTH_CACHE_DIR:-/var/cache/zaqar} @@ -59,6 +60,7 @@ ZAQARCLIENT_BRANCH=${ZAQARCLIENT_BRANCH:-master} # Set Zaqar Connection Info ZAQAR_SERVICE_HOST=${ZAQAR_SERVICE_HOST:-$SERVICE_HOST} ZAQAR_SERVICE_PORT=${ZAQAR_SERVICE_PORT:-8888} +ZAQAR_WEBSOCKET_PORT=${ZAQAR_WEBSOCKET_PORT:-9000} ZAQAR_SERVICE_PROTOCOL=${ZAQAR_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} # Tell Tempest this project is present @@ -123,7 +125,9 @@ function configure_zaqar { # Enable pooling by default for now iniset $ZAQAR_CONF DEFAULT admin_mode True - iniset $ZAQAR_CONF 'drivers:transport:wsgi' bind $ZAQAR_SERVICE_HOST + iniset $ZAQAR_CONF 'drivers:transport:websocket' bind $ZAQAR_SERVICE_HOST + iniset $ZAQAR_CONF 'drivers:transport:websocket' port $ZAQAR_WEBSOCKET_PORT + iniset $ZAQAR_CONF drivers transport websocket configure_auth_token_middleware $ZAQAR_CONF zaqar $ZAQAR_AUTH_CACHE_DIR @@ -151,6 +155,13 @@ function configure_zaqar { fi iniset_rpc_backend zaqar $ZAQAR_CONF DEFAULT + pip_install uwsgi + iniset $ZAQAR_UWSGI_CONF uwsgi http $ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT + iniset $ZAQAR_UWSGI_CONF uwsgi processes 1 + iniset $ZAQAR_UWSGI_CONF uwsgi threads 4 + iniset $ZAQAR_UWSGI_CONF uwsgi wsgi-file $ZAQAR_DIR/zaqar/transport/wsgi/app.py + iniset $ZAQAR_UWSGI_CONF uwsgi callable app + cleanup_zaqar } @@ -169,6 +180,7 @@ function configure_redis { function configure_mongodb { # Set nssize to 2GB. This increases the number of namespaces supported # # per database. + pip_install pymongo if is_ubuntu; then install_package mongodb-server sudo sed -i -e " @@ -206,9 +218,11 @@ function install_zaqarclient { # start_zaqar() - Start running processes, including screen function start_zaqar { if [[ "$USE_SCREEN" = "False" ]]; then - run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF --daemon" + run_process zaqar-wsgi "uwsgi --ini $ZAQAR_UWSGI_CONF --daemonize $ZAQAR_API_LOG_DIR/uwsgi.log" + run_process zaqar-websocket "zaqar-server --config-file $ZAQAR_CONF --daemon" else - run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF" + run_process zaqar-wsgi "uwsgi --ini $ZAQAR_UWSGI_CONF" + run_process zaqar-websocket "zaqar-server --config-file $ZAQAR_CONF" fi echo "Waiting for Zaqar to start..." @@ -221,7 +235,7 @@ function start_zaqar { function stop_zaqar { local serv # Kill the zaqar screen windows - for serv in zaqar-server; do + for serv in zaqar-wsgi zaqar-websocket; do screen -S $SCREEN_NAME -p $serv -X kill done } @@ -238,14 +252,19 @@ function create_zaqar_accounts { "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \ "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \ "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" + + local zaqar_ws_service=$(get_or_create_service "zaqar-websocket" \ + "messaging-websocket" "Zaqar Service") + get_or_create_endpoint $zaqar_service \ + "$REGION_NAME" \ + "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_WEBSOCKET_PORT" \ + "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_WEBSOCKET_PORT" \ + "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_WEBSOCKET_PORT" fi } - - - -if is_service_enabled zaqar-server; then +if is_service_enabled zaqar-websocket || is_service_enabled zaqar-wsgi; then if [[ "$1" == "stack" && "$2" == "install" ]]; then echo_summary "Installing Zaqar" install_zaqarclient @@ -268,9 +287,6 @@ if is_service_enabled zaqar-server; then if [[ "$1" == "unstack" ]]; then stop_zaqar fi - - #if [[ "$1" == "clean" ]]; then - #fi fi # Restore xtrace diff --git a/devstack/settings b/devstack/settings index 8f74e4816..40e0700f1 100644 --- a/devstack/settings +++ b/devstack/settings @@ -1,4 +1,3 @@ # Devstack settings -# we have to add zaqar-server to enabled services for screen_it to work -enable_service zaqar-server +enable_service zaqar-websocket zaqar-wsgi diff --git a/etc/uwsgi.conf b/etc/uwsgi.conf new file mode 100644 index 000000000..f520435da --- /dev/null +++ b/etc/uwsgi.conf @@ -0,0 +1,7 @@ +[uwsgi] +strict = true +http = :8888 +processes = 1 +threads = 4 +wsgi-file = /opt/stack/zaqar/zaqar/transport/wsgi/app.py +callable = app diff --git a/zaqar/common/configs.py b/zaqar/common/configs.py index 8d2bdb472..22713b7a8 100644 --- a/zaqar/common/configs.py +++ b/zaqar/common/configs.py @@ -30,7 +30,7 @@ _GENERAL_OPTIONS = ( 'catalogue/control plane data is kept.'), deprecated_opts=[cfg.DeprecatedOpt('sharding')]), cfg.BoolOpt('unreliable', default=None, - help='Disable all reliability constrains.'), + help='Disable all reliability constraints.'), ) _DRIVER_OPTIONS = ( diff --git a/zaqar/transport/websocket/driver.py b/zaqar/transport/websocket/driver.py index 874f755ea..3a3bb73ce 100644 --- a/zaqar/transport/websocket/driver.py +++ b/zaqar/transport/websocket/driver.py @@ -33,6 +33,9 @@ _WS_OPTIONS = ( cfg.IntOpt('port', default=9000, help='Port on which the self-hosting server will listen.'), + cfg.IntOpt('external-port', default=None, + help='Port on which the service is provided to the user.'), + cfg.BoolOpt('debug', default=False, help='Print debugging output') ) @@ -58,8 +61,9 @@ class Driver(object): @decorators.lazy_property(write=False) def factory(self): uri = 'ws://' + self._ws_conf.bind + ':' + str(self._ws_conf.port) - return factory.ProtocolFactory(uri, debug=self._ws_conf.debug, - handler=self._api) + return factory.ProtocolFactory( + uri, debug=self._ws_conf.debug, handler=self._api, + external_port=self._ws_conf.external_port) def listen(self): """Self-host using 'bind' and 'port' from the WS config group.""" diff --git a/zaqar/transport/websocket/factory.py b/zaqar/transport/websocket/factory.py index b43e07418..50f82b6dd 100644 --- a/zaqar/transport/websocket/factory.py +++ b/zaqar/transport/websocket/factory.py @@ -22,8 +22,9 @@ class ProtocolFactory(websocket.WebSocketServerFactory): protocol = protocol.MessagingProtocol - def __init__(self, uri, debug, handler): - websocket.WebSocketServerFactory.__init__(self, uri, debug) + def __init__(self, uri, debug, handler, external_port): + websocket.WebSocketServerFactory.__init__( + self, url=uri, debug=debug, externalPort=external_port) self._handler = handler def __call__(self): diff --git a/zaqar/transport/wsgi/app.py b/zaqar/transport/wsgi/app.py index 312eb8552..91feb7de9 100644 --- a/zaqar/transport/wsgi/app.py +++ b/zaqar/transport/wsgi/app.py @@ -36,4 +36,6 @@ from zaqar import bootstrap conf = cfg.CONF conf(project='zaqar', prog='zaqar-queues', args=[]) -app = bootstrap.Bootstrap(conf).transport.app +boot = bootstrap.Bootstrap(conf) +conf.drivers.transport = 'wsgi' +app = boot.transport.app