feat(yarn_client): SSL/TLS config for YARN REST connections

Add per-Connection ssl_verify / ssl_ca_bundle plus global defaults so
CDH 5 / on-prem clusters with self-signed certs or custom CA bundles can
be queried without patching code.

- Connection gets ssl_verify (bool|None) and ssl_ca_bundle (str|None)
- Settings gets ssl_verify_default and ssl_ca_bundle_default
- New YarnClientConfig dataclass carries the resolved verify= value
- _request passes verify= through to httpx.request
- All public yarn_client functions now take YarnClientConfig instead of
  a bare yarn_rm_url string; tool call sites resolve the Connection
- SaveConnectionRequest exposes the two new fields

Tests cover per-connection CA bundle, per-connection verify=False,
global default fallback, and connection-not-found error.
This commit is contained in:
Claude
2026-06-26 13:50:30 +08:00
parent 5566d55a7c
commit ad557b5984
16 changed files with 362 additions and 87 deletions
+4
View File
@@ -15,6 +15,8 @@ def save_connection(
deploy_mode: str = "cluster",
yarn_rm_url: str | None = None,
spark_conf: dict[str, str] | None = None,
ssl_verify: bool | None = None,
ssl_ca_bundle: str | None = None,
) -> dict[str, str]:
logger.debug(
f"save_connection enter name={name} master={master} deploy_mode={deploy_mode} "
@@ -26,6 +28,8 @@ def save_connection(
deploy_mode=deploy_mode,
yarn_rm_url=yarn_rm_url,
spark_conf=spark_conf or {},
ssl_verify=ssl_verify,
ssl_ca_bundle=ssl_ca_bundle,
)
store.save(conn)
return {"name": name, "status": "SAVED"}
+7 -2
View File
@@ -5,7 +5,8 @@
"""
from common.logging import logger
from spark_executor.core.job_store import JobStore
from spark_executor.core.yarn_client import kill_application
from spark_executor.core.yarn_client import YarnClientConfig, kill_application
from spark_executor.tools.connections import store as conn_store
store = JobStore()
@@ -15,7 +16,11 @@ def kill_job(job_id: str) -> dict[str, str]:
job = store.get(job_id)
if job is None:
raise KeyError(f"Unknown job_id: {job_id}")
kill_application(job.application_id, job.yarn_rm_url)
conn = conn_store.get(job.connection)
if conn is None:
raise KeyError(f"Connection not found: {job.connection}")
config = YarnClientConfig.from_connection(conn)
kill_application(job.application_id, config)
logger.info(f"kill_job ok job_id={job_id} application_id={job.application_id}")
return {
"job_id": job_id,
+7 -2
View File
@@ -5,7 +5,8 @@
"""
from common.logging import logger
from spark_executor.core.job_store import JobStore
from spark_executor.core.yarn_client import get_application_logs
from spark_executor.core.yarn_client import YarnClientConfig, get_application_logs
from spark_executor.tools.connections import store as conn_store
store = JobStore()
@@ -15,7 +16,11 @@ def get_job_logs(job_id: str, tail_chars: int = 5000) -> str:
job = store.get(job_id)
if job is None:
raise KeyError(f"Unknown job_id: {job_id}")
full = get_application_logs(job.application_id, job.yarn_rm_url)
conn = conn_store.get(job.connection)
if conn is None:
raise KeyError(f"Connection not found: {job.connection}")
config = YarnClientConfig.from_connection(conn)
full = get_application_logs(job.application_id, config)
tailed = full[-tail_chars:] if len(full) > tail_chars else full
logger.info(
f"get_job_logs ok job_id={job_id} application_id={job.application_id} "
+2
View File
@@ -22,6 +22,8 @@ class SaveConnectionRequest(BaseModel):
deploy_mode: str = "cluster"
yarn_rm_url: str | None = None
spark_conf: dict[str, str] | None = None
ssl_verify: bool | None = None
ssl_ca_bundle: str | None = None
class PrepareSubmitJobRequest(BaseModel):
+7 -2
View File
@@ -7,7 +7,8 @@ import json
from common.logging import logger
from spark_executor.core.job_store import JobStore
from spark_executor.core.yarn_client import get_application_status
from spark_executor.core.yarn_client import YarnClientConfig, get_application_status
from spark_executor.tools.connections import store as conn_store
from spark_executor.models import JobResult
store = JobStore()
@@ -18,7 +19,11 @@ def get_job_result(job_id: str) -> JobResult:
job = store.get(job_id)
if job is None:
raise KeyError(f"Unknown job_id: {job_id}")
state, raw = get_application_status(job.application_id, job.yarn_rm_url)
conn = conn_store.get(job.connection)
if conn is None:
raise KeyError(f"Connection not found: {job.connection}")
config = YarnClientConfig.from_connection(conn)
state, raw = get_application_status(job.application_id, config)
app = json.loads(raw).get("app", {})
result = JobResult(
application_id=job.application_id,
+7 -1
View File
@@ -4,9 +4,11 @@
@Author :tao.chen
"""
from common.logging import logger
from spark_executor.core.yarn_client import YarnClientConfig
from spark_executor.core.job_store import JobStore
from spark_executor.core.yarn_client import get_application_status
from spark_executor.models import JobStatus
from spark_executor.tools.connections import store as conn_store
store = JobStore()
@@ -16,6 +18,10 @@ def get_job_status(job_id: str) -> JobStatus:
job = store.get(job_id)
if job is None:
raise KeyError(f"Unknown job_id: {job_id}")
state, raw = get_application_status(job.application_id, job.yarn_rm_url)
conn = conn_store.get(job.connection)
if conn is None:
raise KeyError(f"Connection not found: {job.connection}")
config = YarnClientConfig.from_connection(conn)
state, raw = get_application_status(job.application_id, config)
logger.info(f"get_job_status ok job_id={job_id} application_id={job.application_id} state={state}")
return JobStatus(application_id=job.application_id, state=state, raw=raw)