'Executors registering metrics system even before all the jars and dependencies are downloaded/copied

My issue is same as spark cassandra metrics class not found and the spark issue mentioned here https://issues.apache.org/jira/browse/SPARK-18115

Am getting the ClassNotFoundException of custom source in executors, when the jar was still being loaded to executors. Exception:

22/05/14 11:23:31 ERROR org.apache.spark.metrics.MetricsSystem: Source class org.apache.spark.metrics.source.StreamingCustomSource cannot be instantiated
java.lang.ClassNotFoundException: org.apache.spark.metrics.source.StreamingCustomSource
    at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.apache.spark.util.Utils$.classForName(Utils.scala:238)
    at org.apache.spark.metrics.MetricsSystem.$anonfun$registerSources$1(MetricsSystem.scala:184)
    at org.apache.spark.metrics.MetricsSystem.$anonfun$registerSources$1$adapted(MetricsSystem.scala:181)
    at scala.collection.mutable.HashMap.$anonfun$foreach$1(HashMap.scala:149)
    at scala.collection.mutable.HashTable.foreachEntry(HashTable.scala:237)
    at scala.collection.mutable.HashTable.foreachEntry$(HashTable.scala:230)
    at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:44)
    at scala.collection.mutable.HashMap.foreach(HashMap.scala:149)
    at org.apache.spark.metrics.MetricsSystem.registerSources(MetricsSystem.scala:181)
    at org.apache.spark.metrics.MetricsSystem.start(MetricsSystem.scala:102)

Similar issues found Metrics System not recognizing Custom Source/Sink in application jar

@thomas poidevin or @user3714811

Please help me out here if the issue has been resolved for you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source