|
@@ -47,14 +47,14 @@ import org.apache.hadoop.yarn.server.api.records.NodeStatus;
|
|
|
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
|
|
|
import org.apache.hadoop.yarn.util.Records;
|
|
|
import org.apache.hadoop.yarn.util.YarnVersionInfo;
|
|
|
+import org.apache.hadoop.yarn.util.resource.Resources;
|
|
|
import org.mortbay.log.Log;
|
|
|
|
|
|
public class MockNM {
|
|
|
|
|
|
private int responseId;
|
|
|
private NodeId nodeId;
|
|
|
- private long memory;
|
|
|
- private int vCores;
|
|
|
+ private Resource capatibility;
|
|
|
private ResourceTrackerService resourceTracker;
|
|
|
private int httpPort = 2;
|
|
|
private MasterKey currentContainerTokenMasterKey;
|
|
@@ -75,13 +75,25 @@ public class MockNM {
|
|
|
|
|
|
public MockNM(String nodeIdStr, int memory, int vcores,
|
|
|
ResourceTrackerService resourceTracker) {
|
|
|
- this(nodeIdStr, memory, vcores, resourceTracker, YarnVersionInfo.getVersion());
|
|
|
+ this(nodeIdStr, memory, vcores, resourceTracker,
|
|
|
+ YarnVersionInfo.getVersion());
|
|
|
}
|
|
|
|
|
|
public MockNM(String nodeIdStr, int memory, int vcores,
|
|
|
ResourceTrackerService resourceTracker, String version) {
|
|
|
- this.memory = memory;
|
|
|
- this.vCores = vcores;
|
|
|
+ this(nodeIdStr, Resource.newInstance(memory, vcores), resourceTracker,
|
|
|
+ version);
|
|
|
+ }
|
|
|
+
|
|
|
+ public MockNM(String nodeIdStr, Resource capatibility,
|
|
|
+ ResourceTrackerService resourceTracker) {
|
|
|
+ this(nodeIdStr, capatibility, resourceTracker,
|
|
|
+ YarnVersionInfo.getVersion());
|
|
|
+ }
|
|
|
+
|
|
|
+ public MockNM(String nodeIdStr, Resource capatibility,
|
|
|
+ ResourceTrackerService resourceTracker, String version) {
|
|
|
+ this.capatibility = capatibility;
|
|
|
this.resourceTracker = resourceTracker;
|
|
|
this.version = version;
|
|
|
String[] splits = nodeIdStr.split(":");
|
|
@@ -146,8 +158,7 @@ public class MockNM {
|
|
|
RegisterNodeManagerRequest.class);
|
|
|
req.setNodeId(nodeId);
|
|
|
req.setHttpPort(httpPort);
|
|
|
- Resource resource = BuilderUtils.newResource(memory, vCores);
|
|
|
- req.setResource(resource);
|
|
|
+ req.setResource(capatibility);
|
|
|
req.setContainerStatuses(containerReports);
|
|
|
req.setNMVersion(version);
|
|
|
req.setRunningApplications(runningApplications);
|
|
@@ -158,8 +169,7 @@ public class MockNM {
|
|
|
this.currentNMTokenMasterKey = registrationResponse.getNMTokenMasterKey();
|
|
|
Resource newResource = registrationResponse.getResource();
|
|
|
if (newResource != null) {
|
|
|
- memory = (int) newResource.getMemorySize();
|
|
|
- vCores = newResource.getVirtualCores();
|
|
|
+ capatibility = Resources.clone(newResource);
|
|
|
}
|
|
|
containerStats.clear();
|
|
|
if (containerReports != null) {
|
|
@@ -185,7 +195,7 @@ public class MockNM {
|
|
|
long containerId, ContainerState containerState) throws Exception {
|
|
|
ContainerStatus containerStatus = BuilderUtils.newContainerStatus(
|
|
|
BuilderUtils.newContainerId(attemptId, containerId), containerState,
|
|
|
- "Success", 0, BuilderUtils.newResource(memory, vCores));
|
|
|
+ "Success", 0, capatibility);
|
|
|
ArrayList<ContainerStatus> containerStatusList =
|
|
|
new ArrayList<ContainerStatus>(1);
|
|
|
containerStatusList.add(containerStatus);
|
|
@@ -266,19 +276,22 @@ public class MockNM {
|
|
|
|
|
|
Resource newResource = heartbeatResponse.getResource();
|
|
|
if (newResource != null) {
|
|
|
- memory = newResource.getMemorySize();
|
|
|
- vCores = newResource.getVirtualCores();
|
|
|
+ capatibility = Resources.clone(newResource);
|
|
|
}
|
|
|
|
|
|
return heartbeatResponse;
|
|
|
}
|
|
|
|
|
|
public long getMemory() {
|
|
|
- return memory;
|
|
|
+ return capatibility.getMemorySize();
|
|
|
}
|
|
|
|
|
|
public int getvCores() {
|
|
|
- return vCores;
|
|
|
+ return capatibility.getVirtualCores();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Resource getCapatibility() {
|
|
|
+ return capatibility;
|
|
|
}
|
|
|
|
|
|
public String getVersion() {
|