Skip to content

Instantly share code, notes, and snippets.

@vinodkc
Created February 22, 2024 18:02
Show Gist options
  • Save vinodkc/d134515b3fd42a0059bd476f0bd2bd39 to your computer and use it in GitHub Desktop.
Save vinodkc/d134515b3fd42a0059bd476f0bd2bd39 to your computer and use it in GitHub Desktop.
import java.io.{File, FileFilter}
import scala.collection.mutable.HashMap
val hadoopConfFiles = new HashMap[String, File]()
sys.env.get("SPARK_CONF_DIR").foreach { localConfDir =>
println("localConfDir : " + localConfDir)
val dir = new File(localConfDir)
if (dir.isDirectory) {
val files = dir.listFiles(new FileFilter {
override def accept(pathname: File): Boolean = {
pathname.isFile && pathname.getName.endsWith(".xml")
}
})
files.foreach { f =>
println("f : " + f)
hadoopConfFiles(f.getName) = f
println(f)
}
}
}
val confDirs = Seq("HADOOP_CONF_DIR", "YARN_CONF_DIR")
confDirs.foreach { envKey =>
val env = sys.env.get(envKey).toSeq
env.flatMap(_.split(File.pathSeparator)).foreach { path =>
println(path)
val dir = new File(path)
if (dir.isDirectory()) {
val files = dir.listFiles()
if (files == null) {
println("WARN:Failed to list files under directory " + dir)
} else {
files.foreach { file =>
if (file.isFile && !hadoopConfFiles.contains(file.getName())) {
hadoopConfFiles(file.getName()) = file
println("Added " + file)
} else {
println("Not Added " + file)
}
}
}
}
}
}
hadoopConfFiles.foreach { case (name, file) =>
if (file.canRead()) {
println("Can read " + file)
} else {
println("Can not read " + file)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment