<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Execute code on Application End in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/execute-code-on-application-end/m-p/23706#M16421</link>
    <description>&lt;P&gt;Did you find any solution?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Apr 2023 12:21:25 GMT</pubDate>
    <dc:creator>abhilash</dc:creator>
    <dc:date>2023-04-04T12:21:25Z</dc:date>
    <item>
      <title>Execute code on Application End</title>
      <link>https://community.databricks.com/t5/data-engineering/execute-code-on-application-end/m-p/23705#M16420</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to execute a custom code onApplicationEnd. Outisde Databricks, I have used the Spark Listener onApplicationEnd without problems. &lt;/P&gt;&lt;P&gt;But it is not working on Databricks (I tried listener onJobEnd and this one worked).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have also tried Spark plugin, and the logs from the Driver in the init() method are there, but not the ones of the shutdown:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;package com.baikal
&amp;nbsp;
import java.util.{Map =&amp;gt; JMap}
&amp;nbsp;
import org.apache.spark.SparkContext
import org.apache.spark.api.plugin.{DriverPlugin, ExecutorPlugin, PluginContext, SparkPlugin}
import org.apache.spark.scheduler.{SparkListener, SparkListenerApplicationEnd}
import org.slf4j.LoggerFactory
&amp;nbsp;
import scala.collection.JavaConverters._
&amp;nbsp;
object Hello {
&amp;nbsp;
&amp;nbsp;
  def main(args: Array[String]): Unit = {
    val listenerEnd = new OnApplicationEnd
    import org.apache.spark.sql.SparkSession
    val spark = SparkSession.builder()
      .appName("Spark")
      .getOrCreate();
&amp;nbsp;
    spark.sparkContext.addSparkListener(listenerEnd)
&amp;nbsp;
    spark.sparkContext.parallelize(Array(1,2,3,4,5,6,7,8,9,10)).count()
    
  }
&amp;nbsp;
}
&amp;nbsp;
class OnApplicationEnd extends SparkListener {
  lazy val logger = LoggerFactory.getLogger(getClass)
  override def onApplicationEnd(applicationEnd: SparkListenerApplicationEnd): Unit = {
    logger.info("Hellooooooooooooooo")
    println("Hellooooooooooooooo")
    throw new Exception("FAILEEEEEED")
&amp;nbsp;
  }
}
&amp;nbsp;
class DemoPlugin extends SparkPlugin {
  lazy val logger = LoggerFactory.getLogger(getClass)
  override def driverPlugin(): DriverPlugin = {
&amp;nbsp;
    new DriverPlugin() {
      override def init(sc: SparkContext, myContext: PluginContext): JMap[String, String] = {
        println("---------------------------")
        println("INIIIIIIIIIIIIIIIIIIIIIIIIIIITTTTTTTTTTTTTTTTT")
        Map.empty[String, String].asJava
      }
&amp;nbsp;
      override def shutdown(): Unit = {
        logger.info("Hellooooooooooooooo")
        println("Hellooooooooooooooo")
        throw new Exception("FAILEEEEEED")
        super.shutdown()
      }
    }
  }
&amp;nbsp;
  override def executorPlugin(): ExecutorPlugin = {
    new ExecutorPlugin {
&amp;nbsp;
    }
  }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have added this config to the cluster config:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;spark.plugins com.baikal.DemoPlugin
spark.extraListeners com.baikal.OnApplicationEnd,com.databricks.backend.daemon.driver.DBCEventLoggingListener&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Like I said, the init of the plugin works and with the onJobEnd listener too. But I it doesn't work on application end/shutdown.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas? &lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 10:58:40 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/execute-code-on-application-end/m-p/23705#M16420</guid>
      <dc:creator>Eric-JoelBlanco</dc:creator>
      <dc:date>2022-04-05T10:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Execute code on Application End</title>
      <link>https://community.databricks.com/t5/data-engineering/execute-code-on-application-end/m-p/23706#M16421</link>
      <description>&lt;P&gt;Did you find any solution?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 12:21:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/execute-code-on-application-end/m-p/23706#M16421</guid>
      <dc:creator>abhilash</dc:creator>
      <dc:date>2023-04-04T12:21:25Z</dc:date>
    </item>
  </channel>
</rss>

