Search in sources :

Example 1 with OS

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;
}
Also used : OSInfo(com.sohu.cache.server.data.OSInfo) OS(com.sohu.cache.server.data.OS) File(java.io.File)

Example 2 with OS

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;
}
Also used : DistributionVersion(com.sohu.cache.server.data.OSInfo.DistributionVersion) OS(com.sohu.cache.server.data.OS) ProcessorArchitecture(com.sohu.cache.server.data.OSInfo.ProcessorArchitecture) Matcher(java.util.regex.Matcher) OSType(com.sohu.cache.server.data.OSInfo.OSType) DistributionType(com.sohu.cache.server.data.OSInfo.DistributionType)

Example 3 with 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);
}
Also used : OS(com.sohu.cache.server.data.OS) ProcessorArchitecture(com.sohu.cache.server.data.OSInfo.ProcessorArchitecture)

Aggregations

OS (com.sohu.cache.server.data.OS)3 ProcessorArchitecture (com.sohu.cache.server.data.OSInfo.ProcessorArchitecture)2 OSInfo (com.sohu.cache.server.data.OSInfo)1 DistributionType (com.sohu.cache.server.data.OSInfo.DistributionType)1 DistributionVersion (com.sohu.cache.server.data.OSInfo.DistributionVersion)1 OSType (com.sohu.cache.server.data.OSInfo.OSType)1 File (java.io.File)1 Matcher (java.util.regex.Matcher)1