title: How to get SparkContext if Spark runs on Yarn?
body: <p>We have a program based on Spark standalone, and in this program we use <code>SparkContext</code> and <code>SqlContext</code> to do lots of queries. </p>
  
  <p>Now we want to deploy the system on a Spark which runs on Yarn. But when we modify the <code>spark.master</code> to <code>yarn-cluster</code>, the application throws an exception says this works with <code>spark-submit</code> type only. When we switch to <code>yarn-client</code>, although it no longer throws exceptions, it doesn't work properly.</p>
  
  <p>It seems that if runs on Yarn, we can no longer use <code>SparkContext</code> to work, instead we should use something like <code>yarn.Client</code>, but in this way we don't know how to change our code to achieve what we have done before using <code>SparkContext</code> and <code>SqlContext</code>.</p>
  
  <p>Is there a good way to solve this? Can we get <code>SparkContext</code> from <code>yarn.Client</code> or we should change our code to utilize new interfaces of <code>yarn.Client</code>?</p>
  
  <p>Thank you! </p>