|
@@ -298,16 +298,36 @@ public class JsonUtil {
|
|
|
return m;
|
|
|
}
|
|
|
|
|
|
+ private static int getInt(Map<?, ?> m, String key, final int defaultValue) {
|
|
|
+ Object value = m.get(key);
|
|
|
+ if (value == null) {
|
|
|
+ return defaultValue;
|
|
|
+ }
|
|
|
+ return (int) (long) (Long) value;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static long getLong(Map<?, ?> m, String key, final long defaultValue) {
|
|
|
+ Object value = m.get(key);
|
|
|
+ if (value == null) {
|
|
|
+ return defaultValue;
|
|
|
+ }
|
|
|
+ return (long) (Long) value;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getString(Map<?, ?> m, String key,
|
|
|
+ final String defaultValue) {
|
|
|
+ Object value = m.get(key);
|
|
|
+ if (value == null) {
|
|
|
+ return defaultValue;
|
|
|
+ }
|
|
|
+ return (String) value;
|
|
|
+ }
|
|
|
+
|
|
|
/** Convert a Json map to an DatanodeInfo object. */
|
|
|
static DatanodeInfo toDatanodeInfo(final Map<?, ?> m) {
|
|
|
if (m == null) {
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
- Object infoSecurePort = m.get("infoSecurePort");
|
|
|
- if (infoSecurePort == null) {
|
|
|
- infoSecurePort = 0l; // same as the default value in hdfs.proto
|
|
|
- }
|
|
|
|
|
|
return new DatanodeInfo(
|
|
|
(String)m.get("ipAddr"),
|
|
@@ -315,19 +335,19 @@ public class JsonUtil {
|
|
|
(String)m.get("storageID"),
|
|
|
(int)(long)(Long)m.get("xferPort"),
|
|
|
(int)(long)(Long)m.get("infoPort"),
|
|
|
- (int)(long)(Long)infoSecurePort,
|
|
|
+ getInt(m, "infoSecurePort", 0),
|
|
|
(int)(long)(Long)m.get("ipcPort"),
|
|
|
|
|
|
- (Long)m.get("capacity"),
|
|
|
- (Long)m.get("dfsUsed"),
|
|
|
- (Long)m.get("remaining"),
|
|
|
- (Long)m.get("blockPoolUsed"),
|
|
|
- (Long)m.get("cacheCapacity"),
|
|
|
- (Long)m.get("cacheUsed"),
|
|
|
- (Long)m.get("lastUpdate"),
|
|
|
- (int)(long)(Long)m.get("xceiverCount"),
|
|
|
- (String)m.get("networkLocation"),
|
|
|
- AdminStates.valueOf((String)m.get("adminState")));
|
|
|
+ getLong(m, "capacity", 0l),
|
|
|
+ getLong(m, "dfsUsed", 0l),
|
|
|
+ getLong(m, "remaining", 0l),
|
|
|
+ getLong(m, "blockPoolUsed", 0l),
|
|
|
+ getLong(m, "cacheCapacity", 0l),
|
|
|
+ getLong(m, "cacheUsed", 0l),
|
|
|
+ getLong(m, "lastUpdate", 0l),
|
|
|
+ getInt(m, "xceiverCount", 0),
|
|
|
+ getString(m, "networkLocation", ""),
|
|
|
+ AdminStates.valueOf(getString(m, "adminState", "NORMAL")));
|
|
|
}
|
|
|
|
|
|
/** Convert a DatanodeInfo[] to a Json array. */
|