block_location.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. int getXferPort() const {
  37. return xfer_port;
  38. }
  39. void setXferPort(int xfer_port) {
  40. this->xfer_port = xfer_port;
  41. }
  42. int getInfoPort() const {
  43. return info_port;
  44. }
  45. void setInfoPort(int info_port) {
  46. this->info_port = info_port;
  47. }
  48. int getIPCPort() const {
  49. return IPC_port;
  50. }
  51. void setIPCPort(int IPC_port) {
  52. this->IPC_port = IPC_port;
  53. }
  54. int getInfoSecurePort() const {
  55. return info_secure_port;
  56. }
  57. void setInfoSecurePort(int info_secure_port) {
  58. this->info_secure_port = info_secure_port;
  59. }
  60. private:
  61. std::string hostname;
  62. std::string ip_addr;
  63. int xfer_port;
  64. int info_port;
  65. int IPC_port;
  66. int info_secure_port;
  67. };
  68. class BlockLocation {
  69. public:
  70. bool isCorrupt() const {
  71. return corrupt;
  72. }
  73. void setCorrupt(bool corrupt) {
  74. this->corrupt = corrupt;
  75. }
  76. int64_t getLength() const {
  77. return length;
  78. }
  79. void setLength(int64_t length) {
  80. this->length = length;
  81. }
  82. int64_t getOffset() const {
  83. return offset;
  84. }
  85. void setOffset(int64_t offset) {
  86. this->offset = offset;
  87. }
  88. const std::vector<DNInfo> & getDataNodes() const {
  89. return dn_info;
  90. }
  91. void setDataNodes(const std::vector<DNInfo> & dn_info) {
  92. this->dn_info = dn_info;
  93. }
  94. private:
  95. bool corrupt;
  96. int64_t length;
  97. int64_t offset; // Offset of the block in the file
  98. std::vector<DNInfo> dn_info; // Info about who stores each block
  99. };
  100. class FileBlockLocation {
  101. public:
  102. uint64_t getFileLength() {
  103. return fileLength;
  104. }
  105. void setFileLength(uint64_t fileLength) {
  106. this->fileLength = fileLength;
  107. }
  108. bool isLastBlockComplete() const {
  109. return this->lastBlockComplete;
  110. }
  111. void setLastBlockComplete(bool lastBlockComplete) {
  112. this->lastBlockComplete = lastBlockComplete;
  113. }
  114. bool isUnderConstruction() const {
  115. return underConstruction;
  116. }
  117. void setUnderConstruction(bool underConstruction) {
  118. this->underConstruction = underConstruction;
  119. }
  120. const std::vector<BlockLocation> & getBlockLocations() const {
  121. return blockLocations;
  122. }
  123. void setBlockLocations(const std::vector<BlockLocation> & blockLocations) {
  124. this->blockLocations = blockLocations;
  125. }
  126. private:
  127. uint64_t fileLength;
  128. bool lastBlockComplete;
  129. bool underConstruction;
  130. std::vector<BlockLocation> blockLocations;
  131. };
  132. } // namespace hdfs
  133. #endif /* HDFSPP_BLOCK_LOCATION_H */