Hean-Chhinling commented on code in PR #8227:
URL: https://github.com/apache/hadoop/pull/8227#discussion_r2840813405
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/webapp/TestNMWebServices.java:
##########
@@ -901,53 +929,51 @@ private static String getRedirectURL(String url) {
private List<ContainerLogsInfo> readEntity(Response response) throws
JSONException {
JSONObject jsonObject = response.readEntity(JSONObject.class);
- Iterator<String> keys = jsonObject.keys();
List<ContainerLogsInfo> list = new ArrayList<>();
- while (keys.hasNext()) {
- String key = keys.next();
- JSONObject subJsonObject = jsonObject.getJSONObject(key);
- Iterator<String> subKeys = subJsonObject.keys();
- while (subKeys.hasNext()) {
- String subKeyItem = subKeys.next();
- Object object = subJsonObject.get(subKeyItem);
-
- if (object instanceof JSONObject) {
- JSONObject subKeyItemValue = subJsonObject.getJSONObject(subKeyItem);
- ContainerLogsInfo containerLogsInfo =
parseContainerLogsInfo(subKeyItemValue);
- list.add(containerLogsInfo);
- }
+ Object containerLogsTypeInfo = jsonObject.get("containerLogsInfo");
- if(object instanceof JSONArray) {
- JSONArray jsonArray = subJsonObject.getJSONArray(subKeyItem);
- for (int i = 0; i < jsonArray.length(); i++) {
- JSONObject subKeyItemValue = jsonArray.getJSONObject(i);
- ContainerLogsInfo containerLogsInfo =
parseContainerLogsInfo(subKeyItemValue);
- list.add(containerLogsInfo);
- }
- }
+ if (containerLogsTypeInfo instanceof JSONArray) {
+ JSONArray containerLogsInfoArr = (JSONArray) containerLogsTypeInfo;
+ for (int i = 0; i < containerLogsInfoArr.length(); i++) {
+
list.add(parseContainerLogsInfo(containerLogsInfoArr.getJSONObject(i)));
}
+ } else if (containerLogsTypeInfo instanceof JSONObject) {
+ list.add(parseContainerLogsInfo((JSONObject) containerLogsTypeInfo));
}
return list;
}
- private ContainerLogsInfo parseContainerLogsInfo(JSONObject subKeyItemValue)
+ private ContainerLogsInfo parseContainerLogsInfo(JSONObject jsonLogsInfo)
throws JSONException {
- String logAggregationType =
subKeyItemValue.getString("logAggregationType");
- String containerId = subKeyItemValue.getString("containerId");
- String nodeId = subKeyItemValue.getString("nodeId");
-
- JSONObject containerLogInfo =
subKeyItemValue.getJSONObject("containerLogInfo");
- String fileName = containerLogInfo.getString("fileName");
- String fileSize = containerLogInfo.getString("fileSize");
- String lastModifiedTime = containerLogInfo.getString("lastModifiedTime");
+ String logAggregationType = jsonLogsInfo.getString("logAggregationType");
+ String containerId = jsonLogsInfo.getString("containerId");
+ String nodeId = jsonLogsInfo.getString("nodeId");
ContainerLogMeta containerLogMeta = new ContainerLogMeta(containerId,
nodeId);
- containerLogMeta.addLogMeta(fileName, fileSize, lastModifiedTime);
- ContainerLogsInfo containerLogsInfo =
- new ContainerLogsInfo(containerLogMeta, logAggregationType);
- return containerLogsInfo;
+
+ Object containerLogTypeInfo = jsonLogsInfo.get("containerLogInfo");
+ if (containerLogTypeInfo instanceof JSONArray) {
+ JSONArray containerLogInfoArr = (JSONArray) containerLogTypeInfo;
Review Comment:
it will check the response has size 2 already,
[here](https://github.com/apache/hadoop/blob/17cc6ee2ec42d8dbb7479ace2c6942222bbbb3a8/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/webapp/TestNMWebServices.java#L741).
I do not think we need to check here as well
--
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]