Search in sources :

Example 1 with ApplicationUndefinedException

use of info.xiancloud.core.distribution.exception.ApplicationUndefinedException in project xian by happyyangyuan.

the class GetNodeInfoUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    if (StringUtil.isEmpty(msg.get("application"))) {
        JSONArray nodeInfoArray = new JSONArray();
        for (String application : ApplicationDiscovery.singleton.queryForNames()) {
            JSONObject nodeInfo;
            try {
                nodeInfo = nodeInfo(ApplicationRouter.singleton.newestDefinition(application));
            } catch (ApplicationUndefinedException e) {
                LOG.info("忽略未定义的application:" + application);
                continue;
            }
            nodeInfoArray.add(nodeInfo);
        }
        return UnitResponse.success(nodeInfoArray);
    } else
        try {
            JSONArray nodeInfoArray = new JSONArray();
            List<ApplicationInstance> clients = ApplicationRouter.singleton.allInstances(msg.get("application"));
            for (ApplicationInstance instance : clients) {
                nodeInfoArray.add(nodeInfo(instance.getPayload()));
            }
            return UnitResponse.success(nodeInfoArray);
        } catch (ApplicationOfflineException | ApplicationUndefinedException e) {
            return e.toUnitResponse();
        }
}
Also used : ApplicationInstance(info.xiancloud.core.distribution.service_discovery.ApplicationInstance) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) ApplicationUndefinedException(info.xiancloud.core.distribution.exception.ApplicationUndefinedException) List(java.util.List)

Aggregations

JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ApplicationUndefinedException (info.xiancloud.core.distribution.exception.ApplicationUndefinedException)1 ApplicationInstance (info.xiancloud.core.distribution.service_discovery.ApplicationInstance)1 List (java.util.List)1