Explorar o código

YARN-4384. updateNodeResource CLI should not accept negative values for resource. (Junping Du via wangda)

Wangda Tan %!s(int64=9) %!d(string=hai) anos
pai
achega
23c625ec57

+ 3 - 0
hadoop-yarn-project/CHANGES.txt

@@ -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

+ 11 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java

@@ -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();

+ 14 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java

@@ -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" };