Skip to content

Commit

Permalink
HC-496: Updates to optionally support a separate Mozart ES cluster de…
Browse files Browse the repository at this point in the history
…ployment (#103)

* Update to call scripts now to install ILM policy and templates

* update

* typo

* add hysds_dir

* fix path

* not needed

* Get the ES status in a more generic way

* update

* add print statement where Elasticsearch is being pinged

* bump version

---------

Co-authored-by: Mike Cayanan <[email protected]>
  • Loading branch information
mcayanan and Mike Cayanan authored Sep 27, 2023
1 parent 191d10f commit fc18a74
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion sdscli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from __future__ import division
from __future__ import absolute_import

__version__ = "1.2.2"
__version__ = "1.2.3"
__url__ = "https://github.com/sdskit/sdscli"
__description__ = "Command line interface for SDSKit"
19 changes: 11 additions & 8 deletions sdscli/adapters/hysds/fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def install_pkg_es_templates():
if role not in ('grq', 'mozart'):
raise RuntimeError("Invalid fabric function for %s." % role)
with prefix('source %s/bin/activate' % hysds_dir):
run('%s/ops/mozart/scripts/install_es_template.sh %s' % (hysds_dir, role))
run('%s/ops/mozart/scripts/install_es_template.sh' % (hysds_dir))


def install_base_es_template():
Expand All @@ -484,19 +484,24 @@ def install_base_es_template():


def install_es_policy():
role, hysds_dir, hostname = resolve_role()

policy_file_name = "es_ilm_policy_mozart.json"
target_file = f"{ops_dir}/mozart/etc/{policy_file_name}"
send_template(
policy_file_name,
target_file
)
run(f"curl -XPUT 'localhost:9200/_ilm/policy/ilm_policy_mozart?pretty' -H 'Content-Type: application/json' -d@{target_file}")

with prefix('source %s/bin/activate' % hysds_dir):
run(f'{hysds_dir}/ops/{role}/scripts/install_ilm_policy.sh --policy_file {target_file}')


def install_mozart_es_templates():
# install index templates
# Only job_status.template has ILM policy attached
# HC-451 will focus on adding ILM to worker, task, and event status indices
role, hysds_dir, hostname = resolve_role()

# template files located in ~/.sds/files
templates = [
Expand All @@ -505,18 +510,16 @@ def install_mozart_es_templates():
"task_status.template",
"event_status.template"
]

target_dir = f"{ops_dir}/mozart/etc"
for template in templates:
# Copy templates to etc/ directory
target_path = f"{ops_dir}/mozart/etc/{template}"
target_path = f"{target_dir}/{template}"
send_template(
template,
target_path
)
template_doc_name = template.split(".template")[0]
print(f"Creating ES index template for {template}")
run(f"curl -XPUT 'localhost:9200/_index_template/{template_doc_name}?pretty' "
f"-H 'Content-Type: application/json' -d@{target_path}")
with prefix('source %s/bin/activate' % hysds_dir):
run(f"{hysds_dir}/ops/mozart/scripts/install_es_template.sh --install_job_templates --template_dir {target_dir}")


##########################
Expand Down
37 changes: 23 additions & 14 deletions sdscli/adapters/hysds/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,23 @@ def print_redis_status(password, host):

def print_es_status(host):
"""Print status of ES server."""

print(f"[{host}] Pinging ElasticSearch")
service = "elasticsearch"
status = "inactive"
try:
es = elasticsearch.Elasticsearch([host], verify_certs=False)
es.ping()
print(("ES: ", highlight("RUNNING")))
result = es.ping()
if result is True:
status = "active"
except Exception as e:
print(("ES: ", blink(highlight("NOT RUNNING", 'red', True))))
print(e)
# Should we print the exception here?
print(f"Error while getting ElasticSearch status:\n{str(e)}")
pass

if status == 'active':
print(("{}: {}".format(service, highlight(status.upper()))))
else:
print(("{}: {}".format(service, blink(highlight(status.upper(), 'red')))))


def print_http_status(server, url):
Expand Down Expand Up @@ -128,23 +137,23 @@ def print_tps_status(conf, comp, debug=False):
# conf.get('MOZART_REDIS_PVT_IP'))
ret = execute(fab.systemctl, 'status', 'redis', roles=[comp])
print_service_status('redis', ret, debug)
# print_es_status(conf.get('MOZART_ES_PVT_IP'))
ret = execute(fab.systemctl, 'status', 'elasticsearch', roles=[comp])
print_service_status('elasticsearch', ret, debug)
print_es_status(conf.get('MOZART_ES_PVT_IP'))
#ret = execute(fab.systemctl, 'status', 'elasticsearch', roles=[comp])
#print_service_status('elasticsearch', ret, debug)
elif comp == 'metrics':
print_tps_header(comp)
# print_redis_status(conf.get('METRICS_REDIS_PASSWORD'),
# conf.get('METRICS_REDIS_PVT_IP'))
ret = execute(fab.systemctl, 'status', 'redis', roles=[comp])
print_service_status('redis', ret, debug)
# print_es_status(conf.get('METRICS_ES_PVT_IP')) # ES accessible only from localhost
ret = execute(fab.systemctl, 'status', 'elasticsearch', roles=[comp])
print_service_status('elasticsearch', ret, debug)
print_es_status(conf.get('METRICS_ES_PVT_IP')) # ES accessible only from localhost
#ret = execute(fab.systemctl, 'status', 'elasticsearch', roles=[comp])
#print_service_status('elasticsearch', ret, debug)
elif comp == 'grq':
print_tps_header(comp)
# print_es_status(conf.get('GRQ_ES_PVT_IP'))
ret = execute(fab.systemctl, 'status', 'elasticsearch', roles=[comp])
print_service_status('elasticsearch', ret, debug)
print_es_status(conf.get('GRQ_ES_PVT_IP'))
#ret = execute(fab.systemctl, 'status', 'elasticsearch', roles=[comp])
#print_service_status('elasticsearch', ret, debug)
elif comp == 'ci':
print_tps_header(comp)
#print_http_status("Jenkins", "http://{}:8080".format(conf.get('CI_PVT_IP')))
Expand Down

0 comments on commit fc18a74

Please sign in to comment.