Beispiel #1
0
def wait_cluster_available():
    auth_header = get_admin_auth_header()
    wait_elasticsearch(interval=5000, headers=auth_header)
    es_client = start()
    es_client.cluster.health(
        headers=auth_header,
        wait_for_status='yellow',
        request_timeout=240)
Beispiel #2
0
def start_up():
    try:
        auth_header = get_admin_auth_header()
        su_client = start()
        if not su_client.indices.exists(index_name, headers=auth_header):
            logging.info(f"Index {index_name} not found. Creating one.")
            create_index(su_client, index_name, headers=auth_header)
    finally:
        su_client.close()
Beispiel #3
0
def start_up(search_config_id: str,
             search_config_url: str = None,
             search_config_title: str = None,
             detail_config_id: str = None,
             metadata_config_url: str = None,
             detail_config_url: str = None,
             detail_config_title: str = None):
    conf = get_config()
    search_config_index_name = conf.get_string("search-config.index-name")
    search_config = conf.get_config("presets.file-search.search-config")

    detail_config_index_name = conf.get_string("detail-config.index-name")
    detail_config = conf.get_config("presets.file-search.detail-config")

    if detail_config_id is None:
        detail_config_id = search_config_id

    try:
        es_client = start()
        auth_header = get_admin_auth_header()
        if not es_client.exists(search_config_index_name,
                                search_config_id,
                                headers=auth_header):
            create_search_config(es_client,
                                 search_config_index_name,
                                 search_config_id,
                                 search_config,
                                 search_config_url,
                                 search_config_title,
                                 headers=auth_header)

        if not es_client.exists(detail_config_index_name,
                                detail_config_id,
                                headers=auth_header):
            create_detail_config(es_client,
                                 detail_config_index_name,
                                 detail_config_id,
                                 detail_config,
                                 metadata_config_url,
                                 detail_config_url,
                                 detail_config_title,
                                 headers=auth_header)
    finally:
        es_client.close()
Beispiel #4
0
def wait_elasticsearch(interval=2000,
                       max_retries=30,
                       params=None,
                       headers=None):
    attempts = 0
    while attempts < max_retries:
        try:
            es_client = start()
            resp = es_client.info(params=params, headers=headers)
            logging.info("Connected to elasticsearch.")
            return resp
        except:
            logging.warn(
                f"Could not connect to Elasticsearch. Retry will occur in {interval}ms.")
            attempts += 1
            time.sleep(interval/1000)
        finally:
            es_client.close()
    raise Exception("Could not connect to Elasticsearch.")
Beispiel #5
0
def start_up():
    try:
        es_client = start()
        auth_header = get_admin_auth_header()
        if not es_client.indices.exists(index_name, headers=auth_header):
            create_sample_index(es_client, index_name, headers=auth_header)
            load_sample_data(es_client,
                             index_name,
                             num_docs=30,
                             headers=auth_header)
            load_sample_config(
                es_client,
                index_name=conf.get_string("search-config.index-name"),
                headers=auth_header)
            load_detail_config(
                es_client,
                index_name=conf.get_string("detail-config.index-name"),
                headers=auth_header)
    finally:
        es_client.close()
Beispiel #6
0
from start_client import start
import logging

client = start()


def get_client():
    return client