vanzin commented on a change in pull request #19616: [SPARK-22404][YARN] Provide an option to use unmanaged AM in yarn-client mode URL: https://github.com/apache/spark/pull/19616#discussion_r242716228
########## File path: resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala ########## @@ -1098,14 +1109,39 @@ private[spark] class Client( if (returnOnRunning && state == YarnApplicationState.RUNNING) { return createAppReport(report) } - + if (state == YarnApplicationState.ACCEPTED && isClientUnmanagedAMEnabled + && !amServiceStarted && report.getAMRMToken != null) { + amServiceStarted = true + startApplicationMasterService(report) + } lastState = state } // Never reached, but keeps compiler happy throw new SparkException("While loop is depleted! This should never happen...") } + private def startApplicationMasterService(report: ApplicationReport) = { + // Add AMRMToken to establish connection between RM and AM + val token = report.getAMRMToken + val amRMToken: org.apache.hadoop.security.token.Token[AMRMTokenIdentifier] = + new org.apache.hadoop.security.token.Token[AMRMTokenIdentifier]( + token.getIdentifier().array(), token.getPassword().array, + new Text(token.getKind()), new Text(token.getService())) + val currentUGI = UserGroupInformation.getCurrentUser + currentUGI.addToken(amRMToken) + + sparkConf.set("spark.yarn.containerId", + ContainerId.newContainerId(report.getCurrentApplicationAttemptId, 1).toString) + // Start Application Service in a separate thread and continue with application monitoring + val amService = new Thread("Unmanaged Application Master Service") { + override def run(): Unit = new ApplicationMaster(new ApplicationMasterArguments(Array.empty), Review comment: This is a pretty long line. Break it down. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org