Add 3 new MCP tools for inspecting YARN applications NOT submitted through this service: get_external_job_logs, get_external_job_status, get_external_job_result. Each takes application_id + connection_name and queries YARN directly, bypassing the local JobStore. - spark_executor/tools/external_jobs.py: 3 tool functions - spark_executor/tools/requests.py: 3 new Pydantic body models (ExternalJobLogsRequest, ExternalJobStatusRequest, ExternalJobResultRequest) - spark_executor/server.py: 3 new POST routes with explicit operation_id - tests/unit/test_external_jobs.py: 7 unit tests - tests/integration/test_mcp_routes.py: assert 20 tool routes - README.md: list the 3 new tools To make the LLM pick the right tool and not guess at field values, also: - Add Pydantic field descriptions for 22 fields across 8 request models (SaveConnectionRequest, UpdatePendingJobRequest, GetJobLogsRequest, JobIdRequest, PendingIdRequest, ConnectionNameRequest, plus the new ExternalJob*Request models). - Update 12 route descriptions with cross-references, prerequisite context, and 400 behavior notes. - Refactor _unknown_job_error: an input that looks like a YARN application_id (starts with 'application_') now returns HTTP 400 (ValueError) with a hint message naming the right external tool; other not-found cases still return 404 (KeyError). This catches the common LLM mistake of passing application_id to the internal get_job_* / kill_job tools. - 4 new unit tests for the 400 behavior. Tests: 356 passed (up from 242). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
# coding=utf-8
|
|
"""
|
|
@Time :2026/6/24
|
|
@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
|
|
from spark_executor.tools.logs import _unknown_job_error
|
|
|
|
store = JobStore()
|
|
|
|
|
|
def get_job_status(job_id: str) -> JobStatus:
|
|
"""Query YARN for a job's current status.
|
|
|
|
`job_id` accepts either the local job_id (returned by
|
|
confirm_submit_job) or the YARN application_id.
|
|
"""
|
|
logger.debug(f"get_job_status enter job_id={job_id}")
|
|
job = store.get_either(job_id)
|
|
if job is None:
|
|
raise _unknown_job_error(
|
|
job_id,
|
|
external_tool_hint="get_external_job_status(application_id, connection_name)",
|
|
)
|
|
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.job_id} application_id={job.application_id} state={state}")
|
|
return JobStatus(application_id=job.application_id, state=state, raw=raw)
|