You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/08/23 19:19:54 UTC

[GitHub] [ozone] yuangu002 opened a new pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

yuangu002 opened a new pull request #2565:
URL: https://github.com/apache/ozone/pull/2565


   ## What changes were proposed in this pull request?
   
   Add the ozone admin shell command ozone admin namespace summary
   
   From the design doc:
   
   $ ozone admin namespace summary --all /vol1/bucket1/MyDir
   
   Entity Type : Directory
   Directories : 1
   Keys : 10
   
   DU
     Size  DiskUsage   Path
     21G     63G          /volume1/bucket1
     5G      15G          /volume1/bucket2
   
   File Size Distribution
     1KB - 2KB - 50% (5)
     2KB - 4KB - 50% (5)
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-5368
   
   ## How was this patch tested?
   
   Configs:
   ```
   ozone sh volume create /vol1
   ozone sh volume create /vol2
   ozone sh bucket create /vol1/bucket11
   ozone sh bucket create /vol1/bucket12
   ozone sh bucket create /vol2/bucket21
   ozone sh bucket create /vol2/bucket22
   ozone sh key put --replication=THREE /vol1/bucket11/key1 README.md
   ozone sh key put --replication=THREE /vol1/bucket11/key2s README.md
   ozone sh key put --replication=THREE /vol1/bucket11/dir1/key3 README.md
   ozone sh key put /vol2/bucket21/key4 CONTRIBUTING.md
   ozone sh key put /vol2/bucket21/key5 CONTRIBUTING.md
   ozone sh key put /vol2/bucket22/key6 README.md
   ozone sh key put --replication=THREE /vol2/bucket22/dir22/key7 LICENSE.txt
   ozone sh key put /vol1/bucket12/dir1-1/key8 README.md
   ozone sh key put /vol1/bucket12/dir1-2/key9 CONTRIBUTING.md
   ozone sh key put --replication=THREE /vol1/bucket12/directKey README.md
   ```
   Usage:
   `ozone admin namespace [summary | du | quota | dist] [-options] <path>`
   
   Example: `ozone admin namespace summary /`
   ![Screen Shot 2021-08-23 at 3 12 10 PM](https://user-images.githubusercontent.com/53324985/130504249-fd3592f2-fe18-45b6-9c7d-ebb0ffa28c3b.png)
   
   (du with replica)
   `ozone admin namespace du --replica /`
   ![Screen Shot 2021-08-23 at 3 14 28 PM](https://user-images.githubusercontent.com/53324985/130504531-b06bf23c-9eb7-4d1b-bcb0-942ab8a681d6.png)
   
   (du with listing direct keys)
   ozone admin namespace du --replica --file /vol1/bucket12
   ![Screen Shot 2021-08-23 at 3 17 30 PM](https://user-images.githubusercontent.com/53324985/130504859-5b89a128-97ff-447d-9224-d95b90bb7d40.png)
   
   Other option usage for `du`:
   ![Screen Shot 2021-08-23 at 3 13 08 PM](https://user-images.githubusercontent.com/53324985/130504353-733f8412-742d-491f-a09f-99655db95188.png)
   
   `ozone admin namespace quota /`
   ![Screen Shot 2021-08-23 at 3 15 15 PM](https://user-images.githubusercontent.com/53324985/130504629-a0ae7f3e-92e1-4090-8398-78547b2f2206.png)
   
   `ozone admin namespace dist /`
   ![Screen Shot 2021-08-23 at 3 16 14 PM](https://user-images.githubusercontent.com/53324985/130504718-706aa08b-a4b3-4045-a732-de540c6c1fb4.png)
   
   cc @smengcl @avijayanhwx for reviews.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#issuecomment-907571902


   CI is green. Will merge shortly.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] yuangu002 commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
yuangu002 commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r696032635



##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/nssummary/NSSummaryAdmin.java
##########
@@ -76,21 +87,39 @@ public boolean isFSOEnabled() {
   public String getReconWebAddress() {
     OzoneConfiguration conf = parent.getOzoneConf();
     String protocolPrefix = "";
-    InetSocketAddress reconSocket = null;
-    if (OzoneSecurityUtil.isHttpSecurityEnabled(conf)) {
+    HttpConfig.Policy webPolicy = getHttpPolicy(conf);
+
+    String name = null;
+
+    if (webPolicy == HttpConfig.Policy.HTTPS_ONLY) {
       protocolPrefix = "https://";
-      reconSocket = HddsUtils.getReconHTTPSAddresses(conf);
+      name = conf.get(OZONE_RECON_HTTPS_ADDRESS_KEY,
+          OZONE_RECON_HTTPS_ADDRESS_DEFAULT);
     } else {
       protocolPrefix = "http://";
-      reconSocket = HddsUtils.getReconHTTPAddresses(conf);
+      name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY,
+          OZONE_RECON_HTTP_ADDRESS_DEFAULT);
+    }
+
+    if (StringUtils.isEmpty(name)) {
+      return null;
+    }
+
+    String reconDefaultAddress = conf.get(OZONE_RECON_ADDRESS_KEY,
+        OZONE_RECON_ADDRESS_DEFAULT);
+    Optional<String> hostname = getHostName(reconDefaultAddress);
+    if (!hostname.isPresent()) {
+      throw new IllegalArgumentException("Invalid hostname for Recon: "
+          + reconDefaultAddress);
     }
-    return protocolPrefix + reconSocket.getHostName()
-        + ":" + reconSocket.getPort();
+
+    int port = getHostPort(name).orElse(OZONE_RECON_DATANODE_PORT_DEFAULT);
+    return protocolPrefix + hostname.get() + ":" + port;
   }
 
-  public boolean isSecurityEnabled() {
+  public boolean isHTTPSEnabled() {
     OzoneConfiguration conf = parent.getOzoneConf();
-    return OzoneSecurityUtil.isHttpSecurityEnabled(conf);
+    return getHttpPolicy(conf) == HttpConfig.Policy.HTTPS_ONLY;

Review comment:
       should we follow @avijayanhwx suggestion yesterday that if the policy is `HTTP_AND_HTTPS`, we will fall back to `HTTP`?




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r695103932



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
##########
@@ -314,6 +316,48 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of recon HTTP.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);

Review comment:
       Yes. We need the port from `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY`.
   
   The logic could be:
   
   If address in `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` is set, we should use the address from them.
   
   But if address in `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` is **not** set, we should just fallback to the address from `OZONE_RECON_ADDRESS_KEY`. And use the default port in this case.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] yuangu002 commented on pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
yuangu002 commented on pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#issuecomment-905629696


   Addressed comments. Moved du percentage to hoverinfo in frontend in order to avoid text overlapping.
   PTAL.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r695913011



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/recon/ReconConfigKeys.java
##########
@@ -40,6 +40,12 @@ private ReconConfigKeys() {
       "ozone.recon.http-address";
   public static final String OZONE_RECON_HTTPS_ADDRESS_KEY =
       "ozone.recon.https-address";
+  public static final String OZONE_RECON_ADDRESS_DEFAULT =
+      "recon:9891";
+  public static final String OZONE_RECON_HTTP_ADDRESS_DEFAULT =
+      "0.0.0.0:9888";
+  public static final String OZONE_RECON_HTTPS_ADDRESS_DEFAULT =
+      "0.0.0.0:9889";

Review comment:
       Reorder the variables. Make them in the order of KEY / DEFAULT / KEY / DEFAULT / KEY / DEFAULT.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r695103932



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
##########
@@ -314,6 +316,48 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of recon HTTP.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);

Review comment:
       Yes. We (at lease) need the port from `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY`.
   
   The logic could be:
   
   If address in `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` is set, we should use the address from them.
   
   But if address in `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` is **not** set, we should attampt to fallback to the address in `OZONE_RECON_ADDRESS_KEY` (exclude the port). And use the default port in this case.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] yuangu002 commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
yuangu002 commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r694991611



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
##########
@@ -314,6 +316,48 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of recon HTTP.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);

Review comment:
       `OZONE_RECON_ADDRESS_KEY` maps to `recon:9891`, which is the address for RPC client. In our case, I think we still need `OZONE_RECON_HTTP_ADDRESS_KEY` and `OZONE_RECON_HTTPS_ADDRESS_KEY` which maps to web endpoints.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r695915073



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/recon/ReconConfigKeys.java
##########
@@ -40,6 +40,12 @@ private ReconConfigKeys() {
       "ozone.recon.http-address";
   public static final String OZONE_RECON_HTTPS_ADDRESS_KEY =
       "ozone.recon.https-address";
+  public static final String OZONE_RECON_ADDRESS_DEFAULT =
+      "recon:9891";

Review comment:
       Recon RPC address default host should not be `recon`. This default value isn't just for the testing environment. `0.0.0.0` should allow Recon server to start up normally and listen on all interfaces.
   
   But we should expect admins to set this address properly for **clients**.
   
   ```suggestion
         "0.0.0.0:9891";
   ```




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#issuecomment-907571969


   Thanks @yuangu002 for the patch. Thanks @avijayanhwx for reviewing.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] yuangu002 commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
yuangu002 commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r695108953



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
##########
@@ -314,6 +316,48 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of recon HTTP.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);

Review comment:
       Can we assume default port is 9888 and 9889 for HTTP and HTTPs?




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r694494559



##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/nssummary/DiskUsageSubCommand.java
##########
@@ -0,0 +1,215 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.ozone.admin.nssummary;
+
+import com.google.gson.internal.LinkedTreeMap;
+import org.apache.commons.io.FileUtils;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.ozone.shell.ListOptions;
+import picocli.CommandLine;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.concurrent.Callable;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.getResponseMap;
+import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.makeHttpCall;
+import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.parseInputPath;
+import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.printEmptyPathRequest;
+import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.printFSOReminder;
+import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.printKVSeparator;
+import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.printNewLines;
+import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.printPathNotFound;
+import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.printSpaces;
+import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.printWithUnderline;
+
+/**
+ * Disk Usage Subcommand.
+ */
+@CommandLine.Command(
+    name = "du",
+    description = "Get disk usage for a path request.",
+    mixinStandardHelpOptions = true,
+    versionProvider = HddsVersionProvider.class
+)
+
+public class DiskUsageSubCommand implements Callable {
+  @CommandLine.ParentCommand
+  private NSSummaryAdmin parent;
+
+  @CommandLine.Parameters(index = "0", arity = "0..1",
+      description = "Non-empty path request without any protocol prefix.")
+  private String path;
+
+  @CommandLine.Option(names = {"-f", "--file"},
+      description = "List direct files as a sub path.")
+  private boolean listFiles;
+
+  @CommandLine.Option(names = {"-r", "--replica"},
+      description = "Show disk usage with replication.")
+  private boolean withReplica;
+
+  @CommandLine.Option(names = {"-n", "--no-header"},
+      description = "Show DU without the header for current path.")
+  private boolean noHeader;
+

Review comment:
       ```suggestion
   ```

##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/recon/ReconConfigKeys.java
##########
@@ -36,6 +36,10 @@ private ReconConfigKeys() {
       "ozone.recon.datanode.address";
   public static final String OZONE_RECON_ADDRESS_KEY =
       "ozone.recon.address";
+  public static final String OZONE_RECON_HTTP_ADDRESS_KEY =
+      "ozone.recon.http-address";
+  public static final String OZONE_RECON_HTTPS_ADDRESS_KEY =
+      "ozone.recon.https-address";

Review comment:
       We already have these in `ReconServerConfigKeys`. No need to add them here.
   ```suggestion
   ```

##########
File path: hadoop-ozone/dist/src/main/compose/ozone/docker-config
##########
@@ -31,6 +31,8 @@ OZONE-SITE.XML_ozone.recon.db.dir=/data/metadata/recon
 OZONE-SITE.XML_ozone.scm.client.address=scm
 OZONE-SITE.XML_hdds.datanode.dir=/data/hdds
 OZONE-SITE.XML_ozone.recon.address=recon:9891
+OZONE-SITE.XML_ozone.recon.http-address=recon:9888
+OZONE-SITE.XML_ozone.recon.https-address=recon:9889

Review comment:
       Just use `0.0.0.0` as only the port portion matters.
   
   ```suggestion
   OZONE-SITE.XML_ozone.recon.http-address=0.0.0.0:9888
   OZONE-SITE.XML_ozone.recon.https-address=0.0.0.0:9889
   ```

##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
##########
@@ -314,6 +316,48 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of recon HTTP.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);

Review comment:
       We should still use `OZONE_RECON_ADDRESS_KEY` here, as it is expected that Recon RPC and REST share the same **host**.
   
   The rationale is that `ozone-default.xml` has `ozone.recon.http-address=0.0.0.0:9888`. So one doesn't have to manually add another config entry to `ozone-site.xml`, when the CLI feature lands, it should just work without extra configs.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] avijayanhwx commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
avijayanhwx commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r695287031



##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/nssummary/NSSummaryCLIUtils.java
##########
@@ -0,0 +1,174 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.ozone.admin.nssummary;
+
+import com.google.gson.Gson;
+import org.apache.commons.io.IOUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdfs.web.URLConnectionFactory;
+import picocli.CommandLine.Help.Ansi;
+
+import javax.security.sasl.AuthenticationException;
+import java.io.InputStream;
+import java.net.ConnectException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+
+import static java.net.HttpURLConnection.HTTP_CREATED;
+import static java.net.HttpURLConnection.HTTP_OK;
+
+/**
+ * Utility class to support Namespace CLI.
+ */
+public final class NSSummaryCLIUtils {
+
+  private NSSummaryCLIUtils() {
+
+  }
+
+  private static final String OFS_PREFIX = "ofs://";
+
+  public static String makeHttpCall(StringBuffer url, String path,
+                                    boolean isSpnegoEnabled,
+                                    ConfigurationSource conf)
+      throws Exception {
+    return makeHttpCall(url, path, false, false, isSpnegoEnabled, conf);
+  }
+
+  public static String makeHttpCall(StringBuffer url, String path,
+                                    boolean listFile, boolean withReplica,
+                                    boolean isSpnegoEnabled,
+                                    ConfigurationSource conf)
+      throws Exception {
+
+    url.append("?path=").append(path);
+
+    if (listFile) {
+      url.append("&files=true");
+    }
+    if (withReplica) {
+      url.append("&replica=true");
+    }
+
+    System.out.println("Connecting to Recon: " + url + "...");
+    final URLConnectionFactory connectionFactory =
+        URLConnectionFactory.newDefaultURLConnectionFactory(
+            (Configuration) conf);
+
+    HttpURLConnection httpURLConnection;
+
+    try {
+      httpURLConnection = (HttpURLConnection)
+          connectionFactory.openConnection(new URL(url.toString()),
+              isSpnegoEnabled);
+      httpURLConnection.connect();
+      int errorCode = httpURLConnection.getResponseCode();
+      InputStream inputStream = httpURLConnection.getInputStream();
+
+      if ((errorCode == HTTP_OK) || (errorCode == HTTP_CREATED)) {
+        return IOUtils.toString(inputStream, StandardCharsets.UTF_8);
+      }
+
+      if (httpURLConnection.getErrorStream() != null) {
+        System.out.println("Recon is being initialized. Please wait a moment");
+        return null;
+      } else {
+        System.out.println("Unexpected null in http payload," +
+            " while processing request");
+      }
+      return null;
+    } catch (ConnectException ex) {
+      System.err.println("Connection Refused. Please make sure the " +
+          "Recon Server has been started.");
+      return null;
+    } catch (AuthenticationException authEx) {
+      System.err.println("Authentication Failed. Please make sure you " +
+          "have login or disable Ozone security settings.");
+      return null;
+    }
+  }
+
+  public static HashMap<String, Object> getResponseMap(String response) {
+    return new Gson().fromJson(response, HashMap.class);
+  }
+
+  public static void printNewLines(int cnt) {
+    for (int i = 0; i < cnt; ++i) {
+      System.out.println();
+    }
+  }
+
+  public static void printSpaces(int cnt) {
+    for (int i = 0; i < cnt; ++i) {
+      System.out.print(" ");
+    }
+  }
+
+  public static void printEmptyPathRequest() {
+    System.err.println("The path parameter is empty.\n" +
+        "If you mean the root path, use / instead.");
+  }
+
+  public static void printPathNotFound() {
+    System.err.println("Path not found in the system.\n" +
+        "Did you remove any protocol prefix before the path?");
+  }
+
+  public static void printTypeNA(String requestType) {
+    String markUp = "@|underline " + requestType + "|@";
+    System.err.println("Path found in the system.\nBut the entity type " +
+        "is not applicable to the " + Ansi.AUTO.string(markUp) + " request");
+  }
+
+  public static void printKVSeparator() {
+    System.out.print(" : ");
+  }
+
+  public static void printWithUnderline(String str, boolean newLine) {
+    String markupStr = "@|underline " + str + "|@";
+    if (newLine) {
+      System.out.println(Ansi.AUTO.string(markupStr));
+    } else {
+      System.out.print(Ansi.AUTO.string(markupStr));
+    }
+  }
+
+  public static void printFSOReminder() {
+    printNewLines(1);
+    System.out.println("[Warning] FSO is NOT enabled. " +
+        "Namespace CLI is only designed for FSO mode.\n" +
+        "To enable FSO set ozone.om.enable.filesystem.paths to true " +
+        "and ozone.om.metadata.layout to PREFIX.");
+    printNewLines(1);
+  }
+
+  public static String parseInputPath(String path) {
+    if (!path.startsWith("ofs://")) {
+      return path;
+    }
+    int idx = path.indexOf("/", OFS_PREFIX.length());

Review comment:
       ofs:// path takes in OM host:port or service id as the first part after the ofs:// prefix. Hence, this code needs to handle that as well. 

##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/nssummary/NSSummaryAdmin.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.ozone.admin.nssummary;
+
+import org.apache.hadoop.hdds.HddsUtils;
+import org.apache.hadoop.hdds.cli.GenericCli;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.cli.OzoneAdmin;
+import org.apache.hadoop.hdds.cli.SubcommandWithParent;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.OzoneSecurityUtil;
+import org.kohsuke.MetaInfServices;
+import picocli.CommandLine;
+
+import java.net.InetSocketAddress;
+
+/**
+ * Subcommand for admin operations related to OM.
+ */
+@CommandLine.Command(
+    name = "namespace",
+    description = "Namespace Summary specific admin operations",
+    mixinStandardHelpOptions = true,
+    versionProvider = HddsVersionProvider.class,
+    subcommands = {
+        SummarySubCommand.class,
+        DiskUsageSubCommand.class,
+        QuotaUsageSubCommand.class,
+        FileSizeDistSubCommand.class
+    })
+@MetaInfServices(SubcommandWithParent.class)
+public class NSSummaryAdmin extends GenericCli implements SubcommandWithParent {
+  @CommandLine.ParentCommand
+  private OzoneAdmin parent;
+
+  @CommandLine.Spec
+  private CommandLine.Model.CommandSpec spec;
+
+  public OzoneAdmin getParent() {
+    return parent;
+  }
+
+  @Override
+  public Void call() throws Exception {
+    GenericCli.missingSubcommand(spec);
+    return null;
+  }
+
+  @Override
+  public Class<?> getParentType() {
+    return OzoneAdmin.class;
+  }
+
+  public boolean isFSOEnabled() {
+    OzoneConfiguration conf = parent.getOzoneConf();
+    return conf.getBoolean("ozone.om.enable.filesystem.paths", false)
+        && conf.get("ozone.om.metadata.layout").equalsIgnoreCase("PREFIX");
+  }
+
+  public String getReconWebAddress() {
+    OzoneConfiguration conf = parent.getOzoneConf();
+    String protocolPrefix = "";
+    InetSocketAddress reconSocket = null;
+    if (OzoneSecurityUtil.isHttpSecurityEnabled(conf)) {

Review comment:
       Need to look at ozone.http.policy to determine http vs https here.

##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
##########
@@ -314,6 +316,48 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of recon HTTP.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);
+    if (StringUtils.isEmpty(name)) {
+      return null;
+    }
+    Optional<String> hostname = getHostName(name);
+    if (!hostname.isPresent()) {
+      throw new IllegalArgumentException("Invalid hostname for Recon: "
+          + name);
+    }
+    int port = getHostPort(name).orElse(OZONE_RECON_DATANODE_PORT_DEFAULT);
+    return NetUtils.createSocketAddr(hostname.get(), port);
+  }
+
+  /**
+   * Retrieve the socket addresses of recon HTTPS.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPSAddresses(

Review comment:
       Seems to have common logic with last method, maybe single method is good? 

##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/nssummary/NSSummaryCLIUtils.java
##########
@@ -0,0 +1,174 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.ozone.admin.nssummary;
+
+import com.google.gson.Gson;
+import org.apache.commons.io.IOUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdfs.web.URLConnectionFactory;
+import picocli.CommandLine.Help.Ansi;
+
+import javax.security.sasl.AuthenticationException;
+import java.io.InputStream;
+import java.net.ConnectException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+
+import static java.net.HttpURLConnection.HTTP_CREATED;
+import static java.net.HttpURLConnection.HTTP_OK;
+
+/**
+ * Utility class to support Namespace CLI.
+ */
+public final class NSSummaryCLIUtils {
+
+  private NSSummaryCLIUtils() {
+
+  }
+
+  private static final String OFS_PREFIX = "ofs://";
+
+  public static String makeHttpCall(StringBuffer url, String path,
+                                    boolean isSpnegoEnabled,
+                                    ConfigurationSource conf)
+      throws Exception {
+    return makeHttpCall(url, path, false, false, isSpnegoEnabled, conf);
+  }
+
+  public static String makeHttpCall(StringBuffer url, String path,
+                                    boolean listFile, boolean withReplica,
+                                    boolean isSpnegoEnabled,
+                                    ConfigurationSource conf)
+      throws Exception {
+
+    url.append("?path=").append(path);
+
+    if (listFile) {
+      url.append("&files=true");
+    }
+    if (withReplica) {
+      url.append("&replica=true");
+    }
+
+    System.out.println("Connecting to Recon: " + url + "...");
+    final URLConnectionFactory connectionFactory =
+        URLConnectionFactory.newDefaultURLConnectionFactory(
+            (Configuration) conf);
+
+    HttpURLConnection httpURLConnection;
+
+    try {
+      httpURLConnection = (HttpURLConnection)
+          connectionFactory.openConnection(new URL(url.toString()),
+              isSpnegoEnabled);
+      httpURLConnection.connect();
+      int errorCode = httpURLConnection.getResponseCode();
+      InputStream inputStream = httpURLConnection.getInputStream();
+
+      if ((errorCode == HTTP_OK) || (errorCode == HTTP_CREATED)) {
+        return IOUtils.toString(inputStream, StandardCharsets.UTF_8);
+      }
+
+      if (httpURLConnection.getErrorStream() != null) {
+        System.out.println("Recon is being initialized. Please wait a moment");
+        return null;
+      } else {
+        System.out.println("Unexpected null in http payload," +
+            " while processing request");
+      }
+      return null;
+    } catch (ConnectException ex) {
+      System.err.println("Connection Refused. Please make sure the " +
+          "Recon Server has been started.");
+      return null;
+    } catch (AuthenticationException authEx) {
+      System.err.println("Authentication Failed. Please make sure you " +
+          "have login or disable Ozone security settings.");
+      return null;
+    }
+  }
+
+  public static HashMap<String, Object> getResponseMap(String response) {
+    return new Gson().fromJson(response, HashMap.class);
+  }
+
+  public static void printNewLines(int cnt) {
+    for (int i = 0; i < cnt; ++i) {
+      System.out.println();
+    }
+  }
+
+  public static void printSpaces(int cnt) {
+    for (int i = 0; i < cnt; ++i) {
+      System.out.print(" ");
+    }
+  }
+
+  public static void printEmptyPathRequest() {
+    System.err.println("The path parameter is empty.\n" +
+        "If you mean the root path, use / instead.");
+  }
+
+  public static void printPathNotFound() {
+    System.err.println("Path not found in the system.\n" +
+        "Did you remove any protocol prefix before the path?");
+  }
+
+  public static void printTypeNA(String requestType) {
+    String markUp = "@|underline " + requestType + "|@";
+    System.err.println("Path found in the system.\nBut the entity type " +
+        "is not applicable to the " + Ansi.AUTO.string(markUp) + " request");
+  }
+
+  public static void printKVSeparator() {
+    System.out.print(" : ");
+  }
+
+  public static void printWithUnderline(String str, boolean newLine) {
+    String markupStr = "@|underline " + str + "|@";
+    if (newLine) {
+      System.out.println(Ansi.AUTO.string(markupStr));
+    } else {
+      System.out.print(Ansi.AUTO.string(markupStr));
+    }
+  }
+
+  public static void printFSOReminder() {
+    printNewLines(1);
+    System.out.println("[Warning] FSO is NOT enabled. " +
+        "Namespace CLI is only designed for FSO mode.\n" +
+        "To enable FSO set ozone.om.enable.filesystem.paths to true " +
+        "and ozone.om.metadata.layout to PREFIX.");
+    printNewLines(1);
+  }
+
+  public static String parseInputPath(String path) {
+    if (!path.startsWith("ofs://")) {
+      return path;
+    }
+    int idx = path.indexOf("/", OFS_PREFIX.length());

Review comment:
       ofs:// path takes in service id or om host as the first part. This logic needs to strip out that as well.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl merged pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl merged pull request #2565:
URL: https://github.com/apache/ozone/pull/2565


   


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#issuecomment-907436841


   The failure in the test is fixed by https://github.com/apache/ozone/pull/2592.
   
   I tested that by applying https://github.com/apache/ozone/pull/2592 to this dev branch. The integration test would pass with it.
   
   Will merge https://github.com/apache/ozone/pull/2592 first. Then merge master to this branch to resolve conflicts, if any.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r694490747



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
##########
@@ -314,6 +316,48 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of recon HTTP.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);
+    if (StringUtils.isEmpty(name)) {
+      return null;
+    }
+    Optional<String> hostname = getHostName(name);
+    if (!hostname.isPresent()) {
+      throw new IllegalArgumentException("Invalid hostname for Recon: "
+          + name);
+    }
+    int port = getHostPort(name).orElse(OZONE_RECON_DATANODE_PORT_DEFAULT);
+    return NetUtils.createSocketAddr(hostname.get(), port);
+  }
+
+  /**
+   * Retrieve the socket addresses of recon HTTPS.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPSAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTPS_ADDRESS_KEY);
+    if (StringUtils.isEmpty(name)) {
+      return null;
+    }
+    Optional<String> hostname = getHostName(name);
+    if (!hostname.isPresent()) {
+      throw new IllegalArgumentException("Invalid hostname for Recon: "
+          + name);
+    }
+    int port = getHostPort(name).orElse(OZONE_RECON_DATANODE_PORT_DEFAULT);
+    return NetUtils.createSocketAddr(hostname.get(), port);
+  }

Review comment:
       Can we combine two helper functions into one? It can check `isHttpSecurityEnabled` directly from `conf`.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r696058664



##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/nssummary/NSSummaryAdmin.java
##########
@@ -76,21 +87,39 @@ public boolean isFSOEnabled() {
   public String getReconWebAddress() {
     OzoneConfiguration conf = parent.getOzoneConf();
     String protocolPrefix = "";
-    InetSocketAddress reconSocket = null;
-    if (OzoneSecurityUtil.isHttpSecurityEnabled(conf)) {
+    HttpConfig.Policy webPolicy = getHttpPolicy(conf);
+
+    String name = null;
+
+    if (webPolicy == HttpConfig.Policy.HTTPS_ONLY) {
       protocolPrefix = "https://";
-      reconSocket = HddsUtils.getReconHTTPSAddresses(conf);
+      name = conf.get(OZONE_RECON_HTTPS_ADDRESS_KEY,
+          OZONE_RECON_HTTPS_ADDRESS_DEFAULT);
     } else {
       protocolPrefix = "http://";
-      reconSocket = HddsUtils.getReconHTTPAddresses(conf);
+      name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY,
+          OZONE_RECON_HTTP_ADDRESS_DEFAULT);
+    }
+
+    if (StringUtils.isEmpty(name)) {
+      return null;
+    }
+
+    String reconDefaultAddress = conf.get(OZONE_RECON_ADDRESS_KEY,
+        OZONE_RECON_ADDRESS_DEFAULT);
+    Optional<String> hostname = getHostName(reconDefaultAddress);
+    if (!hostname.isPresent()) {
+      throw new IllegalArgumentException("Invalid hostname for Recon: "
+          + reconDefaultAddress);
     }
-    return protocolPrefix + reconSocket.getHostName()
-        + ":" + reconSocket.getPort();
+
+    int port = getHostPort(name).orElse(OZONE_RECON_DATANODE_PORT_DEFAULT);
+    return protocolPrefix + hostname.get() + ":" + port;
   }
 
-  public boolean isSecurityEnabled() {
+  public boolean isHTTPSEnabled() {
     OzoneConfiguration conf = parent.getOzoneConf();
-    return OzoneSecurityUtil.isHttpSecurityEnabled(conf);
+    return getHttpPolicy(conf) == HttpConfig.Policy.HTTPS_ONLY;

Review comment:
       Nope. In this case where client config has both http and https, client should reach out to https, not http.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] avijayanhwx commented on pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
avijayanhwx commented on pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#issuecomment-905049198


   Thanks for working on this @yuangu002. Patch looks great. A few comments inline.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r695911494



##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/nssummary/NSSummaryAdmin.java
##########
@@ -76,21 +87,39 @@ public boolean isFSOEnabled() {
   public String getReconWebAddress() {
     OzoneConfiguration conf = parent.getOzoneConf();
     String protocolPrefix = "";
-    InetSocketAddress reconSocket = null;
-    if (OzoneSecurityUtil.isHttpSecurityEnabled(conf)) {
+    HttpConfig.Policy webPolicy = getHttpPolicy(conf);
+
+    String name = null;
+
+    if (webPolicy == HttpConfig.Policy.HTTPS_ONLY) {
       protocolPrefix = "https://";
-      reconSocket = HddsUtils.getReconHTTPSAddresses(conf);
+      name = conf.get(OZONE_RECON_HTTPS_ADDRESS_KEY,
+          OZONE_RECON_HTTPS_ADDRESS_DEFAULT);
     } else {
       protocolPrefix = "http://";
-      reconSocket = HddsUtils.getReconHTTPAddresses(conf);
+      name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY,
+          OZONE_RECON_HTTP_ADDRESS_DEFAULT);
+    }
+
+    if (StringUtils.isEmpty(name)) {
+      return null;
+    }
+
+    String reconDefaultAddress = conf.get(OZONE_RECON_ADDRESS_KEY,
+        OZONE_RECON_ADDRESS_DEFAULT);
+    Optional<String> hostname = getHostName(reconDefaultAddress);
+    if (!hostname.isPresent()) {
+      throw new IllegalArgumentException("Invalid hostname for Recon: "
+          + reconDefaultAddress);
     }
-    return protocolPrefix + reconSocket.getHostName()
-        + ":" + reconSocket.getPort();
+
+    int port = getHostPort(name).orElse(OZONE_RECON_DATANODE_PORT_DEFAULT);
+    return protocolPrefix + hostname.get() + ":" + port;
   }
 
-  public boolean isSecurityEnabled() {
+  public boolean isHTTPSEnabled() {
     OzoneConfiguration conf = parent.getOzoneConf();
-    return OzoneSecurityUtil.isHttpSecurityEnabled(conf);
+    return getHttpPolicy(conf) == HttpConfig.Policy.HTTPS_ONLY;

Review comment:
       `|| this == HttpConfig.Policy.HTTP_AND_HTTPS`
   
   Also, why not use `getHttpPolicy(conf).isHttpsEnabled()` directly?
   
   https://github.com/apache/ozone/blob/79a9d39da7f33e71bc00183e280105562354cca4/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/HttpConfig.java#L59




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r694490747



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
##########
@@ -314,6 +316,48 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of recon HTTP.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);
+    if (StringUtils.isEmpty(name)) {
+      return null;
+    }
+    Optional<String> hostname = getHostName(name);
+    if (!hostname.isPresent()) {
+      throw new IllegalArgumentException("Invalid hostname for Recon: "
+          + name);
+    }
+    int port = getHostPort(name).orElse(OZONE_RECON_DATANODE_PORT_DEFAULT);
+    return NetUtils.createSocketAddr(hostname.get(), port);
+  }
+
+  /**
+   * Retrieve the socket addresses of recon HTTPS.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPSAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTPS_ADDRESS_KEY);
+    if (StringUtils.isEmpty(name)) {
+      return null;
+    }
+    Optional<String> hostname = getHostName(name);
+    if (!hostname.isPresent()) {
+      throw new IllegalArgumentException("Invalid hostname for Recon: "
+          + name);
+    }
+    int port = getHostPort(name).orElse(OZONE_RECON_DATANODE_PORT_DEFAULT);
+    return NetUtils.createSocketAddr(hostname.get(), port);
+  }

Review comment:
       Can we combine two methods into one? It can check `isHttpSecurityEnabled` directly from `conf`.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r695103932



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
##########
@@ -314,6 +316,48 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of recon HTTP.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);

Review comment:
       Yes. We (at lease) need the port from `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY`.
   
   The logic could be:
   
   If address in `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` is set, we should use the address from them.
   
   But if address in `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` is **not** set, we should just fallback to the address from `OZONE_RECON_ADDRESS_KEY`. And use the default port in this case.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r695103932



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
##########
@@ -314,6 +316,48 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of recon HTTP.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);

Review comment:
       Yes. We (at lease) need the port from `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY`.
   
   The logic could be:
   
   If address in `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` is set, we should use the address from them.
   
   But if address in `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` is **not** set, we should attampt to fallback to the address in `OZONE_RECON_ADDRESS_KEY` (exclude the port). And use the default port from `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` in this case.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a change in pull request #2565: HDDS-5368. Add CLI command: ozone admin namespace summary

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2565:
URL: https://github.com/apache/ozone/pull/2565#discussion_r695103932



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
##########
@@ -314,6 +316,48 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of recon HTTP.
+   *
+   * @return Recon address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getReconHTTPAddresses(
+      ConfigurationSource conf) {
+    String name = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);

Review comment:
       Yes. We (at least) need the port from `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY`.
   
   The logic could be:
   
   If address in `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` is set, we should use the address from them.
   
   But if address in `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` is **not** set, we should attampt to fallback to the address in `OZONE_RECON_ADDRESS_KEY` (exclude the port). And use the default port from `OZONE_RECON_HTTP_ADDRESS_KEY`/`OZONE_RECON_HTTPS_ADDRESS_KEY` in this case.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org