Skip to content

Commit 726e557

Browse files
committed
upsert
1 parent 137e243 commit 726e557

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import org.apache.kyuubi.engine.ApplicationState.{isTerminated, ApplicationState
3838
import org.apache.kyuubi.engine.KubernetesResourceEventTypes.KubernetesResourceEventType
3939
import org.apache.kyuubi.operation.OperationState
4040
import org.apache.kyuubi.server.KyuubiServer
41+
import org.apache.kyuubi.server.metadata.api.KubernetesMetadata
4142
import org.apache.kyuubi.session.KyuubiSessionManager
4243
import org.apache.kyuubi.util.{KubernetesUtils, ThreadUtils}
4344

@@ -336,7 +337,7 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
336337
updateApplicationState(kubernetesInfo, newPod, eventType)
337338
val appState = toApplicationState(newPod, appStateSource, appStateContainer, eventType)
338339
if (isTerminated(appState)) {
339-
markApplicationTerminated(newPod, eventType)
340+
markApplicationTerminated(kubernetesInfo, newPod, eventType)
340341
}
341342
KubernetesApplicationAuditLogger.audit(
342343
eventType,
@@ -354,7 +355,7 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
354355
if (isSparkEnginePod(pod)) {
355356
val eventType = KubernetesResourceEventTypes.DELETE
356357
updateApplicationState(kubernetesInfo, pod, eventType)
357-
markApplicationTerminated(pod, eventType)
358+
markApplicationTerminated(kubernetesInfo, pod, eventType)
358359
KubernetesApplicationAuditLogger.audit(
359360
eventType,
360361
kubernetesInfo,
@@ -450,13 +451,24 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
450451
}
451452

452453
private def markApplicationTerminated(
454+
kubernetesInfo: KubernetesInfo,
453455
pod: Pod,
454456
eventType: KubernetesResourceEventType): Unit = synchronized {
455457
val key = pod.getMetadata.getLabels.get(LABEL_KYUUBI_UNIQUE_KEY)
458+
val (appState, appError) =
459+
toApplicationStateAndError(pod, appStateSource, appStateContainer, eventType)
460+
// upsert the kubernetes metadata when the application is terminated
461+
metadataManager.foreach(_.upsertKubernetesMetadata(
462+
KubernetesMetadata(
463+
identifier = key,
464+
context = kubernetesInfo.context,
465+
namespace = kubernetesInfo.namespace,
466+
podName = pod.getMetadata.getName,
467+
appId = pod.getMetadata.getLabels.get(SPARK_APP_ID_LABEL),
468+
appState = appState.toString,
469+
appError = appError)))
456470
if (cleanupTerminatedAppInfoTrigger.getIfPresent(key) == null) {
457-
cleanupTerminatedAppInfoTrigger.put(
458-
key,
459-
toApplicationState(pod, appStateSource, appStateContainer, eventType))
471+
cleanupTerminatedAppInfoTrigger.put(key, appState)
460472
}
461473
}
462474

kyuubi-server/src/main/scala/org/apache/kyuubi/server/metadata/api/KubernetesMetadata.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ package org.apache.kyuubi.server.metadata.api
2323
* @param identifier the kubernetes unique identifier.
2424
* @param context the kubernetes context.
2525
* @param namespace the kubernetes namespace.
26-
* @param pod the kubernetes pod name.
26+
* @param podName the kubernetes pod name.
2727
* @param appId the application id.
2828
* @param appState the application state.
2929
* @param appError the application error diagnose.
@@ -34,7 +34,7 @@ case class KubernetesMetadata(
3434
identifier: String,
3535
context: Option[String],
3636
namespace: Option[String],
37-
pod: String,
37+
podName: String,
3838
appId: String,
3939
appState: String,
4040
appError: Option[String],

kyuubi-server/src/main/scala/org/apache/kyuubi/server/metadata/jdbc/JDBCMetadataStore.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ class JDBCMetadataStore(conf: KyuubiConf) extends MetadataStore with Logging {
429429
|pod_name,
430430
|app_id,
431431
|app_state,
432-
|app_error
432+
|app_error,
433+
|create_time
433434
|)
434435
|VALUES(?, ?, ?, ?, ?, ?, ?)
435436
|WHERE NOT EXISTS (
@@ -443,10 +444,11 @@ class JDBCMetadataStore(conf: KyuubiConf) extends MetadataStore with Logging {
443444
metadata.identifier,
444445
metadata.context.orNull,
445446
metadata.namespace.orNull,
446-
metadata.pod,
447+
metadata.podName,
447448
metadata.appId,
448449
metadata.appState,
449450
metadata.appError.orNull,
451+
System.currentTimeMillis(),
450452
metadata.identifier)
451453
}
452454
}
@@ -465,7 +467,7 @@ class JDBCMetadataStore(conf: KyuubiConf) extends MetadataStore with Logging {
465467
setClauses += "namespace = ?"
466468
params += namespace
467469
}
468-
Option(metadata.pod).foreach { pod =>
470+
Option(metadata.podName).foreach { pod =>
469471
setClauses += "pod = ?"
470472
params += pod
471473
}
@@ -605,7 +607,7 @@ class JDBCMetadataStore(conf: KyuubiConf) extends MetadataStore with Logging {
605607
identifier = identifier,
606608
context = context,
607609
namespace = namespace,
608-
pod = pod,
610+
podName = pod,
609611
appId = appId,
610612
appState = appState,
611613
appError = appError,

0 commit comments

Comments
 (0)