namenode_operations.h 4.6 KB

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