Java Code Examples for org.apache.commons.collections.MapUtils#getInteger()

The following examples show how to use org.apache.commons.collections.MapUtils#getInteger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisCenterImpl.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@Override
public HostAndPort getMaster(String ip, int port, String password) {
    JedisPool jedisPool = maintainJedisPool(ip, port, password);
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        String info = jedis.info(RedisConstant.Replication.getValue());
        Map<RedisConstant, Map<String, Object>> infoMap = processRedisStats(info);
        Map<String, Object> map = infoMap.get(RedisConstant.Replication);
        if (map == null) {
            return null;
        }
        String masterHost = MapUtils.getString(map, RedisInfoEnum.master_host.getValue(), null);
        int masterPort = MapUtils.getInteger(map, RedisInfoEnum.master_port.getValue(), 0);
        if (StringUtils.isNotBlank(masterHost) && masterPort > 0) {
            return new HostAndPort(masterHost, masterPort);
        }
        return null;
    } catch (Exception e) {
        logger.error("{}:{} getMaster failed {}", ip, port, e.getMessage(), e);
        return null;
    } finally {
        if (jedis != null)
            jedis.close();
    }
}
 
Example 2
Source File: SeckillServiceImpl.java    From nguSeckill with MIT License 5 votes vote down vote up
@Override
public SeckillExecution executeSeckillProcedure(long seckillId, long userPhone, String md5) {
    if (md5 == null || !md5.equals(getMd5(seckillId))) {
        return new SeckillExecution(seckillId, SeckillStatEnum.DATE_REWRITE);
    }
    Date killTime = new Date();
    Map<String, Object> map = new HashMap<>();
    map.put("seckillId", seckillId);
    map.put("phone", userPhone);
    map.put("killTime", killTime);
    map.put("result", null);
    // 执行储存过程,result被复制
    try {
        seckillMapper.killByProcedure(map);
        // 获取result
        int result = MapUtils.getInteger(map, "result", -2);
        if (result == 1) {
            SuccessKilled successKilled = successKilledMapper.queryByIdWithSeckill(seckillId, userPhone);
            return new SeckillExecution(seckillId, SeckillStatEnum.SUCCESS, successKilled);
        } else {
            return new SeckillExecution(seckillId, SeckillStatEnum.stateOf(result));
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new SeckillExecution(seckillId, SeckillStatEnum.INNER_ERROR);
    }
}
 
Example 3
Source File: SeckillServiceImpl.java    From seckill with MIT License 5 votes vote down vote up
@Override
public SeckillExecution executeSeckillProcedure(long seckillId, long userPhone, String md5) {
	if (md5 == null || !md5.equals(getMD5(seckillId))) {
		return new SeckillExecution(seckillId, SeckillStateEnum.DATA_REWRITE);
	}
	Date killTime = new Date();
	Map<String, Object> map = new HashMap<String, Object>();
	map.put("seckillId", seckillId);
	map.put("phone", userPhone);
	map.put("killTime", killTime);
	map.put("result", null);
	// 执行存储过程,result被赋值
	try {
		seckillDao.killByProcedure(map);
		// 获取result
		int result = MapUtils.getInteger(map, "result", -2);
		if (result == 1) {
			SuccessKilled sk = successKilledDao.queryByIdWithSeckill(seckillId, userPhone);
			return new SeckillExecution(seckillId, SeckillStateEnum.SUCCESS, sk);
		} else {
			return new SeckillExecution(seckillId, SeckillStateEnum.stateOf(result));
		}
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		return new SeckillExecution(seckillId, SeckillStateEnum.INNER_ERROR);
	}
}
 
Example 4
Source File: SeckillServiceImpl.java    From seckill-demo with MIT License 5 votes vote down vote up
@Override
public SeckillExecution executeSeckillProcedure(long seckillId, long userPhone, String md5) {
	if (md5 == null || !md5.equals(getMD5(seckillId))) {
		return new SeckillExecution(seckillId, SeckillStateEnum.DATA_REWRITE);
	}
	Date killTime = new Date();
	Map<String, Object> map = new HashMap<String, Object>();
	map.put("seckillId", seckillId);
	map.put("phone", userPhone);
	map.put("killTime", killTime);
	map.put("result", null);
	// 执行存储过程,result被赋值
	try {
		seckillDao.killByProcedure(map);
		// 获取result
		int result = MapUtils.getInteger(map, "result", -2);
		if (result == 1) {
			SuccessKilled sk = successKilledDao.queryByIdWithSeckill(seckillId, userPhone);
			return new SeckillExecution(seckillId, SeckillStateEnum.SUCCESS, sk);
		} else {
			return new SeckillExecution(seckillId, SeckillStateEnum.stateOf(result));
		}
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		return new SeckillExecution(seckillId, SeckillStateEnum.INNER_ERROR);
	}
}
 
Example 5
Source File: SeckillServiceImpl.java    From imooc-seckill with MIT License 5 votes vote down vote up
/**
 * @param seckillId
 * @param userPhone
 * @param md5
 * @return
 * @throws SeckillException
 * @throws RepeteKillException
 * @throws SeckillCloseException
 */
public SeckillExecution excuteSeckillProcedure(long seckillId, long userPhone, String md5) {
    if (md5 == null || (!md5.equals(getMD5(seckillId)))) {
        throw new SeckillException("Seckill data rewrite");
    }
    Date killTime = new Date();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("seckillId", seckillId);
    map.put("phone", userPhone);
    map.put("killTime", killTime);
    map.put("result", null);
    //执行存储过程,result被赋值
    try {
        seckillDao.killByProcedure(map);
        //获取result
        int result = MapUtils.getInteger(map, "result", -2);
        if (result == 1) {
            SuccessKilled successKilled = successKilledDao.queryByIdWithSeckill(seckillId, userPhone);
            return new SeckillExecution(seckillId, SeckillStateEnum.SUCCESS, successKilled);
        } else {
            return new SeckillExecution(seckillId, SeckillStateEnum.stateOf(result));
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new SeckillExecution(seckillId, SeckillStateEnum.INNER_ERROR);
    }
}
 
Example 6
Source File: ClientReportExceptionServiceImpl.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public void batchSave(ClientReportBean clientReportBean) {
    try {
        // 1.client上报
        final String clientIp = clientReportBean.getClientIp();
        final long collectTime = clientReportBean.getCollectTime();
        final long reportTime = clientReportBean.getReportTimeStamp();
        final List<Map<String, Object>> datas = clientReportBean.getDatas();
        if (datas == null || datas.isEmpty()) {
            logger.warn("datas field {} is empty", clientReportBean);
            return;
        }

        // 2.结果集
        List<AppClientExceptionStat> appClientExceptionStatList = new ArrayList<AppClientExceptionStat>();

        // 3.解析
        for (Map<String, Object> map : datas) {
            Integer clientDataType = MapUtils.getInteger(map, ClientReportConstant.CLIENT_DATA_TYPE, -1);
            ClientCollectDataTypeEnum clientCollectDataTypeEnum = ClientCollectDataTypeEnum.MAP.get(clientDataType);
            if (clientCollectDataTypeEnum == null) {
                continue;
            }
            if (ClientCollectDataTypeEnum.EXCEPTION_TYPE.equals(clientCollectDataTypeEnum)) {
                AppClientExceptionStat appClientExceptionStat = generate(clientIp, collectTime, reportTime, map);
                if (appClientExceptionStat != null) {
                    appClientExceptionStatList.add(appClientExceptionStat);
                }
            }
        }
        
        // 4.批量保存
        if (CollectionUtils.isNotEmpty(appClientExceptionStatList)) {
            appClientExceptionStatDao.batchSave(appClientExceptionStatList);
        }
        
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 7
Source File: ClientReportValueDistriServiceImplV2.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public void batchSave(ClientReportBean clientReportBean) {
    try {
        // 1.client上报
        final long collectTime = clientReportBean.getCollectTime();
        final long reportTime = clientReportBean.getReportTimeStamp();
        final List<Map<String, Object>> datas = clientReportBean.getDatas();
        if (datas == null || datas.isEmpty()) {
            logger.warn("datas field {} is empty", clientReportBean);
            return;
        }

        // 3.解析
        for (Map<String, Object> map : datas) {
            Integer clientDataType = MapUtils.getInteger(map, ClientReportConstant.CLIENT_DATA_TYPE, -1);
            ClientCollectDataTypeEnum clientCollectDataTypeEnum = ClientCollectDataTypeEnum.MAP.get(clientDataType);
            if (clientCollectDataTypeEnum == null) {
                continue;
            }
            if (ClientCollectDataTypeEnum.VALUE_LENGTH_DISTRI_TYPE.equals(clientCollectDataTypeEnum)) {
                AppClientValueDistriStatTotal appClientValueDistriStat = generate(collectTime, reportTime, map);
                if (appClientValueDistriStat != null) {
                    appClientValueStatDao.save(appClientValueDistriStat);
                }
            }
        }

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 8
Source File: ClientReportDataSizeServiceImpl.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public void save(ClientReportBean clientReportBean) {
    try {
        // 1.client上报
        final String clientIp = clientReportBean.getClientIp();
        final long collectTime = clientReportBean.getCollectTime();
        final long reportTime = clientReportBean.getReportTimeStamp();
        final Map<String, Object> otherInfo = clientReportBean.getOtherInfo();
        if (otherInfo == null || otherInfo.isEmpty()) {
            logger.warn("otherInfo field is empty, client ip {}", clientIp);
            return;
        }
        int costMapSize = MapUtils.getInteger(otherInfo, ClientReportConstant.COST_MAP_SIZE, 0);
        int valueMapSize = MapUtils.getInteger(otherInfo, ClientReportConstant.VALUE_MAP_SIZE, 0);
        int exceptionMapSize = MapUtils.getInteger(otherInfo, ClientReportConstant.EXCEPTION_MAP_SIZE, 0);
        int collectMapSize = MapUtils.getInteger(otherInfo, ClientReportConstant.COLLECTION_MAP_SIZE, 0);
        // 只记录大于minSize
        int minSize = 100;
        if (costMapSize < minSize && valueMapSize < minSize && exceptionMapSize < minSize && collectMapSize < minSize) {
            return;
        }
        // 设置实体
        AppClientDataSizeStat appClientDataSizeStat = new AppClientDataSizeStat();
        appClientDataSizeStat.setClientIp(clientIp);
        appClientDataSizeStat.setCollectTime(collectTime);
        appClientDataSizeStat.setCollectMapSize(collectMapSize);
        appClientDataSizeStat.setCostMapSize(costMapSize);
        appClientDataSizeStat.setValueMapSize(valueMapSize);
        appClientDataSizeStat.setExceptionMapSize(exceptionMapSize);
        appClientDataSizeStat.setCreateTime(new Date());
        appClientDataSizeStat.setReportTime(new Date(reportTime));
        
        appClientReportDataSizeDao.save(appClientDataSizeStat);
        
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 9
Source File: AppDataMigrateCenterImpl.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
@Override
public AppDataMigrateResult stopMigrate(long id) {
    // 获取基本信息
    AppDataMigrateStatus appDataMigrateStatus = appDataMigrateStatusDao.get(id);
    if (appDataMigrateStatus == null) {
        return AppDataMigrateResult.fail("id=" + id + "迁移记录不存在!");
    }
    // 获取进程号
    String migrateMachineIp = appDataMigrateStatus.getMigrateMachineIp();
    String migrateMachineHostPort = migrateMachineIp + ":" + appDataMigrateStatus.getMigrateMachinePort();
    Map<RedisMigrateToolConstant, Map<String, Object>> redisMigrateToolStatMap = showMiragteToolProcess(id);
    if (MapUtils.isEmpty(redisMigrateToolStatMap)) {
        return AppDataMigrateResult.fail("获取" + migrateMachineHostPort + "相关信息失败,可能是进程不存在或者客户端超时,请查找原因或重试!");
    }
    Map<String, Object> serverMap = redisMigrateToolStatMap.get(RedisMigrateToolConstant.Server);
    int pid = MapUtils.getInteger(serverMap, "process_id", -1);
    if (pid <= 0) {
        return AppDataMigrateResult.fail("获取" + migrateMachineHostPort + "的进程号" + pid + "异常");
    }

    // 确认进程号是redis-migrate-tool进程
    Boolean exist = checkPidWhetherIsRmt(migrateMachineIp, pid);
    if (exist == null) {
        return AppDataMigrateResult.fail("执行过程中发生异常,请查看系统日志!");
    } else if (exist.equals(false)) {
        return AppDataMigrateResult.fail(migrateMachineIp + "进程号" + pid + "不存在,请确认!");
    }

    // kill掉进程
    try {
        String cmd = "kill " + pid;
        SSHUtil.execute(migrateMachineIp, cmd);
        exist = checkPidWhetherIsRmt(migrateMachineIp, pid);
        if (exist == null) {
            return AppDataMigrateResult.fail(ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
        } else if (exist.equals(false)) {
            // 更新记录完成更新
            appDataMigrateStatusDao.updateStatus(id, AppDataMigrateStatusEnum.END.getStatus());
            return AppDataMigrateResult.success("已经成功停止了id=" + id + "的迁移任务");
        } else {
            return AppDataMigrateResult.fail(migrateMachineIp + "进程号" + pid + "仍然存在,没有kill掉,请确认!");
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
        return AppDataMigrateResult.fail(ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
    }
}
 
Example 10
Source File: ClientReportCostDistriServiceImpl.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
private AppClientCostTimeStat generate(String clientIp, long collectTime, long reportTime, Map<String, Object> map) {
        try {
            Integer count = MapUtils.getInteger(map, ClientReportConstant.COST_COUNT, 0);
            String command = MapUtils.getString(map, ClientReportConstant.COST_COMMAND, "");
            if (StringUtils.isBlank(command)) {
                logger.warn("command is empty!");
                return null;
            }
            String hostPort = MapUtils.getString(map, ClientReportConstant.COST_HOST_PORT, "");
            if (StringUtils.isBlank(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;
            }
            String host = hostPort.substring(0, index);
            int 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;
            }
            long appId = instanceInfo.getAppId();
            // 耗时分布详情
            double mean = MapUtils.getDouble(map, ClientReportConstant.COST_TIME_MEAN, 0.0);
            Integer median = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_MEDIAN, 0);
            Integer ninetyPercentMax = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_90_MAX, 0);
            Integer ninetyNinePercentMax = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_99_MAX, 0);
            Integer hunredMax = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_100_MAX, 0);

            AppClientCostTimeStat stat = new AppClientCostTimeStat();
            stat.setAppId(appId);
            stat.setClientIp(clientIp);
            stat.setReportTime(new Date(reportTime));
            stat.setCollectTime(collectTime);
            stat.setCreateTime(new Date());
            stat.setCommand(command);
            stat.setCount(count);
            stat.setInstanceHost(host);
            stat.setInstancePort(port);
            stat.setMean(NumberUtils.toDouble(new DecimalFormat("#.00").format(mean)));
            stat.setMedian(median);
            stat.setNinetyPercentMax(ninetyPercentMax);
            stat.setNinetyNinePercentMax(ninetyNinePercentMax);
            stat.setHundredMax(hunredMax);
            stat.setInstanceId(instanceInfo.getId());

            return stat;
            
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
 
Example 11
Source File: ClientReportCostDistriServiceImpl.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
@Override
public void batchSave(ClientReportBean clientReportBean) {
    try {
        // 1.client上报
        final String clientIp = clientReportBean.getClientIp();
        final long collectTime = clientReportBean.getCollectTime();
        final long reportTime = clientReportBean.getReportTimeStamp();
        final List<Map<String, Object>> datas = clientReportBean.getDatas();
        if (datas == null || datas.isEmpty()) {
            logger.warn("datas field {} is empty", clientReportBean);
            return;
        }
        
        // 2.结果集
        List<AppClientCostTimeStat> appClientCostTimeStatList = new ArrayList<AppClientCostTimeStat>();

        // 3.解析结果
        for (Map<String, Object> map : datas) {
            Integer clientDataType = MapUtils.getInteger(map, ClientReportConstant.CLIENT_DATA_TYPE, -1);
            ClientCollectDataTypeEnum clientCollectDataTypeEnum = ClientCollectDataTypeEnum.MAP.get(clientDataType);
            if (clientCollectDataTypeEnum == null) {
                continue;
            }
            if (ClientCollectDataTypeEnum.COST_TIME_DISTRI_TYPE.equals(clientCollectDataTypeEnum)) {
                AppClientCostTimeStat appClientCostTimeStat = generate(clientIp, collectTime, reportTime, map);
                if (appClientCostTimeStat != null) {
                    appClientCostTimeStatList.add(appClientCostTimeStat);
                }
            }
        }
        
        if (CollectionUtils.isNotEmpty(appClientCostTimeStatList)) {
            // 4.批量保存
            appClientCostTimeStatDao.batchSave(appClientCostTimeStatList);
            // 5.合并app统计结果
            List<AppClientCostTimeTotalStat> appClientCostTimeTotalStatList = mergeAppClientCostTimeStat(appClientCostTimeStatList);
            if (CollectionUtils.isNotEmpty(appClientCostTimeTotalStatList)) {
                appClientCostTimeTotalStatDao.batchSave(appClientCostTimeTotalStatList);
            }
            // 6.保存应用下节点和客户端关系
            appInstanceClientRelationService.batchSave(appClientCostTimeStatList);
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 12
Source File: ClientReportExceptionServiceImpl.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
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;
    }
 
Example 13
Source File: ClientReportValueDistriServiceImplV2.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
private AppClientValueDistriStatTotal generate(long collectTime, long reportTime, Map<String, Object> map) {
    String valueDistri = MapUtils.getString(map, ClientReportConstant.VALUE_DISTRI, "");
    ValueSizeDistriEnum valueSizeDistriEnum = ValueSizeDistriEnum.getByValue(valueDistri);
    if (valueSizeDistriEnum == null) {
        logger.warn("valueDistri {} is wrong, not in enums {}", valueDistri, ValueSizeDistriEnum.values());
    }

    // 次数
    Integer count = MapUtils.getInteger(map, ClientReportConstant.VALUE_COUNT, 0);

    // 命令
    String command = MapUtils.getString(map, ClientReportConstant.VALUE_COMMAND, "");
    if (StringUtils.isBlank(command)) {
        logger.warn("command is empty!");
        return null;
    }
    if (excludeCommands.contains(command)) {
        return null;
    }

    // 实例host:port
    String hostPort = MapUtils.getString(map, ClientReportConstant.VALUE_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;
    }
    String host = hostPort.substring(0, index);
    int 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;
    }

    AppClientValueDistriStatTotal stat = new AppClientValueDistriStatTotal();
    stat.setAppId(instanceInfo.getAppId());
    stat.setCollectTime(collectTime);
    stat.setUpdateTime(new Date());
    stat.setCommand(command);
    stat.setDistributeType(valueSizeDistriEnum.getType());
    stat.setCount(count);

    return stat;
}
 
Example 14
Source File: RedisIsolationPersistenceInspector.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
private boolean isAofEnabled(Map<String, String> infoMap) {
    Integer aofEnabled = MapUtils.getInteger(infoMap, "aof_enabled", null);
    return aofEnabled != null && aofEnabled == 1;
}
 
Example 15
Source File: RedisIsolationPersistenceInspector.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
@Override
public boolean inspect(Map<InspectParamEnum, Object> paramMap) {
    final String host = MapUtils.getString(paramMap, InspectParamEnum.SPLIT_KEY);
    List<InstanceInfo> list = (List<InstanceInfo>) paramMap.get(InspectParamEnum.INSTANCE_LIST);
    outer:
    for (InstanceInfo info : list) {
        final int port = info.getPort();
        final int type = info.getType();
        final long appId = info.getAppId();
        int status = info.getStatus();
        //非正常节点
        if (status != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
            continue;
        }
        if (TypeUtil.isRedisDataType(type)) {
            Jedis jedis = redisCenter.getJedis(appId, host, port, REDIS_DEFAULT_TIME, REDIS_DEFAULT_TIME);
            try {
                Map<String, String> persistenceMap = parseMap(jedis);
                if (persistenceMap.isEmpty()) {
                    logger.error("{}:{} get persistenceMap failed", host, port);
                    continue;
                }
                if (!isAofEnabled(persistenceMap)) {
                    continue;
                }
                long aofCurrentSize = MapUtils.getLongValue(persistenceMap, RedisInfoEnum.aof_current_size.getValue());
                long aofBaseSize = MapUtils.getLongValue(persistenceMap, RedisInfoEnum.aof_base_size.getValue());
                //阀值大于60%
                long aofThresholdSize = (long) (aofBaseSize * 1.6);
                double percentage = getPercentage(aofCurrentSize, aofBaseSize);
                if (aofCurrentSize >= aofThresholdSize
                        //大于64Mb
                        && aofCurrentSize > (64 * 1024 * 1024)) {
                    //bgRewriteAof
                    boolean isInvoke = invokeBgRewriteAof(jedis);
                    if (!isInvoke) {
                        logger.error("{}:{} invokeBgRewriteAof failed", host, port);
                        continue;
                    } else {
                        logger.warn("{}:{} invokeBgRewriteAof started percentage={}", host, port, percentage);
                    }
                    while (true) {
                        try {
                            //before wait 1s
                            TimeUnit.SECONDS.sleep(1);
                            Map<String, String> loopMap = parseMap(jedis);
                            Integer aofRewriteInProgress = MapUtils.getInteger(loopMap, "aof_rewrite_in_progress", null);
                            if (aofRewriteInProgress == null) {
                                logger.error("loop watch:{}:{} return failed", host, port);
                                break;
                            } else if (aofRewriteInProgress <= 0) {
                                //bgrewriteaof Done
                                logger.warn("{}:{} bgrewriteaof Done lastSize:{}Mb,currentSize:{}Mb", host, port, getMb(aofCurrentSize), getMb(MapUtils.getLongValue(loopMap, "aof_current_size")));
                                break;
                            } else {
                                //wait 1s
                                TimeUnit.SECONDS.sleep(1);
                            }
                        } catch (Exception e) {
                            logger.error(e.getMessage(), e);
                        }
                    }
                } else {
                    if (percentage > 50D) {
                        long currentSize = getMb(aofCurrentSize);
                        logger.info("checked {}:{} aof increase percentage:{}% currentSize:{}Mb", host, port, percentage, currentSize > 0 ? currentSize : "<1");
                    }
                }
            } finally {
                jedis.close();
            }
        }
    }
    return true;
}
 
Example 16
Source File: S3S3CopierOptions.java    From circus-train with Apache License 2.0 4 votes vote down vote up
public int getMaxCopyAttempts() {
  Integer maxCopyAttempts = MapUtils.getInteger(copierOptions, Keys.MAX_COPY_ATTEMPTS.keyName(), 3);
  return maxCopyAttempts < 1 ? 3 : maxCopyAttempts;
}
 
Example 17
Source File: S3S3CopierOptions.java    From circus-train with Apache License 2.0 4 votes vote down vote up
public int getMaxThreadPoolSize() {
  return MapUtils.getInteger(copierOptions, Keys.MAX_THREAD_POOL_SIZE.keyName(), DEFAULT_MAX_THREAD_POOL_SIZE);
}
 
Example 18
Source File: S3MapReduceCpOptionsParser.java    From circus-train with Apache License 2.0 4 votes vote down vote up
protected S3MapReduceCpOptions parse(Map<String, Object> copierOptions) {
  if (copierOptions == null) {
    LOG.debug("Null copier options: nothing to parse");
    return optionsBuilder.build();
  }

  optionsBuilder
      .credentialsProvider(MoreMapUtils.getUri(copierOptions, CREDENTIAL_PROVIDER, defaultCredentialsProvider));

  long multipartUploadPartSize = MapUtils.getLongValue(copierOptions, MULTIPART_UPLOAD_CHUNK_SIZE,
      ConfigurationVariable.MULTIPART_UPLOAD_THRESHOLD.defaultLongValue());
  if (multipartUploadPartSize <= 0) {
    throw new IllegalArgumentException("Parameter " + MULTIPART_UPLOAD_CHUNK_SIZE + " must be greater than zero");
  }
  optionsBuilder.multipartUploadPartSize(multipartUploadPartSize);

  optionsBuilder.s3ServerSideEncryption(MapUtils.getBoolean(copierOptions, S3_SERVER_SIDE_ENCRYPTION, true));

  optionsBuilder.storageClass(
      MapUtils.getString(copierOptions, STORAGE_CLASS, ConfigurationVariable.STORAGE_CLASS.defaultValue()));

  long maxBandwidth = MapUtils.getLongValue(copierOptions, TASK_BANDWIDTH,
      ConfigurationVariable.MAX_BANDWIDTH.defaultLongValue());
  if (maxBandwidth <= 0) {
    throw new IllegalArgumentException(
        "Parameter " + TASK_BANDWIDTH + " must be a positive number greater then zero");
  }
  optionsBuilder.maxBandwidth(maxBandwidth);

  int numberOfUploadWorkers = MapUtils.getIntValue(copierOptions, NUMBER_OF_WORKERS_PER_MAP,
      ConfigurationVariable.NUMBER_OF_UPLOAD_WORKERS.defaultIntValue());
  if (numberOfUploadWorkers <= 0) {
    throw new IllegalArgumentException(
        "Parameter " + NUMBER_OF_WORKERS_PER_MAP + " must be a positive number greater than zero");
  }
  optionsBuilder.numberOfUploadWorkers(numberOfUploadWorkers);

  long multipartUploadThreshold = MapUtils.getLongValue(copierOptions, MULTIPART_UPLOAD_THRESHOLD,
      ConfigurationVariable.MULTIPART_UPLOAD_THRESHOLD.defaultLongValue());
  if (multipartUploadThreshold <= 0) {
    throw new IllegalArgumentException("Parameter " + MULTIPART_UPLOAD_THRESHOLD + " must be greater than zero");
  }
  optionsBuilder.multipartUploadThreshold(multipartUploadThreshold);

  int maxMaps = MapUtils.getIntValue(copierOptions, MAX_MAPS, ConfigurationVariable.MAX_MAPS.defaultIntValue());
  if (maxMaps <= 0) {
    throw new IllegalArgumentException("Parameter " + MAX_MAPS + " must be a positive number greater than zero");
  }
  optionsBuilder.maxMaps(maxMaps);

  optionsBuilder.copyStrategy(
      MapUtils.getString(copierOptions, COPY_STRATEGY, ConfigurationVariable.COPY_STRATEGY.defaultValue()));

  Path logPath = MoreMapUtils.getHadoopPath(copierOptions, LOG_PATH, null);
  if (logPath != null) {
    optionsBuilder.logPath(logPath);
  }

  optionsBuilder.region(MapUtils.getString(copierOptions, REGION, ConfigurationVariable.REGION.defaultValue()));

  optionsBuilder.ignoreFailures(MapUtils.getBoolean(copierOptions, IGNORE_FAILURES,
      ConfigurationVariable.IGNORE_FAILURES.defaultBooleanValue()));

  optionsBuilder.s3EndpointUri(
      MoreMapUtils.getUri(copierOptions, S3_ENDPOINT_URI, ConfigurationVariable.S3_ENDPOINT_URI.defaultURIValue()));

  int uploadRetryCount = MapUtils.getInteger(copierOptions, UPLOAD_RETRY_COUNT,
      ConfigurationVariable.UPLOAD_RETRY_COUNT.defaultIntValue());
  if (uploadRetryCount < 0) {
    throw new IllegalArgumentException("Parameter " + UPLOAD_RETRY_COUNT + " must be a positive number");
  }
  optionsBuilder.uploadRetryCount(uploadRetryCount);

  long uploadRetryDelaysMs = MapUtils.getLong(copierOptions, UPLOAD_RETRY_DELAY_MS,
      ConfigurationVariable.UPLOAD_RETRY_DELAY_MS.defaultLongValue());
  optionsBuilder.uploadRetryDelayMs(uploadRetryDelaysMs);
  if (uploadRetryDelaysMs < 0) {
    throw new IllegalArgumentException("Parameter " + UPLOAD_RETRY_DELAY_MS + " must be a positive number");
  }

  int uploadBufferSize = MapUtils.getInteger(copierOptions, UPLOAD_BUFFER_SIZE,
      ConfigurationVariable.UPLOAD_BUFFER_SIZE.defaultIntValue());
  if (uploadBufferSize < 0) {
    throw new IllegalArgumentException("Parameter " + UPLOAD_BUFFER_SIZE + " must be a positive number");
  }
  optionsBuilder.uploadBufferSize(uploadBufferSize);

  optionsBuilder.cannedAcl(MapUtils.getString(copierOptions, CANNED_ACL, ConfigurationVariable.CANNED_ACL.defaultValue()));

  optionsBuilder.assumeRole(MapUtils.getString(copierOptions, ASSUME_ROLE, ConfigurationVariable.ASSUME_ROLE.defaultValue()));

  return optionsBuilder.build();
}