Skip to content
This repository was archived by the owner on May 17, 2022. It is now read-only.

Commit e765bb1

Browse files
committed
Fixed byte/str issue #9 in serverextension
Removed stray print statements in scala SparkListener.
1 parent 7025e23 commit e765bb1

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

extension/MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
graft sparkmonitor/static
2-
recursive-include sparkmonitor *.jar
2+
recursive-include sparkmonitor *.jar
3+
include VERSION

extension/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.0.8
1+
v0.0.9

extension/scalalistener/CustomListener.scala

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,34 @@ import java.io._
3030
*/
3131
class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
3232

33-
println("SPARKLISTENER: Started SparkListener for Jupyter Notebook")
33+
println("SPARKMONITOR_LISTENER: Started SparkListener for Jupyter Notebook")
3434
val port = scala.util.Properties.envOrElse("SPARKMONITOR_KERNEL_PORT", "ERRORNOTFOUND")
35-
println("SPARKLISTENER: Port obtained from environment: " + port)
35+
println("SPARKMONITOR_LISTENER: Port obtained from environment: " + port)
3636
var socket: Socket = null
3737
var out: OutputStreamWriter = null
3838
// Open the socket to the kernel. The kernel is the server already waiting for connections.
3939
try {
4040
socket = new Socket("localhost", port.toInt)
4141
out = new OutputStreamWriter(socket.getOutputStream())
4242
} catch {
43-
case exception: Throwable => println("\nSPARKLISTENER: Exception creating socket:" + exception + "\n")
43+
case exception: Throwable => println("\nSPARKMONITOR_LISTENER: Exception creating socket:" + exception + "\n")
4444
}
4545

4646
/** Send a string message to the kernel using the open socket.*/
4747
def send(msg: String): Unit = {
4848
try {
49-
//println("\nSPARKLISTENER: --------------Sending Message:------------------\n"+msg+
50-
// "\nSPARKLISTENER: -------------------------------------------------\n") // Uncomment to see all events
49+
//println("\nSPARKMONITOR_LISTENER: --------------Sending Message:------------------\n"+msg+
50+
// "\nSPARKMONITOR_LISTENER: -------------------------------------------------\n") // Uncomment to see all events
5151
out.write(msg + ";EOD:")
5252
out.flush()
5353
} catch {
54-
case exception: Throwable => println("\nSPARKLISTENER: Exception sending socket message:" + exception + "\n")
54+
case exception: Throwable => println("\nSPARKMONITOR_LISTENER: Exception sending socket message:" + exception + "\n")
5555
}
5656
}
5757

5858
/** Close the socket connection to the kernel.*/
5959
def closeConnection(): Unit = {
60-
println("SPARKLISTNER: Closing Connection")
60+
println("SPARKMONITOR_LISTENER: Closing Connection")
6161
out.close()
6262
socket.close()
6363
}
@@ -112,7 +112,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
112112
override def onApplicationStart(appStarted: SparkListenerApplicationStart): Unit = {
113113
startTime = appStarted.time
114114
appId = appStarted.appId.getOrElse("null")
115-
println("SPARKLISTENER Application Started: " + appId + " ...Start Time: " + appStarted.time)
115+
println("SPARKMONITOR_LISTENER: Application Started: " + appId + " ...Start Time: " + appStarted.time)
116116
val json = ("msgtype" -> "sparkApplicationStart") ~
117117
("startTime" -> startTime) ~
118118
("appId" -> appId) ~
@@ -129,7 +129,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
129129
* Closes the socket connection to the kernel.
130130
*/
131131
override def onApplicationEnd(appEnded: SparkListenerApplicationEnd): Unit = {
132-
println("SPARKLISTENER Application ending...End Time: " + appEnded.time)
132+
println("SPARKMONITOR_LISTENER: Application ending...End Time: " + appEnded.time)
133133
endTime = appEnded.time
134134
val json = ("msgtype" -> "sparkApplicationEnd") ~
135135
("endTime" -> endTime)
@@ -195,7 +195,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
195195
stageIdToData.getOrElseUpdate((stageInfo.stageId, stageInfo.attemptId), new StageUIData)
196196
}
197197
val name = jobStart.properties.getProperty("callSite.short", "null")
198-
println("Num Executors" + numExecutors.toInt)
198+
// println("Num Executors" + numExecutors.toInt)
199199
val json = ("msgtype" -> "sparkJobStart") ~
200200
("jobGroup" -> jobGroup.getOrElse("null")) ~
201201
("jobId" -> jobStart.jobId) ~
@@ -208,14 +208,14 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
208208
("appId" -> appId) ~
209209
("numExecutors" -> numExecutors) ~
210210
("name" -> name)
211-
println("SPARKLISTENER JobStart: \n" + pretty(render(json)) + "\n")
211+
// println("SPARKMONITOR_LISTENER: JobStart: \n" + pretty(render(json)) + "\n")
212212
send(pretty(render(json)))
213213
}
214214

