YARN-4384. updateNodeResource CLI should not accept negative values for resource. (Junping Du via wangda)
This commit is contained in:
parent
78ec38b2ed
commit
23c625ec57
|
@ -1069,6 +1069,9 @@ Release 2.8.0 - UNRELEASED
|
||||||
|
|
||||||
YARN-4387. Fix typo in FairScheduler log message. (Xin Wang via ozawa)
|
YARN-4387. Fix typo in FairScheduler log message. (Xin Wang via ozawa)
|
||||||
|
|
||||||
|
YARN-4384. updateNodeResource CLI should not accept negative values for resource.
|
||||||
|
(Junping Du via wangda)
|
||||||
|
|
||||||
Release 2.7.3 - UNRELEASED
|
Release 2.7.3 - UNRELEASED
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -418,11 +418,17 @@ public class RMAdminCLI extends HAAdmin {
|
||||||
|
|
||||||
private int updateNodeResource(String nodeIdStr, int memSize,
|
private int updateNodeResource(String nodeIdStr, int memSize,
|
||||||
int cores, int overCommitTimeout) throws IOException, YarnException {
|
int cores, int overCommitTimeout) throws IOException, YarnException {
|
||||||
|
// check resource value first
|
||||||
|
if (invalidResourceValue(memSize, cores)) {
|
||||||
|
throw new IllegalArgumentException("Invalid resource value: " + "(" +
|
||||||
|
memSize + "," + cores + ") for updateNodeResource.");
|
||||||
|
}
|
||||||
// Refresh the nodes
|
// Refresh the nodes
|
||||||
ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol();
|
ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol();
|
||||||
UpdateNodeResourceRequest request =
|
UpdateNodeResourceRequest request =
|
||||||
recordFactory.newRecordInstance(UpdateNodeResourceRequest.class);
|
recordFactory.newRecordInstance(UpdateNodeResourceRequest.class);
|
||||||
NodeId nodeId = ConverterUtils.toNodeId(nodeIdStr);
|
NodeId nodeId = ConverterUtils.toNodeId(nodeIdStr);
|
||||||
|
|
||||||
Resource resource = Resources.createResource(memSize, cores);
|
Resource resource = Resources.createResource(memSize, cores);
|
||||||
Map<NodeId, ResourceOption> resourceMap =
|
Map<NodeId, ResourceOption> resourceMap =
|
||||||
new HashMap<NodeId, ResourceOption>();
|
new HashMap<NodeId, ResourceOption>();
|
||||||
|
@ -433,6 +439,11 @@ public class RMAdminCLI extends HAAdmin {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// complain negative value for cpu or memory.
|
||||||
|
private boolean invalidResourceValue(int memValue, int coreValue) {
|
||||||
|
return (memValue < 0) || (coreValue < 0);
|
||||||
|
}
|
||||||
|
|
||||||
private int getGroups(String[] usernames) throws IOException {
|
private int getGroups(String[] usernames) throws IOException {
|
||||||
// Get groups users belongs to
|
// Get groups users belongs to
|
||||||
ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol();
|
ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol();
|
||||||
|
|
|
@ -218,6 +218,20 @@ public class TestRMAdminCLI {
|
||||||
resource);
|
resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout=500)
|
||||||
|
public void testUpdateNodeResourceWithInvalidValue() throws Exception {
|
||||||
|
String nodeIdStr = "0.0.0.0:0";
|
||||||
|
int memSize = -2048;
|
||||||
|
int cores = 2;
|
||||||
|
String[] args = { "-updateNodeResource", nodeIdStr,
|
||||||
|
Integer.toString(memSize), Integer.toString(cores) };
|
||||||
|
// execution of command line is expected to be failed
|
||||||
|
assertEquals(-1, rmAdminCLI.run(args));
|
||||||
|
// verify admin protocol never calls.
|
||||||
|
verify(admin,times(0)).updateNodeResource(
|
||||||
|
any(UpdateNodeResourceRequest.class));
|
||||||
|
}
|
||||||
|
|
||||||
@Test(timeout=500)
|
@Test(timeout=500)
|
||||||
public void testRefreshNodes() throws Exception {
|
public void testRefreshNodes() throws Exception {
|
||||||
String[] args = { "-refreshNodes" };
|
String[] args = { "-refreshNodes" };
|
||||||
|
|
Loading…
Reference in New Issue