Skip to content

Instantly share code, notes, and snippets.

@bepcyc
Last active December 15, 2021 11:55
Show Gist options
  • Save bepcyc/55f7acdcbf29c4cc34dcf6fdee9a149a to your computer and use it in GitHub Desktop.
Save bepcyc/55f7acdcbf29c4cc34dcf6fdee9a149a to your computer and use it in GitHub Desktop.
Kill all running YARN applications. Workaround for multi RM setups.
# In case you're getting an error like:
# This is standby RM. The redirect url is:
# or (for yarn util):
# INFO client.INFO retry.RetryInvocationHandler: java.net.ConnectException: Call From xxx to yyy:pppp failed on connection exception: java.net.ConnectException: Connection refused; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused, while invoking ApplicationClientProtocolPBClientImpl.getApplications over rm2 after 1 failover attempts. Trying to failover after sleeping for x ms.ConfiguredRMFailoverProxyProvider: Failing over to rm2
#
# this workaround might be needed for multi-master setups (for exanple AWS EMR 5.x YARN has this issue)
ACTIVE_HOST=$(curl -s -i http://${HOSTNAME}:8088/ws/v1/cluster/metrics | grep "Location:" | grep http | cut -d' ' -f2 | cut -d'/' -f3 | cut -d':' -f1)
RM_HOSTNAME=${ACTIVE_HOST:-$HOSTNAME}
curl -s -L http://${RM_HOSTNAME}:8088/ws/v1/cluster/apps?state=RUNNING | jq -c ".apps.app[].id" | xargs yarn application --kill
# or alternatively do everything via REST API:
# curl -L http://${RM_HOSTNAME}:8088/ws/v1/cluster/apps?state=RUNNING | jq -c ".apps.app[].id" | xargs -I{} curl -X PUT -d state=KILLED http://${RM_HOSTNAME}:8088/ws/v1/cluster/apps/{}/state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment