当前位置: 首页>>代码示例>>Java>>正文


Java NodeInfo类代码示例

本文整理汇总了Java中org.libvirt.NodeInfo的典型用法代码示例。如果您正苦于以下问题:Java NodeInfo类的具体用法?Java NodeInfo怎么用?Java NodeInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NodeInfo类属于org.libvirt包,在下文中一共展示了NodeInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mockConnect

import org.libvirt.NodeInfo; //导入依赖的package包/类
private static Connect mockConnect(boolean cpu1, boolean wordSize32bits, int memoryInKB)
    throws IOException, LibvirtException {
    StringWriter capabilitiesXML = new StringWriter();
    Capabilities capabilities = new Capabilities();
    Guest guest = new Guest();
    Arch arch = new Arch();
    arch.setWordSize(getWordSize(wordSize32bits));
    arch.setName(getCpu(cpu1));
    guest.setArch(arch);
    capabilities.addGuest(guest);
    new CapabilitiesDom4jWriter().write(capabilitiesXML, capabilities);

    Connect connect = mock(Connect.class);
    when(connect.getCapabilities()).thenReturn(capabilitiesXML.toString());
    NodeInfo nodeInfo = new NodeInfo();
    nodeInfo.memory = memoryInKB;
    when(connect.nodeInfo()).thenReturn(nodeInfo);
    return connect;
}
 
开发者ID:fduminy,项目名称:jtestplatform,代码行数:20,代码来源:PlatformSupportManagerTest.java

示例2: calculateFreeMemory

import org.libvirt.NodeInfo; //导入依赖的package包/类
private long calculateFreeMemory() throws IOException {
    NodeInfo nodeInfo = libvirtManager.getNodeInfo();
    long nodeMemoryInMB = nodeInfo.memory / ONE_THOUSAND_TWENTY_FOUR;

    xenConfigurationParser.init(this.xenConfigPath);
    long xenMinMemoryInMB = xenConfigurationParser.getLongValue("dom0-min-mem");

    LOG.debug(String.format("Available Node memory (from libvirt): %dMB, Memory reserved for dom0 in xen config: %dMB, Memory reserved for Xen in p2p-app-config: %dMB", nodeMemoryInMB, configReservedMem, xenMinMemoryInMB));

    long usedMemory = 0;
    Collection<Domain> allRunInstances = libvirtManager.getAllInstances();
    for (Domain domain : allRunInstances) {
        try {
            if (StringUtils.isBlank(domain.getName()) || !domain.getName().toLowerCase(Locale.UK).contains("domain"))
                usedMemory += domain.getMaxMemory() / ONE_THOUSAND_TWENTY_FOUR;
        } catch (LibvirtException e) {
            LOG.warn(String.format(UNABLE_TO_GET_NODE_INFORMATION_FOR_INSTANCE_IN_XEN_WITH_ID_S, domain), e);
        }
    }

    // deduct 64M as an extra buffer for xen
    long freeMemoryInMB = nodeMemoryInMB - usedMemory - xenMinMemoryInMB - configReservedMem - SIXTY_FOUR;

    LOG.debug(String.format("Free memory available in xen: %d", freeMemoryInMB));
    return freeMemoryInMB;
}
 
开发者ID:barnyard,项目名称:pi,代码行数:27,代码来源:SystemResourceState.java

示例3: getCpuSpeed

