Skip to content

Commit

Permalink
install ES templates for containers, job_specs, and hysds_ios indices
Browse files Browse the repository at this point in the history
  • Loading branch information
pymonger committed Mar 5, 2018
1 parent f5c865c commit b248074
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
53 changes: 53 additions & 0 deletions config/es_template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"order" : 0,
"template" : "{{ index }}",
"settings" : {
"index.refresh_interval" : "5s",
"analysis": {
"analyzer": {
"default": {
"filter": [
"standard",
"lowercase",
"word_delimiter"
],
"tokenizer": "keyword"
}
}
}
},
"mappings" : {
"_default_" : {
"dynamic_templates" : [ {
"string_fields" : {
"mapping" : {
"index" : "analyzed",
"omit_norms" : true,
"type" : "string",
"fields" : {
"raw" : {
"index" : "not_analyzed",
"ignore_above" : 256,
"type" : "string"
}
}
},
"match_mapping_type" : "string",
"match" : "*"
}
} ],
"_id": {
"type": "string",
"store": true,
"index": "not_analyzed"
},
"_timestamp": {
"enabled": true,
"store": true
},
"_all" : {
"enabled" : true
}
}
}
}
35 changes: 35 additions & 0 deletions scripts/install_es_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python
import os, sys, json, requests
from jinja2 import Template

from hysds.celery import app


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

with open(tmpl_file) as f:
tmpl = Template(f.read()).render(index=index)
tmpl_url = "%s/_template/%s" % (es_url, index)
r = requests.delete(tmpl_url)
r = requests.put(tmpl_url, data=tmpl)
r.raise_for_status()
print r.json()
print "Successfully installed template %s at %s." % (index, tmpl_url)


if __name__ == "__main__":
node = sys.argv[1]
if node == "mozart":
es_url = app.conf['JOBS_ES_URL']
indices = [ "containers", "job_specs", "hysds_ios" ]
elif node == "grq":
es_url = app.conf['GRQ_ES_URL']
indices = [ "hysds_ios" ]
else:
raise RuntimeError("Invalid node: %s" % node)
tmpl_file = os.path.normpath(os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', 'config', 'es_template.json'
)))
for index in indices:
write_template(es_url, index, tmpl_file)
7 changes: 7 additions & 0 deletions scripts/install_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 templates for containers, job_specs, and hysds_ios
$BASE_PATH/install_es_template.py $*

0 comments on commit b248074

Please sign in to comment.