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-4384. updateNodeResource CLI should not accept negative values for resource.
|
||||
(Junping Du via wangda)
|
||||
|
||||
Release 2.7.3 - UNRELEASED
|
||||
|
||||
INCOMPATIBLE CHANGES
|
||||
|
|
|
@ -418,11 +418,17 @@ public class RMAdminCLI extends HAAdmin {
|
|||
|
||||
private int updateNodeResource(String nodeIdStr, int memSize,
|
||||
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
|
||||
ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol();
|
||||
UpdateNodeResourceRequest request =
|
||||
recordFactory.newRecordInstance(UpdateNodeResourceRequest.class);
|
||||
NodeId nodeId = ConverterUtils.toNodeId(nodeIdStr);
|
||||
|
||||
Resource resource = Resources.createResource(memSize, cores);
|
||||
Map<NodeId, ResourceOption> resourceMap =
|
||||
new HashMap<NodeId, ResourceOption>();
|
||||
|
@ -433,6 +439,11 @@ public class RMAdminCLI extends HAAdmin {
|
|||
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 {
|
||||
// Get groups users belongs to
|
||||
ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol();
|
||||
|
|
|
@ -218,6 +218,20 @@ public class TestRMAdminCLI {
|
|||
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)
|
||||
public void testRefreshNodes() throws Exception {
|
||||
String[] args = { "-refreshNodes" };
|
||||
|
|
Loading…
Reference in New Issue