|
@@ -20,12 +20,14 @@ package org.apache.hadoop.yarn.server.resourcemanager;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
+import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
|
import org.apache.hadoop.yarn.api.records.ContainerState;
|
|
|
import org.apache.hadoop.yarn.api.records.ContainerStatus;
|
|
|
import org.apache.hadoop.yarn.api.records.NodeId;
|
|
@@ -55,6 +57,8 @@ public class MockNM {
|
|
|
private MasterKey currentContainerTokenMasterKey;
|
|
|
private MasterKey currentNMTokenMasterKey;
|
|
|
private String version;
|
|
|
+ private Map<ContainerId, ContainerStatus> containerStats =
|
|
|
+ new HashMap<ContainerId, ContainerStatus>();
|
|
|
|
|
|
public MockNM(String nodeIdStr, int memory, ResourceTrackerService resourceTracker) {
|
|
|
// scale vcores based on the requested memory
|
|
@@ -129,18 +133,27 @@ public class MockNM {
|
|
|
this.currentContainerTokenMasterKey =
|
|
|
registrationResponse.getContainerTokenMasterKey();
|
|
|
this.currentNMTokenMasterKey = registrationResponse.getNMTokenMasterKey();
|
|
|
+ containerStats.clear();
|
|
|
+ if (containerReports != null) {
|
|
|
+ for (NMContainerStatus report : containerReports) {
|
|
|
+ if (report.getContainerState() != ContainerState.COMPLETE) {
|
|
|
+ containerStats.put(report.getContainerId(),
|
|
|
+ ContainerStatus.newInstance(report.getContainerId(),
|
|
|
+ report.getContainerState(), report.getDiagnostics(),
|
|
|
+ report.getContainerExitStatus()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return registrationResponse;
|
|
|
}
|
|
|
|
|
|
public NodeHeartbeatResponse nodeHeartbeat(boolean isHealthy) throws Exception {
|
|
|
- return nodeHeartbeat(new HashMap<ApplicationId, List<ContainerStatus>>(),
|
|
|
+ return nodeHeartbeat(Collections.<ContainerStatus>emptyList(),
|
|
|
isHealthy, ++responseId);
|
|
|
}
|
|
|
|
|
|
public NodeHeartbeatResponse nodeHeartbeat(ApplicationAttemptId attemptId,
|
|
|
long containerId, ContainerState containerState) throws Exception {
|
|
|
- HashMap<ApplicationId, List<ContainerStatus>> nodeUpdate =
|
|
|
- new HashMap<ApplicationId, List<ContainerStatus>>(1);
|
|
|
ContainerStatus containerStatus = BuilderUtils.newContainerStatus(
|
|
|
BuilderUtils.newContainerId(attemptId, containerId), containerState,
|
|
|
"Success", 0);
|
|
@@ -148,8 +161,7 @@ public class MockNM {
|
|
|
new ArrayList<ContainerStatus>(1);
|
|
|
containerStatusList.add(containerStatus);
|
|
|
Log.info("ContainerStatus: " + containerStatus);
|
|
|
- nodeUpdate.put(attemptId.getApplicationId(), containerStatusList);
|
|
|
- return nodeHeartbeat(nodeUpdate, true);
|
|
|
+ return nodeHeartbeat(containerStatusList, true, ++responseId);
|
|
|
}
|
|
|
|
|
|
public NodeHeartbeatResponse nodeHeartbeat(Map<ApplicationId,
|
|
@@ -159,13 +171,30 @@ public class MockNM {
|
|
|
|
|
|
public NodeHeartbeatResponse nodeHeartbeat(Map<ApplicationId,
|
|
|
List<ContainerStatus>> conts, boolean isHealthy, int resId) throws Exception {
|
|
|
+ ArrayList<ContainerStatus> updatedStats = new ArrayList<ContainerStatus>();
|
|
|
+ for (List<ContainerStatus> stats : conts.values()) {
|
|
|
+ updatedStats.addAll(stats);
|
|
|
+ }
|
|
|
+ return nodeHeartbeat(updatedStats, isHealthy, resId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public NodeHeartbeatResponse nodeHeartbeat(List<ContainerStatus> updatedStats,
|
|
|
+ boolean isHealthy, int resId) throws Exception {
|
|
|
NodeHeartbeatRequest req = Records.newRecord(NodeHeartbeatRequest.class);
|
|
|
NodeStatus status = Records.newRecord(NodeStatus.class);
|
|
|
status.setResponseId(resId);
|
|
|
status.setNodeId(nodeId);
|
|
|
- for (Map.Entry<ApplicationId, List<ContainerStatus>> entry : conts.entrySet()) {
|
|
|
- Log.info("entry.getValue() " + entry.getValue());
|
|
|
- status.setContainersStatuses(entry.getValue());
|
|
|
+ ArrayList<ContainerId> completedContainers = new ArrayList<ContainerId>();
|
|
|
+ for (ContainerStatus stat : updatedStats) {
|
|
|
+ if (stat.getState() == ContainerState.COMPLETE) {
|
|
|
+ completedContainers.add(stat.getContainerId());
|
|
|
+ }
|
|
|
+ containerStats.put(stat.getContainerId(), stat);
|
|
|
+ }
|
|
|
+ status.setContainersStatuses(
|
|
|
+ new ArrayList<ContainerStatus>(containerStats.values()));
|
|
|
+ for (ContainerId cid : completedContainers) {
|
|
|
+ containerStats.remove(cid);
|
|
|
}
|
|
|
NodeHealthStatus healthStatus = Records.newRecord(NodeHealthStatus.class);
|
|
|
healthStatus.setHealthReport("");
|