Search in sources :

Example 16 with MachineInfo

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

Aggregations

MachineInfo (com.sohu.cache.entity.MachineInfo)16 InstanceInfo (com.sohu.cache.entity.InstanceInfo)5 InstanceStats (com.sohu.cache.entity.InstanceStats)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 MachineStats (com.sohu.cache.entity.MachineStats)2 BaseTest (com.sohu.test.BaseTest)2 Date (java.util.Date)2 Test (org.junit.Test)2 AppDesc (com.sohu.cache.entity.AppDesc)1 MachineMemInfo (com.sohu.cache.entity.MachineMemInfo)1 SSHException (com.sohu.cache.exception.SSHException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1