Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How can I sort rest api response, I'm looking rest call for resource manager using curl

avatar
New Contributor

Do we have sort option for resource manager when we access through curl rest api?

I'm using as below, but it is not resulting in sorted order.

curl -get "http://resource-manager-hostname:8088/ws/v1/cluster/apps?sort=queueUsagePercentage&order_by=asc&state=running&limit=20"

Can someone help here on this.

Thanks,

Purna Chandra Mahesh.

1 ACCEPTED SOLUTION

avatar
Expert Contributor
@Purna Chandra Mahesh Bhogavalli

There is no sort or order_by query parameter supported in the ResourceManager rest api. For your curl request, you can check the documentation at http://hadoop.apache.org/docs/stable/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html#Cluster_A...

The only option now is to sort at the client side. For command line, one easy way is to install a tool called jq https://stedolan.github.io/jq/download/ if you are interested. For your use case, you can do something like follows:

curl -get "http://resource-manager-hostname:8088/ws/v1/cluster/apps?state=running&limit=20" | jq '.apps.app|sort_by(.queueUsagePercentage)'

For descending sort you can use,

curl -get "http://resource-manager-hostname:8088/ws/v1/cluster/apps?state=running&limit=20" | jq '.apps.app|sort_by(.queueUsagePercentage)|reverse'

Hope this helps.

View solution in original post

1 REPLY 1

avatar
Expert Contributor
@Purna Chandra Mahesh Bhogavalli

There is no sort or order_by query parameter supported in the ResourceManager rest api. For your curl request, you can check the documentation at http://hadoop.apache.org/docs/stable/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html#Cluster_A...

The only option now is to sort at the client side. For command line, one easy way is to install a tool called jq https://stedolan.github.io/jq/download/ if you are interested. For your use case, you can do something like follows:

curl -get "http://resource-manager-hostname:8088/ws/v1/cluster/apps?state=running&limit=20" | jq '.apps.app|sort_by(.queueUsagePercentage)'

For descending sort you can use,

curl -get "http://resource-manager-hostname:8088/ws/v1/cluster/apps?state=running&limit=20" | jq '.apps.app|sort_by(.queueUsagePercentage)|reverse'

Hope this helps.