Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

[EAGLE-1094] change JSONObject.getString() to optString() to avoid exception #1000

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ public List<String> extractVolumeList(JSONObject response){
JSONArray list = (JSONArray) response.get("data");
for(int i = 0; i< list.length();i++ ){
JSONObject element = (JSONObject) list.get(i);
result.add(element.getString("volumename"));
result.add(element.optString("volumename"));
}
return result;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ private String extractVolumeId(JSONObject response){
JSONArray list = (JSONArray) response.get("data");
if(list.length()!=0) {
JSONObject jsonObject = (JSONObject) list.get(0);
volumeId = jsonObject.getString("volumeid");
String string = jsonObject.optString("volumeid");
if (!string.isEmpty()) {
volumeId = string;
}
}
return volumeId;
}
Expand Down Expand Up @@ -193,4 +196,4 @@ private Map<String, Object> getAppConfig(String site, String appType){



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,21 @@ private void createAllJournalNodeEntities(JMXBean bean, long updateTime, Topolog
}
String jnInfoString = (String) bean.getPropertyMap().get(JN_TRANSACTION_INFO);
JSONObject jsonObject = new JSONObject(jnInfoString);
long lastTxId = Long.parseLong(jsonObject.getString(LAST_TX_ID));
String lstIdStr = jsonObject.optString(LAST_TX_ID);
if (lstIdStr.isEmpty()) {
return;
}
long lastTxId = Long.parseLong(lstIdStr);

String journalnodeString = (String) bean.getPropertyMap().get(JN_STATUS);
JSONArray jsonArray = new JSONArray(journalnodeString);
JSONObject jsonMap = (JSONObject) jsonArray.get(0);

Map<String, HdfsServiceTopologyAPIEntity> journalNodesMap = new HashMap<>();
String manager = jsonMap.getString("manager");
String manager = jsonMap.optString("manager");
if (manager.isEmpty()) {
return;
}
Pattern qjm = Pattern.compile(QJM_PATTERN);
Matcher jpmMatcher = qjm.matcher(manager);
while (jpmMatcher.find()) {
Expand All @@ -177,7 +184,7 @@ private void createAllJournalNodeEntities(JMXBean bean, long updateTime, Topolog
return;
}

String stream = jsonMap.getString("stream");
String stream = jsonMap.optString("stream");
Pattern status = Pattern.compile(STATUS_PATTERN);
Matcher statusMatcher = status.matcher(stream);
long numLiveJournalNodes = 0;
Expand Down Expand Up @@ -288,4 +295,4 @@ public TopologyConstants.TopologyType getTopologyType() {
public TopologyConstants.HadoopVersion getHadoopVersion() {
return TopologyConstants.HadoopVersion.V2;
}
}
}