Search in sources :

Example 1 with AppClientVersion

use of com.sohu.cache.entity.AppClientVersion in project cachecloud by sohutv.

the class ClientReportExceptionServiceImpl method generate.

private AppClientExceptionStat generate(String clientIp, long collectTime, long reportTime, Map<String, Object> map) {
    // 异常信息
    String exceptionClass = MapUtils.getString(map, ClientReportConstant.EXCEPTION_CLASS, "");
    Long exceptionCount = MapUtils.getLong(map, ClientReportConstant.EXCEPTION_COUNT, 0L);
    int exceptionType = MapUtils.getInteger(map, ClientReportConstant.EXCEPTION_TYPE, ClientExceptionType.REDIS_TYPE.getType());
    String host = null;
    Integer port = null;
    Integer instanceId = null;
    long appId;
    if (ClientExceptionType.REDIS_TYPE.getType() == exceptionType) {
        // 实例host:port
        String hostPort = MapUtils.getString(map, ClientReportConstant.EXCEPTION_HOST_PORT, "");
        if (StringUtils.isEmpty(hostPort)) {
            logger.warn("hostPort is empty", hostPort);
            return null;
        }
        int index = hostPort.indexOf(":");
        if (index <= 0) {
            logger.warn("hostPort {} format is wrong", hostPort);
            return null;
        }
        host = hostPort.substring(0, index);
        port = NumberUtils.toInt(hostPort.substring(index + 1));
        // 实例信息
        InstanceInfo instanceInfo = clientReportInstanceService.getInstanceInfoByHostPort(host, port);
        if (instanceInfo == null) {
            //                logger.warn("instanceInfo is empty, host is {}, port is {}", host, port);
            return null;
        }
        // 实例id
        instanceId = instanceInfo.getId();
        // 应用id
        appId = instanceInfo.getAppId();
    } else {
        List<AppClientVersion> appClientVersion = appClientVersionDao.getByClientIp(clientIp);
        if (CollectionUtils.isNotEmpty(appClientVersion)) {
            appId = appClientVersion.get(0).getAppId();
        } else {
            appId = 0;
        }
    }
    // 组装AppClientExceptionStat
    AppClientExceptionStat stat = new AppClientExceptionStat();
    stat.setAppId(appId);
    stat.setClientIp(clientIp);
    stat.setReportTime(new Date(reportTime));
    stat.setCollectTime(collectTime);
    stat.setCreateTime(new Date());
    stat.setExceptionClass(exceptionClass);
    stat.setExceptionCount(exceptionCount);
    stat.setInstanceHost(host);
    stat.setInstancePort(port);
    stat.setInstanceId(instanceId);
    stat.setType(exceptionType);
    return stat;
}
Also used : AppClientExceptionStat(com.sohu.cache.entity.AppClientExceptionStat) InstanceInfo(com.sohu.cache.entity.InstanceInfo) AppClientVersion(com.sohu.cache.entity.AppClientVersion) Date(java.util.Date)

Example 2 with AppClientVersion

use of com.sohu.cache.entity.AppClientVersion in project cachecloud by sohutv.

the class ClientVersionServiceImpl method saveOrUpdateClientVersion.

@Override
public void saveOrUpdateClientVersion(long appId, String appClientIp, String clientVersion) {
    try {
        AppClientVersion appClientVersion = new AppClientVersion();
        appClientVersion.setAppId(appId);
        appClientVersion.setClientIp(appClientIp);
        appClientVersion.setClientVersion(clientVersion);
        appClientVersion.setReportTime(new Date());
        appClientVersionDao.saveOrUpdateClientVersion(appClientVersion);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : AppClientVersion(com.sohu.cache.entity.AppClientVersion) Date(java.util.Date)

Example 3 with AppClientVersion

use of com.sohu.cache.entity.AppClientVersion in project cachecloud by sohutv.

the class ClientVersionServiceImpl method getAppAllServerClientVersion.

@Override
public List<AppClientVersion> getAppAllServerClientVersion(long appId) {
    List<AppClientVersion> appClientVersionList = getAppAllClientVersion(appId);
    if (CollectionUtils.isEmpty(appClientVersionList)) {
        return Collections.emptyList();
    }
    List<AppClientVersion> appClientVersionServerList = new ArrayList<AppClientVersion>();
    for (AppClientVersion appClientVersion : appClientVersionList) {
        String clientIp = appClientVersion.getClientIp();
        String[] items = clientIp.split(".");
        //过滤办公网段ip
        if (!OFFICE_IP.contains(items[0] + "." + items[1])) {
            appClientVersionServerList.add(appClientVersion);
        }
    }
    return appClientVersionServerList;
}
Also used : ArrayList(java.util.ArrayList) AppClientVersion(com.sohu.cache.entity.AppClientVersion)

Aggregations

AppClientVersion (com.sohu.cache.entity.AppClientVersion)3 Date (java.util.Date)2 AppClientExceptionStat (com.sohu.cache.entity.AppClientExceptionStat)1 InstanceInfo (com.sohu.cache.entity.InstanceInfo)1 ArrayList (java.util.ArrayList)1