in thriftserver/server/src/main/scala/org/apache/livy/thriftserver/LivyThriftSessionManager.scala [161:209]
def getOrCreateLivySession(
sessionHandle: SessionHandle,
sessionId: Option[Int],
sessionName: Option[String],
username: String,
createLivySession: () => InteractiveSession): InteractiveSession = {
sessionId match {
case Some(id) =>
server.livySessionManager.get(id) match {
case None =>
warn(s"InteractiveSession $id doesn't exist.")
throw new IllegalArgumentException(s"Session $id doesn't exist.")
case Some(session) if !server.isAllowedToUse(username, session) =>
warn(s"$username has no modify permissions to InteractiveSession $id.")
throw new IllegalAccessException(
s"$username is not allowed to use InteractiveSession $id.")
case Some(session) =>
if (session.state.isActive) {
info(s"Reusing Session $id for $sessionHandle.")
session
} else {
warn(s"InteractiveSession $id is not active anymore.")
throw new IllegalArgumentException(s"Session $id is not active anymore.")
}
}
case None =>
sessionName match {
case Some(name) =>
server.livySessionManager.get(name) match {
case None =>
createLivySession()
case Some(session) if !server.isAllowedToUse(username, session) =>
warn(s"$username has no modify permissions to InteractiveSession $name.")
throw new IllegalAccessException(
s"$username is not allowed to use InteractiveSession $name.")
case Some(session) =>
if (session.state.isActive) {
info(s"Reusing Session $name for $sessionHandle.")
session
} else {
warn(s"InteractiveSession $name is not active anymore.")
throw new IllegalArgumentException(s"Session $name is not active anymore.")
}
}
case None =>
createLivySession()
}
}
}