Exemplo n.º 1
0
def main():
    # Clean
    logger.info("Clean memcached before init")
    memcached_host, memcached_port = get_memcached_config()
    mem_nfv = MemcachedNFV(memcached_host, memcached_port)
    mem_nfv.clean_memcached()
    mem_nfv.disconnect()
    # Init server list
    init_server_cached_list_api()

    # Scheduler for get statistic
    data_config = read_config_json_file(NFV_CONFIG_PATH)
    interval = int(data_config['interval'])

    executors = {
        'default': {
            'type': 'threadpool',
            'max_workers': 20
        },
        'processpool': ProcessPoolExecutor(max_workers=5)
    }
    job_defaults = {'coalesce': False, 'max_instances': 3}
    scheduler = BlockingScheduler()
    scheduler.configure(executors=executors, job_defaults=job_defaults)
    scheduler.add_job(scheduler_get_statistic_job,
                      'interval',
                      seconds=interval)
    scheduler.start()
Exemplo n.º 2
0
def scheduler_get_statistic_job():
    """
    Scheduler to get statistic job
    """
    # init
    memcached_host, memcached_port = get_memcached_config()
    mem_nfv = MemcachedNFV(memcached_host, memcached_port)
    statistics = collect_statistics(mem_nfv)
    # Close
    mem_nfv.disconnect()
    logger.info('Get statistic: %s' % statistics)
def init_server_cached_list():
    """[init_server_cached_list: call api get servers in bam with CONFIGURATION_NAME]

    Returns:
        [json] -- [
                    Success:    return  {"Status": "SUCCESS"}
                    Fail:       return  {"Status": "FAIL"}]
    """
    try:
        data_config = read_config_json_file(NFV_CONFIG_PATH)
        memcached_host = data_config['memcached_host']
        memcached_port = int(data_config['memcached_port'])
        configuration_name = data_config['bam_config_name']
        g.user.logger.debug(
            'Init_server_cached_list - configuration_name: {}'.format(
                configuration_name))
        configuration_id = gateway_nfv_management.get_configuration_id(
            configuration_name)
        g.user.logger.info(
            'Get list server of configure_id {}'.format(configuration_id))
        list_servers = gateway_nfv_management.get_list_servers(
            configuration_id)
        g.user.logger.info(
            'Init_server_cached_list - Number of get list server: {}'.format(
                len(list_servers)))
        # Init memcached
        mem_nfv = MemcachedNFV(memcached_host, memcached_port)
        # Set bam server info to memcached server
        bam_ip = data_config['bam'][0]['ip']
        bam_name = data_config['bam'][0]['name']
        mem_nfv.set_server({
            'name': bam_name,
            'ipv4_address': bam_ip
        }, ServerType.BAM)
        # Set bdds server info to memcached server
        list_udf_name = [udf['name'] for udf in data_config['udfs_for_server']]
        for server in list_servers:
            mem_nfv.set_server(server, ServerType.BDDS, bam_ip, list_udf_name)
        # Set VM_HOST server info to memcached server
        vm_host_ip = data_config["vm_host_ip"]
        vm_name = data_config['vm_host_name']
        mem_nfv.set_server({
            'name': vm_name,
            'ipv4_address': vm_host_ip
        }, ServerType.VM_HOST)
        mem_nfv.disconnect()
    except Exception as exception:
        g.user.logger.error('Init_server_cached_list - {}'.format(exception))
        g.user.logger.error(traceback.format_exc())
        return jsonify({"Status": "FAIL"})
    return jsonify({"Status": "SUCCESS"})