Skip to content

Commit

Permalink
[TOREE-541] Reply message should implement status field
Browse files Browse the repository at this point in the history
  • Loading branch information
pan3793 committed Aug 6, 2023
1 parent fb8368b commit 7fb3869
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class StdinClient(
val inputRequest =
Json.parse(kernelMessage.contentString).as[InputRequest]
val value = responseFunc(inputRequest.prompt, inputRequest.password)
val inputReply = InputReply(value)
val inputReply = InputReply("ok", value)

val newKernelMessage = KMBuilder()
.withParent(kernelMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CommInfoRequestHandler(
commStorage.getTargets().map(buildCommMap(_)).reduce(_ ++ _)
}
}
val commInfoReply = CommInfoReply(commMap.asInstanceOf[Map[String, Map[String, String]]])
val commInfoReply = CommInfoReply("ok", commMap.asInstanceOf[Map[String, Map[String, String]]])

val kernelInfo = SparkKernelInfo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class KernelInfoRequestHandler(actorLoader: ActorLoader, languageInfo: LanguageI

val kernelInfo = SparkKernelInfo
val kernelInfoReply = KernelInfoReply(
"ok",
kernelInfo.protocolVersion,
kernelInfo.implementation,
kernelInfo.implementationVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ShutdownHandler(

val kernelInfo = SparkKernelInfo

val shutdownReply = ShutdownReply(false)
val shutdownReply = ShutdownReply("ok", false)

val replyHeader = Header(
java.util.UUID.randomUUID.toString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class InputRequestReplyHandlerSpec
msg_type = MessageType.Incoming.InputReply.toString,
session = session
))
.withContentString(InputReply(expected))
.withContentString(InputReply("ok", expected))
.build

// Add our fake sender actor to the receiving end of the message
Expand All @@ -125,7 +125,7 @@ class InputRequestReplyHandlerSpec
msg_type = MessageType.Incoming.InputReply.toString,
session = session
))
.withContentString(InputReply(expected))
.withContentString(InputReply("ok", expected))
.build

fakeSender.send(inputRequestReplyHandler, inputReplyMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import org.apache.toree.kernel.protocol.v5.KernelMessageContent
import play.api.libs.json.Json

case class CommInfoReply(
status: String,
comms: Map[String, Map[String, String]]
) extends KernelMessageContent {
) extends KernelMessageContent with ReplyContent {
override def content : String =
Json.toJson(this)(CommInfoReply.commInfoReplyWrites).toString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ case class CompleteReply (
ename: Option[String],
evalue: Option[String],
traceback: Option[List[String]]
) extends KernelMessageContent {
) extends KernelMessageContent with ReplyContent {
override def content : String =
Json.toJson(this)(CompleteReply.completeReplyWrites).toString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ package org.apache.toree.kernel.protocol.v5.content
import org.apache.toree.kernel.protocol.v5.KernelMessageContent
import play.api.libs.json.Json

@deprecated(
"""Deprecated since version 5.1: connect_request/reply have not proved useful, and are
|considered deprecated. Kernels are not expected to implement handlers for this message.
|""".stripMargin)
case class ConnectReply(
shell_port: Int,
iopub_port: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ package org.apache.toree.kernel.protocol.v5.content
import org.apache.toree.kernel.protocol.v5.KernelMessageContent
import play.api.libs.json._

@deprecated(
"""Deprecated since version 5.1: connect_request/reply have not proved useful, and are
|considered deprecated. Kernels are not expected to implement handlers for this message.
|""".stripMargin)
case class ConnectRequest() extends KernelMessageContent {
override def content : String =
Json.toJson(this)(ConnectRequest.connectRequestWrites).toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ case class ExecuteReply(
ename: Option[String],
evalue: Option[String],
traceback: Option[List[String]]
) extends KernelMessageContent {
) extends KernelMessageContent with ReplyContent {

override def content : String =
Json.toJson(this)(ExecuteReply.executeReplyWrites).toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import play.api.libs.json.Json


case class HistoryReply(
status: String,
// TODO: This is really (String, String, String | (String, String)), look
// TODO: into writing implicits to handle tuples

// NOTE: Currently, only handle (String, String, String)
history: List[String]
) extends KernelMessageContent {
) extends KernelMessageContent with ReplyContent {
override def content : String =
Json.toJson(this)(HistoryReply.historyReplyWrites).toString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import org.apache.toree.kernel.protocol.v5.KernelMessageContent
import play.api.libs.json._

case class InputReply(
status: String,
value: String
) extends KernelMessageContent {
) extends KernelMessageContent with ReplyContent{
override def content : String =
Json.toJson(this)(InputReply.inputReplyWrites).toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ case class InspectReply(
ename: Option[String],
evalue: Option[String],
traceback: Option[List[String]]
) extends KernelMessageContent {
) extends KernelMessageContent with ReplyContent {
override def content : String =
Json.toJson(this)(InspectReply.inspectReplyOkWrites).toString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

package org.apache.toree.kernel.protocol.v5.content

import org.apache.toree.kernel.protocol.v5.{KernelMessageContent}
import org.apache.toree.kernel.protocol.v5.KernelMessageContent
import play.api.libs.json.{Json, Reads, Writes}

case class IsCompleteReply (
status: String,
indent: String
) extends KernelMessageContent {
case class IsCompleteReply(
status: String,
indent: String
) extends KernelMessageContent with ReplyContent {
override def content : String =
Json.toJson(this)(IsCompleteReply.isCompleteReplyWrites).toString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import org.apache.toree.kernel.protocol.v5.LanguageInfo
import play.api.libs.json.Json

case class KernelInfoReply (
status: String,
protocol_version: String,
implementation: String,
implementation_version: String,
language_info: LanguageInfo,
banner: String
) extends KernelMessageContent {
) extends KernelMessageContent with ReplyContent {
override def content: String =
Json.toJson(this)(KernelInfoReply.kernelInfoReplyWrites).toString
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/

package org.apache.toree.kernel.protocol.v5.content

import org.apache.toree.kernel.protocol.v5.KernelMessageContent

/**
* Represents a series of subclasses of KernelMessageContent that embodies the
* xyzReply content types.
*/
trait ReplyContent {
this: KernelMessageContent =>

def status: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import org.apache.toree.kernel.protocol.v5.KernelMessageContent
import play.api.libs.json.Json

case class ShutdownReply(
status: String,
restart: Boolean
) extends KernelMessageContent {
) extends KernelMessageContent with ReplyContent {
override def content : String =
Json.toJson(this)(ShutdownReply.shutdownReplyWrites).toString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import org.apache.toree.kernel.protocol.v5._
class HistoryReplySpec extends FunSpec with Matchers {
val historyReplyJson: JsValue = Json.parse("""
{
"status": "ok",
"history": ["<STRING>", "<STRING2>", "<STRING3>"]
}
""")

val historyReply = HistoryReply(
"ok",
List("<STRING>", "<STRING2>", "<STRING3>")
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import play.api.libs.json._
class InputReplySpec extends FunSpec with Matchers {
val inputReplyJson: JsValue = Json.parse("""
{
"status": "ok",
"value": "<STRING>"
}
""")

val inputReply = InputReply(
"ok",
"<STRING>"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import play.api.libs.json._
class KernelInfoReplySpec extends FunSpec with Matchers {
val kernelInfoReplyJson: JsValue = Json.parse("""
{
"status": "ok",
"protocol_version": "x.y.z",
"implementation": "<name>",
"implementation_version": "z.y.x",
Expand All @@ -34,7 +35,7 @@ class KernelInfoReplySpec extends FunSpec with Matchers {
""")

val kernelInfoReply: KernelInfoReply = KernelInfoReply(
"x.y.z", "<name>", "z.y.x", LanguageInfo("<some language>", "a.b.c", Some("<some extension>")), "<some banner>"
"ok", "x.y.z", "<name>", "z.y.x", LanguageInfo("<some language>", "a.b.c", Some("<some extension>")), "<some banner>"
)

describe("KernelInfoReply") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import play.api.libs.json._
class ShutdownReplySpec extends FunSpec with Matchers {
val shutdownReplyJson: JsValue = Json.parse("""
{
"status": "ok",
"restart": true
}
""")

val shutdownReply: ShutdownReply = ShutdownReply(
"ok",
true
)

Expand Down

0 comments on commit 7fb3869

Please sign in to comment.