@@ -24,11 +24,9 @@ import java.util.Base64
2424
2525import scala .sys .process ._
2626import scala .language .postfixOps
27-
2827import org .apache .hadoop .fs .{FileSystem , Path }
2928import org .apache .hadoop .io .Text
3029import org .apache .hadoop .security .{Credentials , UserGroupInformation }
31-
3230import org .apache .spark .deploy .SparkHadoopUtil
3331import org .apache .spark .internal .Logging
3432import org .apache .spark .internal .config ._
@@ -37,6 +35,9 @@ import org.apache.spark.launcher.SparkLauncher
3735import org .apache .spark .network .sasl .SecretKeyHolder
3836import org .apache .spark .util .Utils
3937
38+ import scala .annotation .tailrec
39+ import scala .util .{Failure , Try }
40+
4041/**
4142 * Spark class responsible for security.
4243 *
@@ -129,6 +130,22 @@ private[spark] class SecurityManager(
129130 s " $sparkBase/spark- $sparkVersion"
130131 }
131132
133+ @ tailrec
134+ private def genViaManageSSLScript (stdWriter : PrintWriter ,
135+ manageSslKeysScriptLocal : String ,
136+ sslKeyStorePass : String ,
137+ count : Int ): Int = {
138+ Try (s " $manageSslKeysScriptLocal $sslKeyStorePass" ! ProcessLogger (stdWriter println, stdWriter println)) match {
139+ case Failure (_) =>
140+ if (count == 0 ) - 1 else {
141+ logInfo(" manageSSLKeys.sh script is busy, waiting..." )
142+ Thread .sleep(5000 )
143+ genViaManageSSLScript(stdWriter, manageSslKeysScriptLocal, sslKeyStorePass, count - 1 )
144+ }
145+ case _ => 0
146+ }
147+ }
148+
132149 def genSSLCertsIfNeededAndPushToMapRFS (): Unit = {
133150 if (isSSLCertGenerationNeededForWebUI(getSSLOptions(" ui" ))) {
134151 val username = UserGroupInformation .getCurrentUser.getShortUserName
@@ -150,9 +167,8 @@ private[spark] class SecurityManager(
150167 val localBaseDir = s " $currentUserHomeDir/__spark-internal__/security_keys "
151168 val manageSslKeysScriptLocal = s " $localBaseDir/ $certGeneratorName"
152169
153- if (! fs.exists(new Path (manageSslKeysScriptLocal))) {
154- fs.copyToLocalFile(new Path (mfsManageSslKeysScriptRemote), new Path (manageSslKeysScriptLocal))
155- }
170+ fs.copyToLocalFile(new Path (mfsManageSslKeysScriptRemote), new Path (manageSslKeysScriptLocal))
171+
156172 val manageSslKeysLocalFile = new File (manageSslKeysScriptLocal)
157173
158174 manageSslKeysLocalFile.setExecutable(true )
@@ -163,11 +179,7 @@ private[spark] class SecurityManager(
163179 val stdStream = new OutputStreamWriter (new FileOutputStream (file), UTF_8 )
164180 val stdWriter = new PrintWriter (stdStream)
165181
166- while (s " pgrep -fl $certGeneratorName" .lineStream_!.nonEmpty) {
167- logInfo(" manageSSLKeys.sh script is busy, waiting..." )
168- Thread .sleep(5000 )
169- }
170- val res = s " $manageSslKeysScriptLocal $sslKeyStorePass" ! ProcessLogger (stdWriter println, stdWriter println)
182+ val res = genViaManageSSLScript(stdWriter, manageSslKeysScriptLocal, sslKeyStorePass, 10 )
171183 stdWriter.close()
172184
173185 val certGeneratorLogMfsLocation = s " /apps/spark/ $certGeneratorLog"
0 commit comments