1/********************************************************************
2 * Copyright (c) 2013 - 2014, Pivotal Inc.
3 * All rights reserved.
4 *
5 * Author: Zhanwei Wang
6 ********************************************************************/
7/********************************************************************
8 * 2014 -
9 * open source under Apache License Version 2.0
10 ********************************************************************/
11/**
12 * Licensed to the Apache Software Foundation (ASF) under one
13 * or more contributor license agreements. See the NOTICE file
14 * distributed with this work for additional information
15 * regarding copyright ownership. The ASF licenses this file
16 * to you under the Apache License, Version 2.0 (the
17 * "License"); you may not use this file except in compliance
18 * with the License. You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
28#ifndef _HDFS_LIBHDFS3_SERVER_DATANODEINFO_H_
29#define _HDFS_LIBHDFS3_SERVER_DATANODEINFO_H_
30
31#include <string>
32#include <sstream>
33
34namespace Hdfs {
35namespace Internal {
36
37/**
38 * This class extends the primary identifier of a Datanode with ephemeral
39 * state, eg usage information, current administrative state, and the
40 * network location that is communicated to clients.
41 */
42class DatanodeInfo {
43public:
44 const std::string & getHostName() const {
45 return hostName;
46 }
47
48 void setHostName(const std::string & hostName) {
49 this->hostName = hostName;
50 }
51
52 uint32_t getInfoPort() const {
53 return infoPort;
54 }
55
56 void setInfoPort(uint32_t infoPort) {
57 this->infoPort = infoPort;
58 }
59
60 const std::string & getIpAddr() const {
61 return ipAddr;
62 }
63
64 void setIpAddr(const std::string & ipAddr) {
65 this->ipAddr = ipAddr;
66 }
67
68 uint32_t getIpcPort() const {
69 return ipcPort;
70 }
71
72 void setIpcPort(uint32_t ipcPort) {
73 this->ipcPort = ipcPort;
74 }
75
76 const std::string & getDatanodeId() const {
77 return datanodeId;
78 }
79
80 void setDatanodeId(const std::string & storageId) {
81 this->datanodeId = storageId;
82 }
83
84 uint32_t getXferPort() const {
85 return xferPort;
86 }
87
88 void setXferPort(uint32_t xferPort) {
89 this->xferPort = xferPort;
90 }
91
92 const std::string formatAddress() const {
93 std::stringstream ss;
94 ss.imbue(std::locale::classic());
95 ss << hostName << "(" << getIpAddr() << ")";
96 return ss.str();
97 }
98
99 bool operator <(const DatanodeInfo & other) const {
100 return datanodeId < other.datanodeId;
101 }
102
103 bool operator ==(const DatanodeInfo & other) const {
104 return this->datanodeId == other.datanodeId
105 && this->ipAddr == other.ipAddr;
106 }
107
108 const std::string & getLocation() const {
109 return location;
110 }
111
112 void setLocation(const std::string & location) {
113 this->location = location;
114 }
115
116 std::string getXferAddr() const {
117 std::stringstream ss;
118 ss.imbue(std::locale::classic());
119 ss << getIpAddr() << ":" << getXferPort();
120 return ss.str();
121 }
122
123private:
124 uint32_t xferPort;
125 uint32_t infoPort;
126 uint32_t ipcPort;
127 std::string ipAddr;
128 std::string hostName;
129 std::string datanodeId;
130 std::string location;
131};
132
133}
134}
135
136#endif /* _HDFS_LIBHDFS3_SERVER_DATANODEINFO_H_ */
137