tomicooler commented on a change in pull request #3342:
URL: https://github.com/apache/hadoop/pull/3342#discussion_r698311057



##########
File path: 
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueuePath.java
##########
@@ -116,8 +121,79 @@ public boolean hasParent() {
     return parent != null;
   }
 
+  /**
+   * Creates a new {@code QueuePath} from the current full path as parent, and
+   * the appended child queue path as leaf.
+   * @param childQueue path of leaf queue
+   * @return new queue path made of current full path and appended leaf path
+   */
+  public QueuePath append(String childQueue) {
+    return new QueuePath(getFullPath(), childQueue);
+  }
+
+  /**
+   * Returns an iterator of queue path parts, starting from the highest level
+   * (generally root).
+   * @return queue part iterator
+   */
+  @Override
+  public Iterator<String> iterator() {
+    return 
Arrays.asList(getFullPath().split(QUEUE_REGEX_DELIMITER)).iterator();

Review comment:
       I had to try this :)
   
   With a C++ background this looked dangerous - returning a reference for a 
temporary object. I guess the iterator will keep the list alive in Java 
(probably a reference?). 

##########
File path: 
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueuePath.java
##########
@@ -116,8 +121,79 @@ public boolean hasParent() {
     return parent != null;
   }
 
+  /**
+   * Creates a new {@code QueuePath} from the current full path as parent, and
+   * the appended child queue path as leaf.
+   * @param childQueue path of leaf queue
+   * @return new queue path made of current full path and appended leaf path
+   */
+  public QueuePath append(String childQueue) {
+    return new QueuePath(getFullPath(), childQueue);
+  }
+
+  /**
+   * Returns an iterator of queue path parts, starting from the highest level
+   * (generally root).
+   * @return queue part iterator
+   */
+  @Override
+  public Iterator<String> iterator() {
+    return 
Arrays.asList(getFullPath().split(QUEUE_REGEX_DELIMITER)).iterator();
+  }
+
+  /**
+   * Returns an iterator that provides a way to traverse the queue path from
+   * current queue through its parents.
+   * @return queue path iterator
+   */
+  public Iterator<QueuePath> reversePathIterator() {

Review comment:
       This is not yet used in the production code, according the Jira it will 
be utilised later.

##########
File path: 
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueuePath.java
##########
@@ -116,8 +121,79 @@ public boolean hasParent() {
     return parent != null;
   }
 
+  /**
+   * Creates a new {@code QueuePath} from the current full path as parent, and
+   * the appended child queue path as leaf.
+   * @param childQueue path of leaf queue
+   * @return new queue path made of current full path and appended leaf path
+   */
+  public QueuePath append(String childQueue) {

Review comment:
       I think this append method is a bit misleading. It constructs a new 
QueuePath and does not do anything with "this", I think a constructor would be 
easier to understand:
   
   QueuePath(QueuePath parent, String leaf) {}
   
   (A static factory method would do the trick as well.)

##########
File path: 
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueuePathTest.java
##########
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
+
+import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+public class QueuePathTest {
+  private static final String TEST_QUEUE = "root.level_1.level_2.level_3";
+
+  @Test
+  public void testCreation() {
+    QueuePath queuePath = new QueuePath(TEST_QUEUE);
+
+    Assert.assertEquals(TEST_QUEUE, queuePath.getFullPath());
+    Assert.assertEquals("root.level_1.level_2", queuePath.getParent());
+    Assert.assertEquals("level_3", queuePath.getLeafName());
+
+    QueuePath rootPath = new QueuePath(CapacitySchedulerConfiguration.ROOT);
+    Assert.assertNull(rootPath.getParent());
+
+    QueuePath appendedPath = queuePath.append("level_4");
+    Assert.assertEquals(TEST_QUEUE + CapacitySchedulerConfiguration.DOT
+        + "level_4", appendedPath.getFullPath());
+    Assert.assertEquals("root.level_1.level_2.level_3", 
appendedPath.getParent());
+    Assert.assertEquals("level_4", appendedPath.getLeafName());
+  }
+
+  @Test
+  public void testEmptyPart() {
+    QueuePath queuePathWithEmptyPart = new QueuePath("root..level_2");
+    QueuePath queuePathWithoutEmptyPart = new QueuePath(TEST_QUEUE);
+
+    Assert.assertTrue(queuePathWithEmptyPart.hasEmptyPart());
+    Assert.assertFalse(queuePathWithoutEmptyPart.hasEmptyPart());
+  }
+
+  @Test
+  public void testIterator() {
+    QueuePath queuePath = new QueuePath(TEST_QUEUE);
+    QueuePath queuePathWithEmptyPart = new QueuePath("root..level_2");
+    QueuePath rootPath = new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+    List<String> queuePathCollection = 
ImmutableList.copyOf(queuePath.iterator());
+    List<String> queuePathWithEmptyPartCollection = 
ImmutableList.copyOf(queuePathWithEmptyPart.iterator());
+    List<String> rootPathCollection = 
ImmutableList.copyOf(rootPath.iterator());
+
+    Assert.assertEquals(4, queuePathCollection.size());
+    Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, 
queuePathCollection.get(0));
+    Assert.assertEquals("level_3", queuePathCollection.get(3));
+
+    Assert.assertEquals(3, queuePathWithEmptyPartCollection.size());
+    Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, 
queuePathWithEmptyPartCollection.get(0));
+    Assert.assertEquals("level_2", queuePathWithEmptyPartCollection.get(2));
+
+    Assert.assertEquals(1, rootPathCollection.size());
+    Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, 
rootPathCollection.get(0));
+  }
+
+  @Test
+  public void testReversePathIterator() {
+    QueuePath queuePath = new QueuePath(TEST_QUEUE);
+    QueuePath queuePathWithEmptyPart = new QueuePath("root..level_2");
+    QueuePath rootPath = new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+    List<QueuePath> queuePathCollection = 
ImmutableList.copyOf(queuePath.reversePathIterator());
+    List<QueuePath> queuePathWithEmptyPartCollection = 
ImmutableList.copyOf(queuePathWithEmptyPart.reversePathIterator());
+    List<QueuePath> rootPathCollection = 
ImmutableList.copyOf(rootPath.reversePathIterator());
+
+    Assert.assertEquals(4, queuePathCollection.size());
+    Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, 
queuePathCollection.get(3).getFullPath());
+    Assert.assertEquals(TEST_QUEUE, queuePathCollection.get(0).getFullPath());
+
+    Assert.assertEquals(3, queuePathWithEmptyPartCollection.size());
+    Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, 
queuePathWithEmptyPartCollection.get(2).getFullPath());
+    Assert.assertEquals("root..level_2", 
queuePathWithEmptyPartCollection.get(0).getFullPath());
+
+    Assert.assertEquals(1, rootPathCollection.size());
+    Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, 
rootPathCollection.get(0).getFullPath());
+  }
+}

Review comment:
       Missing new line at the end of the file.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to