Thursday, November 27, 2014

Script -- Find the JAR file which contains the class name in current directory

When troubleshooting hadoop issues, so many times they are showing up:
"No such method", "Can not find the class", "Class A is not Class B"....

This perl script is to find out which JAR file has the class name in current directory.
Save it as "findjar" for example.

#!/usr/bin/perl
use File::Find;

if ($#ARGV != 0) {
 print "usage: findjar.pl classname\n";
 exit;
}

my $classname = $ARGV[0];

find(\&wanted, ".");

sub wanted{
 my $file = $_;
 if ((-f $file) && ($file =~ /\.jar$/)){
  my @result = qx (jar -tf $file |grep -i $classname);
  if (@result){
   print "==============$file===============\n";
   print @result;
  }

 }
}

Usage:
[root@yarn-fcs-1 mapr]# findjar org.apache.spark.deploy.yarn.ExecutorLauncher
==============spark-assembly-1.1.0-hadoop2.4.1-mapr-1408.jar===============
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$waitForSparkMaster$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$org$apache$spark$deploy$yarn$ExecutorLauncher$$allocateMissingExecutor$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$MonitorActor.class
org/apache/spark/deploy/yarn/ExecutorLauncher$MonitorActor$$anonfun$preStart$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$allocateExecutors$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$launchReporterThread$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$waitForSparkMaster$3.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$waitForSparkMaster$4.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$waitForSparkMaster$2.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$finishApplicationMaster$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$MonitorActor$$anonfun$receive$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$allocateExecutors$2.class
org/apache/spark/deploy/yarn/ExecutorLauncher$MonitorActor$$anonfun$receive$1$$anonfun$applyOrElse$2.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$registerApplicationMaster$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anon$1$$anonfun$run$2.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$main$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$MonitorActor$$anonfun$receive$1$$anonfun$applyOrElse$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anon$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$run$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher.class
[root@yarn-fcs-1 mapr]# findjar org/apache/spark/deploy/yarn/ExecutorLauncher
==============spark-assembly-1.1.0-hadoop2.4.1-mapr-1408.jar===============
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$waitForSparkMaster$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$org$apache$spark$deploy$yarn$ExecutorLauncher$$allocateMissingExecutor$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$MonitorActor.class
org/apache/spark/deploy/yarn/ExecutorLauncher$MonitorActor$$anonfun$preStart$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$allocateExecutors$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$launchReporterThread$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$waitForSparkMaster$3.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$waitForSparkMaster$4.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$waitForSparkMaster$2.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$finishApplicationMaster$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$MonitorActor$$anonfun$receive$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$allocateExecutors$2.class
org/apache/spark/deploy/yarn/ExecutorLauncher$MonitorActor$$anonfun$receive$1$$anonfun$applyOrElse$2.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$registerApplicationMaster$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anon$1$$anonfun$run$2.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$main$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$MonitorActor$$anonfun$receive$1$$anonfun$applyOrElse$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anon$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher$$anonfun$run$1.class
org/apache/spark/deploy/yarn/ExecutorLauncher.class


No comments:

Post a Comment

Popular Posts