@@ -3,14 +3,15 @@ package spark.jobserver.python
3
3
import java .io .File
4
4
import java .nio .file .Files
5
5
6
- import com .typesafe .config .{ConfigRenderOptions , Config , ConfigFactory }
6
+ import com .typesafe .config .{Config , ConfigFactory , ConfigRenderOptions }
7
7
import org .apache .spark .SparkContext
8
8
import org .apache .spark .api .java .JavaSparkContext
9
9
import org .apache .spark .sql .SQLContext
10
10
import org .apache .spark .sql .hive .HiveContext
11
11
import org .apache .spark .{SparkConf , SparkContext }
12
- import org .scalatest .{BeforeAndAfterAll , Matchers , FunSpec }
12
+ import org .scalatest .{BeforeAndAfterAll , FunSpec , Matchers }
13
13
import py4j .GatewayServer
14
+ import py4j .GatewayServer .GatewayServerBuilder
14
15
15
16
import scala .collection .JavaConverters ._
16
17
import scala .sys .process .Process
@@ -34,10 +35,10 @@ object SubprocessSpec {
34
35
lazy val jobServerPath = getPythonDir(" src/python" )
35
36
36
37
lazy val pysparkPath = sys.env.get(" SPARK_HOME" ).map(d => s " $d/python/lib/pyspark.zip " )
37
- lazy val py4jPath = sys.env.get(" SPARK_HOME" ).map(d => s " $d/python/lib/py4j-0.10.4 -src.zip " )
38
+ lazy val py4jPath = sys.env.get(" SPARK_HOME" ).map(d => s " $d/python/lib/py4j-0.10.7 -src.zip " )
38
39
lazy val sparkPaths = sys.env.get(" SPARK_HOME" ).map{sh =>
39
40
val pysparkPath = s " $sh/python/lib/pyspark.zip "
40
- val py4jPath = s " $sh/python/lib/py4j-0.10.4 -src.zip "
41
+ val py4jPath = s " $sh/python/lib/py4j-0.10.7 -src.zip "
41
42
Seq (pysparkPath, py4jPath)
42
43
}.getOrElse(Seq ())
43
44
lazy val originalPythonPath = sys.env.get(" PYTHONPATH" )
@@ -93,18 +94,28 @@ class SubprocessSpec extends FunSpec with Matchers with BeforeAndAfterAll {
93
94
val pathList = Seq (jobServerPath) ++ sparkPaths ++ originalPythonPath.toSeq
94
95
val p = pathList.mkString(pythonPathDelimiter)
95
96
// Scarman 10-13-2016
96
- // println(p)
97
+ println(p)
97
98
p
98
99
}
99
100
101
+ lazy val env = Seq (
102
+ " PYTHONPATH" -> pythonPath,
103
+ " PYSPARK_GATEWAY_SECRET" -> secret
104
+ )
105
+
100
106
// creates a stub warehouse dir for derby/hive metastore
101
107
def makeWarehouseDir (): File = {
102
108
val warehouseDir = Files .createTempDirectory(" warehouse" ).toFile()
103
109
warehouseDir.delete()
104
110
warehouseDir
105
111
}
112
+ val secret = " Test"
106
113
def buildGateway (endpoint : TestEndpoint ): GatewayServer = {
107
- val server = new GatewayServer (endpoint, 0 )
114
+ val server = new GatewayServerBuilder ()
115
+ .entryPoint(endpoint)
116
+ .javaPort(0 )
117
+ .authToken(secret)
118
+ .build()
108
119
// Server runs asynchronously on a dedicated thread. See Py4J source for more detail
109
120
server.start()
110
121
server
@@ -162,7 +173,7 @@ class SubprocessSpec extends FunSpec with Matchers with BeforeAndAfterAll {
162
173
Process (
163
174
Seq (" python" , " -m" , " sparkjobserver.subprocess" , gw.getListeningPort.toString),
164
175
None ,
165
- " PYTHONPATH " -> pythonPath )
176
+ env : _* )
166
177
val pythonExitCode = process.!
167
178
pythonExitCode should be (0 )
168
179
endpoint.result should matchPattern {
@@ -181,7 +192,7 @@ class SubprocessSpec extends FunSpec with Matchers with BeforeAndAfterAll {
181
192
Process (
182
193
Seq (" python" , " -m" , " sparkjobserver.subprocess" , gw.getListeningPort.toString),
183
194
None ,
184
- " PYTHONPATH " -> pythonPath )
195
+ env : _* )
185
196
val pythonExitCode = process.!
186
197
pythonExitCode should be (1 )
187
198
endpoint.validationProblems should be (Some (Seq (" config input.strings not found" )))
@@ -205,7 +216,7 @@ class SubprocessSpec extends FunSpec with Matchers with BeforeAndAfterAll {
205
216
Process (
206
217
Seq (" python" , " -m" , " sparkjobserver.subprocess" , gw.getListeningPort.toString),
207
218
None ,
208
- " PYTHONPATH " -> pythonPath )
219
+ env : _* )
209
220
val pythonExitCode = process.!
210
221
pythonExitCode should be (0 )
211
222
endpoint.result should matchPattern {
@@ -235,7 +246,7 @@ class SubprocessSpec extends FunSpec with Matchers with BeforeAndAfterAll {
235
246
Process (
236
247
Seq (" python" , " -m" , " sparkjobserver.subprocess" , gw.getListeningPort.toString),
237
248
None ,
238
- " PYTHONPATH " -> pythonPath )
249
+ env : _* )
239
250
val pythonExitCode = process.!
240
251
pythonExitCode should be (0 )
241
252
endpoint.result should matchPattern {
@@ -268,7 +279,7 @@ class SubprocessSpec extends FunSpec with Matchers with BeforeAndAfterAll {
268
279
Process (
269
280
Seq (" python" , " -m" , " sparkjobserver.subprocess" , gw.getListeningPort.toString),
270
281
None ,
271
- " PYTHONPATH " -> pythonPath )
282
+ env : _* )
272
283
val pythonExitCode = process.!
273
284
pythonExitCode should be (0 )
274
285
endpoint.result should be (" done" )
@@ -283,7 +294,7 @@ class SubprocessSpec extends FunSpec with Matchers with BeforeAndAfterAll {
283
294
Process (
284
295
Seq (" python" , " -m" , " sparkjobserver.subprocess" , gw2.getListeningPort.toString),
285
296
None ,
286
- " PYTHONPATH " -> pythonPath )
297
+ env : _* )
287
298
val pythonExitCode2 = process2.!
288
299
pythonExitCode2 should be (0 )
289
300
endpoint2.result should matchPattern {
@@ -308,7 +319,7 @@ class SubprocessSpec extends FunSpec with Matchers with BeforeAndAfterAll {
308
319
Process (
309
320
Seq (" python" , " -m" , " sparkjobserver.subprocess" , gw.getListeningPort.toString),
310
321
None ,
311
- " PYTHONPATH " -> pythonPath )
322
+ env : _* )
312
323
val pythonExitCode = process.!
313
324
pythonExitCode should be (2 )
314
325
stopGateway(gw)
@@ -323,7 +334,7 @@ class SubprocessSpec extends FunSpec with Matchers with BeforeAndAfterAll {
323
334
Process (
324
335
Seq (" python" , " -m" , " sparkjobserver.subprocess" , gw.getListeningPort.toString),
325
336
None ,
326
- " PYTHONPATH " -> pythonPath )
337
+ env : _* )
327
338
val pythonExitCode = process.!
328
339
pythonExitCode should be (4 )
329
340
stopGateway(gw)
@@ -338,7 +349,7 @@ class SubprocessSpec extends FunSpec with Matchers with BeforeAndAfterAll {
338
349
Process (
339
350
Seq (" python" , " -m" , " sparkjobserver.subprocess" , gw.getListeningPort.toString),
340
351
None ,
341
- " PYTHONPATH " -> pythonPath )
352
+ env : _* )
342
353
val pythonExitCode = process.!
343
354
pythonExitCode should be (3 )
344
355
stopGateway(gw)
@@ -356,7 +367,7 @@ class SubprocessSpec extends FunSpec with Matchers with BeforeAndAfterAll {
356
367
Process (
357
368
Seq (" python" , " -m" , " sparkjobserver.subprocess" , gw.getListeningPort.toString),
358
369
None ,
359
- " PYTHONPATH " -> pythonPath )
370
+ env : _* )
360
371
val pythonExitCode = process.!
361
372
pythonExitCode should be (0 )
362
373
endpoint.result should be (" Hello World 3" )
0 commit comments