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);
}
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations