Skip to content

Commit

Permalink
Revert c306090 and make state always lowercase
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chu <[email protected]>
  • Loading branch information
noCharger committed Aug 9, 2024
1 parent e11abc3 commit 949c654
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.opensearch.flint.common.model

import java.util.Locale

import org.json4s.{Formats, NoTypeHints}
import org.json4s.JsonAST.JString
import org.json4s.native.JsonMethods.parse
Expand Down Expand Up @@ -53,10 +55,13 @@ class FlintStatement(
def fail(): Unit = state = StatementStates.FAILED
def timeout(): Unit = state = StatementStates.TIMEOUT

def isRunning: Boolean = state == StatementStates.RUNNING
def isComplete: Boolean = state == StatementStates.SUCCESS
def isFailed: Boolean = state == StatementStates.FAILED
def isWaiting: Boolean = state == StatementStates.WAITING
def isRunning: Boolean = state.equalsIgnoreCase(StatementStates.RUNNING)

def isComplete: Boolean = state.equalsIgnoreCase(StatementStates.SUCCESS)

def isFailed: Boolean = state.equalsIgnoreCase(StatementStates.FAILED)

def isWaiting: Boolean = state.equalsIgnoreCase(StatementStates.WAITING)

// Does not include context, which could contain sensitive information.
override def toString: String =
Expand All @@ -69,7 +74,7 @@ object FlintStatement {

def deserialize(statement: String): FlintStatement = {
val meta = parse(statement)
val state = (meta \ "state").extract[String]
val state = (meta \ "state").extract[String].toLowerCase(Locale.ROOT)
val query = (meta \ "query").extract[String]
val statementId = (meta \ "statementId").extract[String]
val queryId = (meta \ "queryId").extract[String]
Expand All @@ -85,6 +90,8 @@ object FlintStatement {
def serialize(flintStatement: FlintStatement): String = {
// we only need to modify state and error
Serialization.write(
Map("state" -> flintStatement.state, "error" -> flintStatement.error.getOrElse("")))
Map(
"state" -> flintStatement.state.toLowerCase(Locale.ROOT),
"error" -> flintStatement.error.getOrElse("")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package org.opensearch.flint.common.model

import java.util.{Map => JavaMap}
import java.util.{Locale, Map => JavaMap}

import scala.collection.JavaConverters._

Expand Down Expand Up @@ -59,9 +59,11 @@ class InteractiveSession(
def complete(): Unit = state = SessionStates.DEAD
def fail(): Unit = state = SessionStates.FAIL

def isRunning: Boolean = state == SessionStates.RUNNING
def isComplete: Boolean = state == SessionStates.DEAD
def isFail: Boolean = state == SessionStates.FAIL
def isRunning: Boolean = state.equalsIgnoreCase(SessionStates.RUNNING)

def isComplete: Boolean = state.equalsIgnoreCase(SessionStates.DEAD)

def isFail: Boolean = state.equalsIgnoreCase(SessionStates.FAIL)

override def toString: String = {
val excludedJobIdsStr = excludedJobIds.mkString("[", ", ", "]")
Expand All @@ -79,7 +81,7 @@ object InteractiveSession {
def deserialize(job: String): InteractiveSession = {
val meta = parse(job)
val applicationId = (meta \ "applicationId").extract[String]
val state = (meta \ "state").extract[String]
val state = (meta \ "state").extract[String].toLowerCase(Locale.ROOT)
val jobId = (meta \ "jobId").extract[String]
val sessionId = (meta \ "sessionId").extract[String]
val lastUpdateTime = (meta \ "lastUpdateTime").extract[Long]
Expand Down Expand Up @@ -118,7 +120,7 @@ object InteractiveSession {
val scalaSource = source.asScala

val applicationId = scalaSource("applicationId").asInstanceOf[String]
val state = scalaSource("state").asInstanceOf[String]
val state = scalaSource("state").asInstanceOf[String].toLowerCase(Locale.ROOT)
val jobId = scalaSource("jobId").asInstanceOf[String]
val sessionId = scalaSource("sessionId").asInstanceOf[String]
val lastUpdateTime = scalaSource("lastUpdateTime").asInstanceOf[Long]
Expand Down Expand Up @@ -180,7 +182,7 @@ object InteractiveSession {
"sessionId" -> job.sessionId,
"error" -> job.error.getOrElse(""),
"applicationId" -> job.applicationId,
"state" -> job.state,
"state" -> job.state.toLowerCase(Locale.ROOT),
// update last update time
"lastUpdateTime" -> currentTime,
// Convert a Seq[String] into a comma-separated string, such as "id1,id2".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InteractiveSessionTest extends SparkFunSuite with Matchers {
instance.applicationId shouldBe "app-123"
instance.jobId shouldBe "job-456"
instance.sessionId shouldBe "session-789"
instance.state shouldBe "RUNNING"
instance.state shouldBe "running"
instance.lastUpdateTime shouldBe 1620000000000L
instance.jobStartTime shouldBe 1620000001000L
instance.excludedJobIds should contain allOf ("job-101", "job-202")
Expand All @@ -44,7 +44,7 @@ class InteractiveSessionTest extends SparkFunSuite with Matchers {
json should include(""""applicationId":"app-123"""")
json should not include (""""jobId":"job-456"""")
json should include(""""sessionId":"session-789"""")
json should include(""""state":"RUNNING"""")
json should include(""""state":"running"""")
json should include(s""""lastUpdateTime":$currentTime""")
json should include(
""""excludeJobIds":"job-101,job-202""""
Expand Down Expand Up @@ -149,7 +149,7 @@ class InteractiveSessionTest extends SparkFunSuite with Matchers {
instance.applicationId shouldBe "app-123"
instance.jobId shouldBe "job-456"
instance.sessionId shouldBe "session-789"
instance.state shouldBe "RUNNING"
instance.state shouldBe "running"
instance.lastUpdateTime shouldBe 1620000000000L
instance.jobStartTime shouldBe 0L // Default or expected value for missing jobStartTime
instance.excludedJobIds should contain allOf ("job-101", "job-202")
Expand Down

0 comments on commit 949c654

Please sign in to comment.