diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/block_location.h b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/block_location.h index cbe34be3642..5a03f41d9e7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/block_location.h +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/block_location.h @@ -41,6 +41,14 @@ public: this->ip_addr = ip_addr; } + std::string getNetworkLocation() const { + return network_location; + } + + void setNetworkLocation(const std::string & location) { + this->network_location = location; + } + int getXferPort() const { return xfer_port; } @@ -75,6 +83,7 @@ public: private: std::string hostname; std::string ip_addr; + std::string network_location; int xfer_port; int info_port; int IPC_port; diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/hdfs_ext.h b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/hdfs_ext.h index b41857ca144..72434e6b222 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/hdfs_ext.h +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/hdfs_ext.h @@ -132,6 +132,7 @@ int hdfsBuilderConfGetLong(struct hdfsBuilder *bld, const char *key, int64_t *va struct hdfsDNInfo { const char * ip_address; const char * hostname; + const char * network_location; int xfer_port; int info_port; int IPC_port; diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc index a43d94f6612..dd7d00c75ad 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc @@ -1248,6 +1248,10 @@ int hdfsGetBlockLocations(hdfsFS fs, const char *path, struct hdfsBlockLocations buf = new char[ppDNInfo.getIPAddr().size() + 1]; strncpy(buf, ppDNInfo.getIPAddr().c_str(), ppDNInfo.getIPAddr().size() + 1); dn_info->ip_address = buf; + + buf = new char[ppDNInfo.getNetworkLocation().size() + 1]; + strncpy(buf, ppDNInfo.getNetworkLocation().c_str(), ppDNInfo.getNetworkLocation().size() + 1); + dn_info->network_location = buf; } } @@ -1270,6 +1274,7 @@ int hdfsFreeBlockLocations(struct hdfsBlockLocations * blockLocations) { auto location = &block->locations[j]; delete[] location->hostname; delete[] location->ip_address; + delete[] location->network_location; } } delete[] blockLocations->blocks; diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filesystem.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filesystem.cc index 72b30e5dfda..5d5b9f2ac79 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filesystem.cc +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filesystem.cc @@ -354,6 +354,8 @@ BlockLocation LocatedBlockToBlockLocation(const hadoop::hdfs::LocatedBlockProto newInfo.setIPCPort(id.ipcport()); if (id.has_infosecureport()) newInfo.setInfoSecurePort(id.infosecureport()); + if (datanode_info.has_location()) + newInfo.setNetworkLocation(datanode_info.location()); dn_info.push_back(newInfo); } result.setDataNodes(dn_info); diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/hdfs_ext_test.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/hdfs_ext_test.cc index c160f7fb066..400b97c879a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/hdfs_ext_test.cc +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/hdfs_ext_test.cc @@ -56,6 +56,7 @@ TEST_F(HdfsExtTest, TestGetBlockLocations) { EXPECT_EQ(1, blocks->blocks->num_locations); EXPECT_NE(nullptr, blocks->blocks->locations->hostname); EXPECT_NE(nullptr, blocks->blocks->locations->ip_address); + EXPECT_NE(nullptr, blocks->blocks->locations->network_location); EXPECT_NE(0, blocks->blocks->locations->xfer_port); result = hdfsFreeBlockLocations(blocks);