block_location.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 HDFSPP_BLOCK_LOCATION_H
  19. #define HDFSPP_BLOCK_LOCATION_H
  20. namespace hdfs {
  21. class DNInfo {
  22. public:
  23. DNInfo() : xfer_port_(-1), info_port_(-1), IPC_port_(-1), info_secure_port_(-1) {}
  24. std::string getHostname() const {
  25. return hostname_;
  26. }
  27. void setHostname(const std::string & hostname) {
  28. this->hostname_ = hostname;
  29. }
  30. std::string getIPAddr() const {
  31. return ip_addr_;
  32. }
  33. void setIPAddr(const std::string & ip_addr) {
  34. this->ip_addr_ = ip_addr;
  35. }
  36. std::string getNetworkLocation() const {
  37. return network_location_;
  38. }
  39. void setNetworkLocation(const std::string & location) {
  40. this->network_location_ = location;
  41. }
  42. int getXferPort() const {
  43. return xfer_port_;
  44. }
  45. void setXferPort(int xfer_port) {
  46. this->xfer_port_ = xfer_port;
  47. }
  48. int getInfoPort() const {
  49. return info_port_;
  50. }
  51. void setInfoPort(int info_port) {
  52. this->info_port_ = info_port;
  53. }
  54. int getIPCPort() const {
  55. return IPC_port_;
  56. }
  57. void setIPCPort(int IPC_port) {
  58. this->IPC_port_ = IPC_port;
  59. }
  60. int getInfoSecurePort() const {
  61. return info_secure_port_;
  62. }
  63. void setInfoSecurePort(int info_secure_port) {
  64. this->info_secure_port_ = info_secure_port;
  65. }
  66. private:
  67. std::string hostname_;
  68. std::string ip_addr_;
  69. std::string network_location_;
  70. int xfer_port_;
  71. int info_port_;
  72. int IPC_port_;
  73. int info_secure_port_;
  74. };
  75. class BlockLocation {
  76. public:
  77. bool isCorrupt() const {
  78. return corrupt_;
  79. }
  80. void setCorrupt(bool corrupt) {
  81. this->corrupt_ = corrupt;
  82. }
  83. int64_t getLength() const {
  84. return length_;
  85. }
  86. void setLength(int64_t length) {
  87. this->length_ = length;
  88. }
  89. int64_t getOffset() const {
  90. return offset_;
  91. }
  92. void setOffset(int64_t offset) {
  93. this->offset_ = offset;
  94. }
  95. const std::vector<DNInfo> & getDataNodes() const {
  96. return dn_info_;
  97. }
  98. void setDataNodes(const std::vector<DNInfo> & dn_info) {
  99. this->dn_info_ = dn_info;
  100. }
  101. private:
  102. bool corrupt_;
  103. int64_t length_;
  104. int64_t offset_; // Offset of the block in the file
  105. std::vector<DNInfo> dn_info_; // Info about who stores each block
  106. };
  107. class FileBlockLocation {
  108. public:
  109. uint64_t getFileLength() {
  110. return fileLength_;
  111. }
  112. void setFileLength(uint64_t fileLength) {
  113. this->fileLength_ = fileLength;
  114. }
  115. bool isLastBlockComplete() const {
  116. return this->lastBlockComplete_;
  117. }
  118. void setLastBlockComplete(bool lastBlockComplete) {
  119. this->lastBlockComplete_ = lastBlockComplete;
  120. }
  121. bool isUnderConstruction() const {
  122. return underConstruction_;
  123. }
  124. void setUnderConstruction(bool underConstruction) {
  125. this->underConstruction_ = underConstruction;
  126. }
  127. const std::vector<BlockLocation> & getBlockLocations() const {
  128. return blockLocations_;
  129. }
  130. void setBlockLocations(const std::vector<BlockLocation> & blockLocations) {
  131. this->blockLocations_ = blockLocations;
  132. }
  133. private:
  134. uint64_t fileLength_;
  135. bool lastBlockComplete_;
  136. bool underConstruction_;
  137. std::vector<BlockLocation> blockLocations_;
  138. };
  139. } // namespace hdfs
  140. #endif /* HDFSPP_BLOCK_LOCATION_H */