feat(submit): confirm defaults instead of removing them

Restore defaults for queue/executor_memory/executor_cores/num_executors
in prepare_submit_job, but require the caller to explicitly confirm
them. If any defaulted field is omitted, the route returns HTTP 400
listing the defaults and asks the caller to resubmit with explicit
values.

app_name remains required (no meaningful default). extra_args remains
optional.

Tests cover rejection of unconfirmed defaults and acceptance of
explicitly confirmed defaults.
This commit is contained in:
Claude
2026-06-26 15:16:43 +08:00
parent 4b07617af0
commit f170c3045b
6 changed files with 103 additions and 9 deletions
+15
View File
@@ -42,6 +42,14 @@ from spark_executor.tools.result import get_job_result
app = FastAPI(title="Spark Executor MCP", version="0.0.1", description="Spark Executor MCP Server")
_DEFAULTS_TO_CONFIRM = {
"queue": "default",
"executor_memory": "4G",
"executor_cores": 2,
"num_executors": 2,
}
# --- Exception handlers: translate tool-layer errors into proper HTTP statuses ---
#
# Tool functions raise KeyError for "unknown id" (job_id, pending_id, connection
@@ -88,6 +96,13 @@ def health_check():
),
)
def _prepare_submit_job(req: PrepareSubmitJobRequest):
omitted = [f for f in _DEFAULTS_TO_CONFIRM if f not in req.model_fields_set]
if omitted:
details = ", ".join(f"{f}={_DEFAULTS_TO_CONFIRM[f]!r}" for f in omitted)
raise ValueError(
f"Please confirm default values: {details}. "
f"Resubmit with these fields explicitly set."
)
return prepare_submit_job(**req.model_dump())
+4 -4
View File
@@ -50,19 +50,19 @@ class PrepareSubmitJobRequest(BaseModel):
),
)
queue: str = Field(
...,
default="default",
description="YARN queue to submit to. Must be explicitly confirmed by the caller.",
)
executor_memory: str = Field(
...,
default="4G",
description="Executor memory, e.g. '4G'. Must be explicitly confirmed by the caller.",
)
executor_cores: int = Field(
...,
default=2,
description="Number of cores per executor. Must be explicitly confirmed by the caller.",
)
num_executors: int = Field(
...,
default=2,
description="Total number of executors. Must be explicitly confirmed by the caller.",
)
extra_args: dict[str, str] | None = Field(
+4 -4
View File
@@ -64,10 +64,10 @@ def prepare_submit_job(
*,
connection: str,
script_path: str,
queue: str,
executor_memory: str,
executor_cores: int,
num_executors: int,
queue: str = "default",
executor_memory: str = "4G",
executor_cores: int = 2,
num_executors: int = 2,
app_name: str,
extra_args: dict[str, str] | None = None,
) -> dict[str, object]: