use of com.sohu.cache.entity.MachineInfo in project cachecloud by sohutv.
the class AppDataMigrateCenterImpl method checkMigrateMachine.
/**
* 检查迁移的机器是否正常
*
* @param migrateMachineIp
* @return
*/
private AppDataMigrateResult checkMigrateMachine(String migrateMachineIp) {
if (StringUtils.isBlank(migrateMachineIp)) {
return AppDataMigrateResult.fail("redis-migrate-tool所在机器的IP不能为空");
}
// 1. 检查机器是否存在在机器列表中
try {
MachineInfo machineInfo = machineCenter.getMachineInfoByIp(migrateMachineIp);
if (machineInfo == null) {
return AppDataMigrateResult.fail(migrateMachineIp + "没有在机器管理列表中");
} else if (machineInfo.isOffline()) {
return AppDataMigrateResult.fail(migrateMachineIp + ",该机器已经被删除");
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
return AppDataMigrateResult.fail("检测发生异常,请观察日志");
}
// 2. 检查是否安装redis-migrate-tool
try {
String cmd = ConstUtils.getRedisMigrateToolCmd();
String response = SSHUtil.execute(migrateMachineIp, cmd);
if (StringUtils.isBlank(response) || !response.contains("source") || !response.contains("target")) {
return AppDataMigrateResult.fail(migrateMachineIp + "下," + cmd + "执行失败,请确保redis-migrate-tool安装正确!");
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
return AppDataMigrateResult.fail("检测发生异常,请观察日志");
}
// 3.2 查看进程是否存在
try {
String cmd = "/bin/ps -ef | grep redis-migrate-tool | grep -v grep | grep -v tail";
String response = SSHUtil.execute(migrateMachineIp, cmd);
if (StringUtils.isNotBlank(response)) {
return AppDataMigrateResult.fail(migrateMachineIp + "下有redis-migrate-tool进程,请确保只有一台机器只有一个迁移任务进行");
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
return AppDataMigrateResult.fail("检测发生异常,请观察日志");
}
return AppDataMigrateResult.success();
}
Aggregations