1
0

hdfs-create-snapshot.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef LIBHDFSPP_TOOLS_HDFS_CREATE_SNAPSHOT
  19. #define LIBHDFSPP_TOOLS_HDFS_CREATE_SNAPSHOT
  20. #include <optional>
  21. #include <string>
  22. #include <boost/program_options.hpp>
  23. #include "hdfs-tool.h"
  24. namespace hdfs::tools {
  25. /**
  26. * {@class CreateSnapshot} is an {@class HdfsTool} that facilitates the creation
  27. * of the snapshot of a snapshot-able directory located at PATH.
  28. */
  29. class CreateSnapshot : public HdfsTool {
  30. public:
  31. /**
  32. * {@inheritdoc}
  33. */
  34. CreateSnapshot(int argc, char **argv);
  35. // Abiding to the Rule of 5
  36. CreateSnapshot(const CreateSnapshot &) = default;
  37. CreateSnapshot(CreateSnapshot &&) = default;
  38. CreateSnapshot &operator=(const CreateSnapshot &) = delete;
  39. CreateSnapshot &operator=(CreateSnapshot &&) = delete;
  40. ~CreateSnapshot() override = default;
  41. /**
  42. * {@inheritdoc}
  43. */
  44. [[nodiscard]] std::string GetDescription() const override;
  45. /**
  46. * {@inheritdoc}
  47. */
  48. [[nodiscard]] bool Do() override;
  49. protected:
  50. /**
  51. * {@inheritdoc}
  52. */
  53. [[nodiscard]] bool Initialize() override;
  54. /**
  55. * {@inheritdoc}
  56. */
  57. [[nodiscard]] bool ValidateConstraints() const override;
  58. /**
  59. * {@inheritdoc}
  60. */
  61. [[nodiscard]] bool HandleHelp() const override;
  62. /**
  63. * Handle the path argument that's passed to this tool.
  64. *
  65. * @param path The path to the snapshot-able directory for which the snapshot
  66. * needs to be created.
  67. * @param name The name to assign to the snapshot after creating it.
  68. *
  69. * @return A boolean indicating the result of this operation.
  70. */
  71. [[nodiscard]] virtual bool
  72. HandleSnapshot(const std::string &path,
  73. const std::optional<std::string> &name = std::nullopt) const;
  74. private:
  75. /**
  76. * A boost data-structure containing the description of positional arguments
  77. * passed to the command-line.
  78. */
  79. po::positional_options_description pos_opt_desc_;
  80. };
  81. } // namespace hdfs::tools
  82. #endif