215215
/** Called when a job ends. */
216216
override def onJobEnd(jobEnd: SparkListenerJobEnd): Unit = synchronized {
217217
val jobData = activeJobs.remove(jobEnd.jobId).getOrElse {
218-
println("SPARKLISTENER:Job completed for unknown job: " + jobEnd.jobId)
218+
println("SPARKMONITOR_LISTENER: Job completed for unknown job: " + jobEnd.jobId)
219219
new JobUIData(jobId = jobEnd.jobId)
220220
}
221221
jobData.completionTime = Option(jobEnd.time).filter(_ >= 0)
@@ -266,7 +266,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
266266
val stage = stageCompleted.stageInfo
267267
stageIdToInfo(stage.stageId) = stage
268268
val stageData = stageIdToData.getOrElseUpdate((stage.stageId, stage.attemptId), {
269-
println("SPARKLISTENER: Stage completed for unknown stage " + stage.stageId)
269+
println("SPARKMONITOR_LISTENER: Stage completed for unknown stage " + stage.stageId)
270270
new StageUIData
271271
})
272272
var status = "UNKNOWN"
@@ -306,7 +306,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
306306
("numTasks" -> stage.numTasks) ~
307307
("status" -> status)
308308

309-
println("SPARKLISTENER Stage Completed: \n" + pretty(render(json)) + "\n")
309+
// println("SPARKMONITOR_LISTENER: Stage Completed: \n" + pretty(render(json)) + "\n")
310310
send(pretty(render(json)))
311311
}
312312

@@ -342,7 +342,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
342342
("parentIds" -> stage.parentIds) ~
343343
("submissionTime" -> submissionTime) ~
344344
("jobIds" -> jobIds)
345-
println("SPARKLISTENER Stage Submitted: \n" + pretty(render(json)) + "\n")
345+
// println("SPARKMONITOR_LISTENER Stage Submitted: \n" + pretty(render(json)) + "\n")
346346
send(pretty(render(json)))
347347
}
348348

@@ -351,7 +351,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
351351
val taskInfo = taskStart.taskInfo
352352
if (taskInfo != null) {
353353
val stageData = stageIdToData.getOrElseUpdate((taskStart.stageId, taskStart.stageAttemptId), {
354-
println("SPARKLISTENER: Task start for unknown stage " + taskStart.stageId)
354+
println("SPARKMONITOR_LISTENER: Task start for unknown stage " + taskStart.stageId)
355355
new StageUIData
356356
})
357357
stageData.numActiveTasks += 1
@@ -387,7 +387,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
387387
("status" -> taskInfo.status) ~
388388
("speculative" -> taskInfo.speculative)
389389

390-
//println("SPARKLISTENER Task Started: \n"+ pretty(render(json)) + "\n")
390+
//println("SPARKMONITOR_LISTENER: Task Started: \n"+ pretty(render(json)) + "\n")
391391
send(pretty(render(json)))
392392
}
393393

@@ -400,7 +400,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
400400
var errorMessage: Option[String] = None
401401
if (info != null && taskEnd.stageAttemptId != -1) {
402402
val stageData = stageIdToData.getOrElseUpdate((taskEnd.stageId, taskEnd.stageAttemptId), {
403-
println("SPARKLISTENER: Task end for unknown stage " + taskEnd.stageId)
403+
println("SPARKMONITOR_LISTENER: Task end for unknown stage " + taskEnd.stageId)
404404
new StageUIData
405405
})
406406
stageData.numActiveTasks -= 1
@@ -517,7 +517,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
517517
("errorMessage" -> errorMessage) ~
518518
("metrics" -> jsonMetrics)
519519

520-
println("SPARKLISTENER Task Ended: \n" + pretty(render(json)) + "\n")
520+
// println("SPARKMONITOR_LISTENER: Task Ended: \n" + pretty(render(json)) + "\n")
521521
send(pretty(render(json)))
522522
}
523523

@@ -573,7 +573,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
573573
("numCores" -> executorAdded.executorInfo.totalCores) ~
574574
("totalCores" -> totalCores) // Sending this as browser data can be lost during reloads
575575

576-
println("SPARKLISTENER Executor Added: \n" + pretty(render(json)) + "\n")
576+
// println("SPARKMONITOR_LISTENER: Executor Added: \n" + pretty(render(json)) + "\n")
577577
send(pretty(render(json)))
578578
}
579579

@@ -586,7 +586,7 @@ class JupyterSparkMonitorListener(conf: SparkConf) extends SparkListener {
586586
("time" -> executorRemoved.time) ~
587587
("totalCores" -> totalCores) // Sending this as browser data can be lost during reloads
588588

589-
println("SPARKLISTENER Executor Removed: \n" + pretty(render(json)) + "\n")
589+
// println("SPARKMONITOR_LISTENER: Executor Removed: \n" + pretty(render(json)) + "\n")
590590
send(pretty(render(json)))
591591
}
592592
}

extension/sparkmonitor/serverextension.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def get(self):
4242
self.request.uri.index(proxy_root) + len(proxy_root) + 1):]
4343
self.replace_path = self.request.uri[:self.request.uri.index(
4444
proxy_root) + len(proxy_root)]
45-
print("SPARKMONITOR_SERVER: Request_path " +
46-
request_path + " \n Replace_path:" + self.replace_path)
45+
# print("SPARKMONITOR_SERVER: Request_path " + request_path + " \n Replace_path:" + self.replace_path)
4746
backendurl = url_path_join(url, request_path)
4847
self.debug_url = url
4948
self.backendurl = backendurl
@@ -64,8 +63,8 @@ def handle_response(self, response):
6463
if "text/html" in content_type:
6564
content = replace(response.body, self.replace_path)
6665
elif "javascript" in content_type:
67-
content = response.body.replace(
68-
"location.origin", "location.origin +'" + self.replace_path + "' ")
66+
body="location.origin +'" + self.replace_path + "' "
67+
content = response.body.replace(b"location.origin",body.encode())
6968
else:
7069
# Probably binary response, send it directly.
7170
content = response.body

0 commit comments

Comments
 (0)