[ 
https://issues.apache.org/jira/browse/HDFS-16260?focusedWorklogId=663627&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-663627
 ]

ASF GitHub Bot logged work on HDFS-16260:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 11/Oct/21 16:08
            Start Date: 11/Oct/21 16:08
    Worklog Time Spent: 10m 
      Work Description: goiri commented on a change in pull request #3532:
URL: https://github.com/apache/hadoop/pull/3532#discussion_r726268863



##########
File path: 
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs-delete-snapshot/hdfs-delete-snapshot.cc
##########
@@ -0,0 +1,133 @@
+/*
+  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.
+*/
+
+#include <iostream>
+#include <memory>
+#include <ostream>
+#include <sstream>
+#include <string>
+
+#include "hdfs-delete-snapshot.h"
+#include "tools_common.h"
+
+namespace hdfs::tools {
+DeleteSnapshot::DeleteSnapshot(const int argc, char **argv)
+    : HdfsTool(argc, argv) {}
+
+bool DeleteSnapshot::Initialize() {
+  auto add_options = opt_desc_.add_options();
+  add_options("help,h", "Show the help for hdfs_deleteSnapshot");
+  add_options("path", po::value<std::string>(),
+              "The path to the directory that is snapshot-able");
+  add_options("name", po::value<std::string>(), "The name of the snapshot");
+
+  // Register "path" and "name" as positional arguments.
+  // We allow only two arguments to be passed to this tool. An exception is
+  // thrown if more than two arguments are passed.
+  pos_opt_desc_.add("path", 1);
+  pos_opt_desc_.add("name", 1);
+
+  po::store(po::command_line_parser(argc_, argv_)
+                .options(opt_desc_)
+                .positional(pos_opt_desc_)
+                .run(),
+            opt_val_);
+  po::notify(opt_val_);
+  return true;
+}
+
+bool DeleteSnapshot::ValidateConstraints() const {
+  // Only "help" is allowed as single argument
+  if (argc_ == 2) {
+    if (opt_val_.count("help") > 0) {
+      return true;
+    }
+    return false;
+  }
+
+  // Rest of the cases must contain more than 1 argument on the command line
+  return argc_ > 2;
+}
+
+std::string DeleteSnapshot::GetDescription() const {
+  std::stringstream desc;
+  desc << "Usage: hdfs_deleteSnapshot [OPTION] PATH NAME" << std::endl
+       << std::endl
+       << "Delete a snapshot NAME from a snapshot-able directory." << std::endl
+       << "This operation requires owner privilege of the snapshot-able "
+          "directory."
+       << std::endl
+       << std::endl
+       << "  -h        display this help and exit" << std::endl
+       << std::endl
+       << "Examples:" << std::endl
+       << "hdfs_deleteSnapshot hdfs://localhost.localdomain:8020/dir 
mySnapshot"
+       << std::endl
+       << "hdfs_deleteSnapshot /dir1/dir2 mySnapshot" << std::endl;
+  return desc.str();
+}
+
+bool DeleteSnapshot::Do() {
+  if (!Initialize()) {
+    std::cerr << "Unable to initialize HDFS delete snapshot tool" << std::endl;
+    return false;
+  }
+
+  if (!ValidateConstraints()) {
+    std::cout << GetDescription();
+    return false;
+  }
+
+  if (opt_val_.count("help") > 0) {

Review comment:
       This used to be `h` or `?`

##########
File path: 
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs_deleteSnapshot.cc
##########
@@ -1,87 +0,0 @@
-/*
-  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.
-*/
-
-#include <google/protobuf/stubs/common.h>
-#include <unistd.h>
-#include "tools_common.h"
-
-void usage(){
-  std::cout << "Usage: hdfs_deleteSnapshot [OPTION] PATH NAME"
-      << std::endl
-      << std::endl << "Delete a snapshot NAME from a snapshottable directory."
-      << std::endl << "This operation requires owner privilege of the 
snapshottable directory."
-      << std::endl
-      << std::endl << "  -h        display this help and exit"
-      << std::endl
-      << std::endl << "Examples:"
-      << std::endl << "hdfs_deleteSnapshot 
hdfs://localhost.localdomain:8020/dir mySnapshot"
-      << std::endl << "hdfs_deleteSnapshot /dir1/dir2 mySnapshot"
-      << std::endl;
-}
-
-int main(int argc, char *argv[]) {
-  //We should have at least 2 arguments
-  if (argc < 2) {
-    usage();
-    exit(EXIT_FAILURE);
-  }
-
-  int input;
-
-  //Using GetOpt to read in the values
-  opterr = 0;
-  while ((input = getopt(argc, argv, "h")) != -1) {

Review comment:
       Was `getopt` the only non compatible thing?




-- 
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: common-issues-unsubscr...@hadoop.apache.org

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 663627)
    Time Spent: 1h 40m  (was: 1.5h)

> Make hdfs_deleteSnapshot tool cross platform
> --------------------------------------------
>
>                 Key: HDFS-16260
>                 URL: https://issues.apache.org/jira/browse/HDFS-16260
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>          Components: hdfs-client, libhdfs++, tools
>    Affects Versions: 3.4.0
>         Environment: Centos 7, Centos 8, Debian 10, Ubuntu Focal
>            Reporter: Gautham Banasandra
>            Assignee: Gautham Banasandra
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h 40m
>  Remaining Estimate: 0h
>
> The source files for hdfs_deleteSnapshot uses *getopt* for parsing the 
> command line arguments. getopt is available only on Linux and thus, isn't 
> cross platform. We need to replace getopt with *boost::program_options* to 
> make this cross platform.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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

Reply via email to