-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HC-469: Python tool to install the base ES template (#49)
* Add script to install base template * bump version --------- Co-authored-by: Mike Cayanan <michael.d.cayanan@jpl.nasa.gov>
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $* |