Search in sources :

Example 6 with MachineInfo

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

the class MachineManageController method doMachineInstances.

/**
     * 机器实例展示
     * @param ip
     * @return
     */
@RequestMapping(value = "/machineInstances")
public ModelAndView doMachineInstances(HttpServletRequest request, HttpServletResponse response, Model model, String ip) {
    //机器以及机器下面的实例信息
    MachineInfo machineInfo = machineCenter.getMachineInfoByIp(ip);
    List<InstanceInfo> instanceList = machineCenter.getMachineInstanceInfo(ip);
    List<InstanceStats> instanceStatList = machineCenter.getMachineInstanceStatsByIp(ip);
    //统计信息
    fillInstanceModel(instanceList, instanceStatList, model);
    model.addAttribute("machineInfo", machineInfo);
    model.addAttribute("machineActive", SuccessEnum.SUCCESS.value());
    return new ModelAndView("manage/machine/machineInstances");
}
Also used : MachineInfo(com.sohu.cache.entity.MachineInfo) InstanceStats(com.sohu.cache.entity.InstanceStats) ModelAndView(org.springframework.web.servlet.ModelAndView) InstanceInfo(com.sohu.cache.entity.InstanceInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with MachineInfo

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

the class MachineManageController method doAdd.

@RequestMapping(value = "/add", method = { RequestMethod.POST })
public ModelAndView doAdd(HttpServletRequest request, HttpServletResponse response, Model model) {
    MachineInfo machineInfo = new MachineInfo();
    machineInfo.setIp(request.getParameter("ip"));
    machineInfo.setRoom(request.getParameter("room"));
    machineInfo.setMem(NumberUtils.toInt(request.getParameter("mem"), 0));
    machineInfo.setCpu(NumberUtils.toInt(request.getParameter("cpu"), 0));
    machineInfo.setVirtual(NumberUtils.toInt(request.getParameter("virtual"), 0));
    machineInfo.setRealIp(request.getParameter("realIp"));
    machineInfo.setType(NumberUtils.toInt(request.getParameter("machineType"), 0));
    machineInfo.setExtraDesc(request.getParameter("extraDesc"));
    machineInfo.setCollect(NumberUtils.toInt(request.getParameter("collect"), 1));
    Date date = new Date();
    machineInfo.setSshUser(ConstUtils.USERNAME);
    machineInfo.setSshPasswd(ConstUtils.PASSWORD);
    machineInfo.setServiceTime(date);
    machineInfo.setModifyTime(date);
    machineInfo.setAvailable(MachineInfoEnum.AvailableEnum.YES.getValue());
    boolean isSuccess = machineDeployCenter.addMachine(machineInfo);
    model.addAttribute("result", isSuccess);
    return new ModelAndView("");
}
Also used : MachineInfo(com.sohu.cache.entity.MachineInfo) ModelAndView(org.springframework.web.servlet.ModelAndView) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 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 9 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 10 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