Search in sources :

Example 1 with CommandResult

use of com.sohu.cache.constant.CommandResult in project cachecloud by sohutv.

the class AppDataMigrateController method checkData.

/**
     * 查看迁移进度
     * @return
     */
@RequestMapping(value = "/checkData")
public ModelAndView checkData(HttpServletRequest request, HttpServletResponse response, Model model) {
    long id = NumberUtils.toLong(request.getParameter("id"));
    int nums = 1000 + new Random().nextInt(2000);
    //为了方便,直接传入命令
    CommandResult commandResult = appDataMigrateCenter.sampleCheckData(id, nums);
    String message = commandResult.getResult();
    List<String> checkDataResultList = new ArrayList<String>();
    checkDataResultList.add("一共随机检验了" + nums + "个key" + ",检查结果如下:");
    String[] lineArr = message.split(ConstUtils.NEXT_LINE);
    for (String line : lineArr) {
        if (StringUtils.isBlank(line)) {
            continue;
        }
        // 行数太多显示会有问题
        if (lineArr.length > 100 && !isUsefulLine(line)) {
            continue;
        }
        //message格式显示有点问题
        line = line.replace("[0m", "");
        line = line.replace("[31m", "");
        line = line.replace("[33m", "");
        checkDataResultList.add(line.trim());
    }
    model.addAttribute("checkDataResultList", checkDataResultList);
    model.addAttribute("checkDataCommand", commandResult.getCommand());
    return new ModelAndView("migrate/checkData");
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) CommandResult(com.sohu.cache.constant.CommandResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CommandResult

use of com.sohu.cache.constant.CommandResult in project cachecloud by sohutv.

the class AppDataMigrateCenterImpl method sampleCheckData.

@Override
public CommandResult sampleCheckData(long id, int nums) {
    AppDataMigrateStatus appDataMigrateStatus = appDataMigrateStatusDao.get(id);
    if (appDataMigrateStatus == null) {
        return null;
    }
    String ip = appDataMigrateStatus.getMigrateMachineIp();
    String configPath = appDataMigrateStatus.getConfigPath();
    String sampleCheckDataCmd = ConstUtils.getRedisMigrateToolCmd() + " -c " + configPath + " -C" + " 'redis_check " + nums + "'";
    logger.warn("sampleCheckDataCmd: {}", sampleCheckDataCmd);
    try {
        return new CommandResult(sampleCheckDataCmd, SSHUtil.execute(ip, sampleCheckDataCmd));
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new CommandResult(sampleCheckDataCmd, ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
    }
}
Also used : AppDataMigrateStatus(com.sohu.cache.entity.AppDataMigrateStatus) IOException(java.io.IOException) SSHException(com.sohu.cache.exception.SSHException) CommandResult(com.sohu.cache.constant.CommandResult)

Aggregations

CommandResult (com.sohu.cache.constant.CommandResult)2 AppDataMigrateStatus (com.sohu.cache.entity.AppDataMigrateStatus)1 SSHException (com.sohu.cache.exception.SSHException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1