hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rohithsharm...@apache.org
Subject hadoop git commit: YARN-4654. Yarn node label CLI should parse "=" correctly when trying to remove all labels on a node. (Naganarasimha G R via rohithsharmaks)
Date Thu, 18 Feb 2016 08:52:35 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2.8 3a8c7ffeb -> f18d092bd


YARN-4654. Yarn node label CLI should parse "=" correctly when trying to remove all labels
on a node. (Naganarasimha G R via rohithsharmaks)

(cherry picked from commit c1afac3a98a4889d30a6ec7574a364fcbb6bb5b0)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/f18d092b
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/f18d092b
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/f18d092b

Branch: refs/heads/branch-2.8
Commit: f18d092bda7f8acf2002c7d049fe79a5cfaf897f
Parents: 3a8c7ff
Author: Rohith Sharma K S <rohithsharmaks@apache.org>
Authored: Thu Feb 18 14:10:37 2016 +0530
Committer: Rohith Sharma K S <rohithsharmaks@apache.org>
Committed: Thu Feb 18 14:21:55 2016 +0530

----------------------------------------------------------------------
 hadoop-yarn-project/CHANGES.txt                 |  3 ++
 .../hadoop/yarn/client/cli/RMAdminCLI.java      | 25 ++++++++-------
 .../hadoop/yarn/client/cli/TestRMAdminCLI.java  | 32 +++++++++++++++++++-
 3 files changed, 48 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/f18d092b/hadoop-yarn-project/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt
index 78f8a71..c37c510 100644
--- a/hadoop-yarn-project/CHANGES.txt
+++ b/hadoop-yarn-project/CHANGES.txt
@@ -1211,6 +1211,9 @@ Release 2.8.0 - UNRELEASED
     YARN-4667. RM Admin CLI for refreshNodesResources throws NPE when nothing
     is configured. (Naganarasimha G R via devaraj)
 
+    YARN-4654. Yarn node label CLI should parse "=" correctly when trying to 
+    remove all labels on a node. (Naganarasimha G R via rohithsharmaks)
+
 Release 2.7.3 - UNRELEASED
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/f18d092b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java
index 5c3b1d8..d407c20 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java
@@ -59,8 +59,8 @@ import org.apache.hadoop.yarn.server.api.protocolrecords.CheckForDecommissioning
 import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshAdminAclsRequest;
 import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshClusterMaxPriorityRequest;
 import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshNodesRequest;
-import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshQueuesRequest;
 import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshNodesResourcesRequest;
+import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshQueuesRequest;
 import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshServiceAclsRequest;
 import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshSuperUserGroupsConfigurationRequest;
 import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshUserToGroupsMappingsRequest;
@@ -592,26 +592,29 @@ public class RMAdminCLI extends HAAdmin {
         continue;
       }
 
-      // "," also supported for compatibility
       String[] splits = nodeToLabels.split("=");
-      int index = 0;
-      if (splits.length != 2) {
-        splits = nodeToLabels.split(",");
-        index = 1;
-      }
-
+      int labelsStartIndex = 0;
       String nodeIdStr = splits[0];
-      if (index == 0) {
+
+      if (splits.length == 2) {
         splits = splits[1].split(",");
+      } else if (nodeToLabels.endsWith("=")) {
+        //case where no labels are mapped to a node
+        splits = new String[0];
+      } else {
+        // "," also supported for compatibility
+        splits = nodeToLabels.split(",");
+        nodeIdStr = splits[0];
+        labelsStartIndex = 1;
       }
-      
+
       Preconditions.checkArgument(!nodeIdStr.trim().isEmpty(),
           "node name cannot be empty");
 
       NodeId nodeId = ConverterUtils.toNodeIdWithDefaultPort(nodeIdStr);
       map.put(nodeId, new HashSet<String>());
 
-      for (int i = index; i < splits.length; i++) {
+      for (int i = labelsStartIndex; i < splits.length; i++) {
         if (!splits[i].trim().isEmpty()) {
           map.get(nodeId).add(splits[i].trim());
         }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/f18d092b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java
index 08e63ea..057594d 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java
@@ -36,7 +36,9 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.ha.HAServiceProtocol;
@@ -145,7 +147,20 @@ public class TestRMAdminCLI {
   private void initDummyNodeLabelsManager() {
     Configuration conf = new YarnConfiguration();
     conf.setBoolean(YarnConfiguration.NODE_LABELS_ENABLED, true);
-    dummyNodeLabelsManager = new DummyCommonNodeLabelsManager();
+    dummyNodeLabelsManager = new DummyCommonNodeLabelsManager() {
+      @Override
+      public void replaceLabelsOnNode(
+          Map<NodeId, Set<String>> replaceLabelsToNode) throws IOException {
+        Iterator<NodeId> iterator = replaceLabelsToNode.keySet().iterator();
+        while(iterator.hasNext()) {
+          NodeId nodeId=iterator.next();
+          if(nodeId.getHost().endsWith("=")){
+            throw new IOException("Parsing of Input String failed");
+          }
+        }
+        super.replaceLabelsOnNode(replaceLabelsToNode);
+      }
+    };
     dummyNodeLabelsManager.init(conf);
   }
   
@@ -712,6 +727,21 @@ public class TestRMAdminCLI {
     assertTrue(0 != rmAdminCLI.run(args));
   }
 
+  @Test
+  public void testRemoveLabelsOnNodes() throws Exception {
+    // Successfully replace labels
+    dummyNodeLabelsManager
+        .addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("x", "y"));
+    String[] args = { "-replaceLabelsOnNode", "node1=x node2=y",
+        "-directlyAccessNodeLabelStore" };
+    assertTrue(0 == rmAdminCLI.run(args));
+
+    args = new String[] { "-replaceLabelsOnNode", "node1= node2=",
+        "-directlyAccessNodeLabelStore" };
+    assertTrue("Labels should get replaced even '=' is used ",
+        0 == rmAdminCLI.run(args));
+  }
+
   private void testError(String[] args, String template,
       ByteArrayOutputStream data, int resultCode) throws Exception {
     int actualResultCode = rmAdminCLI.run(args);


Mime
View raw message