mirror of
https://github.com/clearml/clearml-server
synced 2025-02-26 05:59:20 +00:00
Refactor es_factory to better support override host/port
This commit is contained in:
parent
174f692edf
commit
dadb996d22
@ -1,5 +1,6 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from os import getenv
|
from os import getenv
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
from boltons.iterutils import first
|
from boltons.iterutils import first
|
||||||
from elasticsearch import Elasticsearch, Transport
|
from elasticsearch import Elasticsearch, Transport
|
||||||
@ -75,6 +76,10 @@ class ESFactory:
|
|||||||
def get_all_cluster_names(cls):
|
def get_all_cluster_names(cls):
|
||||||
return list(config.get("hosts.elastic"))
|
return list(config.get("hosts.elastic"))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_override(cls, cluster_name: str) -> Tuple[str, str]:
|
||||||
|
return OVERRIDE_HOST, OVERRIDE_PORT
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_cluster_config(cls, cluster_name):
|
def get_cluster_config(cls, cluster_name):
|
||||||
"""
|
"""
|
||||||
@ -89,14 +94,16 @@ class ESFactory:
|
|||||||
raise MissingClusterConfiguration(cluster_name)
|
raise MissingClusterConfiguration(cluster_name)
|
||||||
|
|
||||||
def set_host_prop(key, value):
|
def set_host_prop(key, value):
|
||||||
for host in cluster_config.get("hosts", []):
|
for entry in cluster_config.get("hosts", []):
|
||||||
host[key] = value
|
entry[key] = value
|
||||||
|
|
||||||
if OVERRIDE_HOST:
|
host, port = cls.get_override(cluster_name)
|
||||||
set_host_prop("host", OVERRIDE_HOST)
|
|
||||||
|
|
||||||
if OVERRIDE_PORT:
|
if host:
|
||||||
set_host_prop("port", OVERRIDE_PORT)
|
set_host_prop("host", host)
|
||||||
|
|
||||||
|
if port:
|
||||||
|
set_host_prop("port", port)
|
||||||
|
|
||||||
return cluster_config
|
return cluster_config
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user