cxzl25 commented on code in PR #5868: URL: https://github.com/apache/kyuubi/pull/5868#discussion_r1433654439
########## externals/kyuubi-hive-sql-engine/src/main/scala/org/apache/kyuubi/engine/hive/deploy/ApplicationMaster.scala: ########## @@ -0,0 +1,118 @@ +/* + * 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.engine.hive.deploy + +import org.apache.hadoop.yarn.api.records.FinalApplicationStatus +import org.apache.hadoop.yarn.client.api.AMRMClient +import org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest +import org.apache.hadoop.yarn.conf.YarnConfiguration + +import org.apache.kyuubi.{Logging, Utils} +import org.apache.kyuubi.config.KyuubiConf +import org.apache.kyuubi.engine.hive.{HiveSQLEngine, HiveTBinaryFrontendService} +import org.apache.kyuubi.util.KyuubiHadoopUtils + +object ApplicationMaster extends Logging { + + private var amClient: AMRMClient[ContainerRequest] = _ + private var yarnConf: YarnConfiguration = _ + + private var currentEngine: HiveSQLEngine = _ + private val kyuubiConf = new KyuubiConf() + + private var finalMsg: String = _ + + @volatile private var registered: Boolean = false + @volatile private var unregistered: Boolean = false + @volatile private var finalStatus = FinalApplicationStatus.UNDEFINED + + def main(args: Array[String]): Unit = { + try { + kyuubiConf.loadFileDefaults() + yarnConf = KyuubiHadoopUtils.newYarnConfiguration(kyuubiConf) + Utils.addShutdownHook(() => { + if (!unregistered) { + if (currentEngine != null && currentEngine.selfExist) { + finalMsg = "Kyuubi Application Master is shutting down." + finalStatus = FinalApplicationStatus.SUCCEEDED + } else { + finalMsg = "Kyuubi Application Master is shutting down with error." + finalStatus = FinalApplicationStatus.FAILED + } + unregister(finalStatus, finalMsg) + } + }) + runApplicationMaster(args) + } catch { + case t: Throwable => + error("Error running ApplicationMaster", t) + finalStatus = FinalApplicationStatus.FAILED + finalMsg = t.getMessage + unregister(finalStatus, finalMsg) + if (currentEngine != null) { + currentEngine.stop() + } + } + } + + def runApplicationMaster(args: Array[String]): Unit = { + amClient = AMRMClient.createAMRMClient() + amClient.init(yarnConf) + amClient.start() + + runHiveEngine(args) + + registryAM() + } + + def runHiveEngine(args: Array[String]): Unit = { + HiveSQLEngine.runEngine(args) + currentEngine = HiveSQLEngine.getCurrentEngine + } + + def initAmClient(): Unit = { + amClient = AMRMClient.createAMRMClient() + amClient.init(yarnConf) + amClient.start() + } + + def registryAM(): Unit = { Review Comment: ```suggestion def registerAM(): Unit = { ``` ########## externals/kyuubi-hive-sql-engine/src/main/scala/org/apache/kyuubi/engine/hive/deploy/ApplicationMaster.scala: ########## @@ -0,0 +1,118 @@ +/* + * 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.engine.hive.deploy + +import org.apache.hadoop.yarn.api.records.FinalApplicationStatus +import org.apache.hadoop.yarn.client.api.AMRMClient +import org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest +import org.apache.hadoop.yarn.conf.YarnConfiguration + +import org.apache.kyuubi.{Logging, Utils} +import org.apache.kyuubi.config.KyuubiConf +import org.apache.kyuubi.engine.hive.{HiveSQLEngine, HiveTBinaryFrontendService} +import org.apache.kyuubi.util.KyuubiHadoopUtils + +object ApplicationMaster extends Logging { + + private var amClient: AMRMClient[ContainerRequest] = _ + private var yarnConf: YarnConfiguration = _ + + private var currentEngine: HiveSQLEngine = _ + private val kyuubiConf = new KyuubiConf() + + private var finalMsg: String = _ + + @volatile private var registered: Boolean = false + @volatile private var unregistered: Boolean = false + @volatile private var finalStatus = FinalApplicationStatus.UNDEFINED + + def main(args: Array[String]): Unit = { + try { + kyuubiConf.loadFileDefaults() + yarnConf = KyuubiHadoopUtils.newYarnConfiguration(kyuubiConf) + Utils.addShutdownHook(() => { + if (!unregistered) { + if (currentEngine != null && currentEngine.selfExist) { + finalMsg = "Kyuubi Application Master is shutting down." + finalStatus = FinalApplicationStatus.SUCCEEDED + } else { + finalMsg = "Kyuubi Application Master is shutting down with error." + finalStatus = FinalApplicationStatus.FAILED + } + unregister(finalStatus, finalMsg) + } + }) + runApplicationMaster(args) + } catch { + case t: Throwable => + error("Error running ApplicationMaster", t) + finalStatus = FinalApplicationStatus.FAILED + finalMsg = t.getMessage + unregister(finalStatus, finalMsg) + if (currentEngine != null) { + currentEngine.stop() + } + } + } + + def runApplicationMaster(args: Array[String]): Unit = { + amClient = AMRMClient.createAMRMClient() + amClient.init(yarnConf) + amClient.start() Review Comment: ```suggestion initAmClient() ``` -- 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]
