import json
import logging
from pathlib import Path
from yr.cli.component.base import ComponentLauncher
from yr.cli.const import DEFAULT_LOG_DIR
logger = logging.getLogger(__name__)
class FunctionMasterLauncher(ComponentLauncher):
def health_check(self) -> bool:
logger.info(f"{self.name}: performing custom health check")
args_config = self.resolver.rendered_config[self.component_config.name]["args"]
node_id = self.resolver.rendered_config[self.name]["args"][
"node_id"
]
pid = self.component_config.pid
endpoint = self.resolver.rendered_config[self.component_config.name]["health_check"]["endpoint"]
logger.info(
f"{self.name}: health check endpoint: {endpoint}, node_id: {node_id}, pid: {pid}",
)
base_path = args_config.get("ssl_base_path", "")
ca_path = args_config.get("ssl_root_file", "")
cert_file = args_config.get("ssl_cert_file", "")
key_file = args_config.get("ssl_key_file", "")
if base_path and ca_path and cert_file and key_file:
tls_cacert = Path(base_path) / ca_path
tls_cert = Path(base_path) / cert_file
tls_key = Path(base_path) / key_file
else:
tls_cacert = None
tls_cert = None
tls_key = None
return self._check_http_or_https_health(
node_id=node_id,
pid=str(pid),
tls_cacert=tls_cacert,
tls_cert=tls_cert,
tls_key=tls_key,
)
def prestart_hook(self) -> None:
logger.info(f"{self.name}: prestart hook executing")
log_config = self.resolver.rendered_config[self.component_config.name]["args"]["log_config"]
fs_log_path = json.loads(log_config).get("filepath", f"{DEFAULT_LOG_DIR}/function_system")
Path(fs_log_path).mkdir(parents=True, exist_ok=True)