use of com.sohu.cache.server.data.OS in project cachecloud by sohutv.
the class NMONService method initNmon.
/**
* 尝试修复启动失败的错误
* @param ip
* @param session
*/
private OSInfo initNmon(String ip, SSHSession session) {
//获取nmon版本
String version = getNMONVersion(ip, session);
//获取操作系统原始信息
OSInfo osInfo = getOSInfo(ip, session);
OS os = null;
//nmon文件不存在,需要根据操作系统识别是否支持
if (null == version) {
logger.warn("{} not exist {}", ip, NMON_FILE);
//将原始信息转换为可识别的操作系统
os = OSFactory.getOS(osInfo);
} else {
//nmon存在,但是版本有问题,此时不应该再判断系统信息了,直接用默认的
logger.warn("{} {} version err:" + version, ip, NMON_FILE);
os = OSFactory.getDefaultOS(osInfo);
}
if (os == null) {
logger.error("unkonw os info={}", osInfo);
return null;
}
//获取nmon文件
File nmonFile = NMONFileFactory.getNMONFile(os);
if (nmonFile == null) {
logger.warn("{} no corresponding nmon file", os);
nmonFile = NMONFileFactory.getNMONFile(OSFactory.getDefaultOS(osInfo));
}
//将nmon文件传输至服务器
sendNMONToServer(ip, session, nmonFile);
return osInfo;
}
use of com.sohu.cache.server.data.OS in project cachecloud by sohutv.
the class OSFactory method getOS.
/**
* 采用uname -a信息和/etc/issue解析出目前能够支持的操作系统
* @param osInfo
* @return OS
*/
public static OS getOS(OSInfo osInfo) {
String uname = osInfo.getUname();
String issue = osInfo.getIssue();
OSType osType = OSType.LINUX;
ProcessorArchitecture defaultArch = ProcessorArchitecture.X86_64;
DistributionType defaultDist = DistributionType.LINUX_OLD;
DistributionVersion version = DistributionVersion.DEFAULT;
//无法获取系统类型,位数 版本,采用默认
if (uname == null || issue == null) {
OS os = new OS(osType, defaultDist, version, defaultArch);
return os;
}
uname = uname.toLowerCase();
//首先获取操作系统类型
if (!uname.contains(OSType.LINUX.getValue())) {
logger.error("os={} is temporarily not supported", uname);
return null;
}
//其次获取操作系统位数
if (!uname.contains(defaultArch.getValue())) {
defaultArch = ProcessorArchitecture.X86;
}
//再次解析操作系统发行版本
issue = issue.toLowerCase();
DistributionType findType = DistributionType.findByContains(issue);
//没有找到匹配的版本,使用默认
if (findType == null) {
logger.warn("dist cannot matched, {}", issue);
OS os = new OS(osType, defaultDist, version, defaultArch);
return os;
}
//最后解析版本号
Matcher matcher = VERSION_PATTERN.matcher(issue);
//没有版本好用默认的
if (!matcher.find()) {
logger.warn("version not matched, {}", issue);
OS os = new OS(osType, defaultDist, version, defaultArch);
return os;
}
String ver = matcher.group();
ver = ver.replaceAll("\\.", "");
logger.info("version matched, {} - {}", ver, issue);
DistributionVersion versionResult = findVersion(findType.getVersions(), ver);
//没有具体的版本能匹配上
if (versionResult == null) {
logger.info("version {} not found, {}", ver);
OS os = new OS(osType, defaultDist, version, defaultArch);
return os;
}
OS os = new OS(osType, findType, versionResult, defaultArch);
logger.info("find OS={}", os);
return os;
}
use of com.sohu.cache.server.data.OS in project cachecloud by sohutv.
the class OSFactory method getDefaultOS.
public static OS getDefaultOS(OSInfo osInfo) {
String uname = osInfo.getUname();
//无法获取系统位数
if (uname == null) {
return null;
}
uname = uname.toLowerCase();
ProcessorArchitecture defaultArch = ProcessorArchitecture.X86_64;
//其次获取操作系统位数
if (!uname.contains(defaultArch.getValue())) {
defaultArch = ProcessorArchitecture.X86;
}
return new OS(OSType.LINUX, DistributionType.LINUX_OLD, DistributionVersion.DEFAULT, defaultArch);
}
Aggregations