use of com.sohu.cache.constant.RedisMigrateToolConstant in project cachecloud by sohutv.
the class AppDataMigrateCenterImpl method processRedisMigrateToolStats.
/**
* 处理迁移工具状态
* @param statResult
* @return
*/
private Map<RedisMigrateToolConstant, Map<String, Object>> processRedisMigrateToolStats(String statResult) {
Map<RedisMigrateToolConstant, Map<String, Object>> redisStatMap = new HashMap<RedisMigrateToolConstant, Map<String, Object>>();
String[] data = statResult.split("\r\n");
String key;
int i = 0;
int length = data.length;
while (i < length) {
if (data[i].contains("#")) {
int index = data[i].indexOf('#');
key = data[i].substring(index + 1);
++i;
RedisMigrateToolConstant redisMigrateToolConstant = RedisMigrateToolConstant.value(key.trim());
if (redisMigrateToolConstant == null) {
continue;
}
Map<String, Object> sectionMap = new LinkedHashMap<String, Object>();
while (i < length && data[i].contains(":")) {
String[] pair = data[i].split(":");
sectionMap.put(pair[0], pair[1]);
i++;
}
redisStatMap.put(redisMigrateToolConstant, sectionMap);
} else {
i++;
}
}
return redisStatMap;
}
use of com.sohu.cache.constant.RedisMigrateToolConstant in project cachecloud by sohutv.
the class AppDataMigrateCenterImpl method stopMigrate.
@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());
}
}
Aggregations