Skip to content

Commit

Permalink
Add server healthy method
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Sep 12, 2018
1 parent 6bc0521 commit 8b29515
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,6 @@ public interface NamingService {
* @throws NacosException
*/
List<ServiceInfo> getSubscribeServices() throws NacosException;

boolean serverHealthy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @author dungu.zpf
*/
public class ServiceInfo {

@JSONField(serialize = false)
private String jsonFromServer = StringUtils.EMPTY;
public static final String SPLITER = "@@";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,9 @@ public ListView<String> getServicesOfServer(int pageNo, int pageSize) throws Nac
public List<ServiceInfo> getSubscribeServices() {
return new ArrayList<>(hostReactor.getServiceInfoMap().values());
}

@Override
public boolean serverHealthy() {
return serverProxy.serverHealthy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ public void deRegDom(String dom, String ip, int port, String cluster) throws Nac
}
}

public boolean serverHealthy() {

try {
reqAPI(UtilAndComs.NACOS_URL_BASE + "/api/hello", new HashMap<>());
} catch (Exception e) {
return false;
}

return true;
}

public ListView<String> getServiceList(int pageNo, int pageSize) throws NacosException {

Map<String, String> params = new HashMap<String, String>(4);
Expand All @@ -244,7 +255,8 @@ public ListView<String> getServiceList(int pageNo, int pageSize) throws NacosExc
JSONObject json = JSON.parseObject(result);
ListView<String> listView = new ListView<>();
listView.setCount(json.getInteger("count"));
listView.setData(JSON.parseObject(json.getString("doms"), new TypeReference<List<String>>(){}));
listView.setData(JSON.parseObject(json.getString("doms"), new TypeReference<List<String>>() {
}));

return listView;
}
Expand Down

0 comments on commit 8b29515

Please sign in to comment.