YARN-6617. Services API delete call first attempt usually fails. Contributed by 
Jian He


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/c9d9c94c
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/c9d9c94c
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/c9d9c94c

Branch: refs/heads/yarn-native-services
Commit: c9d9c94cafe4ace6063d7fd04a6c39f06c1d9700
Parents: 5e96cb8
Author: Billie Rinaldi <bil...@apache.org>
Authored: Fri May 26 12:15:28 2017 -0700
Committer: Sunil G <sun...@apache.org>
Committed: Tue May 30 21:31:42 2017 +0530

----------------------------------------------------------------------
 .../org/apache/slider/client/SliderClient.java  | 36 ++++++++++++++++----
 1 file changed, 30 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/c9d9c94c/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/client/SliderClient.java
----------------------------------------------------------------------
diff --git 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/client/SliderClient.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/client/SliderClient.java
index 29ca471..a3ba8c0 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/client/SliderClient.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/client/SliderClient.java
@@ -230,6 +230,9 @@ public class SliderClient extends 
AbstractSliderLaunchedService implements RunSe
   @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized")
   private RegistryOperations registryOperations;
 
+  private static EnumSet<YarnApplicationState> terminatedStates = EnumSet
+      .of(YarnApplicationState.FINISHED, YarnApplicationState.FAILED,
+          YarnApplicationState.KILLED);
   /**
    * Constructor
    */
@@ -699,7 +702,7 @@ public class SliderClient extends 
AbstractSliderLaunchedService implements RunSe
     //TODO set retry window
     submissionContext.setResource(Resource.newInstance(
         conf.getLong(KEY_AM_RESOURCE_MEM, DEFAULT_KEY_AM_RESOURCE_MEM), 1));
-    submissionContext.setQueue(conf.get(KEY_YARN_QUEUE, DEFAULT_YARN_QUEUE));
+    submissionContext.setQueue(conf.get(KEY_YARN_QUEUE, app.getQueue()));
     submissionContext.setApplicationName(appName);
     submissionContext.setApplicationType(SliderKeys.APP_TYPE);
     Set<String> appTags =
@@ -1725,9 +1728,8 @@ public class SliderClient extends 
AbstractSliderLaunchedService implements RunSe
           "Application " + appName + " doesn't exist in RM.");
     }
 
-    if (app.getYarnApplicationState().ordinal() >= 
YarnApplicationState.FINISHED
-        .ordinal()) {
-      log.info("Application {} is in a terminated state {}", appName,
+    if (terminatedStates.contains(app.getYarnApplicationState())) {
+      log.info("Application {} is already in a terminated state {}", appName,
           app.getYarnApplicationState());
       return EXIT_SUCCESS;
     }
@@ -1738,8 +1740,30 @@ public class SliderClient extends 
AbstractSliderLaunchedService implements RunSe
           Messages.StopClusterRequestProto.newBuilder()
               .setMessage(freezeArgs.message).build();
       appMaster.stopCluster(r);
-      log.info("Application " + appName + " is gracefully stopped.");
-    } catch (IOException | YarnException e){
+      log.info("Application " + appName + " is being gracefully stopped...");
+      long startTime = System.currentTimeMillis();
+      int pollCount = 0;
+      while (true) {
+        Thread.sleep(200);
+        ApplicationReport report =
+            yarnClient.getApplicationReport(app.getApplicationId());
+        if (terminatedStates.contains(report.getYarnApplicationState())) {
+          log.info("Application " + appName + " is stopped.");
+          break;
+        }
+        // kill after 10 seconds.
+        if ((System.currentTimeMillis() - startTime) > 10000) {
+          log.info("Stop operation timeout stopping, forcefully kill the app "
+              + appName);
+          yarnClient
+              .killApplication(app.getApplicationId(), freezeArgs.message);
+          break;
+        }
+        if (++pollCount % 10 == 0) {
+          log.info("Waiting for application " + appName + " to be stopped.");
+        }
+      }
+    } catch (IOException | YarnException | InterruptedException e) {
       log.info("Failed to stop " + appName
           + " gracefully, forcefully kill the app.");
       yarnClient.killApplication(app.getApplicationId(), freezeArgs.message);


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to