turboFei commented on code in PR #2353: URL: https://github.com/apache/incubator-kyuubi/pull/2353#discussion_r850335339
########## kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiBatchSessionImpl.scala: ########## @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kyuubi.session + +import com.codahale.metrics.MetricRegistry +import org.apache.hive.service.rpc.thrift.TProtocolVersion + +import org.apache.kyuubi.config.KyuubiConf +import org.apache.kyuubi.events.{EventBus, KyuubiEvent, KyuubiSessionEvent} +import org.apache.kyuubi.metrics.MetricsConstants.{CONN_OPEN, CONN_TOTAL} +import org.apache.kyuubi.metrics.MetricsSystem +import org.apache.kyuubi.operation.OperationState +import org.apache.kyuubi.server.api.v1.BatchRequest + +class KyuubiBatchSessionImpl( + protocol: TProtocolVersion, + user: String, + password: String, + ipAddress: String, + conf: Map[String, String], + sessionManager: KyuubiSessionManager, + val sessionConf: KyuubiConf, + batchRequest: BatchRequest) + extends AbstractSession(protocol, user, password, ipAddress, conf, sessionManager) { + override val handle: SessionHandle = sessionManager.newBatchSessionHandle(protocol) + val batchId: String = handle.identifier.toString + + private[kyuubi] lazy val batchJobSubmissionOp = sessionManager.operationManager + .newBatchJobSubmissionOperation(this, batchRequest) + + private val sessionEvent = KyuubiSessionEvent(this) + EventBus.post(sessionEvent) + + override def getSessionEvent: Option[KyuubiEvent] = { + Option(sessionEvent) + } + + override def open(): Unit = { + MetricsSystem.tracing { ms => + ms.incCount(CONN_TOTAL) + ms.incCount(MetricRegistry.name(CONN_OPEN, user)) + } + + // we should call super.open before running batch job submission operation + super.open() + + runOperation(batchJobSubmissionOp) + } + + override def close(): Unit = { + if (!OperationState.isTerminal(batchJobSubmissionOp.getStatus.state)) { + closeOperation(batchJobSubmissionOp.getHandle) Review Comment: good question, I have thought about this. I think that, now the behavior in this PR is align with that of `spark-submit`. When closing the session, we destroy the spark-submit process builder. I think we do not need kill the running spark application for special. - for yarn-client or local mode, it will terminate the running application - For yarn-cluster mode, when using spark-submit, we might also cancel the spark-submit process, but it does not kill the running application. I think we can align with this. Users can make decision themself, they can get the applicationId of the batch, and then kill the application. - Or we can add an option to kill the application for `DELETE /batches/${batchId}?killApp=true` to kill the application -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
