Skip to content

Commit

Permalink
Update ES parameters handling.
Browse files Browse the repository at this point in the history
- Show an error message and exit if no host, port, or index is specified.
- Remove default values of the parameters.
  • Loading branch information
Evildoor committed Apr 18, 2019
1 parent 46cf0af commit 72d85a9
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Utils/Dataflow/071_esConsistency/consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def load_config(fname):
:type fname: str
'''
cfg = {
'ES_HOST': 'localhost',
'ES_PORT': '9200',
'ES_HOST': '',
'ES_PORT': '',
'ES_USER': '',
'ES_PASSWORD': '',
'ES_INDEX': ''
Expand Down Expand Up @@ -85,6 +85,13 @@ def es_connect(cfg):
:param cfg: connection parameters
:type cfg: dict
'''
if not cfg['ES_HOST']:
log('No ES host specified', 'ERROR')
return False
if not cfg['ES_PORT']:
log('No ES port specified', 'ERROR')
return False

global es
if cfg['ES_USER'] and cfg['ES_PASSWORD']:
s = 'http://%s:%s@%s:%s/' % (cfg['ES_USER'],
Expand All @@ -94,6 +101,7 @@ def es_connect(cfg):
else:
s = '%s:%s' % (cfg['ES_HOST'], cfg['ES_PORT'])
es = elasticsearch.Elasticsearch([s])
return True


def get_fields(index, _id, _type, fields):
Expand Down Expand Up @@ -182,10 +190,14 @@ def main(args):
stage.parse_args(args)
cfg = load_config(stage.ARGS.conf)
stage.process = process
es_connect(cfg)
if not es.indices.exists(INDEX):
log('No such index: %s' % INDEX, 'ERROR')
if not es_connect(cfg):
exit_code = 4
elif not INDEX:
log('No ES index specified', 'ERROR')
exit_code = 5
elif not es.indices.exists(INDEX):
log('No such index: %s' % INDEX, 'ERROR')
exit_code = 6
else:
stage.run()
except (DataflowException, RuntimeError), err:
Expand Down

0 comments on commit 72d85a9

Please sign in to comment.