Prechádzať zdrojové kódy

AMBARI-18588 Ambari server should not crash with NPE when parsing HTTP response for YARN RM properties (dili)

Di Li 9 rokov pred
rodič
commit
fb6a71318e

+ 4 - 2
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/JsonHttpPropertyRequest.java

@@ -62,7 +62,9 @@ public abstract class JsonHttpPropertyRequest extends HttpPropertyProvider.HttpP
 
     try {
       Map<String, Object> responseMap = GSON.fromJson(IOUtils.toString(inputStream, "UTF-8"), MAP_TYPE);
-
+      if (responseMap == null){
+        LOG.error("Properties map from HTTP response is null");
+      }
       for (Map.Entry<String, String> entry : getPropertyMappings().entrySet()) {
         Object propertyValueToSet = getPropertyValue(responseMap, entry.getKey());
         resource.setProperty(entry.getValue(), propertyValueToSet);
@@ -77,7 +79,7 @@ public abstract class JsonHttpPropertyRequest extends HttpPropertyProvider.HttpP
 
   // get the property value from the response map for the given property name
   private Object getPropertyValue(Map<String, Object> responseMap, String property) throws SystemException {
-    if (property == null) {
+    if (property == null || responseMap == null) {
       return null;
     }
 

+ 3 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java

@@ -241,6 +241,9 @@ public class URLStreamProvider implements StreamProvider {
     } else {
         // not a 401 Unauthorized status code
         // we would let the original response propagate
+        if (statusCode == HttpStatus.SC_NOT_FOUND || statusCode == HttpStatus.SC_FORBIDDEN){
+          LOG.error(String.format("Received HTTP %s response from URL: %s", statusCode, spec));
+        }
         return connection;
     }
   }