use of com.microsoft.frameworklauncher.common.exceptions.AggregateException in project pai by Microsoft.
the class RetryUtils method executeWithRetry.
public static <T> T executeWithRetry(Callable<T> action, int maxRetryCount, int retryIntervalSec, Predicate<Exception> shouldRetry) throws AggregateException, InterruptedException {
int retriedCount = 0;
AggregateException ae = new AggregateException();
while (true) {
try {
return action.call();
} catch (Exception e) {
ae.addException(e);
String logPrefix = String.format("Retry [%s / %s]: ", retriedCount, maxRetryCount);
if ((shouldRetry != null && !shouldRetry.test(e)) || (maxRetryCount != GlobalConstants.USING_UNLIMITED_VALUE && retriedCount >= maxRetryCount)) {
LOGGER.logError(e, logPrefix + "Failed Finally.");
throw ae;
} else {
LOGGER.logWarning(e, logPrefix + "Failed. Scheduled to Retry after %ss.", retryIntervalSec);
if (retryIntervalSec > 0) {
Thread.sleep(retryIntervalSec * 1000);
}
retriedCount++;
}
}
}
}
use of com.microsoft.frameworklauncher.common.exceptions.AggregateException in project pai by Microsoft.
the class ApplicationMaster method stop.
// THREAD SAFE
@Override
public synchronized void stop(StopStatus stopStatus) {
// Best Effort to stop Gracefully
super.stop(stopStatus);
AggregateException ae = new AggregateException();
// Since here is Best Effort, leave the GC work of zkStore and hdfsStore to LauncherService.
try {
if (yarnClient != null) {
yarnClient.stop();
}
} catch (Exception e) {
ae.addException(e);
}
try {
if (statusManager != null) {
statusManager.stop(stopStatus);
}
} catch (Exception e) {
ae.addException(e);
}
try {
if (requestManager != null) {
requestManager.stop(stopStatus);
}
} catch (Exception e) {
ae.addException(e);
}
// allowed to process the application, such as generate application's diagnostics.
try {
if (rmClient != null) {
if (stopStatus.getNeedUnregister()) {
LOGGER.logInfo("Unregistering %s to RM", serviceName);
rmClient.unregisterApplicationMaster(stopStatus.getCode() == 0 ? FinalApplicationStatus.SUCCEEDED : FinalApplicationStatus.FAILED, stopStatus.getDiagnostics(), conf.getAmTrackingUrl());
}
rmClient.stop();
}
} catch (Exception e) {
ae.addException(e);
}
if (ae.getExceptions().size() > 0) {
LOGGER.logWarning(ae, "Failed to stop %s gracefully", serviceName);
}
LOGGER.logInfo("%s stopped", serviceName);
System.exit(stopStatus.getCode());
}
Aggregations