Quellcode durchsuchen

AMBARI-18028. Failed to load stack versions (aonishuk)

Andrew Onishuk vor 9 Jahren
Ursprung
Commit
234fa6aa92

+ 2 - 6
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariHandlerList.java

@@ -140,10 +140,8 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
     } else {
       // if there is a view target (as in a view resource request) then set the view class loader
       ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
-      ClassLoader viewClassLoader    = null;
-
       try {
-        viewClassLoader = viewEntity.getClassLoader();
+        ClassLoader viewClassLoader = viewEntity.getClassLoader();
         if (viewClassLoader == null) {
           LOG.debug("No class loader associated with view " + viewEntity.getName() + ".");
         } else {
@@ -151,9 +149,7 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
         }
         processHandlers(target, baseRequest, request, response);
       } finally {
-        if (viewClassLoader != null) {
-          Thread.currentThread().setContextClassLoader(contextClassLoader);
-        }
+        Thread.currentThread().setContextClassLoader(contextClassLoader);
       }
     }
   }

+ 23 - 18
contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsUtil.java

@@ -114,27 +114,32 @@ public class HdfsUtil {
    */
   public static synchronized HdfsApi connectToHDFSApi(ViewContext context) throws HdfsApiException {
     HdfsApi api = null;
+    ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
     Thread.currentThread().setContextClassLoader(null);
-
-    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(context);
-    AuthConfigurationBuilder authConfigurationBuilder = new AuthConfigurationBuilder(context);
-
-    Map<String, String> authParams = authConfigurationBuilder.build();
-    configurationBuilder.setAuthParams(authParams);
-
     try {
-      api = new HdfsApi(configurationBuilder, getHdfsUsername(context));
-      LOG.info("HdfsApi connected OK");
-    } catch (IOException e) {
-      String message = "HDFS040 Couldn't open connection to HDFS";
-      LOG.error(message);
-      throw new HdfsApiException(message, e);
-    } catch (InterruptedException e) {
-      String message = "HDFS041 Couldn't open connection to HDFS";
-      LOG.error(message);
-      throw new HdfsApiException(message, e);
+      ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(context);
+      AuthConfigurationBuilder authConfigurationBuilder = new AuthConfigurationBuilder(context);
+
+      Map<String, String> authParams = authConfigurationBuilder.build();
+      configurationBuilder.setAuthParams(authParams);
+
+      try {
+        api = new HdfsApi(configurationBuilder, getHdfsUsername(context));
+        LOG.info("HdfsApi connected OK");
+      } catch (IOException e) {
+        String message = "HDFS040 Couldn't open connection to HDFS";
+        LOG.error(message);
+        throw new HdfsApiException(message, e);
+      } catch (InterruptedException e) {
+        String message = "HDFS041 Couldn't open connection to HDFS";
+        LOG.error(message);
+        throw new HdfsApiException(message, e);
+      }
+      return api;
+    }
+    finally {
+      Thread.currentThread().setContextClassLoader(currentClassLoader);
     }
-    return api;
   }
 
   /**