namenode_operations.h 4.2 KB

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