|
@@ -28,6 +28,7 @@ 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.Container;
|
|
|
+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;
|
|
@@ -59,6 +60,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
|
|
@@ -108,14 +111,12 @@ public class MockNM {
|
|
|
}
|
|
|
|
|
|
public void containerIncreaseStatus(Container container) throws Exception {
|
|
|
- Map<ApplicationId, List<ContainerStatus>> conts = new HashMap<>();
|
|
|
ContainerStatus containerStatus = BuilderUtils.newContainerStatus(
|
|
|
container.getId(), ContainerState.RUNNING, "Success", 0,
|
|
|
container.getResource());
|
|
|
- conts.put(container.getId().getApplicationAttemptId().getApplicationId(),
|
|
|
- Collections.singletonList(containerStatus));
|
|
|
List<Container> increasedConts = Collections.singletonList(container);
|
|
|
- nodeHeartbeat(conts, increasedConts, true, ++responseId);
|
|
|
+ nodeHeartbeat(Collections.singletonList(containerStatus), increasedConts,
|
|
|
+ true, ++responseId);
|
|
|
}
|
|
|
|
|
|
public RegisterNodeManagerResponse registerNode() throws Exception {
|
|
@@ -144,18 +145,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>>(),
|
|
|
- isHealthy, ++responseId);
|
|
|
+ return nodeHeartbeat(Collections.<ContainerStatus>emptyList(),
|
|
|
+ Collections.<Container>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, BuilderUtils.newResource(memory, vCores));
|
|
@@ -163,8 +173,8 @@ 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,
|
|
|
+ Collections.<Container>emptyList(), true, ++responseId);
|
|
|
}
|
|
|
|
|
|
public NodeHeartbeatResponse nodeHeartbeat(Map<ApplicationId,
|
|
@@ -174,19 +184,32 @@ public class MockNM {
|
|
|
|
|
|
public NodeHeartbeatResponse nodeHeartbeat(Map<ApplicationId,
|
|
|
List<ContainerStatus>> conts, boolean isHealthy, int resId) throws Exception {
|
|
|
- return nodeHeartbeat(conts, new ArrayList<Container>(), isHealthy, resId);
|
|
|
+ ArrayList<ContainerStatus> updatedStats = new ArrayList<ContainerStatus>();
|
|
|
+ for (List<ContainerStatus> stats : conts.values()) {
|
|
|
+ updatedStats.addAll(stats);
|
|
|
+ }
|
|
|
+ return nodeHeartbeat(updatedStats, Collections.<Container>emptyList(),
|
|
|
+ isHealthy, resId);
|
|
|
}
|
|
|
|
|
|
- public NodeHeartbeatResponse nodeHeartbeat(Map<ApplicationId,
|
|
|
- List<ContainerStatus>> conts, List<Container> increasedConts,
|
|
|
- boolean isHealthy, int resId) throws Exception {
|
|
|
+ public NodeHeartbeatResponse nodeHeartbeat(List<ContainerStatus> updatedStats,
|
|
|
+ List<Container> increasedConts, 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);
|
|
|
}
|
|
|
status.setIncreasedContainers(increasedConts);
|
|
|
NodeHealthStatus healthStatus = Records.newRecord(NodeHealthStatus.class);
|