Search in sources :

Example 1 with GroupOfflineException

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

the class GroupRouter method loadBalancedInstance.

public GroupInstance loadBalancedInstance(String groupName) throws GroupOfflineException, GroupUndefinedException {
    GroupInstance instance = localInstance(groupName);
    if (instance != null)
        return instance;
    newestDefinition(groupName);
    if (GroupDiscovery.singleton != null)
        instance = GroupDiscovery.singleton.lb(groupName);
    if (instance != null)
        return instance;
    throw new GroupOfflineException(groupName);
}
Also used : GroupOfflineException(info.xiancloud.core.distribution.exception.GroupOfflineException) GroupInstance(info.xiancloud.core.distribution.service_discovery.GroupInstance)

Example 2 with GroupOfflineException

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

the class GroupRouter method allInstances.

public List<GroupInstance> allInstances(String groupName) throws GroupOfflineException, GroupUndefinedException {
    newestDefinition(groupName);
    List<GroupInstance> instances;
    if (GroupDiscovery.singleton != null)
        instances = GroupDiscovery.singleton.all(groupName);
    else {
        instances = new ArrayList<>();
        instances.add(localInstance(groupName));
    }
    if (instances.isEmpty())
        throw new GroupOfflineException(groupName);
    /*instances.sort(Comparator.comparing(GroupInstance::getNodeId));
         we do not sort any more, sort by your self if you need consistent hash.
         */
    return instances;
}
Also used : GroupOfflineException(info.xiancloud.core.distribution.exception.GroupOfflineException) GroupInstance(info.xiancloud.core.distribution.service_discovery.GroupInstance)

Example 3 with GroupOfflineException

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

the class FactorCollector method collect.

public static JSONObject collect() {
    JSONObject factorOriented = new JSONObject();
    String diyMonitorServiceName = new DiyMonitorGroup().getName();
    Set<String> diyMonitorUnitNames = new HashSet<>();
    try {
        for (GroupInstance serviceInstance : GroupRouter.singleton.allInstances(diyMonitorServiceName)) {
            diyMonitorUnitNames.addAll(serviceInstance.getPayload().getUnitNames());
        }
    } catch (GroupOfflineException | GroupUndefinedException e) {
        throw new RuntimeException(e);
    }
    for (String diyMonitorUnitName : diyMonitorUnitNames) {
        UnitResponse o = SyncXian.call(diyMonitorServiceName, diyMonitorUnitName, new HashMap());
        if (o.succeeded()) {
            try {
                LOG.debug("data可以是单纯的数字,也可以是json/jsonArray");
                factorOriented.put(diyMonitorUnitName, o.getData());
            } catch (Throwable e) {
                LOG.error("收集指标 '" + diyMonitorUnitName + "' 时出现异常,返回-1作为指标值", e);
                factorOriented.put(diyMonitorUnitName, ERROR_VALUE_NEGATIVE_1);
            }
        } else {
            LOG.error("收集指标 '" + diyMonitorUnitName + "' 失败 !  返回-1作为指标值   .   失败内容为 :" + o);
            factorOriented.put(diyMonitorUnitName, ERROR_VALUE_NEGATIVE_1);
        }
    }
    return factorOriented;
}
Also used : HashMap(java.util.HashMap) GroupOfflineException(info.xiancloud.core.distribution.exception.GroupOfflineException) GroupUndefinedException(info.xiancloud.core.distribution.exception.GroupUndefinedException) DiyMonitorGroup(info.xiancloud.core.support.falcon.DiyMonitorGroup) JSONObject(com.alibaba.fastjson.JSONObject) UnitResponse(info.xiancloud.core.message.UnitResponse) GroupInstance(info.xiancloud.core.distribution.service_discovery.GroupInstance) HashSet(java.util.HashSet)

Example 4 with GroupOfflineException

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

the class GroupRouter method firstInstance.

@Override
public GroupInstance firstInstance(String groupName) throws GroupOfflineException, GroupUndefinedException {
    GroupInstance instance = localInstance(groupName);
    if (instance != null)
        return instance;
    newestDefinition(groupName);
    if (GroupDiscovery.singleton != null)
        instance = GroupDiscovery.singleton.firstInstance(groupName);
    if (instance != null)
        return instance;
    throw new GroupOfflineException(groupName);
}
Also used : GroupOfflineException(info.xiancloud.core.distribution.exception.GroupOfflineException) GroupInstance(info.xiancloud.core.distribution.service_discovery.GroupInstance)

Aggregations

GroupOfflineException (info.xiancloud.core.distribution.exception.GroupOfflineException)4 GroupInstance (info.xiancloud.core.distribution.service_discovery.GroupInstance)4 JSONObject (com.alibaba.fastjson.JSONObject)1 GroupUndefinedException (info.xiancloud.core.distribution.exception.GroupUndefinedException)1 UnitResponse (info.xiancloud.core.message.UnitResponse)1 DiyMonitorGroup (info.xiancloud.core.support.falcon.DiyMonitorGroup)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1