2015-02-28 04:39:44 +00:00
<!-- -
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. See accompanying LICENSE file.
-->
Hadoop YARN - Introduction to the web services REST API's
==========================================================
* [Overview ](#Overview )
* [URI's ](#URIs )
* [HTTP Requests ](#HTTP_Requests )
* [Summary of HTTP operations ](#Summary_of_HTTP_operations )
* [Security ](#Security )
* [Headers Supported ](#Headers_Supported )
* [HTTP Responses ](#HTTP_Responses )
* [Compression ](#Compression )
* [Response Formats ](#Response_Formats )
* [Response Errors ](#Response_Errors )
* [Response Examples ](#Response_Examples )
* [Sample Usage ](#Sample_Usage )
Overview
--------
The Hadoop YARN web service REST APIs are a set of URI resources that give access to the cluster, nodes, applications, and application historical information. The URI resources are grouped into APIs based on the type of information returned. Some URI resources return collections while others return singletons.
URI's
-----
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The URIs for the REST-based Web services have the following syntax:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
http://{http address of service}/ws/{version}/{resourcepath}
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The elements in this syntax are as follows:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
{http address of service} - The http address of the service to get information about.
Currently supported are the ResourceManager, NodeManager,
MapReduce application master, and history server.
{version} - The version of the APIs. In this release, the version is v1.
{resourcepath} - A path that defines a singleton resource or a collection of resources.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
HTTP Requests
-------------
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
To invoke a REST API, your application calls an HTTP operation on the URI associated with a resource.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
### Summary of HTTP operations
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Currently only GET is supported. It retrieves information about the resource specified.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
### Security
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The web service REST API's go through the same security as the web UI. If your cluster adminstrators have filters enabled you must authenticate via the mechanism they specified.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
### Headers Supported
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
* Accept
* Accept-Encoding
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Currently the only fields used in the header is `Accept` and `Accept-Encoding` . `Accept` currently supports XML and JSON for the response type you accept. `Accept-Encoding` currently supports only gzip format and will return gzip compressed output if this is specified, otherwise output is uncompressed. All other header fields are ignored.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
HTTP Responses
--------------
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The next few sections describe some of the syntax and other details of the HTTP Responses of the web service REST APIs.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
### Compression
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
This release supports gzip compression if you specify gzip in the Accept-Encoding header of the HTTP request (Accept-Encoding: gzip).
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
### Response Formats
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
This release of the web service REST APIs supports responses in JSON and XML formats. JSON is the default. To set the response format, you can specify the format in the Accept header of the HTTP request.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
As specified in HTTP Response Codes, the response body can contain the data that represents the resource or an error message. In the case of success, the response body is in the selected format, either JSON or XML. In the case of error, the resonse body is in either JSON or XML based on the format requested. The Content-Type header of the response contains the format requested. If the application requests an unsupported format, the response status code is 500. Note that the order of the fields within response body is not specified and might change. Also, additional fields might be added to a response body. Therefore, your applications should use parsing routines that can extract data from a response body in any order.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
### Response Errors
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
After calling an HTTP request, an application should check the response status code to verify success or detect an error. If the response status code indicates an error, the response body contains an error message. The first field is the exception type, currently only RemoteException is returned. The following table lists the items within the RemoteException error message:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
| Item | Data Type | Description |
|:---- |:---- |:---- |
| exception | String | Exception type |
| javaClassName | String | Java class name of exception |
| message | String | Detailed message of exception |
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
### Response Examples
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
#### JSON response with single resource
2012-01-21 00:53:02 +00:00
2015-04-14 19:13:55 +00:00
HTTP Request: GET http://rmhost.domain:8088/ws/v1/cluster/apps/application\_1324057493980\_0001
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Response Status Line: HTTP/1.1 200 OK
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Response Header:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
Server: Jetty(6.1.26)
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Response Body:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
```json
2012-01-21 00:53:02 +00:00
{
app":
{
"id":"application_1324057493980_0001",
"user":"user1",
"name":"",
"queue":"default",
"state":"ACCEPTED",
"finalStatus":"UNDEFINED",
"progress":0,
"trackingUI":"UNASSIGNED",
"diagnostics":"",
"clusterId":1324057493980,
"startedTime":1324057495921,
"finishedTime":0,
"elapsedTime":2063,
"amContainerLogs":"http:\/\/amNM:2\/node\/containerlogs\/container_1324057493980_0001_01_000001",
"amHostHttpAddress":"amNM:2"
}
}
2015-02-28 04:39:44 +00:00
```
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
#### JSON response with Error response
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Here we request information about an application that doesn't exist yet.
2012-01-21 00:53:02 +00:00
2015-04-14 19:13:55 +00:00
HTTP Request: GET http://rmhost.domain:8088/ws/v1/cluster/apps/application\_1324057493980\_9999
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Response Status Line: HTTP/1.1 404 Not Found
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Response Header:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
HTTP/1.1 404 Not Found
Content-Type: application/json
Transfer-Encoding: chunked
Server: Jetty(6.1.26)
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Response Body:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
```json
2012-01-21 00:53:02 +00:00
{
"RemoteException" : {
"javaClassName" : "org.apache.hadoop.yarn.webapp.NotFoundException",
"exception" : "NotFoundException",
"message" : "java.lang.Exception: app with id: application_1324057493980_9999 not found"
}
}
2015-02-28 04:39:44 +00:00
```
Sample Usage
-------------
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
You can use any number of ways/languages to use the web services REST API's. This example uses the curl command line interface to do the REST GET calls.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
In this example, a user submits a MapReduce application to the ResourceManager using a command like:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
hadoop jar hadoop-mapreduce-test.jar sleep -Dmapred.job.queue.name=a1 -m 1 -r 1 -rt 1200000 -mt 20
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The client prints information about the job submitted along with the application id, similar to:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
12/01/18 04:25:15 INFO mapred.ResourceMgrDelegate: Submitted application application_1326821518301_0010 to ResourceManager at host.domain.com/10.10.10.10:8032
12/01/18 04:25:15 INFO mapreduce.Job: Running job: job_1326821518301_0010
12/01/18 04:25:21 INFO mapred.ClientServiceDelegate: The url to track the job: host.domain.com:8088/proxy/application_1326821518301_0010/
12/01/18 04:25:22 INFO mapreduce.Job: Job job_1326821518301_0010 running in uber mode : false
12/01/18 04:25:22 INFO mapreduce.Job: map 0% reduce 0%
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The user then wishes to track the application. The users starts by getting the information about the application from the ResourceManager. Use the --comopressed option to request output compressed. curl handles uncompressing on client side.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
curl --compressed -H "Accept: application/json" -X GET "http://host.domain.com:8088/ws/v1/cluster/apps/application_1326821518301_0010"
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Output:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
```json
2012-01-21 00:53:02 +00:00
{
"app" : {
"finishedTime" : 0,
2012-02-29 15:49:27 +00:00
"amContainerLogs" : "http://host.domain.com:8042/node/containerlogs/container_1326821518301_0010_01_000001",
2012-01-21 00:53:02 +00:00
"trackingUI" : "ApplicationMaster",
"state" : "RUNNING",
"user" : "user1",
"id" : "application_1326821518301_0010",
"clusterId" : 1326821518301,
"finalStatus" : "UNDEFINED",
2012-02-29 15:49:27 +00:00
"amHostHttpAddress" : "host.domain.com:8042",
2012-01-21 00:53:02 +00:00
"progress" : 82.44703,
"name" : "Sleep job",
"startedTime" : 1326860715335,
"elapsedTime" : 31814,
"diagnostics" : "",
"trackingUrl" : "http://host.domain.com:8088/proxy/application_1326821518301_0010/",
"queue" : "a1"
}
}
2015-02-28 04:39:44 +00:00
```
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The user then wishes to get more details about the running application and goes directly to the MapReduce application master for this application. The ResourceManager lists the trackingUrl that can be used for this application: http://host.domain.com:8088/proxy/application\_1326821518301\_0010. This could either go to the web browser or use the web service REST API's. The user uses the web services REST API's to get the list of jobs this MapReduce application master is running:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
curl --compressed -H "Accept: application/json" -X GET "http://host.domain.com:8088/proxy/application_1326821518301_0010/ws/v1/mapreduce/jobs"
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Output:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
```json
2012-01-21 00:53:02 +00:00
{
"jobs" : {
"job" : [
{
"runningReduceAttempts" : 1,
"reduceProgress" : 72.104515,
"failedReduceAttempts" : 0,
"newMapAttempts" : 0,
"mapsRunning" : 0,
"state" : "RUNNING",
"successfulReduceAttempts" : 0,
"reducesRunning" : 1,
"acls" : [
{
"value" : " ",
"name" : "mapreduce.job.acl-modify-job"
},
{
"value" : " ",
"name" : "mapreduce.job.acl-view-job"
}
],
"reducesPending" : 0,
"user" : "user1",
"reducesTotal" : 1,
"mapsCompleted" : 1,
"startTime" : 1326860720902,
"id" : "job_1326821518301_10_10",
"successfulMapAttempts" : 1,
"runningMapAttempts" : 0,
"newReduceAttempts" : 0,
"name" : "Sleep job",
"mapsPending" : 0,
"elapsedTime" : 64432,
"reducesCompleted" : 0,
"mapProgress" : 100,
"diagnostics" : "",
"failedMapAttempts" : 0,
"killedReduceAttempts" : 0,
"mapsTotal" : 1,
"uberized" : false,
"killedMapAttempts" : 0,
"finishTime" : 0
}
]
}
}
2015-02-28 04:39:44 +00:00
```
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The user then wishes to get the task details about the job with job id job\_1326821518301\_10\_10 that was listed above.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
curl --compressed -H "Accept: application/json" -X GET "http://host.domain.com:8088/proxy/application_1326821518301_0010/ws/v1/mapreduce/jobs/job_1326821518301_10_10/tasks"
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Output:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
```json
2012-01-21 00:53:02 +00:00
{
"tasks" : {
"task" : [
{
"progress" : 100,
"elapsedTime" : 5059,
"state" : "SUCCEEDED",
"startTime" : 1326860725014,
"id" : "task_1326821518301_10_10_m_0",
"type" : "MAP",
"successfulAttempt" : "attempt_1326821518301_10_10_m_0_0",
"finishTime" : 1326860730073
},
{
"progress" : 72.104515,
"elapsedTime" : 0,
"state" : "RUNNING",
"startTime" : 1326860732984,
"id" : "task_1326821518301_10_10_r_0",
"type" : "REDUCE",
"successfulAttempt" : "",
"finishTime" : 0
}
]
}
}
2015-02-28 04:39:44 +00:00
```
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The map task has finished but the reduce task is still running. The users wishes to get the task attempt information for the reduce task task\_1326821518301\_10\_10\_r\_0, note that the Accept header isn't really required here since JSON is the default output format:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
curl --compressed -X GET "http://host.domain.com:8088/proxy/application_1326821518301_0010/ws/v1/mapreduce/jobs/job_1326821518301_10_10/tasks/task_1326821518301_10_10_r_0/attempts"
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Output:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
```json
2012-01-21 00:53:02 +00:00
{
"taskAttempts" : {
"taskAttempt" : [
{
"elapsedMergeTime" : 158,
"shuffleFinishTime" : 1326860735378,
"assignedContainerId" : "container_1326821518301_0010_01_000003",
"progress" : 72.104515,
"elapsedTime" : 0,
"state" : "RUNNING",
"elapsedShuffleTime" : 2394,
"mergeFinishTime" : 1326860735536,
"rack" : "/10.10.10.0",
"elapsedReduceTime" : 0,
2012-02-29 15:49:27 +00:00
"nodeHttpAddress" : "host.domain.com:8042",
2012-01-21 00:53:02 +00:00
"type" : "REDUCE",
"startTime" : 1326860732984,
"id" : "attempt_1326821518301_10_10_r_0_0",
"finishTime" : 0
}
]
}
}
2015-02-28 04:39:44 +00:00
```
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The reduce attempt is still running and the user wishes to see the current counter values for that attempt:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
curl --compressed -H "Accept: application/json" -X GET "http://host.domain.com:8088/proxy/application_1326821518301_0010/ws/v1/mapreduce/jobs/job_1326821518301_10_10/tasks/task_1326821518301_10_10_r_0/attempts/attempt_1326821518301_10_10_r_0_0/counters"
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Output:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
```json
2012-01-21 00:53:02 +00:00
{
"JobTaskAttemptCounters" : {
"taskAttemptCounterGroup" : [
{
"counterGroupName" : "org.apache.hadoop.mapreduce.FileSystemCounter",
"counter" : [
{
"value" : 4216,
"name" : "FILE_BYTES_READ"
},
{
"value" : 77151,
"name" : "FILE_BYTES_WRITTEN"
},
{
"value" : 0,
"name" : "FILE_READ_OPS"
},
{
"value" : 0,
"name" : "FILE_LARGE_READ_OPS"
},
{
"value" : 0,
"name" : "FILE_WRITE_OPS"
},
{
"value" : 0,
"name" : "HDFS_BYTES_READ"
},
{
"value" : 0,
"name" : "HDFS_BYTES_WRITTEN"
},
{
"value" : 0,
"name" : "HDFS_READ_OPS"
},
{
"value" : 0,
"name" : "HDFS_LARGE_READ_OPS"
},
{
"value" : 0,
"name" : "HDFS_WRITE_OPS"
}
]
},
{
"counterGroupName" : "org.apache.hadoop.mapreduce.TaskCounter",
"counter" : [
{
"value" : 0,
"name" : "COMBINE_INPUT_RECORDS"
},
{
"value" : 0,
"name" : "COMBINE_OUTPUT_RECORDS"
},
{
"value" : 1767,
"name" : "REDUCE_INPUT_GROUPS"
},
{
"value" : 25104,
"name" : "REDUCE_SHUFFLE_BYTES"
},
{
"value" : 1767,
"name" : "REDUCE_INPUT_RECORDS"
},
{
"value" : 0,
"name" : "REDUCE_OUTPUT_RECORDS"
},
{
"value" : 0,
"name" : "SPILLED_RECORDS"
},
{
"value" : 1,
"name" : "SHUFFLED_MAPS"
},
{
"value" : 0,
"name" : "FAILED_SHUFFLE"
},
{
"value" : 1,
"name" : "MERGED_MAP_OUTPUTS"
},
{
"value" : 50,
"name" : "GC_TIME_MILLIS"
},
{
"value" : 1580,
"name" : "CPU_MILLISECONDS"
},
{
"value" : 141320192,
"name" : "PHYSICAL_MEMORY_BYTES"
},
{
"value" : 1118552064,
"name" : "VIRTUAL_MEMORY_BYTES"
},
{
"value" : 73728000,
"name" : "COMMITTED_HEAP_BYTES"
}
]
},
{
"counterGroupName" : "Shuffle Errors",
"counter" : [
{
"value" : 0,
"name" : "BAD_ID"
},
{
"value" : 0,
"name" : "CONNECTION"
},
{
"value" : 0,
"name" : "IO_ERROR"
},
{
"value" : 0,
"name" : "WRONG_LENGTH"
},
{
"value" : 0,
"name" : "WRONG_MAP"
},
{
"value" : 0,
"name" : "WRONG_REDUCE"
}
]
},
{
"counterGroupName" : "org.apache.hadoop.mapreduce.lib.output.FileOutputFormatCounter",
"counter" : [
{
"value" : 0,
"name" : "BYTES_WRITTEN"
}
]
}
],
"id" : "attempt_1326821518301_10_10_r_0_0"
}
}
2015-02-28 04:39:44 +00:00
```
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The job finishes and the user wishes to get the final job information from the history server for this job.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
curl --compressed -X GET "http://host.domain.com:19888/ws/v1/history/mapreduce/jobs/job_1326821518301_10_10"
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Output:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
```json
2012-01-21 00:53:02 +00:00
{
"job" : {
"avgReduceTime" : 1250784,
"failedReduceAttempts" : 0,
"state" : "SUCCEEDED",
"successfulReduceAttempts" : 1,
"acls" : [
{
"value" : " ",
"name" : "mapreduce.job.acl-modify-job"
},
{
"value" : " ",
"name" : "mapreduce.job.acl-view-job"
}
],
"user" : "user1",
"reducesTotal" : 1,
"mapsCompleted" : 1,
"startTime" : 1326860720902,
"id" : "job_1326821518301_10_10",
"avgMapTime" : 5059,
"successfulMapAttempts" : 1,
"name" : "Sleep job",
"avgShuffleTime" : 2394,
"reducesCompleted" : 1,
"diagnostics" : "",
"failedMapAttempts" : 0,
"avgMergeTime" : 2552,
"killedReduceAttempts" : 0,
"mapsTotal" : 1,
"queue" : "a1",
"uberized" : false,
"killedMapAttempts" : 0,
"finishTime" : 1326861986164
}
}
2015-02-28 04:39:44 +00:00
```
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
The user also gets the final applications information from the ResourceManager.
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
curl --compressed -H "Accept: application/json" -X GET "http://host.domain.com:8088/ws/v1/cluster/apps/application_1326821518301_0010"
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
Output:
2012-01-21 00:53:02 +00:00
2015-02-28 04:39:44 +00:00
```json
2012-01-21 00:53:02 +00:00
{
"app" : {
"finishedTime" : 1326861991282,
2012-02-29 15:49:27 +00:00
"amContainerLogs" : "http://host.domain.com:8042/node/containerlogs/container_1326821518301_0010_01_000001",
2012-01-21 00:53:02 +00:00
"trackingUI" : "History",
"state" : "FINISHED",
"user" : "user1",
"id" : "application_1326821518301_0010",
"clusterId" : 1326821518301,
"finalStatus" : "SUCCEEDED",
2012-02-29 15:49:27 +00:00
"amHostHttpAddress" : "host.domain.com:8042",
2012-01-21 00:53:02 +00:00
"progress" : 100,
"name" : "Sleep job",
"startedTime" : 1326860715335,
"elapsedTime" : 1275947,
"diagnostics" : "",
"trackingUrl" : "http://host.domain.com:8088/proxy/application_1326821518301_0010/jobhistory/job/job_1326821518301_10_10",
"queue" : "a1"
}
}
2015-04-14 19:13:55 +00:00
```