Search in sources :

Example 46 with YarnRuntimeException

use of org.apache.hadoop.yarn.exceptions.YarnRuntimeException in project hadoop by apache.

the class AdHocLogDumper method dumpLogs.

public void dumpLogs(String level, int timePeriod) throws YarnRuntimeException, IOException {
    synchronized (lock) {
        if (logFlag) {
            LOG.info("Attempt to dump logs when appender is already running");
            throw new YarnRuntimeException("Appender is already dumping logs");
        }
        Level targetLevel = Level.toLevel(level);
        Log log = LogFactory.getLog(name);
        appenderLevels.clear();
        if (log instanceof Log4JLogger) {
            Logger packageLogger = ((Log4JLogger) log).getLogger();
            currentLogLevel = packageLogger.getLevel();
            Level currentEffectiveLevel = packageLogger.getEffectiveLevel();
            // make sure we can create the appender first
            Layout layout = new PatternLayout("%d{ISO8601} %p %c: %m%n");
            FileAppender fApp;
            File file = new File(System.getProperty("yarn.log.dir"), targetFilename);
            try {
                fApp = new FileAppender(layout, file.getAbsolutePath(), false);
            } catch (IOException ie) {
                LOG.warn("Error creating file, can't dump logs to " + file.getAbsolutePath(), ie);
                throw ie;
            }
            fApp.setName(AdHocLogDumper.AD_HOC_DUMPER_APPENDER);
            fApp.setThreshold(targetLevel);
            // level
            for (Enumeration appenders = Logger.getRootLogger().getAllAppenders(); appenders.hasMoreElements(); ) {
                Object obj = appenders.nextElement();
                if (obj instanceof AppenderSkeleton) {
                    AppenderSkeleton appender = (AppenderSkeleton) obj;
                    appenderLevels.put(appender.getName(), appender.getThreshold());
                    appender.setThreshold(currentEffectiveLevel);
                }
            }
            packageLogger.addAppender(fApp);
            LOG.info("Dumping adhoc logs for " + name + " to " + file.getAbsolutePath() + " for " + timePeriod + " milliseconds");
            packageLogger.setLevel(targetLevel);
            logFlag = true;
            TimerTask restoreLogLevel = new RestoreLogLevel();
            Timer restoreLogLevelTimer = new Timer();
            restoreLogLevelTimer.schedule(restoreLogLevel, timePeriod);
        }
    }
}
Also used : Log(org.apache.commons.logging.Log) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) IOException(java.io.IOException) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) File(java.io.File)

Example 47 with YarnRuntimeException

use of org.apache.hadoop.yarn.exceptions.YarnRuntimeException in project hadoop by apache.

the class RMProxy method createRetryPolicy.

/**
   * Fetch retry policy from Configuration and create the
   * retry policy with specified retryTime and retry interval.
   */
protected static RetryPolicy createRetryPolicy(Configuration conf, long retryTime, long retryInterval, boolean isHAEnabled) {
    long rmConnectWaitMS = retryTime;
    long rmConnectionRetryIntervalMS = retryInterval;
    boolean waitForEver = (rmConnectWaitMS == -1);
    if (!waitForEver) {
        if (rmConnectWaitMS < 0) {
            throw new YarnRuntimeException("Invalid Configuration. " + YarnConfiguration.RESOURCEMANAGER_CONNECT_MAX_WAIT_MS + " can be -1, but can not be other negative numbers");
        }
        // try connect once
        if (rmConnectWaitMS < rmConnectionRetryIntervalMS) {
            LOG.warn(YarnConfiguration.RESOURCEMANAGER_CONNECT_MAX_WAIT_MS + " is smaller than " + YarnConfiguration.RESOURCEMANAGER_CONNECT_RETRY_INTERVAL_MS + ". Only try connect once.");
            rmConnectWaitMS = 0;
        }
    }
    // Handle HA case first
    if (isHAEnabled) {
        final long failoverSleepBaseMs = conf.getLong(YarnConfiguration.CLIENT_FAILOVER_SLEEPTIME_BASE_MS, rmConnectionRetryIntervalMS);
        final long failoverSleepMaxMs = conf.getLong(YarnConfiguration.CLIENT_FAILOVER_SLEEPTIME_MAX_MS, rmConnectionRetryIntervalMS);
        int maxFailoverAttempts = conf.getInt(YarnConfiguration.CLIENT_FAILOVER_MAX_ATTEMPTS, -1);
        if (maxFailoverAttempts == -1) {
            if (waitForEver) {
                maxFailoverAttempts = Integer.MAX_VALUE;
            } else {
                maxFailoverAttempts = (int) (rmConnectWaitMS / failoverSleepBaseMs);
            }
        }
        return RetryPolicies.failoverOnNetworkException(RetryPolicies.TRY_ONCE_THEN_FAIL, maxFailoverAttempts, failoverSleepBaseMs, failoverSleepMaxMs);
    }
    if (rmConnectionRetryIntervalMS < 0) {
        throw new YarnRuntimeException("Invalid Configuration. " + YarnConfiguration.RESOURCEMANAGER_CONNECT_RETRY_INTERVAL_MS + " should not be negative.");
    }
    RetryPolicy retryPolicy = null;
    if (waitForEver) {
        retryPolicy = RetryPolicies.retryForeverWithFixedSleep(rmConnectionRetryIntervalMS, TimeUnit.MILLISECONDS);
    } else {
        retryPolicy = RetryPolicies.retryUpToMaximumTimeWithFixedSleep(rmConnectWaitMS, rmConnectionRetryIntervalMS, TimeUnit.MILLISECONDS);
    }
    Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap = new HashMap<Class<? extends Exception>, RetryPolicy>();
    exceptionToPolicyMap.put(EOFException.class, retryPolicy);
    exceptionToPolicyMap.put(ConnectException.class, retryPolicy);
    exceptionToPolicyMap.put(NoRouteToHostException.class, retryPolicy);
    exceptionToPolicyMap.put(UnknownHostException.class, retryPolicy);
    exceptionToPolicyMap.put(ConnectTimeoutException.class, retryPolicy);
    exceptionToPolicyMap.put(RetriableException.class, retryPolicy);
    exceptionToPolicyMap.put(SocketException.class, retryPolicy);
    exceptionToPolicyMap.put(StandbyException.class, retryPolicy);
    // YARN-4288: local IOException is also possible.
    exceptionToPolicyMap.put(IOException.class, retryPolicy);
    // Not retry on remote IO exception.
    return RetryPolicies.retryOtherThanRemoteException(RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap);
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) HashMap(java.util.HashMap) RetryPolicy(org.apache.hadoop.io.retry.RetryPolicy) ConnectTimeoutException(org.apache.hadoop.net.ConnectTimeoutException) SocketException(java.net.SocketException) ConnectException(java.net.ConnectException) StandbyException(org.apache.hadoop.ipc.StandbyException) IOException(java.io.IOException) EOFException(java.io.EOFException) UnknownHostException(java.net.UnknownHostException) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) RetriableException(org.apache.hadoop.ipc.RetriableException) NoRouteToHostException(java.net.NoRouteToHostException)

