Skip to content

Commit

Permalink
HC-469: Python tool to install the base ES template (#49)
Browse files Browse the repository at this point in the history
* Add script to install base template

* bump version

---------

Co-authored-by: Mike Cayanan <michael.d.cayanan@jpl.nasa.gov>
  • Loading branch information
mcayanan and Mike Cayanan authored May 12, 2023
1 parent f278eb9 commit 9088127
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
33 changes: 33 additions & 0 deletions scripts/install_base_es_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from builtins import open
from future import standard_library
standard_library.install_aliases()
import os
import sys
import json

from hysds.es_util import get_mozart_es
mozart_es = get_mozart_es()


def write_template(tmpl_file):
"""Write template to ES."""

with open(tmpl_file) as f:
tmpl = json.load(f)

# https://elasticsearch-py.readthedocs.io/en/1.3.0/api.html#elasticsearch.Elasticsearch.put_template
mozart_es.es.indices.put_template(name="index_defaults", body=tmpl, ignore=400)
print(f"Successfully installed template to index_defaults:\n{json.dumps(tmpl, indent=2)}")


if __name__ == "__main__":

# get template file
tmpl_file = os.path.abspath(sys.argv[1])

write_template(tmpl_file)
7 changes: 7 additions & 0 deletions scripts/install_base_es_template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
BASE_PATH=$(dirname "${BASH_SOURCE}")
BASE_PATH=$(cd "${BASE_PATH}"; pwd)
export PYTHONPATH=$BASE_PATH/..:$PYTHONPATH

# install ops and dev templates
$BASE_PATH/install_base_es_template.py $*

0 comments on commit 9088127

Please sign in to comment.