Search in sources :

Example 1 with AppDataMigrateStatus

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==============");
}
Also used : AppDataMigrateStatus(com.sohu.cache.entity.AppDataMigrateStatus) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

Example 2 with AppDataMigrateStatus

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==============");
}
Also used : AppDataMigrateStatus(com.sohu.cache.entity.AppDataMigrateStatus) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

Example 3 with AppDataMigrateStatus

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;
}
Also used : AppDataMigrateStatus(com.sohu.cache.entity.AppDataMigrateStatus) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) IOException(java.io.IOException) SSHException(com.sohu.cache.exception.SSHException)

Example 4 with AppDataMigrateStatus

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 "";
    }
}
Also used : AppDataMigrateStatus(com.sohu.cache.entity.AppDataMigrateStatus) SSHException(com.sohu.cache.exception.SSHException)

Example 5 with AppDataMigrateStatus

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);
}
Also used : Jedis(redis.clients.jedis.Jedis) AppDataMigrateStatus(com.sohu.cache.entity.AppDataMigrateStatus) IOException(java.io.IOException) SSHException(com.sohu.cache.exception.SSHException)

Aggregations

AppDataMigrateStatus (com.sohu.cache.entity.AppDataMigrateStatus)10 SSHException (com.sohu.cache.exception.SSHException)6 BaseTest (com.sohu.test.BaseTest)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 Date (java.util.Date)2 CommandResult (com.sohu.cache.constant.CommandResult)1 RedisMigrateToolConstant (com.sohu.cache.constant.RedisMigrateToolConstant)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Jedis (redis.clients.jedis.Jedis)1