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");
}
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());
}
}
Aggregations