2019-07-08 21:01:16 +00:00
|
|
|
from functools import lru_cache
|
2019-12-14 21:33:04 +00:00
|
|
|
from os import getenv
|
2019-12-21 16:13:05 +00:00
|
|
|
from pathlib import Path
|
2019-07-08 21:01:16 +00:00
|
|
|
|
2021-05-03 14:26:44 +00:00
|
|
|
from boltons.iterutils import first
|
|
|
|
|
2021-01-05 14:44:31 +00:00
|
|
|
from apiserver.config_repo import config
|
2021-01-05 14:28:49 +00:00
|
|
|
from apiserver.version import __version__
|
2020-01-02 13:20:55 +00:00
|
|
|
|
2019-07-08 21:01:16 +00:00
|
|
|
root = Path(__file__).parent.parent
|
|
|
|
|
|
|
|
|
2019-12-21 16:13:05 +00:00
|
|
|
def _get(prop_name, env_suffix=None, default=""):
|
2021-05-03 14:26:44 +00:00
|
|
|
suffix = env_suffix or prop_name
|
|
|
|
keys = [f"{p}_SERVER_{suffix}" for p in ("CLEARML", "TRAINS")]
|
|
|
|
value = first(map(getenv, keys))
|
2019-12-21 16:13:05 +00:00
|
|
|
if value:
|
|
|
|
return value
|
|
|
|
|
2019-07-08 21:01:16 +00:00
|
|
|
try:
|
2019-12-21 16:13:05 +00:00
|
|
|
return (root / prop_name).read_text().strip()
|
2019-07-08 21:01:16 +00:00
|
|
|
except FileNotFoundError:
|
2019-12-21 16:13:05 +00:00
|
|
|
return default
|
|
|
|
|
|
|
|
|
|
|
|
@lru_cache()
|
|
|
|
def get_build_number():
|
|
|
|
return _get("BUILD")
|
2019-07-08 21:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
@lru_cache()
|
|
|
|
def get_version():
|
2019-12-21 16:13:05 +00:00
|
|
|
return _get("VERSION", default=__version__)
|
2019-09-24 18:34:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
@lru_cache()
|
|
|
|
def get_commit_number():
|
2019-12-21 16:13:05 +00:00
|
|
|
return _get("COMMIT")
|
2019-12-14 21:33:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
@lru_cache()
|
|
|
|
def get_deployment_type() -> str:
|
2019-12-21 16:13:05 +00:00
|
|
|
return _get("DEPLOY", env_suffix="DEPLOYMENT_TYPE", default="manual")
|
2020-01-02 13:20:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_default_company():
|
|
|
|
return config.get("apiserver.default_company")
|
2020-08-10 05:30:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
missed_es_upgrade = False
|
2020-08-10 05:53:41 +00:00
|
|
|
es_connection_error = False
|