[GitHub] [hadoop] goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support setQuota

2019-08-09 Thread GitBox
goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support 
setQuota
URL: https://github.com/apache/hadoop/pull/1253#discussion_r312593255
 
 

 ##
 File path: 
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/resources/TestParam.java
 ##
 @@ -49,7 +51,7 @@
   @Test
   public void testAccessTimeParam() {
 final AccessTimeParam p = new AccessTimeParam(AccessTimeParam.DEFAULT);
-Assert.assertEquals(-1L, p.getValue().longValue());
+assertEquals(-1L, p.getValue().longValue());
 
 Review comment:
   To avoid so much churn, let's just do the assertEquals in the new methods 
and leave this alone for the rest for now.
   we can do a followup JIRA for that if so.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support setQuota

2019-08-09 Thread GitBox
goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support 
setQuota
URL: https://github.com/apache/hadoop/pull/1253#discussion_r312592614
 
 

 ##
 File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java
 ##
 @@ -1788,6 +1788,34 @@ public QuotaUsage getQuotaUsage(Path f) throws 
IOException {
 return getContentSummary(f);
   }
 
+  /**
+   * Set quota for the given {@link Path}.
+   *
+   * @param src the target path to set quota for
+   * @param namespaceQuota the namespace quota (i.e., # of files/directories) 
to set
+   * @param storagespaceQuota the storage space quota to set
+   * @throws IOException IO failure
+   */
+  public void setQuota(Path src, final long namespaceQuota,
+  final long storagespaceQuota) throws IOException {
+throw new UnsupportedOperationException(getClass().getCanonicalName() +
 
 Review comment:
   Let's do just the new two functions in this JIRA so we introduce the 
function.
   Afterwards we can do a separate JIRA to replace all.
   To get the method, one could do 
Thread.currentThread().getStackTrace()[index].getMethodName().
   The index sometimes is tricky, but doable.
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support setQuota

2019-08-08 Thread GitBox
goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support 
setQuota
URL: https://github.com/apache/hadoop/pull/1253#discussion_r312143772
 
 

 ##
 File path: 
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/NameSpaceQuotaParam.java
 ##
 @@ -0,0 +1,45 @@
+/**
+ * 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.hdfs.web.resources;
+
+import org.apache.hadoop.hdfs.protocol.HdfsConstants;
+
+/** The name space quota parameter for directory. */
+public class NameSpaceQuotaParam extends LongParam {
+  /** Parameter name. */
+  public static final String NAME = "namespacequota";
+  /** Default parameter value ({@link Long#MAX_VALUE}). */
+  // public static final String DEFAULT = String.valueOf(Long.MAX_VALUE);
 
 Review comment:
   Cleanup?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support setQuota

2019-08-08 Thread GitBox
goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support 
setQuota
URL: https://github.com/apache/hadoop/pull/1253#discussion_r312143159
 
 

 ##
 File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java
 ##
 @@ -1788,6 +1788,34 @@ public QuotaUsage getQuotaUsage(Path f) throws 
IOException {
 return getContentSummary(f);
   }
 
+  /**
+   * Set quota for the given {@link Path}.
+   *
+   * @param src the target path to set quota for
+   * @param namespaceQuota the namespace quota (i.e., # of files/directories) 
to set
+   * @param storagespaceQuota the storage space quota to set
+   * @throws IOException IO failure
+   */
+  public void setQuota(Path src, final long namespaceQuota,
+  final long storagespaceQuota) throws IOException {
+throw new UnsupportedOperationException(getClass().getCanonicalName() +
 
 Review comment:
   This is a pattern used in many places.
   I think we should have a static method to do this.
   I think the easiest way to get the function name is to get the stack trace.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support setQuota

2019-08-08 Thread GitBox
goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support 
setQuota
URL: https://github.com/apache/hadoop/pull/1253#discussion_r312143990
 
 

 ##
 File path: 
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/StorageSpaceQuotaParam.java
 ##
 @@ -0,0 +1,45 @@
+/**
+ * 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.hdfs.web.resources;
+
+import org.apache.hadoop.hdfs.protocol.HdfsConstants;
+
+/** The storage space quota parameter for directory. */
+public class StorageSpaceQuotaParam extends LongParam {
+  /** Parameter name. */
+  public static final String NAME = "storagespacequota";
+  /** Default parameter value ({@link Long#MAX_VALUE}). */
+  public static final String DEFAULT = "9223372036854775807";
 
 Review comment:
   Use the toString of MAX_VALUE


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support setQuota

2019-08-08 Thread GitBox
goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support 
setQuota
URL: https://github.com/apache/hadoop/pull/1253#discussion_r312144937
 
 

 ##
 File path: 
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java
 ##
 @@ -1129,9 +1129,88 @@ public void testQuotaUsage() throws Exception {
 cluster.shutdown();
   }
 }
+  }
+
+  @Test
+  public void testSetQuota() throws Exception {
+MiniDFSCluster cluster = null;
+final Configuration conf = WebHdfsTestUtil.createConf();
+final Path path = new Path("/TestDir");
+try {
+  cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build();
+  final WebHdfsFileSystem webHdfs = WebHdfsTestUtil.getWebHdfsFileSystem(
+  conf, WebHdfsConstants.WEBHDFS_SCHEME);
+  final DistributedFileSystem dfs = cluster.getFileSystem();
 
+  final long nsQuota = 100;
+  final long spaceQuota = 1024;
+
+  webHdfs.mkdirs(path);
+
+  webHdfs.setQuota(path, nsQuota, spaceQuota);
+  QuotaUsage quotaUsage = dfs.getQuotaUsage(path);
+  assertEquals(nsQuota, quotaUsage.getQuota());
+  assertEquals(spaceQuota, quotaUsage.getSpaceQuota());
+
+  webHdfs.setQuota(path,
+  HdfsConstants.QUOTA_RESET, HdfsConstants.QUOTA_RESET);
+  quotaUsage = dfs.getQuotaUsage(path);
+  assertEquals(HdfsConstants.QUOTA_RESET, quotaUsage.getQuota());
+  assertEquals(HdfsConstants.QUOTA_RESET, quotaUsage.getSpaceQuota());
+
+  webHdfs.setQuotaByStorageType(path, StorageType.DISK, spaceQuota);
+  webHdfs.setQuotaByStorageType(path, StorageType.ARCHIVE, spaceQuota);
+  webHdfs.setQuotaByStorageType(path, StorageType.SSD, spaceQuota);
+  quotaUsage = dfs.getQuotaUsage(path);
+  assertEquals(spaceQuota, quotaUsage.getTypeQuota(StorageType.DISK));
+  assertEquals(spaceQuota, quotaUsage.getTypeQuota(StorageType.ARCHIVE));
+  assertEquals(spaceQuota, quotaUsage.getTypeQuota(StorageType.SSD));
+
+  // Test invalid parameters
+
+  try {
+webHdfs.setQuota(path, -100, 100);
+fail("Should have thrown exception");
+  } catch (IllegalArgumentException e) {
+assertTrue(e.getMessage().contains("Invalid values for quota"));
 
 Review comment:
   I would use LambdaTestUtils.intercept for all this.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support setQuota

2019-08-08 Thread GitBox
goiri commented on a change in pull request #1253: HDFS-8631. WebHDFS : Support 
setQuota
URL: https://github.com/apache/hadoop/pull/1253#discussion_r312144647
 
 

 ##
 File path: 
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/resources/TestParam.java
 ##
 @@ -494,23 +496,50 @@ public void testFsActionParam() {
   public void testStartAfterParam() throws Exception {
 String s = "/helloWorld";
 StartAfterParam param = new StartAfterParam(s);
-Assert.assertEquals(s, param.getValue());
+assertEquals(s, param.getValue());
   }
 
   @Test
   public void testStoragePolicyParam() {
 StoragePolicyParam p = new StoragePolicyParam(StoragePolicyParam.DEFAULT);
-Assert.assertEquals(null, p.getValue());
+assertEquals(null, p.getValue());
 p = new StoragePolicyParam("COLD");
-Assert.assertEquals("COLD", p.getValue());
+assertEquals("COLD", p.getValue());
+  }
+
+  @Test
+  public void testNamespaceQuotaParam() {
+NameSpaceQuotaParam p =
+new NameSpaceQuotaParam(NameSpaceQuotaParam.DEFAULT);
+assertEquals(Long.valueOf(NameSpaceQuotaParam.DEFAULT), p.getValue());
+p = new NameSpaceQuotaParam(100L);
+assertEquals(new Long(100), p.getValue());
+  }
+
+  @Test
+  public void testStorageSpaceQuotaParam() {
+StorageSpaceQuotaParam sp = new StorageSpaceQuotaParam(
+StorageSpaceQuotaParam.DEFAULT);
+assertEquals(Long.valueOf(StorageSpaceQuotaParam.DEFAULT),
+sp.getValue());
+sp = new StorageSpaceQuotaParam(100L);
+assertEquals(new Long(100), sp.getValue());
 
 Review comment:
   Can we use "assertEquals(100L,"?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org