Example 48 with YarnRuntimeException

use of org.apache.hadoop.yarn.exceptions.YarnRuntimeException in project hadoop by apache.

the class SerializedExceptionPBImpl method deSerialize.

@SuppressWarnings("unchecked")
@Override
public Throwable deSerialize() {
    SerializedException cause = getCause();
    SerializedExceptionProtoOrBuilder p = viaProto ? proto : builder;
    Class<?> realClass = null;
    try {
        realClass = Class.forName(p.getClassName());
    } catch (ClassNotFoundException e) {
        throw new YarnRuntimeException(e);
    }
    Class classType = null;
    if (YarnException.class.isAssignableFrom(realClass)) {
        classType = YarnException.class;
    } else if (IOException.class.isAssignableFrom(realClass)) {
        classType = IOException.class;
    } else if (RuntimeException.class.isAssignableFrom(realClass)) {
        classType = RuntimeException.class;
    } else {
        classType = Throwable.class;
    }
    return instantiateException(realClass.asSubclass(classType), getMessage(), cause == null ? null : cause.deSerialize());
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) SerializedException(org.apache.hadoop.yarn.api.records.SerializedException) IOException(java.io.IOException) SerializedExceptionProtoOrBuilder(org.apache.hadoop.yarn.proto.YarnProtos.SerializedExceptionProtoOrBuilder)

Example 49 with YarnRuntimeException

use of org.apache.hadoop.yarn.exceptions.YarnRuntimeException in project hadoop by apache.

the class RecordFactoryPBImpl method newRecordInstance.

@SuppressWarnings("unchecked")
@Override
public <T> T newRecordInstance(Class<T> clazz) {
    Constructor<?> constructor = cache.get(clazz);
    if (constructor == null) {
        Class<?> pbClazz = null;
        try {
            pbClazz = localConf.getClassByName(getPBImplClassName(clazz));
        } catch (ClassNotFoundException e) {
            throw new YarnRuntimeException("Failed to load class: [" + getPBImplClassName(clazz) + "]", e);
        }
        try {
            constructor = pbClazz.getConstructor();
            constructor.setAccessible(true);
            cache.putIfAbsent(clazz, constructor);
        } catch (NoSuchMethodException e) {
            throw new YarnRuntimeException("Could not find 0 argument constructor", e);
        }
    }
    try {
        Object retObject = constructor.newInstance();
        return (T) retObject;
    } catch (InvocationTargetException e) {
        throw new YarnRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new YarnRuntimeException(e);
    } catch (InstantiationException e) {
        throw new YarnRuntimeException(e);
    }
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 50 with YarnRuntimeException

use of org.apache.hadoop.yarn.exceptions.YarnRuntimeException in project hadoop by apache.

the class RpcFactoryProvider method getFactoryClassInstance.

private static Object getFactoryClassInstance(String factoryClassName) {
    try {
        Class<?> clazz = Class.forName(factoryClassName);
        Method method = clazz.getMethod("get");
        method.setAccessible(true);
        return method.invoke(null);
    } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
        throw new YarnRuntimeException(e);
    }
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)147 IOException (java.io.IOException)56 Configuration (org.apache.hadoop.conf.Configuration)38 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)28 Test (org.junit.Test)28 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)17 InetSocketAddress (java.net.InetSocketAddress)12 Path (org.apache.hadoop.fs.Path)12 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 Server (org.apache.hadoop.ipc.Server)8 FileSystem (org.apache.hadoop.fs.FileSystem)7 FsPermission (org.apache.hadoop.fs.permission.FsPermission)7 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)7 FileNotFoundException (java.io.FileNotFoundException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)6 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)6 ConnectException (java.net.ConnectException)5