fix(yarn_client): explicitly request JSON from YARN REST API

YARN ResourceManager REST can return either JSON or XML depending on
the Accept / Content-Type headers. We always parse responses with
resp.json(), so an ambiguous or XML response would break the client.

Add Accept: application/json to every _request call so the response
format is pinned unambiguously. This is compatible with both Hadoop
2.x/CDH 5 and Hadoop 3.x RM endpoints.

Tests: assert that httpx.request receives headers={"Accept": "application/json"}.
This commit is contained in:
Claude
2026-06-26 14:27:50 +08:00
parent 10f075ab7f
commit c44e9bcc55
2 changed files with 11 additions and 1 deletions
+7
View File
@@ -62,6 +62,13 @@ def test_status_parses_app_state():
assert m.call_args.kwargs["verify"] is True
def test_request_sends_accept_json_header():
fake = _resp(200, json_data={"app": {"id": "application_1", "state": "RUNNING"}})
with patch("spark_executor.core.yarn_client.httpx.request", return_value=fake) as m:
get_application_status("application_1", YarnClientConfig(yarn_rm_url=RM))
assert m.call_args.kwargs["headers"] == {"Accept": "application/json"}
def test_status_raises_on_404():
with patch("spark_executor.core.yarn_client.httpx.request", return_value=_resp(404)):
with pytest.raises(YarnError, match="not found"):