From f8152e78cd9b5e9a9551821e1664b0270bccd336 Mon Sep 17 00:00:00 2001 From: Fei Wang Date: Wed, 7 Feb 2024 15:39:03 -0800 Subject: [PATCH] Show more info save --- .../apache/kyuubi/client/util/JsonUtils.java | 9 ++++++++ .../KubernetesApplicationOperation.scala | 22 +++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/util/JsonUtils.java b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/util/JsonUtils.java index 855a152803f..6d1d58e649b 100644 --- a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/util/JsonUtils.java +++ b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/util/JsonUtils.java @@ -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 fromJson(String json, Class clazz) { try { return MAPPER.readValue(json, clazz); diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala index 6afe3257be9..4209323edd4 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala @@ -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 @@ -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 } @@ -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