diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java index 0ad47bb8f9..a798b97af5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java +++ b/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 @@ private List updateNewContainerInfo(RMNode nm, for (Map.Entry c : updateExistContainers) { SchedulerApplication app = applications.get(c.getKey()); ContainerId containerId = c.getValue().getContainerId(); - String strExposedPorts = c.getValue().getExposedPorts(); - Map>> exposedPorts = null; - if (null != strExposedPorts && !strExposedPorts.isEmpty()) { - Gson gson = new Gson(); - exposedPorts = gson.fromJson(strExposedPorts, - new TypeToken>>>() - {}.getType()); + if (app == null || app.getCurrentAppAttempt() == null) { + continue; } - RMContainer rmContainer = app.getCurrentAppAttempt().getRMContainer(containerId); - if (null != rmContainer && - (null == rmContainer.getExposedPorts() - || rmContainer.getExposedPorts().size() == 0)) { + 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(); + if (null != strExposedPorts && !strExposedPorts.isEmpty()) { + Gson gson = new Gson(); + Map>> exposedPorts = + gson.fromJson(strExposedPorts, + new TypeToken>>>() + {}.getType()); LOG.info("update exist container " + containerId.getContainerId() + ", strExposedPorts = " + strExposedPorts); rmContainer.setExposedPorts(exposedPorts);