209209 * The state machine is encapsulated in the implementation of Job interface.
210210 * All state changes happens via Job interface. Each event
211211 * results in a Finite State Transition in Job.
212- *
212+ * <p>
213213 * Tez DAG AppMaster is the composition of loosely coupled services. The services
214214 * interact with each other via events. The components resembles the
215215 * Actors model. The component acts on received event and send out the
216216 * events to other components.
217217 * This keeps it highly concurrent with no or minimal synchronization needs.
218- *
218+ * <p>
219219 * The events are dispatched by a central Dispatch mechanism. All components
220220 * register to the Dispatcher.
221- *
221+ * <p>
222222 * The information is shared across different components using AppContext.
223223 */
224224
@@ -245,9 +245,6 @@ public class DAGAppMaster extends AbstractService {
245245 private String appName ;
246246 private final ApplicationAttemptId appAttemptID ;
247247 private final ContainerId containerID ;
248- private final String nmHost ;
249- private final int nmPort ;
250- private final int nmHttpPort ;
251248 private final String workingDirectory ;
252249 private final String [] localDirs ;
253250 private final String [] logDirs ;
@@ -309,6 +306,7 @@ public class DAGAppMaster extends AbstractService {
309306
310307 private ListeningExecutorService execService ;
311308 private final PluginManager pluginManager ;
309+ private final NodeContext nodeContext ;
312310
313311
314312 /**
@@ -344,20 +342,19 @@ public class DAGAppMaster extends AbstractService {
344342 private TezDAGHook [] hooks = {};
345343
346344 public DAGAppMaster (ApplicationAttemptId applicationAttemptId ,
347- ContainerId containerId , String nmHost , int nmPort , int nmHttpPort ,
345+ ContainerId containerId ,
348346 Clock clock , long appSubmitTime , boolean isSession , String workingDirectory ,
349347 String [] localDirs , String [] logDirs , String clientVersion ,
350- Credentials credentials , String jobUserName , AMPluginDescriptorProto pluginDescriptorProto ) {
348+ Credentials credentials , String jobUserName , AMPluginDescriptorProto pluginDescriptorProto ,
349+ NodeContext nodeContext ) {
351350 super (DAGAppMaster .class .getName ());
352351 this .mdcContext = LoggingUtils .setupLog4j ();
353352 this .clock = clock ;
354353 this .startTime = clock .getTime ();
355354 this .appSubmitTime = appSubmitTime ;
356355 this .appAttemptID = applicationAttemptId ;
357356 this .containerID = containerId ;
358- this .nmHost = nmHost ;
359- this .nmPort = nmPort ;
360- this .nmHttpPort = nmHttpPort ;
357+ this .nodeContext = nodeContext ;
361358 this .state = DAGAppMasterState .NEW ;
362359 this .isSession = isSession ;
363360 this .workingDirectory = workingDirectory ;
@@ -371,9 +368,6 @@ public DAGAppMaster(ApplicationAttemptId applicationAttemptId,
371368 .createRemoteUser (jobUserName );
372369 this .appMasterUgi .addCredentials (amCredentials );
373370
374- this .containerLogs = getRunningLogURL (this .nmHost + ":" + this .nmHttpPort ,
375- this .containerID .toString (), this .appMasterUgi .getShortUserName ());
376-
377371 LOG .info ("Created DAGAppMaster for application " + applicationAttemptId
378372 + ", versionInfo=" + dagVersionInfo );
379373 TezCommonUtils .logCredentials (LOG , this .appMasterUgi .getCredentials (), "am" );
@@ -443,6 +437,14 @@ protected void serviceInit(final Configuration conf) throws Exception {
443437 this .isLocal = conf .getBoolean (TezConfiguration .TEZ_LOCAL_MODE ,
444438 TezConfiguration .TEZ_LOCAL_MODE_DEFAULT );
445439
440+ if (!isLocal ) {
441+ this .containerLogs =
442+ getRunningLogURL (
443+ nodeContext .nodeHost () + ":" + nodeContext .nodeHttpPort (),
444+ this .containerID .toString (),
445+ this .appMasterUgi .getShortUserName ());
446+ }
447+
446448 UserPayload defaultPayload = TezUtils .createUserPayloadFromConf (amConf );
447449
448450 PluginManager .PluginDescriptors pluginDescriptors = pluginManager .parseAllPlugins (isLocal , defaultPayload );
@@ -1207,15 +1209,7 @@ public ContainerId getAppContainerId() {
12071209 }
12081210
12091211 public String getAppNMHost () {
1210- return nmHost ;
1211- }
1212-
1213- public int getAppNMPort () {
1214- return nmPort ;
1215- }
1216-
1217- public int getAppNMHttpPort () {
1218- return nmHttpPort ;
1212+ return nodeContext .nodeHost ();
12191213 }
12201214
12211215 public int getRpcPort () {
@@ -2415,13 +2409,15 @@ public static void main(String[] args) {
24152409 // Install the tez class loader, which can be used add new resources
24162410 TezClassLoader .setupTezClassLoader ();
24172411 Thread .setDefaultUncaughtExceptionHandler (new YarnUncaughtExceptionHandler ());
2418- final String pid = System .getenv ().get ("JVM_PID" );
24192412
2420- String nodeHostString = System .getenv (ApplicationConstants .Environment .NM_HOST .name ());
2421- String nodePortString = System .getenv (ApplicationConstants .Environment .NM_PORT .name ());
2422- String nodeHttpPortString = System .getenv (ApplicationConstants .Environment .NM_HTTP_PORT .name ());
2413+ final String pid = System .getenv ().get ("JVM_PID" );
24232414 String appSubmitTimeStr = System .getenv (ApplicationConstants .APP_SUBMIT_TIME_ENV );
24242415 String clientVersion = System .getenv (TezConstants .TEZ_CLIENT_VERSION_ENV );
2416+ String jobUserName = System .getenv (ApplicationConstants .Environment .USER .name ());
2417+ String pwd = System .getenv (ApplicationConstants .Environment .PWD .name ());
2418+ String localDirs = System .getenv (ApplicationConstants .Environment .LOCAL_DIRS .name ());
2419+ String logDirs = System .getenv (ApplicationConstants .Environment .LOG_DIRS .name ());
2420+
24252421 if (clientVersion == null ) {
24262422 clientVersion = VersionInfo .UNKNOWN ;
24272423 }
@@ -2431,18 +2427,20 @@ public static void main(String[] args) {
24312427
24322428 Configuration conf = new Configuration ();
24332429
2434- AMExtensions amExtensions = getFrameworkService (conf ).getAMExtensions ();
2430+ ServerFrameworkService frameworkService = getFrameworkService (conf );
2431+ AMExtensions amExtensions = frameworkService .getAMExtensions ();
24352432 DAGProtos .ConfigurationProto confProto = amExtensions .loadConfigurationProto ();
24362433 TezUtilsInternal .addUserSpecifiedTezConfiguration (conf , confProto .getConfKeyValuesList ());
24372434
2435+ NodeContext nodeContext = frameworkService .getNodeContext ();
2436+
24382437 ContainerId containerId = amExtensions .allocateContainerId (conf );
24392438
24402439 ApplicationAttemptId applicationAttemptId = containerId .getApplicationAttemptId ();
24412440 org .apache .hadoop .ipc .CallerContext .setCurrent (new org .apache .hadoop .ipc .CallerContext
24422441 .Builder ("tez_appmaster_" + containerId .getApplicationAttemptId ()
24432442 ).build ());
24442443 long appSubmitTime = Long .parseLong (appSubmitTimeStr );
2445- String jobUserName = System .getenv (ApplicationConstants .Environment .USER .name ());
24462444
24472445 // Command line options
24482446 Option option = Option .builder ()
@@ -2462,9 +2460,9 @@ public static void main(String[] args) {
24622460 + ", jvmPid=" + pid
24632461 + ", userFromEnv=" + jobUserName
24642462 + ", cliSessionOption=" + sessionModeCliOption
2465- + ", pwd=" + System . getenv ( ApplicationConstants . Environment . PWD . name ())
2466- + ", localDirs=" + System . getenv ( ApplicationConstants . Environment . LOCAL_DIRS . name ())
2467- + ", logDirs=" + System . getenv ( ApplicationConstants . Environment . LOG_DIRS . name ()) );
2463+ + ", pwd=" + pwd
2464+ + ", localDirs=" + localDirs
2465+ + ", logDirs=" + logDirs );
24682466
24692467 AMPluginDescriptorProto amPluginDescriptorProto = null ;
24702468 if (confProto .hasAmPluginDescriptor ()) {
@@ -2477,20 +2475,26 @@ public static void main(String[] args) {
24772475 TezUtilsInternal .setSecurityUtilConfigration (LOG , conf );
24782476
24792477 DAGAppMaster appMaster =
2480- new DAGAppMaster (applicationAttemptId , containerId , nodeHostString , Integer .parseInt (nodePortString ),
2481- Integer .parseInt (nodeHttpPortString ), new SystemClock (), appSubmitTime , sessionModeCliOption ,
2482- System .getenv (ApplicationConstants .Environment .PWD .name ()),
2483- TezCommonUtils .getTrimmedStrings (System .getenv (ApplicationConstants .Environment .LOCAL_DIRS .name ())),
2484- TezCommonUtils .getTrimmedStrings (System .getenv (ApplicationConstants .Environment .LOG_DIRS .name ())),
2485- clientVersion , credentials , jobUserName , amPluginDescriptorProto );
2478+ new DAGAppMaster (
2479+ applicationAttemptId ,
2480+ containerId ,
2481+ new SystemClock (),
2482+ appSubmitTime ,
2483+ sessionModeCliOption ,
2484+ pwd ,
2485+ TezCommonUtils .getTrimmedStrings (localDirs ),
2486+ TezCommonUtils .getTrimmedStrings (logDirs ),
2487+ clientVersion ,
2488+ credentials ,
2489+ jobUserName ,
2490+ amPluginDescriptorProto ,
2491+ nodeContext );
24862492 ShutdownHookManager .get ().addShutdownHook (new DAGAppMasterShutdownHook (appMaster ), SHUTDOWN_HOOK_PRIORITY );
24872493
24882494 // log the system properties
24892495 if (LOG .isInfoEnabled ()) {
24902496 String systemPropsToLog = TezCommonUtils .getSystemPropertiesToLog (conf );
2491- if (systemPropsToLog != null ) {
2492- LOG .info (systemPropsToLog );
2493- }
2497+ LOG .info (systemPropsToLog );
24942498 }
24952499
24962500 initAndStartAppMaster (appMaster , conf );
0 commit comments