Search in sources :

Example 1 with MachineInfo

use of com.sohu.cache.entity.MachineInfo in project cachecloud by sohutv.

the class PortGeneratorTest method testCheckMaxPort.

@Test
public void testCheckMaxPort() throws SSHException {
    List<MachineInfo> machineList = machineDao.getAllMachines();
    for (MachineInfo machineInfo : machineList) {
        String ip = machineInfo.getIp();
        int sshPort = SSHUtil.getSshPort(ip);
        String m1 = PortGenerator.getMaxPortStrOld(ip, sshPort);
        String m2 = PortGenerator.getMaxPortStr(ip, sshPort);
        boolean isSame = m1.equals(m2);
        if (!isSame) {
            System.out.println(ip + ", m1: " + m1 + ", m2:" + m2);
        }
    }
}
Also used : MachineInfo(com.sohu.cache.entity.MachineInfo) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

Example 2 with MachineInfo

use of com.sohu.cache.entity.MachineInfo in project cachecloud by sohutv.

the class MachineDaoTest method testSaveMachine.

@Test
public void testSaveMachine() throws Exception {
    MachineInfo machineInfo = new MachineInfo();
    machineInfo.setCpu(16);
    machineInfo.setIp("10.10.53.181");
    machineInfo.setMem(96);
    machineInfo.setModifyTime(new Date());
    machineInfo.setRealIp("");
    machineInfo.setRoom("北显");
    machineInfo.setServiceTime(new Date());
    machineInfo.setSshPasswd("cachecloud-open");
    machineInfo.setSshUser("cachecloud-open");
    machineDao.saveMachineInfo(machineInfo);
}
Also used : MachineInfo(com.sohu.cache.entity.MachineInfo) Date(java.util.Date) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

Example 3 with MachineInfo

use of com.sohu.cache.entity.MachineInfo in project cachecloud by sohutv.

the class MachineCenterImpl method getMachineStats.

@Override
public List<MachineStats> getMachineStats(String ipLike) {
    List<MachineInfo> machineInfoList = machineDao.getMachineInfoByLikeIp(ipLike);
    List<MachineStats> machineStatsList = new ArrayList<MachineStats>();
    for (MachineInfo machineInfo : machineInfoList) {
        String ip = machineInfo.getIp();
        MachineStats machineStats = machineStatsDao.getMachineStatsByIp(ip);
        if (machineStats == null) {
            machineStats = new MachineStats();
        }
        machineStats.setMemoryAllocated(instanceDao.getMemoryByHost(ip));
        machineStats.setInfo(machineInfo);
        machineStatsList.add(machineStats);
    }
    return machineStatsList;
}
Also used : MachineInfo(com.sohu.cache.entity.MachineInfo) ArrayList(java.util.ArrayList) MachineStats(com.sohu.cache.entity.MachineStats)

Example 4 with MachineInfo

use of com.sohu.cache.entity.MachineInfo in project cachecloud by sohutv.

the class MachineDeployCenterImpl method addMachine.

/**
     * 将机器加入资源池并统计、监控
     *
     * @param machineInfo
     * @return
     */
@Override
public boolean addMachine(MachineInfo machineInfo) {
    boolean success = true;
    if (machineInfo == null || Strings.isNullOrEmpty(machineInfo.getIp())) {
        logger.error("machineInfo is null or ip is valid.");
        return false;
    }
    // 将机器信息保存到db中
    try {
        machineDao.saveMachineInfo(machineInfo);
    } catch (Exception e) {
        logger.error("save machineInfo: {} to db error.", machineInfo.toString(), e);
        return false;
    }
    // 为机器添加统计和监控的定时任务
    try {
        MachineInfo thisMachine = machineDao.getMachineInfoByIp(machineInfo.getIp());
        if (thisMachine != null) {
            long hostId = thisMachine.getId();
            String ip = thisMachine.getIp();
            if (!machineCenter.deployMachineCollection(hostId, ip)) {
                logger.error("deploy machine collection error, machineInfo: {}", thisMachine.toString());
                success = false;
            }
            if (!machineCenter.deployMachineMonitor(hostId, ip)) {
                logger.error("deploy machine monitor error, machineInfo: {}", thisMachine.toString());
                success = false;
            }
            if (thisMachine.getCollect() == 1) {
                if (!machineCenter.deployServerCollection(hostId, ip)) {
                    logger.error("deploy server monitor error, machineInfo: {}", thisMachine.toString());
                    success = false;
                }
            } else {
                if (!machineCenter.unDeployServerCollection(hostId, ip)) {
                    logger.error("undeploy server monitor error, machineInfo: {}", thisMachine.toString());
                    success = false;
                }
            }
        }
    } catch (Exception e) {
        logger.error("query machineInfo from db error, ip: {}", machineInfo.getIp(), e);
    }
    if (success) {
        logger.info("save and deploy machine ok, machineInfo: {}", machineInfo.toString());
    }
    return success;
}
Also used : MachineInfo(com.sohu.cache.entity.MachineInfo)

Example 5 with MachineInfo

use of com.sohu.cache.entity.MachineInfo in project cachecloud by sohutv.

the class MachineDeployCenterImpl method removeMachine.

/**
     * 删除机器,并删除相关的定时任务
     *
     * @param machineInfo
     * @return
     */
@Override
public boolean removeMachine(MachineInfo machineInfo) {
    if (machineInfo == null || Strings.isNullOrEmpty(machineInfo.getIp())) {
        logger.warn("machineInfo is null or ip is empty.");
        return false;
    }
    String machineIp = machineInfo.getIp();
    //从quartz中删除相关的定时任务
    try {
        MachineInfo thisMachine = machineDao.getMachineInfoByIp(machineIp);
        long hostId = thisMachine.getId();
        if (!machineCenter.unDeployMachineCollection(hostId, machineIp)) {
            logger.error("remove trigger for machine error: {}", thisMachine.toString());
            return false;
        }
        if (!machineCenter.unDeployMachineMonitor(hostId, machineIp)) {
            logger.error("remove trigger for machine monitor error: {}", thisMachine.toString());
            return false;
        }
        if (!machineCenter.unDeployServerCollection(hostId, machineIp)) {
            logger.error("remove trigger for server monitor error: {}", thisMachine.toString());
            return false;
        }
    } catch (Exception e) {
        logger.error("query machineInfo from db error: {}", machineInfo.toString());
    }
    // 从db中删除machine和相关统计信息
    try {
        machineDao.removeMachineInfoByIp(machineIp);
        machineStatsDao.deleteMachineStatsByIp(machineIp);
        serverStatusDao.deleteServerInfo(machineIp);
    } catch (Exception e) {
        logger.error("remove machineInfo from db error, machineInfo: {}", machineInfo.toString(), e);
        return false;
    }
    logger.info("remove and undeploy machine ok: {}", machineInfo.toString());
    return true;
}
Also used : MachineInfo(com.sohu.cache.entity.MachineInfo)

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