namenode_operations.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. void Connect(const std::string &cluster_name,
  45. const std::string &server,
  46. const std::string &service,
  47. std::function<void(const Status &)> &&handler);
  48. void GetBlockLocations(const std::string & path,
  49. std::function<void(const Status &, std::shared_ptr<const struct FileInfo>)> handler);
  50. void GetFileInfo(const std::string & path,
  51. std::function<void(const Status &, const StatInfo &)> handler);
  52. void GetFsStats(std::function<void(const Status &, const FsInfo &)> handler);
  53. // start_after="" for initial call
  54. void GetListing(const std::string & path,
  55. std::function<void(const Status &, std::shared_ptr<std::vector<StatInfo>>&, bool)> handler,
  56. const std::string & start_after = "");
  57. void CreateSnapshot(const std::string & path, const std::string & name,
  58. std::function<void(const Status &)> handler);
  59. void DeleteSnapshot(const std::string & path, const std::string & name,
  60. std::function<void(const Status &)> handler);
  61. void AllowSnapshot(const std::string & path,
  62. std::function<void(const Status &)> handler);
  63. void DisallowSnapshot(const std::string & path,
  64. std::function<void(const Status &)> handler);
  65. void SetFsEventCallback(fs_event_callback callback);
  66. private:
  67. static void HdfsFileStatusProtoToStatInfo(hdfs::StatInfo & si, const ::hadoop::hdfs::HdfsFileStatusProto & fs);
  68. static void DirectoryListingProtoToStatInfo(std::shared_ptr<std::vector<StatInfo>> stat_infos, const ::hadoop::hdfs::DirectoryListingProto & dl);
  69. static void GetFsStatsResponseProtoToFsInfo(hdfs::FsInfo & fs_info, const std::shared_ptr<::hadoop::hdfs::GetFsStatsResponseProto> & fs);
  70. ::asio::io_service * io_service_;
  71. RpcEngine engine_;
  72. ClientNamenodeProtocol namenode_;
  73. };
  74. }
  75. #endif