Search in sources :

Example 1 with UnsupportedTypeException

use of co.cask.common.internal.io.UnsupportedTypeException in project cdap by caskdata.

the class SparkRuntimeService method getShutdownHookRunnable.

@Nullable
private Runnable getShutdownHookRunnable(Object hookEntry) {
    try {
        // Post Hadoop-2.8, the entry is the ShutdownHookManager.HookEntry class
        if (!(hookEntry instanceof Runnable)) {
            Field hookField = hookEntry.getClass().getDeclaredField("hook");
            hookField.setAccessible(true);
            hookEntry = hookField.get(hookEntry);
        }
        if (hookEntry instanceof Runnable) {
            return (Runnable) hookEntry;
        }
        throw new UnsupportedTypeException("Hook entry is not a Runnable: " + hookEntry.getClass().getName());
    } catch (Exception e) {
        LOG.warn("Failed to get Spark shutdown hook Runnable from Hadoop ShutdownHookManager hook entry {} due to {}", hookEntry, e.toString());
    }
    return null;
}
Also used : Field(java.lang.reflect.Field) TxRunnable(co.cask.cdap.api.TxRunnable) TwillRunnable(org.apache.twill.api.TwillRunnable) UnsupportedTypeException(co.cask.common.internal.io.UnsupportedTypeException) URISyntaxException(java.net.URISyntaxException) UnsupportedTypeException(co.cask.common.internal.io.UnsupportedTypeException) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Aggregations

TxRunnable (co.cask.cdap.api.TxRunnable)1 UnsupportedTypeException (co.cask.common.internal.io.UnsupportedTypeException)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 URISyntaxException (java.net.URISyntaxException)1 Nullable (javax.annotation.Nullable)1 TwillRunnable (org.apache.twill.api.TwillRunnable)1