apache/hadoop · error · BadRequestException
Only 'KILLED' is allowed as a target state.
Error message
Only 'KILLED' is allowed as a target state.
What it means
The only state change the AM REST task-attempt endpoint implements is kill. If the requested state differs from the attempt's current state and is not KILLED, AMWebServices throws BadRequestException - HTTP 400 with "Only 'KILLED' is allowed as a target state.". A PUT whose target equals the current state succeeds as a no-op.
Source
Thrown at hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebServices.java:487
init();
Job job = getJobFromJobIdString(jid, appCtx);
checkAccess(job, hsr);
String remoteUser = hsr.getRemoteUser();
UserGroupInformation callerUGI = null;
if (remoteUser != null) {
callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
}
Task task = getTaskFromTaskIdString(tid, job);
TaskAttempt ta = getTaskAttemptFromTaskAttemptString(attId, task);
if (!ta.getState().toString().equals(targetState.getState())) {
// user is attempting to change state. right we only
// allow users to kill the job task attempt
if (targetState.getState().equals(TaskAttemptState.KILLED.toString())) {
return killJobTaskAttempt(ta, callerUGI, hsr);
}
throw new BadRequestException("Only '"
+ TaskAttemptState.KILLED.toString()
+ "' is allowed as a target state.");
}
JobTaskAttemptState ret = new JobTaskAttemptState();
ret.setState(ta.getState().toString());
return Response.status(Status.OK).entity(ret).build();
}
@GET
@Path("/jobs/{jobid}/tasks/{taskid}/attempts/{attemptid}/counters")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public JobTaskAttemptCounterInfo getJobTaskAttemptIdCounters(
@Context HttpServletRequest hsr, @PathParam("jobid") String jid,
@PathParam("taskid") String tid, @PathParam("attemptid") String attId) {
View on GitHub (pinned to 2add963021)
Solutions
- Send {"state":"KILLED"} - the only supported target
- GET .../attempts/{attemptid} first and skip the PUT when the state already matches
- For broader control use the job-level kill: PUT /ws/v1/mapreduce/jobs/{jobid}/state with {"state":"KILLED"}
Example fix
// before
PUT .../tasks/task_1_0001_m_000005/attempts/attempt_1_0001_m_000005_0/state
{ "state": "SUCCEEDED" }
// 400 { "Only 'KILLED' is allowed as a target state." }
// after
{ "state": "KILLED" } Defensive patterns
Strategy: validation
Validate before calling
if (!"KILLED".equals(requestedState)
&& !requestedState.equals(currentAttemptState)) {
throw new IllegalArgumentException(
"Only KILLED is a supported target state via the AM REST API");
} Type guard
static boolean isSupportedAttemptStateChange(String target, String current) {
return target.equals(current) || "KILLED".equals(target);
} Try / catch
try {
return putAttemptState(jid, tid, attId, target);
} catch (javax.ws.rs.BadRequestException bre) {
// only KILLED is allowed; surface to the caller instead of retrying other states
throw new UnsupportedOperationException("attempt state changes limited to KILLED", bre);
} Prevention
- Hard-code KILLED as the only target in automation scripts
- Read the current state first and skip no-op PUTs
- Do not port MRv1 lifecycle control logic to this endpoint - it supports kill only
When it happens
Trigger: PUT /ws/v1/mapreduce/jobs/{jobid}/tasks/{taskid}/attempts/{attemptid}/state with body {"state":"SUCCEEDED"} (or FAILED, RUNNING, ...) while the attempt is in a different state.
Common situations: Clients try to drive attempt lifecycle (rerun, force-fail, succeed) through the REST API; automation ported from MRv1 control interfaces assumes a full state machine that the API does not expose.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- tasktype must be either m or r
- startedTimeEnd must be greater than 0
- startedTimeEnd must be greater than startTimeBegin
- finishedTimeBegin must be greater than 0
- finishedTimeEnd must be greater than 0
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/2f07d7e19b5a5ad6.
Report an issue: GitHub.