Commit cf36d55f authored by Olivier Sallou's avatar Olivier Sallou
Browse files

New upstream version 3.0.17

parent c8964ec3
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
3.0.17:
  Allow use of env variables to override micro.x and rabbitmq variables in global.properties
    like for config.yml.
    Ex: WEB_LOCAL_ENDPOINT_DOWNLOAD defines proxy address for download web service,
        WEB_LOCAL_ENDPOINT defines global proxy address for all web services, etc.
    If not defined, will use values from global.properties
3.0.16:
  After migration checks, update db_schema to current version
3.0.15:
  Add --history option
  Catch SIGTERM to cancel bank update for SIGKILL
3.0.14:
  Fake version for Pypi re-upload
3.0.13:
+24 −1
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ redis_client = redis.StrictRedis(

logging.info("Check database schema and upgrade if necessary")
SchemaVersion.migrate_pendings()
SchemaVersion.set_version()

app = Flask(__name__)

@@ -136,7 +137,9 @@ OPTIONS_PARAMS = {
    'userlogin': None,
    'userpassword': None,
    'proxy': None,
    'schedule': False
    'schedule': False,
    'history': False,
    'historyLimit': 20
}


@@ -543,6 +546,26 @@ def biomaj_daemon_version():
    except Exception as e:
        abort(500, str(e))


@app.route('/api/daemon/history', methods=['GET'])
def biomaj_daemon_history():
    (http_code, options, error) = daemon_api_auth(request)
    if error:
        abort(http_code, error)

    options.history = True
    options.historyLimit = request.args.get('limit', 100)
    try:
        (res, msg) = biomaj_client_action(options, config)
        if res:
            if isinstance(msg, dict):
                return jsonify(msg)
            else:
                return jsonify({'msg': msg})
    except Exception as e:
        abort(500, str(e))


@app.route('/api/daemon/bank', methods=['GET'])
def biomaj_daemon_banks_status():
    (http_code, options, error) = daemon_api_auth(request)
+33 −0
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@ import datetime
import time
import json
import threading
import signal
import sys

import redis
import consul
@@ -82,6 +84,7 @@ class DaemonService(object):

    def __init__(self, config_file):
        self.logger = logging
        self.curBank = None
        self.session = None
        self.executed_callback = None
        with open(config_file, 'r') as ymlfile:
@@ -91,6 +94,24 @@ class DaemonService(object):
        Zipkin.set_config(self.config)

        BiomajConfig.load_config(self.config['biomaj']['config'])
        for svc in Utils.services:
            service = svc.lower()
            if self.config['web'].get('local_endpoint_' + service, None):
                BiomajConfig.global_config.set('GENERAL', 'micro.biomaj.service.' + service , '1')
                BiomajConfig.global_config.set('GENERAL', 'micro.biomaj.proxy.' + service , self.config['web']['local_endpoint_' + service])
        if self.config['web'].get('local_endpoint', None):
            BiomajConfig.global_config.set('GENERAL', 'micro.biomaj.proxy' , self.config['web']['local_endpoint'])
        if self.config.get('rabbitmq', None):
            if self.config['rabbitmq'].get('host', None):
                BiomajConfig.global_config.set('GENERAL', 'micro.biomaj.rabbit_mq' , self.config['rabbitmq']['host'])
            if self.config['rabbitmq'].get('port', None):
                BiomajConfig.global_config.set('GENERAL', 'micro.biomaj.rabbit_mq_port' , str(self.config['rabbitmq']['port']))
            if self.config['rabbitmq'].get('user', None):
                BiomajConfig.global_config.set('GENERAL', 'micro.biomaj.rabbit_mq_user' , self.config['rabbitmq']['user'])
            if self.config['rabbitmq'].get('password', None):
                BiomajConfig.global_config.set('GENERAL', 'micro.biomaj.rabbit_mq_password' , self.config['rabbitmq']['password'])
            if self.config['rabbitmq'].get('virtual_host', None):
                BiomajConfig.global_config.set('GENERAL', 'micro.biomaj.rabbit_mq_virtual_host' , self.config['rabbitmq']['virtual_host'])

        if 'log_config' in self.config:
            for handler in list(self.config['log_config']['handlers'].keys()):
@@ -106,6 +127,16 @@ class DaemonService(object):
        )

        self.logger.info('Daemon service started')
        signal.signal(signal.SIGTERM, self.catch)
        signal.siginterrupt(signal.SIGTERM, False)

    def catch(self, signum, frame):
        self.logger.warn('SIGTERM signal received')
        if self.curBank:
            self.redis_client.set(self.config['redis']['prefix'] + ':' + self.curBank + ':action:cancel', 1)
            self.logger.warn('SIGTERM signal received, cancelling update for ' + self.curBank)
        else:
            sys.exit(1)

    def close(self):
        if self.channel:
@@ -115,6 +146,7 @@ class DaemonService(object):
        self.executed_callback = func

    def __start_action(self, bank, action):
        self.curBank = bank
        whatsup = bank + ':' + str(action)
        self.redis_client.hset(
            self.config['redis']['prefix'] + ':daemons:status',
@@ -133,6 +165,7 @@ class DaemonService(object):
            self.config['consul']['id'],
            'pending'
        )
        self.curBank = None

    def execute(self, options):
        '''
+25 −0
Original line number Diff line number Diff line
@@ -810,11 +810,36 @@ def biomaj_stats(options, config):
        msg += tabulate(results, headers="firstrow", tablefmt="grid")
    return (True, msg)

def biomaj_history(options, config):
    history = Bank.get_history(options.historyLimit)
    results = []
    headers = ["Bank", "Action", "Start", "End", "Updated", "Error"]
    if not options.json:
        results.append(headers)
    msg = 'BioMAJ history\n'
    for h in history:
        results.append([h['bank'],
                        h['action'],
                        datetime.datetime.utcfromtimestamp(h['start']),
                        datetime.datetime.utcfromtimestamp(h['end']),
                        str(h['updated']),
                        str(h['error'])
        ])
    if options.json:
        msg = {'headers': headers, 'history': results}
    else:
        msg += tabulate(results, headers="firstrow", tablefmt="grid")
    return (True, msg)


def biomaj_client_action(options, config=None):
    check_options(options, config)
    if options.version:
        return biomaj_version(options, config)

    if options.history:
        return biomaj_history(options, config)

    if options.stats:
        return biomaj_stats(options, config)

+1 −0
Original line number Diff line number Diff line
@@ -8,3 +8,4 @@ python-consul
prometheus_client>=0.0.18
requests
biomaj-core>=3.0.10
biomaj>=3.1.6
Loading