When a yarn application is about to run, it needs to send a request for the container allocation. How does it know that it needs certain amount of resource to run in certain amount of time. How do I get that by REST api?
The amount of resource a Yarn application will request is completely dependent on the type of Application. For MapReduce, it is generally based on the inputsplit/no. of reducers configured and the memory/vcores configured per mapper/reducer in the JobConf.
To check how much Resources are currently being used by a single application, you can use the following Rest API and check the fields "allocatedMB","allocatedVCores" and "runningContainers"
GET http://<rm http address:port>/ws/v1/cluster/apps/<applicationId>