From ddb5bff97865de0d759c1f2af1f25a2b3246553f Mon Sep 17 00:00:00 2001 From: Drew Meyers <100967535+drewm-jpl@users.noreply.github.com> Date: Mon, 11 Sep 2023 08:37:26 -0700 Subject: [PATCH] HC-487: Test out and deploy locally a Elasticsearch service in clustered mode (multi-node) (#63) * HC-487: Add support for ES cluster mode * HC-487: Add support for ES cluster mode * Fix typo Co-authored-by: Michael Cayanan <42812746+mcayanan@users.noreply.github.com> * HC-487: Bump version --------- Co-authored-by: Michael Cayanan <42812746+mcayanan@users.noreply.github.com> --- grq2/__init__.py | 7 +++---- grq2/es_connection.py | 17 ++++++++++++++--- setup.py | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/grq2/__init__.py b/grq2/__init__.py index b1bd254..cf2b67d 100644 --- a/grq2/__init__.py +++ b/grq2/__init__.py @@ -14,8 +14,8 @@ class ReverseProxied(object): """ Wrap the application in this middleware and configure the - front-end server to add these headers, to let you quietly bind - this to a URL other than / and to an HTTP scheme that is + front-end server to add these headers, to let you quietly bind + this to a URL other than / and to an HTTP scheme that is different than what is used locally. In nginx: @@ -93,8 +93,7 @@ def resource_not_found(e): grq_es = get_grq_es() # initializing connection to Mozart's Elasticsearch -MOZART_ES_URL = app.config['MOZART_ES_URL'] -mozart_es = get_mozart_es(MOZART_ES_URL) +mozart_es = get_mozart_es() # services blueprints from grq2.services.main import mod as main_module diff --git a/grq2/es_connection.py b/grq2/es_connection.py index ba06fd1..7c27359 100644 --- a/grq2/es_connection.py +++ b/grq2/es_connection.py @@ -13,10 +13,16 @@ GRQ_ES = None -def get_mozart_es(es_url, logger=None): +def get_mozart_es(logger=None): global MOZART_ES + es_cluster_mode = app.conf['ES_CLUSTER_MODE'] + if MOZART_ES is None: - MOZART_ES = ElasticsearchUtility(es_url, logger) + if es_cluster_mode: + hosts = [app.conf.JOBS_ES_URL, app.conf.GRQ_ES_URL, app.conf.METRICS_ES_URL] + else: + hosts = [app.conf.JOBS_ES_URL] + MOZART_ES = ElasticsearchUtility(hosts, logger) return MOZART_ES @@ -28,6 +34,7 @@ def get_grq_es(logger=None): es_host = app.conf['GRQ_ES_HOST'] es_url = app.conf['GRQ_ES_URL'] region = app.conf['AWS_REGION'] + es_cluster_mode = app.conf['ES_CLUSTER_MODE'] if aws_es is True: aws_auth = BotoAWSRequestsAuth(aws_host=es_host, aws_region=region, aws_service='es') @@ -44,5 +51,9 @@ def get_grq_es(logger=None): retry_on_timeout=True, ) else: - GRQ_ES = ElasticsearchUtility(es_url, logger) + if es_cluster_mode: + hosts = [app.conf.JOBS_ES_URL, app.conf.GRQ_ES_URL, app.conf.METRICS_ES_URL] + else: + hosts = [es_url] + GRQ_ES = ElasticsearchUtility(hosts, logger) return GRQ_ES diff --git a/setup.py b/setup.py index 2a351ad..8c5770e 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='grq2', - version='2.0.24', + version='2.0.25', long_description='GeoRegionQuery REST API using ElasticSearch backend', packages=find_packages(), include_package_data=True,