namenode_operations.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_LIB_FS_NAMENODEOPERATIONS_H_
  19. #define LIBHDFSPP_LIB_FS_NAMENODEOPERATIONS_H_
  20. #include "rpc/rpc_engine.h"
  21. #include "hdfspp/statinfo.h"
  22. #include "hdfspp/fsinfo.h"
  23. #include "hdfspp/content_summary.h"
  24. #include "common/namenode_info.h"
  25. #include "ClientNamenodeProtocol.pb.h"
  26. #include "ClientNamenodeProtocol.hrpc.inl"
  27. namespace hdfs {
  28. /**
  29. * NameNodeConnection: abstracts the details of communicating with a NameNode
  30. * and the implementation of the communications protocol.
  31. *
  32. * Will eventually handle retry and failover.
  33. *
  34. * Threading model: thread-safe; all operations can be called concurrently
  35. * Lifetime: owned by a FileSystemImpl
  36. */
  37. class NameNodeOperations {
  38. public:
  39. MEMCHECKED_CLASS(NameNodeOperations)
  40. NameNodeOperations(::asio::io_service *io_service, const Options &options,
  41. const std::string &client_name, const std::string &user_name,
  42. const char *protocol_name, int protocol_version) :
  43. io_service_(io_service),
  44. engine_(io_service, options, client_name, user_name, protocol_name, protocol_version),
  45. namenode_(& engine_), options_(options) {}
  46. void Connect(const std::string &cluster_name,
  47. const std::vector<ResolvedNamenodeInfo> &servers,
  48. std::function<void(const Status &)> &&handler);
  49. bool CancelPendingConnect();
  50. void GetBlockLocations(const std::string & path, uint64_t offset, uint64_t length,
  51. std::function<void(const Status &, std::shared_ptr<const struct FileInfo>)> handler);
  52. void GetPreferredBlockSize(const std::string & path,
  53. std::function<void(const Status &, const uint64_t)> handler);
  54. void SetReplication(const std::string & path, int16_t replication,
  55. std::function<void(const Status &)> handler);
  56. void SetTimes(const std::string & path, uint64_t mtime, uint64_t atime,
  57. std::function<void(const Status &)> handler);
  58. void GetFileInfo(const std::string & path,
  59. std::function<void(const Status &, const StatInfo &)> handler);
  60. void GetContentSummary(const std::string & path,
  61. std::function<void(const Status &, const ContentSummary &)> handler);
  62. void GetFsStats(std::function<void(const Status &, const FsInfo &)> handler);
  63. // start_after="" for initial call
  64. void GetListing(const std::string & path,
  65. std::function<void(const Status &, const std::vector<StatInfo> &, bool)> handler,
  66. const std::string & start_after = "");
  67. void Mkdirs(const std::string & path, uint16_t permissions, bool createparent,
  68. std::function<void(const Status &)> handler);
  69. void Delete(const std::string & path, bool recursive,
  70. std::function<void(const Status &)> handler);
  71. void Rename(const std::string & oldPath, const std::string & newPath,
  72. std::function<void(const Status &)> handler);
  73. void SetPermission(const std::string & path, uint16_t permissions,
  74. std::function<void(const Status &)> handler);
  75. void SetOwner(const std::string & path, const std::string & username,
  76. const std::string & groupname, std::function<void(const Status &)> handler);
  77. void CreateSnapshot(const std::string & path, const std::string & name,
  78. std::function<void(const Status &)> handler);
  79. void DeleteSnapshot(const std::string & path, const std::string & name,
  80. std::function<void(const Status &)> handler);
  81. void RenameSnapshot(const std::string & path, const std::string & old_name, const std::string & new_name,
  82. std::function<void(const Status &)> handler);
  83. void AllowSnapshot(const std::string & path,
  84. std::function<void(const Status &)> handler);
  85. void DisallowSnapshot(const std::string & path,
  86. std::function<void(const Status &)> handler);
  87. void SetFsEventCallback(fs_event_callback callback);
  88. private:
  89. static void HdfsFileStatusProtoToStatInfo(hdfs::StatInfo & si, const ::hadoop::hdfs::HdfsFileStatusProto & fs);
  90. static void ContentSummaryProtoToContentSummary(hdfs::ContentSummary & content_summary, const ::hadoop::hdfs::ContentSummaryProto & csp);
  91. static void DirectoryListingProtoToStatInfo(std::shared_ptr<std::vector<StatInfo>> stat_infos, const ::hadoop::hdfs::DirectoryListingProto & dl);
  92. static void GetFsStatsResponseProtoToFsInfo(hdfs::FsInfo & fs_info, const std::shared_ptr<::hadoop::hdfs::GetFsStatsResponseProto> & fs);
  93. ::asio::io_service * io_service_;
  94. RpcEngine engine_;
  95. ClientNamenodeProtocol namenode_;
  96. const Options options_;
  97. };
  98. }
  99. #endif