@@ -24,11 +24,9 @@ import java.util.Base64
24
24
25
25
import scala .sys .process ._
26
26
import scala .language .postfixOps
27
-
28
27
import org .apache .hadoop .fs .{FileSystem , Path }
29
28
import org .apache .hadoop .io .Text
30
29
import org .apache .hadoop .security .{Credentials , UserGroupInformation }
31
-
32
30
import org .apache .spark .deploy .SparkHadoopUtil
33
31
import org .apache .spark .internal .Logging
34
32
import org .apache .spark .internal .config ._
@@ -37,6 +35,9 @@ import org.apache.spark.launcher.SparkLauncher
37
35
import org .apache .spark .network .sasl .SecretKeyHolder
38
36
import org .apache .spark .util .Utils
39
37
38
+ import scala .annotation .tailrec
39
+ import scala .util .{Failure , Try }
40
+
40
41
/**
41
42
* Spark class responsible for security.
42
43
*
@@ -133,6 +134,22 @@ private[spark] class SecurityManager(
133
134
s " $sparkBase/spark- $sparkVersion"
134
135
}
135
136
137
+ @ tailrec
138
+ private def genViaManageSSLScript (stdWriter : PrintWriter ,
139
+ manageSslKeysScriptLocal : String ,
140
+ sslKeyStorePass : String ,
141
+ count : Int ): Int = {
142
+ Try (s " $manageSslKeysScriptLocal $sslKeyStorePass" ! ProcessLogger (stdWriter println, stdWriter println)) match {
143
+ case Failure (_) =>
144
+ if (count == 0 ) - 1 else {
145
+ logInfo(" manageSSLKeys.sh script is busy, waiting..." )
146
+ Thread .sleep(5000 )
147
+ genViaManageSSLScript(stdWriter, manageSslKeysScriptLocal, sslKeyStorePass, count - 1 )
148
+ }
149
+ case _ => 0
150
+ }
151
+ }
152
+
136
153
def genSSLCertsIfNeededAndPushToMapRFS (): Unit = {
137
154
if (isSSLCertGenerationNeededForWebUI(getSSLOptions(" ui" ))) {
138
155
val username = UserGroupInformation .getCurrentUser.getShortUserName
@@ -143,7 +160,7 @@ private[spark] class SecurityManager(
143
160
val fs = FileSystem .get(hadoopConf)
144
161
145
162
// If the manageSSLKeys.sh script is not present, copy it from local spark folder
146
- if (! fs.exists(new Path (mfsManageSslKeysScriptRemote))) {
163
+ if (! fs.exists(new Path (mfsManageSslKeysScriptRemote))) {
147
164
val mfsBaseDirPath = new Path (mfsBaseDir)
148
165
if (! fs.exists(mfsBaseDirPath)) {
149
166
fs.mkdirs(mfsBaseDirPath)
@@ -155,6 +172,7 @@ private[spark] class SecurityManager(
155
172
val manageSslKeysScriptLocal = s " $localBaseDir/ $certGeneratorName"
156
173
157
174
fs.copyToLocalFile(new Path (mfsManageSslKeysScriptRemote), new Path (manageSslKeysScriptLocal))
175
+
158
176
val manageSslKeysLocalFile = new File (manageSslKeysScriptLocal)
159
177
160
178
manageSslKeysLocalFile.setExecutable(true )
@@ -165,11 +183,7 @@ private[spark] class SecurityManager(
165
183
val stdStream = new OutputStreamWriter (new FileOutputStream (file), UTF_8 )
166
184
val stdWriter = new PrintWriter (stdStream)
167
185
168
- while (s " pgrep -fl $certGeneratorName" .lineStream_!.nonEmpty) {
169
- logInfo(" manageSSLKeys.sh script is busy, waiting..." )
170
- Thread .sleep(500 )
171
- }
172
- val res = s " $manageSslKeysScriptLocal $sslKeyStorePass" ! ProcessLogger (stdWriter println, stdWriter println)
186
+ val res = genViaManageSSLScript(stdWriter, manageSslKeysScriptLocal, sslKeyStorePass, 10 )
173
187
stdWriter.close()
174
188
175
189
val certGeneratorLogMfsLocation = s " /apps/spark/ $certGeneratorLog"
0 commit comments