You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tr...@apache.org on 2019/01/10 17:29:08 UTC

[flink] 02/02: [FLINK-11253] Factor out application report logging

This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit a07ce7f6c88dc7d0c0d2ba55a0ab3f2283bf247c
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Thu Jan 10 10:13:09 2019 +0100

    [FLINK-11253] Factor out application report logging
    
    Move final application report logging out of the shutdownCluster method. This allows
    to not log the final application report if the cluster is shut down via a shutdown hook.
    
    This closes #7414.
---
 .../apache/flink/yarn/cli/FlinkYarnSessionCli.java | 34 ++++++++++++++--------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/flink-yarn/src/main/java/org/apache/flink/yarn/cli/FlinkYarnSessionCli.java b/flink-yarn/src/main/java/org/apache/flink/yarn/cli/FlinkYarnSessionCli.java
index 673341e..57a59e6 100644
--- a/flink-yarn/src/main/java/org/apache/flink/yarn/cli/FlinkYarnSessionCli.java
+++ b/flink-yarn/src/main/java/org/apache/flink/yarn/cli/FlinkYarnSessionCli.java
@@ -652,8 +652,10 @@ public class FlinkYarnSessionCli extends AbstractCustomCommandLine<ApplicationId
 						yarnApplicationId,
 						new ScheduledExecutorServiceAdapter(scheduledExecutorService));
 					Thread shutdownHook = ShutdownHookUtil.addShutdownHook(
-						() -> shutdownCluster(yarnClusterDescriptor, clusterClient, scheduledExecutorService,
-							yarnApplicationStatusMonitor, yarnApplicationId),
+						() -> shutdownCluster(
+							clusterClient,
+							scheduledExecutorService,
+							yarnApplicationStatusMonitor),
 						getClass().getSimpleName(),
 						LOG);
 					try {
@@ -662,12 +664,19 @@ public class FlinkYarnSessionCli extends AbstractCustomCommandLine<ApplicationId
 							yarnApplicationStatusMonitor,
 							acceptInteractiveInput);
 					} finally {
-						shutdownCluster(yarnClusterDescriptor, clusterClient, scheduledExecutorService,
-							yarnApplicationStatusMonitor, yarnApplicationId);
+						shutdownCluster(
+							clusterClient,
+							scheduledExecutorService,
+							yarnApplicationStatusMonitor);
+
 						if (shutdownHook != null) {
 							// we do not need the hook anymore as we have just tried to shutdown the cluster.
 							ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);
 						}
+
+						tryRetrieveAndLogApplicationReport(
+							yarnClusterDescriptor.getYarnClient(),
+							yarnApplicationId);
 					}
 				}
 			}
@@ -682,9 +691,10 @@ public class FlinkYarnSessionCli extends AbstractCustomCommandLine<ApplicationId
 		return 0;
 	}
 
-	private void shutdownCluster(AbstractYarnClusterDescriptor yarnClusterDescriptor,
-		ClusterClient clusterClient, ScheduledExecutorService scheduledExecutorService,
-		YarnApplicationStatusMonitor yarnApplicationStatusMonitor, ApplicationId yarnApplicationId) {
+	private void shutdownCluster(
+			ClusterClient clusterClient,
+			ScheduledExecutorService scheduledExecutorService,
+			YarnApplicationStatusMonitor yarnApplicationStatusMonitor) {
 		try {
 			yarnApplicationStatusMonitor.close();
 		} catch (Exception e) {
@@ -706,24 +716,24 @@ public class FlinkYarnSessionCli extends AbstractCustomCommandLine<ApplicationId
 			scheduledExecutorService);
 
 		deleteYarnPropertiesFile();
+	}
 
+	private void tryRetrieveAndLogApplicationReport(YarnClient yarnClient, ApplicationId yarnApplicationId) {
 		ApplicationReport applicationReport;
 
 		try {
-			applicationReport = yarnClusterDescriptor
-				.getYarnClient()
-				.getApplicationReport(yarnApplicationId);
+			applicationReport = yarnClient.getApplicationReport(yarnApplicationId);
 		} catch (YarnException | IOException e) {
 			LOG.info("Could not log the final application report.", e);
 			applicationReport = null;
 		}
 
 		if (applicationReport != null) {
-			logFinalApplicationReport(applicationReport);
+			logApplicationReport(applicationReport);
 		}
 	}
 
-	private void logFinalApplicationReport(ApplicationReport appReport) {
+	private void logApplicationReport(ApplicationReport appReport) {
 		LOG.info("Application " + appReport.getApplicationId() + " finished with state " + appReport
 			.getYarnApplicationState() + " and final state " + appReport
 			.getFinalApplicationStatus() + " at " + appReport.getFinishTime());