Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import com.google.gson.internal.LinkedTreeMap;
import org.apache.hadoop.hdds.client.BlockID;
import org.apache.hadoop.hdds.client.StandaloneReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
Expand All @@ -64,9 +65,9 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.type.TypeReference;

import com.google.gson.Gson;
import com.google.gson.internal.LinkedTreeMap;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -381,16 +382,21 @@ private static OmKeyLocationInfoGroup getOmKeyLocationInfoGroup() {

private long getReconTaskAttributeFromJson(String taskStatusResponse,
String taskName,
String entityAttribute) {
ArrayList<LinkedTreeMap> taskStatusList = new Gson()
.fromJson(taskStatusResponse, ArrayList.class);
String entityAttribute)
throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
ArrayList<LinkedTreeMap> taskStatusList = objectMapper.readValue(
taskStatusResponse, new TypeReference<ArrayList<LinkedTreeMap>>() {
});

Optional<LinkedTreeMap> taskEntity =
taskStatusList
.stream()
.filter(task -> task.get("taskName").equals(taskName))
.findFirst();
assertTrue(taskEntity.isPresent());
return (long) (double) taskEntity.get().get(entityAttribute);
Number number = (Number) taskEntity.get().get(entityAttribute);
return number.longValue();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@
*/
package org.apache.hadoop.ozone.admin.nssummary;

import com.google.gson.internal.LinkedTreeMap;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.ozone.shell.ListOptions;
import picocli.CommandLine;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.Callable;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.getResponseMap;
import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.makeHttpCall;
import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.parseInputPath;
import static org.apache.hadoop.ozone.admin.nssummary.NSSummaryCLIUtils.printEmptyPathRequest;
Expand Down Expand Up @@ -101,21 +99,21 @@ public Void call() throws Exception {
return null;
}

HashMap<String, Object> duResponse = getResponseMap(response);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode duResponse = objectMapper.readTree(response);

if (duResponse.get("status").equals("PATH_NOT_FOUND")) {
if (duResponse.get("status").asText().equals("PATH_NOT_FOUND")) {
printPathNotFound();
} else {
if (parent.isNotValidBucketOrOBSBucket(path)) {
printBucketReminder();
}

long totalSize = (long)(double)duResponse.get("size");

long totalSize = duResponse.get("size").asLong();
if (!noHeader) {
printWithUnderline("Path", false);
printKVSeparator();
System.out.println(duResponse.get("path"));
System.out.println(duResponse.get("path").asText());

printWithUnderline("Total Size", false);
printKVSeparator();
Expand All @@ -124,11 +122,11 @@ public Void call() throws Exception {
if (withReplica) {
printWithUnderline("Total Disk Usage", false);
printKVSeparator();
long du = (long)(double)duResponse.get("sizeWithReplica");
long du = duResponse.get("sizeWithReplica").asLong();
System.out.println(FileUtils.byteCountToDisplaySize(du));
}

long sizeDirectKey = (long)(double)duResponse.get("sizeDirectKey");
long sizeDirectKey = duResponse.get("sizeDirectKey").asLong();
if (!listFiles && sizeDirectKey != -1) {
printWithUnderline("Size of Direct Keys", false);
printKVSeparator();
Expand All @@ -137,7 +135,7 @@ public Void call() throws Exception {
printNewLines(1);
}

if ((double)duResponse.get("subPathCount") == 0) {
if (duResponse.get("subPathCount").asInt() == 0) {
if (totalSize == 0) {
// the object is empty
System.out.println("The object is empty.\n" +
Expand All @@ -160,20 +158,19 @@ public Void call() throws Exception {
seekStr = "";
}

ArrayList duData = (ArrayList)duResponse.get("subPaths");
ArrayNode subPaths = (ArrayNode) duResponse.get("subPaths");
int cnt = 0;
for (int i = 0; i < duData.size(); ++i) {
for (JsonNode subPathDU : subPaths) {
if (cnt >= limit) {
break;
}
LinkedTreeMap subPathDU = (LinkedTreeMap) duData.get(i);
String subPath = subPathDU.get("path").toString();
String subPath = subPathDU.get("path").asText();
// differentiate key from other types
if (!(boolean)subPathDU.get("isKey")) {
if (!subPathDU.get("isKey").asBoolean()) {
subPath += OM_KEY_PREFIX;
}
long size = (long)(double)subPathDU.get("size");
long sizeWithReplica = (long)(double)subPathDU.get("sizeWithReplica");
long size = subPathDU.get("size").asLong();
long sizeWithReplica = subPathDU.get("sizeWithReplica").asLong();
if (subPath.startsWith(seekStr)) {
printDURow(subPath, size, sizeWithReplica);
++cnt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public Void call() throws Exception {
}

printWithUnderline("File Size Distribution", true);
ArrayList fileSizeDist = (ArrayList) distResponse.get("dist");
ArrayList<?> fileSizeDist = (ArrayList<?>) distResponse.get("dist");
double sum = 0;

for (int i = 0; i < fileSizeDist.size(); ++i) {
sum += (double) fileSizeDist.get(i);
for (Object obj : fileSizeDist) {
sum += ((Number) obj).doubleValue();
}
if (sum == 0) {
printSpaces(2);
Expand All @@ -100,11 +100,12 @@ public Void call() throws Exception {
}

for (int i = 0; i < fileSizeDist.size(); ++i) {
if ((double)fileSizeDist.get(i) == 0) {
double count = ((Number) fileSizeDist.get(i)).doubleValue();
if (count == 0) {
continue;
}
String label = convertBinIndexToReadableRange(i);
printDistRow(label, (double) fileSizeDist.get(i), sum);
printDistRow(label, count, sum);
}
}
printNewLines(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@

package org.apache.hadoop.ozone.admin.nssummary;

import com.google.gson.Gson;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdfs.web.URLConnectionFactory;
import picocli.CommandLine.Help.Ansi;

import javax.security.sasl.AuthenticationException;
import java.io.IOException;
import java.io.InputStream;
import java.net.ConnectException;
import java.net.HttpURLConnection;
Expand Down Expand Up @@ -107,8 +109,12 @@ public static String makeHttpCall(StringBuffer url, String path,
}
}

public static HashMap<String, Object> getResponseMap(String response) {
return new Gson().fromJson(response, HashMap.class);
public static HashMap<String, Object> getResponseMap(String response)
throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(response,
new TypeReference<HashMap<String, Object>>() {
});
}

public static void printNewLines(int cnt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ public Void call() throws Exception {
}

printWithUnderline("Quota", true);
long quotaAllowed = (long)(double)quotaResponse.get("allowed");
long quotaUsed = (long)(double)quotaResponse.get("used");

long quotaAllowed = ((Number) quotaResponse.get("allowed")).longValue();
long quotaUsed = ((Number) quotaResponse.get("used")).longValue();

printSpaces(2);
System.out.print("Allowed");
printKVSeparator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ public Void call() throws Exception {
printWithUnderline("Entity Type", false);
printKVSeparator();
System.out.println(summaryResponse.get("type"));
int numVol = ((Double) summaryResponse.get("numVolume")).intValue();
int numBucket = ((Double) summaryResponse.get("numBucket")).intValue();
int numDir = ((Double) summaryResponse.get("numDir")).intValue();
int numKey = ((Double) summaryResponse.get("numKey")).intValue();

int numVol = ((Number) summaryResponse.get("numVolume")).intValue();
int numBucket = ((Number) summaryResponse.get("numBucket")).intValue();
int numDir = ((Number) summaryResponse.get("numDir")).intValue();
int numKey = ((Number) summaryResponse.get("numKey")).intValue();

if (numVol != -1) {
printWithUnderline("Volumes", false);
Expand Down