Search in sources :

Example 1 with AggregateException

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++;
            }
        }
    }
}
Also used : AggregateException(com.microsoft.frameworklauncher.common.exceptions.AggregateException) AggregateException(com.microsoft.frameworklauncher.common.exceptions.AggregateException)

Example 2 with AggregateException

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());
}
Also used : AggregateException(com.microsoft.frameworklauncher.common.exceptions.AggregateException) NonTransientException(com.microsoft.frameworklauncher.common.exceptions.NonTransientException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) AggregateException(com.microsoft.frameworklauncher.common.exceptions.AggregateException) NotAvailableException(com.microsoft.frameworklauncher.common.exceptions.NotAvailableException)

Aggregations

AggregateException (com.microsoft.frameworklauncher.common.exceptions.AggregateException)2 NonTransientException (com.microsoft.frameworklauncher.common.exceptions.NonTransientException)1 NotAvailableException (com.microsoft.frameworklauncher.common.exceptions.NotAvailableException)1 IOException (java.io.IOException)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1