-
-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1170 from BlackOrder/RestApiConfig-0.11.0
Rest api config to /etc/jasmin/rest-api.cfg
- Loading branch information
Showing
9 changed files
with
307 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,26 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Change binding host:port for redis, and amqp | ||
sed -i "/\[redis-client\]/,/host=/ s/host=.*/host=$REDIS_CLIENT_HOST/" ${CONFIG_PATH}/jasmin.cfg | ||
sed -i "/\[redis-client\]/,/port=/ s/port=.*/port=$REDIS_CLIENT_PORT/" ${CONFIG_PATH}/jasmin.cfg | ||
sed -i "/\[amqp-broker\]/,/host=/ s/host=.*/host=$AMQP_BROKER_HOST/" ${CONFIG_PATH}/jasmin.cfg | ||
sed -i "/\[amqp-broker\]/,/port=/ s/port=.*/port=$AMQP_BROKER_PORT/" ${CONFIG_PATH}/jasmin.cfg | ||
|
||
# Clean lock files | ||
echo 'Cleaning lock files' | ||
rm -f /tmp/*.lock | ||
|
||
# RestAPI | ||
if [ "$RESTAPI_MODE" = 1 ]; then | ||
# find jasmin installation directory | ||
jasminRoot=$(python -c "import jasmin as _; print(_.__path__[0])") | ||
# update jasmin-restAPI config | ||
sed -i "/# RESTAPI/,/old_api_uri/ s/old_api_uri.*/old_api_uri = 'http:\/\/$RESTAPI_OLD_HTTP_HOST:1401'/" ${jasminRoot}/protocols/rest/config.py | ||
sed -i "/# CELERY/,/broker_url/ s/broker_url.*/broker_url = 'amqp:\/\/guest:guest@$AMQP_BROKER_HOST:$AMQP_BROKER_PORT\/\/'/" ${jasminRoot}/protocols/rest/config.py | ||
sed -i "/# CELERY/,/result_backend/ s/result_backend.*/result_backend = 'redis:\/\/:@$REDIS_CLIENT_HOST:$REDIS_CLIENT_PORT\/1'/" ${jasminRoot}/protocols/rest/config.py | ||
# If RestAPI http Mode, start Guicorn | ||
if [ "$RESTAPI_HTTP_MODE" = 1 ]; then | ||
# start restapi | ||
exec gunicorn -b 0.0.0.0:8080 jasmin.protocols.rest:api --access-logfile /var/log/jasmin/rest-api.access.log --disable-redirect-access-to-syslog | ||
else | ||
if [ "$ENABLE_PUBLISH_SUBMIT_SM_RESP" = 1 ]; then | ||
# Enable publish_submit_sm_resp | ||
echo 'Enabling publish_submit_sm_resp' | ||
sed -i "s/.*publish_submit_sm_resp\s*=.*/publish_submit_sm_resp=True/g" ${CONFIG_PATH}/jasmin.cfg | ||
else | ||
# Disable publish_submit_sm_resp | ||
echo 'Disabling publish_submit_sm_resp' | ||
sed -i "s/.*publish_submit_sm_resp\s*=.*/publish_submit_sm_resp=False/g" ${CONFIG_PATH}/jasmin.cfg | ||
fi | ||
|
||
# If Celery Worker is enabled, start Celery worker | ||
elif [ "$RESTAPI_WORKER_MODE" = 1 ]; then | ||
echo 'Starting Celery worker' | ||
exec celery -A jasmin.protocols.rest.tasks worker -l INFO -c 4 --autoscale=10,3 | ||
|
||
# Else start jasmind | ||
else | ||
if [ "$2" = "--enable-interceptor-client" ]; then | ||
echo 'Starting interceptord' | ||
interceptord.py & | ||
fi | ||
|
||
echo 'Starting jasmind' | ||
exec "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,73 @@ | ||
"""This is the jasmin-celery and jasmin-restapi configurations""" | ||
|
||
import logging | ||
from jasmin.config import LOG_PATH | ||
|
||
# RESTAPI | ||
old_api_uri = 'http://127.0.0.1:1401' | ||
show_jasmin_version = True | ||
auth_cache_seconds = 10 | ||
auth_cache_max_keys = 500 | ||
|
||
log_level = logging.getLevelName('INFO') | ||
log_file = '%s/restapi.log' % LOG_PATH | ||
log_rotate = 'W6' | ||
log_format = '%(asctime)s %(levelname)-8s %(process)d %(message)s' | ||
log_date_format = '%Y-%m-%d %H:%M:%S' | ||
|
||
# CELERY | ||
broker_url = 'amqp://guest:guest@127.0.0.1:5672//' | ||
result_backend = 'redis://:@127.0.0.1:6379/1' | ||
task_serializer = 'json' | ||
result_serializer = 'json' | ||
accept_content = ['json'] | ||
timezone = 'UTC' | ||
enable_utc = True | ||
# Will push messages back to Jasmin's http api with a maximum throughput *per worker* | ||
# Please consider this is a *per worker* throughput ! | ||
# Set to zero (0) to disable throughput control | ||
http_throughput_per_worker = 8 | ||
# When set to True, the batch executor will consider Jasmin's response time to | ||
# control the batch throughput, slower response time will slow down the throughput | ||
# and vice-versa | ||
smart_qos = True | ||
import os | ||
from jasmin.config import ConfigFile, ROOT_PATH, LOG_PATH | ||
|
||
CONFIG_PATH = os.getenv('CONFIG_PATH', '%s/etc/jasmin/' % ROOT_PATH) | ||
REST_API_CONFIG = os.getenv('REST_API_CONFIG', '%s/rest-api.cfg' % CONFIG_PATH) | ||
|
||
class RestAPIForJasminConfig(ConfigFile): | ||
"""Config handler for 'rest-api' section""" | ||
|
||
def __init__(self, config_file=REST_API_CONFIG): | ||
ConfigFile.__init__(self, config_file) | ||
|
||
# Celery global configuration | ||
self.timezone = self._get('celery', 'timezone', 'UTC') | ||
self.enable_utc = self._getbool('celery', 'enable_utc', True) | ||
self.accept_content = self._get('celery', 'accept_content', 'json').split(',') | ||
|
||
# AMQP Broker Connection configuration | ||
self.broker_url = 'amqp://%s:%s@%s:%s/%s' % ( | ||
self._get('amqp-broker', 'username', 'guest'), | ||
self._get('amqp-broker', 'password', 'guest'), | ||
self._get('amqp-broker', 'host', '127.0.0.1'), | ||
self._getint('amqp-broker', 'port', 5672), | ||
self._get('amqp-broker', 'vhost', '/')) | ||
|
||
self.broker_heartbeat = self._getint('amqp-broker', 'broker_heartbeat', 120) | ||
self.broker_heartbeat_checkrate = self._getint('amqp-broker', 'broker_heartbeat_checkrate', 2) | ||
self.broker_connection_timeout = self._getint('amqp-broker', 'broker_connection_timeout', 4) | ||
self.broker_connection_retry = self._getbool('amqp-broker', 'broker_connection_retry', True) | ||
self.broker_connection_startup_retry = self._getbool('amqp-broker', 'broker_connection_startup_retry', True) | ||
self.broker_connection_max_retries = self._getint('amqp-broker', 'broker_connection_max_retries', 100) | ||
self.task_serializer = self._get('amqp-broker', 'task_serializer', 'json') | ||
|
||
# Redis configuration | ||
redis_password = self._get('redis-client', 'password', None) | ||
self.result_backend = 'redis://:%s@%s:%s/%s' % ( | ||
redis_password if redis_password is not None else '', | ||
self._get('redis-client', 'host', '127.0.0.1'), | ||
self._getint('redis-client', 'port', 6379), | ||
self._getint('redis-client', 'result_dbid', 1)) | ||
|
||
self.redis_socket_timeout = self._getint('redis-client', 'redis_socket_timeout', 120) | ||
self.result_expires = self._getint('redis-client', 'result_expires', 86400) | ||
self.result_serializer = self._get('redis-client', 'result_serializer', 'json') | ||
|
||
|
||
self.http_api_uri = 'http://%s:%s' % ( | ||
self._get('rest-api', 'http_api_host', '127.0.0.1'), | ||
self._get('rest-api', 'http_api_port', '1401')) | ||
|
||
self.show_jasmin_version = self._getbool('rest-api', 'show_jasmin_version', True) | ||
self.auth_cache_seconds = self._getint('rest-api', 'auth_cache_seconds', 10) | ||
self.auth_cache_max_keys = self._getint('rest-api', 'auth_cache_max_keys', 500) | ||
self.http_throughput_per_worker = self._getint('rest-api', 'http_throughput_per_worker', 8) | ||
self.smart_qos = self._getbool('rest-api', 'smart_qos', True) | ||
|
||
self.log_level = logging.getLevelName(self._get('rest-api', 'log_level', 'INFO')) | ||
self.log_file = self._get('rest-api', 'log_file', '%s/rest-api.log' % LOG_PATH) | ||
self.log_rotate = self._get('rest-api', 'log_rotate', 'W6') | ||
self.log_format = self._get('rest-api', 'log_format', '%(asctime)s %(levelname)-8s %(process)d %(message)s') | ||
self.log_date_format = self._get('rest-api', 'log_date_format', '%Y-%m-%d %H:%M:%S') | ||
|
||
self.logger = logging.getLogger('jasmin-restapi') | ||
if len(self.logger.handlers) == 0: | ||
self.logger.setLevel(self.log_level) | ||
handler = logging.handlers.TimedRotatingFileHandler(filename=self.log_file, when=self.log_rotate) | ||
handler.setFormatter(logging.Formatter(self.log_format, self.log_date_format)) | ||
self.logger.addHandler(handler) | ||
|
||
|
Oops, something went wrong.