use of com.sohu.cache.entity.AppDataMigrateStatus in project cachecloud by sohutv.
the class AppDataMigrateStatusDaoTest method testGet.
@Test
public void testGet() {
long id = 1;
AppDataMigrateStatus appDataMigrateStatus = appDataMigrateStatusDao.get(id);
logger.info("==============testGet start==============");
logger.info(appDataMigrateStatus.toString());
logger.info("==============testGet end==============");
}
use of com.sohu.cache.entity.AppDataMigrateStatus in project cachecloud by sohutv.
the class AppDataMigrateStatusDaoTest method testSearch.
@Test
public void testSearch() {
List<AppDataMigrateStatus> list = appDataMigrateStatusDao.search(null);
System.out.println("list.size: " + list.size());
logger.info("==============testSearch start==============");
for (AppDataMigrateStatus appDataMigrateStatus : list) {
logger.info(appDataMigrateStatus.toString());
}
logger.info("==============testSearch end==============");
}
use of com.sohu.cache.entity.AppDataMigrateStatus in project cachecloud by sohutv.
the class AppDataMigrateCenterImpl method migrate.
@Override
public boolean migrate(String migrateMachineIp, AppDataMigrateEnum sourceRedisMigrateEnum, String sourceServers, AppDataMigrateEnum targetRedisMigrateEnum, String targetServers, long sourceAppId, long targetAppId, String redisSourcePass, String redisTargetPass, long userId) {
// 1. 生成配置
int migrateMachinePort = ConstUtils.REDIS_MIGRATE_TOOL_PORT;
String configContent = generateConfig(migrateMachinePort, sourceRedisMigrateEnum, sourceServers, targetRedisMigrateEnum, targetServers, redisSourcePass, redisTargetPass);
// 2. 上传配置
String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
String confileFileName = "rmt-" + timestamp + ".conf";
String logFileName = "rmt-" + timestamp + ".log";
boolean uploadConfig = createRemoteFile(migrateMachineIp, confileFileName, configContent);
if (!uploadConfig) {
return false;
}
// 3. 开始执行: 指定的配置名、目录、日志名
String cmd = ConstUtils.getRedisMigrateToolCmd() + " -c " + ConstUtils.getRedisMigrateToolDir() + confileFileName + " -o " + ConstUtils.getRedisMigrateToolDir() + logFileName + " -d";
logger.warn(cmd);
try {
SSHUtil.execute(migrateMachineIp, cmd);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
}
// 4. 记录执行记录
AppDataMigrateStatus appDataMigrateStatus = new AppDataMigrateStatus();
appDataMigrateStatus.setMigrateMachineIp(migrateMachineIp);
appDataMigrateStatus.setMigrateMachinePort(migrateMachinePort);
appDataMigrateStatus.setStartTime(new Date());
appDataMigrateStatus.setSourceMigrateType(sourceRedisMigrateEnum.getIndex());
appDataMigrateStatus.setSourceServers(sourceServers);
appDataMigrateStatus.setTargetMigrateType(targetRedisMigrateEnum.getIndex());
appDataMigrateStatus.setTargetServers(targetServers);
appDataMigrateStatus.setLogPath(ConstUtils.getRedisMigrateToolDir() + logFileName);
appDataMigrateStatus.setConfigPath(ConstUtils.getRedisMigrateToolDir() + confileFileName);
appDataMigrateStatus.setUserId(userId);
appDataMigrateStatus.setSourceAppId(sourceAppId);
appDataMigrateStatus.setTargetAppId(targetAppId);
appDataMigrateStatus.setStatus(AppDataMigrateStatusEnum.START.getStatus());
appDataMigrateStatusDao.save(appDataMigrateStatus);
return true;
}
use of com.sohu.cache.entity.AppDataMigrateStatus in project cachecloud by sohutv.
the class AppDataMigrateCenterImpl method showDataMigrateLog.
@Override
public String showDataMigrateLog(long id, int pageSize) {
AppDataMigrateStatus appDataMigrateStatus = appDataMigrateStatusDao.get(id);
if (appDataMigrateStatus == null) {
return "";
}
String logPath = appDataMigrateStatus.getLogPath();
String host = appDataMigrateStatus.getMigrateMachineIp();
StringBuilder command = new StringBuilder();
command.append("/usr/bin/tail -n").append(pageSize).append(" ").append(logPath);
try {
return SSHUtil.execute(host, command.toString());
} catch (SSHException e) {
logger.error(e.getMessage(), e);
return "";
}
}
use of com.sohu.cache.entity.AppDataMigrateStatus in project cachecloud by sohutv.
the class AppDataMigrateCenterImpl method showMiragteToolProcess.
@Override
public Map<RedisMigrateToolConstant, Map<String, Object>> showMiragteToolProcess(long id) {
AppDataMigrateStatus appDataMigrateStatus = appDataMigrateStatusDao.get(id);
if (appDataMigrateStatus == null) {
return Collections.emptyMap();
}
String info = "";
String host = appDataMigrateStatus.getMigrateMachineIp();
int port = appDataMigrateStatus.getMigrateMachinePort();
Jedis jedis = null;
try {
jedis = new Jedis(host, port, 5000);
info = jedis.info();
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
if (jedis != null) {
jedis.close();
}
}
if (StringUtils.isBlank(info)) {
return Collections.emptyMap();
}
return processRedisMigrateToolStats(info);
}
Aggregations