adoroszlai commented on code in PR #6147:
URL: https://github.com/apache/ozone/pull/6147#discussion_r1527539322
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/nssummary/DiskUsageSubCommand.java:
##########
@@ -160,20 +161,20 @@ public Void call() throws Exception {
seekStr = "";
}
- ArrayList duData = (ArrayList)duResponse.get("subPaths");
+ ArrayList<?> duData = (ArrayList<?>) duResponse.get("subPaths");
int cnt = 0;
- for (int i = 0; i < duData.size(); ++i) {
+ for (Object o : duData) {
if (cnt >= limit) {
break;
}
- LinkedTreeMap subPathDU = (LinkedTreeMap) duData.get(i);
- String subPath = subPathDU.get("path").toString();
- // differentiate key from other types
- if (!(boolean)subPathDU.get("isKey")) {
+ LinkedTreeMap<?, ?> subPathDU = (LinkedTreeMap<?, ?>) o;
Review Comment:
`LinkedTreeMap` is part of GSON. I guess if we reach this code,
`ClassCastException` will be thrown. Probably needs to be `Map`, but please
confirm by testing it manually.
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainerMetadataInspector.java:
##########
@@ -181,55 +183,62 @@ public String process(ContainerData containerData,
DatanodeStore store,
return null;
}
- JsonObject containerJson = inspectContainer(kvData, store);
+ ObjectNode containerJson = inspectContainer(kvData, store);
boolean correct = checkAndRepair(containerJson, kvData, store);
- Gson gson = new GsonBuilder()
- .setPrettyPrinting()
- .serializeNulls()
- .create();
- String jsonReport = gson.toJson(containerJson);
- if (log != null) {
- if (correct) {
- log.trace(jsonReport);
- } else {
- log.error(jsonReport);
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ // For pretty-printing
+ mapper.enable(SerializationFeature.INDENT_OUTPUT);
+ // To serialize null values
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ String jsonReport = mapper.writeValueAsString(containerJson);
Review Comment:
Let's try to avoid creating a new `ObjectMapper` for each serialization
(also in ~17 other files). Use `JsonUtils`:
https://github.com/apache/ozone/blob/238bff09e9adbd30103c0985bb136e97c776af66/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/server/JsonUtils.java#L59-L74
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/recon/TestReconWithOzoneManager.java:
##########
@@ -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>>() {
Review Comment:
Can we replace `LinkedTreeMap` with `Map` here, too?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]