[SPARK-4010][Web UI]Spark UI returns 500 in yarn-client mode

The problem caused by #1966
CC YanTangZhai andrewor14

Author: GuoQiang Li <witgo@qq.com>

Closes #2858 from witgo/SPARK-4010 and squashes the following commits:

9866fbf [GuoQiang Li] Spark UI returns 500 in yarn-client mode

(cherry picked from commit 51afde9d8b8a67958c4632a13af143d7c7fd1f04)
Signed-off-by: Andrew Or <andrewor14@gmail.com>