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

This commit is contained in:
Billie Rinaldi 2017-05-26 12:15:28 -07:00 committed by Jian He
parent a0574e7f4f
commit a0b9e8a630

View File

@ -230,6 +230,9 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe
@SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized") @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized")
private RegistryOperations registryOperations; private RegistryOperations registryOperations;
private static EnumSet<YarnApplicationState> terminatedStates = EnumSet
.of(YarnApplicationState.FINISHED, YarnApplicationState.FAILED,
YarnApplicationState.KILLED);
/** /**
* Constructor * Constructor
*/ */
@ -699,7 +702,7 @@ private ApplicationId submitApp(Application app)
//TODO set retry window //TODO set retry window
submissionContext.setResource(Resource.newInstance( submissionContext.setResource(Resource.newInstance(
conf.getLong(KEY_AM_RESOURCE_MEM, DEFAULT_KEY_AM_RESOURCE_MEM), 1)); 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.setApplicationName(appName);
submissionContext.setApplicationType(SliderKeys.APP_TYPE); submissionContext.setApplicationType(SliderKeys.APP_TYPE);
Set<String> appTags = Set<String> appTags =
@ -1725,9 +1728,8 @@ public int actionStop(String appName, ActionFreezeArgs freezeArgs)
"Application " + appName + " doesn't exist in RM."); "Application " + appName + " doesn't exist in RM.");
} }
if (app.getYarnApplicationState().ordinal() >= YarnApplicationState.FINISHED if (terminatedStates.contains(app.getYarnApplicationState())) {
.ordinal()) { log.info("Application {} is already in a terminated state {}", appName,
log.info("Application {} is in a terminated state {}", appName,
app.getYarnApplicationState()); app.getYarnApplicationState());
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@ -1738,8 +1740,30 @@ public int actionStop(String appName, ActionFreezeArgs freezeArgs)
Messages.StopClusterRequestProto.newBuilder() Messages.StopClusterRequestProto.newBuilder()
.setMessage(freezeArgs.message).build(); .setMessage(freezeArgs.message).build();
appMaster.stopCluster(r); appMaster.stopCluster(r);
log.info("Application " + appName + " is gracefully stopped."); log.info("Application " + appName + " is being gracefully stopped...");
} catch (IOException | YarnException e){ 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 log.info("Failed to stop " + appName
+ " gracefully, forcefully kill the app."); + " gracefully, forcefully kill the app.");
yarnClient.killApplication(app.getApplicationId(), freezeArgs.message); yarnClient.killApplication(app.getApplicationId(), freezeArgs.message);