import org.libvirt.NodeInfo; //导入依赖的package包/类
protected static long getCpuSpeed(final NodeInfo nodeInfo) {
    try (final Reader reader = new FileReader(
            "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq")) {
        return Long.parseLong(IOUtils.toString(reader).trim()) / 1000;
    } catch (IOException | NumberFormatException e) {
        logger.warn("Could not read cpuinfo_max_freq");
        return nodeInfo.mhz;
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:10,代码来源:LibvirtComputingResource.java

示例4: getNodeInfo

import org.libvirt.NodeInfo; //导入依赖的package包/类
public NodeInfo getNodeInfo() {
	try {
		return libvirtConn.nodeInfo();
	} catch (LibvirtException ex) {
		ex.printStackTrace();
		return null;
	}
}
 
开发者ID:mustafaakin,项目名称:buki-libvirt,代码行数:9,代码来源:Connection.java

示例5: getCpuSpeed

import org.libvirt.NodeInfo; //导入依赖的package包/类
protected static long getCpuSpeed(final NodeInfo nodeInfo) {
    try (final Reader reader = new FileReader(
            "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq")) {
        return Long.parseLong(IOUtils.toString(reader).trim()) / 1000;
    } catch (IOException | NumberFormatException e) {
        s_logger.warn("Could not read cpuinfo_max_freq");
        return nodeInfo.mhz;
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:10,代码来源:LibvirtComputingResource.java

示例6: getNodeInfo

import org.libvirt.NodeInfo; //导入依赖的package包/类
public NodeInfo getNodeInfo() {
    try {
        return connection.getNodeInfo();
    } catch (LibvirtException e) {
        processLibvirtException(e, "Unable to get the node info");
    }
    return null;
}
 
开发者ID:barnyard,项目名称:pi,代码行数:9,代码来源:LibvirtManager.java

示例7: getFreeCores

import org.libvirt.NodeInfo; //导入依赖的package包/类
private int getFreeCores(int usedCpus) {
    int freeCpus = 0;
    if (configMaxCores > 0) {
        freeCpus = configMaxCores - usedCpus;
        LOG.debug(String.format("Using ConfigMaxCores - FreeCpus: %d", freeCpus));
    } else {
        NodeInfo nodeInfo = libvirtManager.getNodeInfo();
        freeCpus = nodeInfo.cpus - usedCpus;
        LOG.debug("Not using ConfigMaxCores - FreeCpus:" + freeCpus);
    }

    LOG.debug(String.format("Free cores available in Xen: %d", freeCpus));
    return freeCpus;
}
 
开发者ID:barnyard,项目名称:pi,代码行数:15,代码来源:SystemResourceState.java

示例8: shouldReturnNodeInfo

import org.libvirt.NodeInfo; //导入依赖的package包/类
@Test
public void shouldReturnNodeInfo() throws Exception {
    // setup
    NodeInfo mockNodeInfo = mock(NodeInfo.class);
    when(mockConnection.getNodeInfo()).thenReturn(mockNodeInfo);

    // act
    NodeInfo nodeInfo = this.libvirtManager.getNodeInfo();

    // assert
    assertEquals(mockNodeInfo, nodeInfo);
}
 
开发者ID:barnyard,项目名称:pi,代码行数:13,代码来源:LibvirtManagerTest.java

示例9: getNodeInfo

import org.libvirt.NodeInfo; //导入依赖的package包/类
@Override
public NodeInfo getNodeInfo() throws LibvirtException {
    addCommand("getNodeInfo");
    NodeInfo nodeInfo = new NodeInfo();
    nodeInfo.memory = FOUR_OH_NINE_SIX * ONE_OH_TWO_FOUR * ONE_OH_TWO_FOUR_LONG;
    nodeInfo.cpus = ONE_OH_TWO_FOUR;
    return nodeInfo;
}
 
开发者ID:barnyard,项目名称:pi,代码行数:9,代码来源:StubLibvirtConnection.java

示例10: nodeInfo

import org.libvirt.NodeInfo; //导入依赖的package包/类
/**
 * Get information about the host hardware
 */
public LibVirtNodeInfo nodeInfo()
{
    this.checkOpen();
    try
    {
        NodeInfo ni = this.connection.nodeInfo();
        return new LibVirtNodeInfo(ni.model, ni.memory * 1024L, ni.cpus, ni.mhz, ni.nodes, ni.sockets, ni.cores, ni.threads);
    }
    catch (LibvirtException e)
    {
        throw new DataException("Cannot get node info", e);
    }
}
 
开发者ID:intrbiz,项目名称:virt,代码行数:17,代码来源:LibVirtAdapter.java

示例11: getHostInfo

import org.libvirt.NodeInfo; //导入依赖的package包/类
protected List<Object> getHostInfo() {
    final ArrayList<Object> info = new ArrayList<>();
    long speed = 0;
    long cpus = 0;
    long ram = 0;
    int cpuSockets = 0;
    String cap = null;
    try {
        final Connect conn = LibvirtConnection.getConnection();
        final NodeInfo hosts = conn.nodeInfo();
        speed = getCpuSpeed(hosts);

  /*
   * Some CPUs report a single socket and multiple NUMA cells.
   * We need to multiply them to get the correct socket count.
   */
        cpuSockets = hosts.sockets;
        if (hosts.nodes > 0) {
            cpuSockets = hosts.sockets * hosts.nodes;
        }
        cpus = hosts.cpus;
        ram = hosts.memory * 1024L;
        final LibvirtCapXmlParser parser = new LibvirtCapXmlParser();
        parser.parseCapabilitiesXml(conn.getCapabilities());
        final ArrayList<String> oss = parser.getGuestOsType();
        for (final String s : oss) {
    /*
     * Even host supports guest os type more than hvm, we only report hvm to management server
     */
            if (s.equalsIgnoreCase("hvm")) {
                cap = "hvm";
            }
        }
    } catch (final LibvirtException e) {
        logger.trace("Ignoring libvirt error.", e);
    }

    if (isSnapshotSupported()) {
        cap = cap + ",snapshot";
    }

    info.add((int) cpus);
    info.add(speed);
    // Report system's RAM as actual RAM minus host OS reserved RAM
    final long dom0MinMem = getHostReservedMemMb();
    ram = ram - dom0MinMem;
    info.add(ram);
    info.add(cap);
    info.add(dom0MinMem);
    info.add(cpuSockets);
    logger.debug("cpus=" + cpus + ", speed=" + speed + ", ram=" + ram + ", _dom0MinMem=" + dom0MinMem + ", cpu sockets=" + cpuSockets);

    return info;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:55,代码来源:LibvirtComputingResource.java

示例12: getCpuSpeed

import org.libvirt.NodeInfo; //导入依赖的package包/类
@Test
public void getCpuSpeed() {
    Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
    final NodeInfo nodeInfo = Mockito.mock(NodeInfo.class);
    LibvirtComputingResource.getCpuSpeed(nodeInfo);
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:7,代码来源:LibvirtComputingResourceTest.java

示例13: getHostInfo

import org.libvirt.NodeInfo; //导入依赖的package包/类
protected List<Object> getHostInfo() {
    final ArrayList<Object> info = new ArrayList<Object>();
    long speed = 0;
    long cpus = 0;
    long ram = 0;
    int cpuSockets = 0;
    String cap = null;
    try {
        final Connect conn = LibvirtConnection.getConnection();
        final NodeInfo hosts = conn.nodeInfo();
        speed = getCpuSpeed(hosts);

        /*
        * Some CPUs report a single socket and multiple NUMA cells.
        * We need to multiply them to get the correct socket count.
        */
        cpuSockets = hosts.sockets;
        if (hosts.nodes > 0) {
            cpuSockets = hosts.sockets * hosts.nodes;
        }
        cpus = hosts.cpus;
        ram = hosts.memory * 1024L;
        final LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
        parser.parseCapabilitiesXML(conn.getCapabilities());
        final ArrayList<String> oss = parser.getGuestOsType();
        for (final String s : oss) {
            /*
             * Even host supports guest os type more than hvm, we only
             * report hvm to management server
             */
            if (s.equalsIgnoreCase("hvm")) {
                cap = "hvm";
            }
        }
    } catch (final LibvirtException e) {
        s_logger.trace("Ignoring libvirt error.", e);
    }

    if (isSnapshotSupported()) {
        cap = cap + ",snapshot";
    }

    info.add((int)cpus);
    info.add(speed);
    // Report system's RAM as actual RAM minus host OS reserved RAM
    ram = ram - _dom0MinMem + _dom0OvercommitMem;
    info.add(ram);
    info.add(cap);
    info.add(_dom0MinMem);
    info.add(cpuSockets);
    s_logger.debug("cpus=" + cpus + ", speed=" + speed + ", ram=" + ram + ", _dom0MinMem=" + _dom0MinMem + ", _dom0OvercommitMem=" + _dom0OvercommitMem + ", cpu sockets=" + cpuSockets);

    return info;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:55,代码来源:LibvirtComputingResource.java

示例14: getNodeInfo

import org.libvirt.NodeInfo; //导入依赖的package包/类
@Override
public NodeInfo getNodeInfo() throws LibvirtException {
    LOG.debug("getNodeInfo()");
    init();
    return this.connect.nodeInfo();
}
 
开发者ID:barnyard,项目名称:pi,代码行数:7,代码来源:LibvirtConnection.java

示例15: setUp

import org.libvirt.NodeInfo; //导入依赖的package包/类
public void setUp(boolean isMockFile) throws Exception {
    if (isMockFile) {
        mockFile = mock(File.class);
        when(mockFile.exists()).thenReturn(true);
        when(mockFile.getFreeSpace()).thenReturn(1024 * 1024 * 1024L);
        systemResourceState = new SystemResourceState() {
            @Override
            protected File getFile(String instancePath) {
                return mockFile;
            }
        };
    } else
        systemResourceState = new SystemResourceState();

    libvirtManager = mock(LibvirtManager.class);
    systemResourceState.setLibvirtManager(libvirtManager);

    xenConfigurationParser = mock(XenConfigurationParser.class);
    systemResourceState.setXenConfigurationParser(xenConfigurationParser);

    mockNodeInfo = new NodeInfo();
    mockNodeInfo.cpus = 10;
    mockNodeInfo.memory = 2048 * 1024;

    domainInfo1 = new DomainInfo();
    domainInfo1.nrVirtCpu = 4;

    domainInfo2 = new DomainInfo();
    domainInfo2.nrVirtCpu = 2;

    mockDomain = mock(Domain.class);
    when(mockDomain.getInfo()).thenReturn(domainInfo1).thenReturn(domainInfo2);
    when(mockDomain.getMaxMemory()).thenReturn(768 * 1024L).thenReturn(256 * 1024L);

    setupLibvirtManagerExpectations(Arrays.asList(new Domain[] { mockDomain, mockDomain }));

    EhCacheFactoryBean ehCacheFactoryBean = new EhCacheFactoryBean();
    ehCacheFactoryBean.setCacheName("unittest");
    ehCacheFactoryBean.setTimeToIdle(cacheTTLSeconds);
    ehCacheFactoryBean.setTimeToLive(cacheTTLSeconds);
    ehCacheFactoryBean.afterPropertiesSet();
    this.cache = (Cache) ehCacheFactoryBean.getObject();

    systemResourceState.setCache(cache);
}
 
开发者ID:barnyard,项目名称:pi,代码行数:46,代码来源:SystemResourceStateTest.java


注:本文中的org.libvirt.NodeInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。