Browse Source

YARN-9179. Fix NPE in AbstractYarnScheduler#updateNewContainerInfo.

Akira Ajisaka 6 năm trước cách đây
mục cha
commit
614af50625

+ 17 - 10
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java

@@ -1040,20 +1040,27 @@ public abstract class AbstractYarnScheduler
     for (Map.Entry<ApplicationId, ContainerStatus> c : updateExistContainers) {
       SchedulerApplication<T> app = applications.get(c.getKey());
       ContainerId containerId = c.getValue().getContainerId();
+      if (app == null || app.getCurrentAppAttempt() == null) {
+        continue;
+      }
+      RMContainer rmContainer
+          = app.getCurrentAppAttempt().getRMContainer(containerId);
+      if (rmContainer == null) {
+        continue;
+      }
+      // exposed ports are already set for the container, skip
+      if (rmContainer.getExposedPorts() != null &&
+          rmContainer.getExposedPorts().size() > 0) {
+        continue;
+      }
+
       String strExposedPorts = c.getValue().getExposedPorts();
-      Map<String, List<Map<String, String>>> exposedPorts = null;
       if (null != strExposedPorts && !strExposedPorts.isEmpty()) {
         Gson gson = new Gson();
-        exposedPorts = gson.fromJson(strExposedPorts,
+        Map<String, List<Map<String, String>>> exposedPorts =
+            gson.fromJson(strExposedPorts,
             new TypeToken<Map<String, List<Map<String, String>>>>()
-            {}.getType());
-      }
-
-      RMContainer rmContainer
-          = app.getCurrentAppAttempt().getRMContainer(containerId);
-      if (null != rmContainer &&
-          (null == rmContainer.getExposedPorts()
-              || rmContainer.getExposedPorts().size() == 0)) {
+                {}.getType());
         LOG.info("update exist container " + containerId.getContainerId()
             + ", strExposedPorts = " + strExposedPorts);
         rmContainer.setExposedPorts(exposedPorts);