Skip to content

Commit

Permalink
Show more info
Browse files Browse the repository at this point in the history
save
  • Loading branch information
turboFei committed Feb 8, 2024
1 parent 8c3f471 commit f8152e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public static String toJson(Object object) {
}
}

public static String toPrettyJson(Object object) {
try {
return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(object);
} catch (Exception e) {
throw new KyuubiRestException(
String.format("Failed to convert object(%s) to json", object), e);
}
}

public static <T> T fromJson(String json, Class<T> clazz) {
try {
return MAPPER.readValue(json, clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import io.fabric8.kubernetes.client.KubernetesClient
import io.fabric8.kubernetes.client.informers.{ResourceEventHandler, SharedIndexInformer}

import org.apache.kyuubi.{KyuubiException, Logging, Utils}
import org.apache.kyuubi.client.util.JsonUtils
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.{KubernetesApplicationStateSource, KubernetesCleanupDriverPodStrategy}
import org.apache.kyuubi.config.KyuubiConf.KubernetesApplicationStateSource.KubernetesApplicationStateSource
Expand Down Expand Up @@ -372,9 +373,18 @@ object KubernetesApplicationOperation extends Logging {
}
val applicationState = containerStateToBuildAppState.map(containerStateToApplicationState)
.getOrElse(podStateToApplicationState(pod.getStatus.getPhase))
val applicationError = containerStateToBuildAppState
.map(cs => containerStateToApplicationError(cs).map(r => s"$podName/$appStateContainer[$r]"))
.getOrElse(Option(pod.getStatus.getReason).map(r => s"$podName[$r]"))
val applicationError = if (ApplicationState.isFailed(applicationState)) {
containerStateToBuildAppState
.map(cs =>
s"""Pod: $podName
|Container: $appStateContainer
|ContainerStatus: ${JsonUtils.toPrettyJson(cs)}""".stripMargin)
.orElse(Some(
s"""Pod: $podName
|PodStatus: ${JsonUtils.toPrettyJson(pod.getStatus)}""".stripMargin))
} else {
None
}
applicationState -> applicationError
}

Expand All @@ -393,12 +403,6 @@ object KubernetesApplicationOperation extends Logging {
}
}

def containerStateToApplicationError(containerState: ContainerState): Option[String] = {
// https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-states
Option(containerState.getWaiting).map(_.getReason)
.orElse(Option(containerState.getTerminated).map(_.getReason))
}

def podStateToApplicationState(podState: String): ApplicationState = podState match {
// https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase
case "Pending" => PENDING
Expand Down

0 comments on commit f8152e7

Please sign in to comment.