use of com.vmware.vim.binding.vim.host.Summary.QuickStats in project flowgate by vmware.
the class VCDataService method feedHostMetaData.
public boolean feedHostMetaData(HostSystem host, HostInfo hostInfo) {
boolean needUpdate = false;
Capability capability = host.getCapability();
if (capability != null) {
if (capability.isMaintenanceModeSupported() != hostInfo.isMaintenanceModeSupported()) {
hostInfo.setMaintenanceModeSupported(capability.isMaintenanceModeSupported());
needUpdate = true;
}
if (capability.isRebootSupported() != hostInfo.isRebootSupported()) {
hostInfo.setRebootSupported(capability.isRebootSupported());
needUpdate = true;
}
Integer maxRunningVMs = capability.getMaxRunningVMs() == null ? 0 : capability.getMaxRunningVMs();
if (maxRunningVMs.intValue() != hostInfo.getMaxRunningVms()) {
hostInfo.setMaxRunningVms(maxRunningVMs);
needUpdate = true;
}
Integer maxSupportedVcpus = capability.getMaxSupportedVcpus() == null ? 0 : capability.getMaxSupportedVcpus();
if (maxSupportedVcpus.intValue() != hostInfo.getMaxSupportedVcpus()) {
hostInfo.setMaxSupportedVcpus(maxSupportedVcpus);
needUpdate = true;
}
Integer maxRegisteredVMs = capability.getMaxRegisteredVMs() == null ? 0 : capability.getMaxRegisteredVMs();
if (maxRegisteredVMs.intValue() != hostInfo.getMaxRegisteredVMs()) {
hostInfo.setMaxRegisteredVMs(maxRegisteredVMs);
needUpdate = true;
}
}
RuntimeInfo runtimeInfo = host.getRuntime();
if (runtimeInfo != null) {
String hostInfoConnectionState = hostInfo.getConnectionState();
String runtimeInfoConnectionState = runtimeInfo.getConnectionState().toString();
if (!StringUtils.equals(hostInfoConnectionState, runtimeInfoConnectionState)) {
hostInfo.setConnectionState(runtimeInfoConnectionState);
needUpdate = true;
}
String hostInfoPowerState = hostInfo.getPowerState();
String runtimeInfoPowerState = runtimeInfo.getPowerState().toString();
if (!StringUtils.equals(hostInfoPowerState, runtimeInfoPowerState)) {
hostInfo.setPowerState(runtimeInfoPowerState);
needUpdate = true;
}
if (runtimeInfo.getBootTime().getTimeInMillis() != hostInfo.getBootTime()) {
hostInfo.setBootTime(runtimeInfo.getBootTime().getTimeInMillis());
needUpdate = true;
}
}
Summary summary = host.getSummary();
if (summary != null) {
if (summary.isRebootRequired() != hostInfo.isRebootRequired()) {
hostInfo.setRebootRequired(summary.isRebootRequired());
needUpdate = true;
}
QuickStats quickStats = summary.getQuickStats();
if (quickStats != null) {
Integer uptime = quickStats.getUptime() == null ? 0 : quickStats.getUptime();
hostInfo.setUptime(uptime);
}
AboutInfo aboutInfo = summary.getConfig().getProduct();
if (aboutInfo != null) {
String build = aboutInfo.getBuild();
String hostInfoHypervisorBuildVersion = hostInfo.getHypervisorBuildVersion();
if (!StringUtils.equals(build, hostInfoHypervisorBuildVersion)) {
hostInfo.setHypervisorBuildVersion(build);
needUpdate = true;
}
String fullName = aboutInfo.getFullName();
String hostInfoHypervisorFullName = hostInfo.getHypervisorFullName();
if (!StringUtils.equals(fullName, hostInfoHypervisorFullName)) {
hostInfo.setHypervisorFullName(fullName);
needUpdate = true;
}
String licenseProductName = aboutInfo.getLicenseProductName();
String hostInfoHypervisorLicenseProductName = hostInfo.getHypervisorLicenseProductName();
if (!StringUtils.equals(licenseProductName, hostInfoHypervisorLicenseProductName)) {
hostInfo.setHypervisorLicenseProductName(licenseProductName);
needUpdate = true;
}
String licenseProductVersion = aboutInfo.getLicenseProductVersion();
String hostInfoHypervisorLicenseProductVersion = hostInfo.getHypervisorLicenseProductVersion();
if (!StringUtils.equals(licenseProductVersion, hostInfoHypervisorLicenseProductVersion)) {
hostInfo.setHypervisorLicenseProductVersion(licenseProductVersion);
needUpdate = true;
}
String version = aboutInfo.getVersion();
String hostInfoHypervisorVersion = hostInfo.getHypervisorVersion();
if (!StringUtils.equals(version, hostInfoHypervisorVersion)) {
hostInfo.setHypervisorVersion(version);
needUpdate = true;
}
}
HardwareSummary hardwareSummary = summary.getHardware();
if (hardwareSummary != null) {
String hostModel = hardwareSummary.getModel();
String hostInfoHostModel = hostInfo.getHostModel();
if (!StringUtils.equals(hostModel, hostInfoHostModel)) {
hostInfo.setHostModel(hostModel);
needUpdate = true;
}
String vendor = hardwareSummary.getVendor();
String hostInfoHypervisorVendor = hostInfo.getHypervisorVendor();
if (!StringUtils.equals(vendor, hostInfoHypervisorVendor)) {
hostInfo.setHypervisorVendor(vendor);
needUpdate = true;
}
if (hardwareSummary.getNumCpuCores() != hostInfo.getCpuTotalCores()) {
hostInfo.setCpuTotalCores(hardwareSummary.getNumCpuCores());
needUpdate = true;
}
if (hardwareSummary.getNumCpuPkgs() != hostInfo.getCpuTotalPackages()) {
hostInfo.setCpuTotalPackages(hardwareSummary.getNumCpuPkgs());
needUpdate = true;
}
if (hardwareSummary.getNumCpuThreads() != hostInfo.getCpuTotalThreads()) {
hostInfo.setCpuTotalThreads(hardwareSummary.getNumCpuThreads());
needUpdate = true;
}
if (hardwareSummary.getCpuMhz() != hostInfo.getSingleCoreCpuMhz()) {
hostInfo.setSingleCoreCpuMhz(hardwareSummary.getCpuMhz());
needUpdate = true;
}
if (hardwareSummary.getMemorySize() != hostInfo.getMemoryCapacity()) {
hostInfo.setMemoryCapacity(hardwareSummary.getMemorySize());
needUpdate = true;
}
}
}
Map<String, HostNic> newHostNicMap = new HashMap<>();
Map<String, HostNic> oldHostNicMap = new HashMap<>();
NetworkInfo networkInfo = host.getConfig().getNetwork();
if (networkInfo != null) {
PhysicalNic[] physicalNics = networkInfo.getPnic();
List<HostNic> hostNics = new ArrayList<HostNic>();
for (PhysicalNic physicalNic : physicalNics) {
HostNic hostNic = new HostNic();
hostNic.setMacAddress(physicalNic.getMac());
hostNic.setDriver(physicalNic.getDriver());
LinkSpeedDuplex physicalNicLinkSpeed = physicalNic.getLinkSpeed();
if (physicalNicLinkSpeed == null) {
hostNic.setDuplex(false);
hostNic.setLinkSpeedMb(0);
} else {
hostNic.setDuplex(physicalNicLinkSpeed.isDuplex());
hostNic.setLinkSpeedMb(physicalNicLinkSpeed.getSpeedMb());
}
hostNic.setName(physicalNic.getDevice());
hostNics.add(hostNic);
newHostNicMap.put(physicalNic.getMac(), hostNic);
}
int nicsNum = physicalNics.length;
if (nicsNum > 0) {
List<HostNic> oldNics = hostInfo.getHostNics();
if (oldNics == null) {
hostInfo.setHostNics(hostNics);
needUpdate = true;
} else {
for (HostNic oldhostNic : oldNics) {
oldHostNicMap.put(oldhostNic.getMacAddress(), oldhostNic);
}
if (newHostNicMap.size() != oldHostNicMap.size()) {
hostInfo.setHostNics(hostNics);
needUpdate = true;
} else {
for (Entry<String, HostNic> entry : oldHostNicMap.entrySet()) {
if (!newHostNicMap.containsKey(entry.getKey())) {
hostInfo.setHostNics(hostNics);
needUpdate = true;
break;
}
}
}
}
}
}
long diskCapacity = 0;
DatastoreInfo[] datastores = host.queryConnectionInfo().getDatastore();
if (datastores != null && datastores.length > 0) {
for (DatastoreInfo datastore : datastores) {
// TODO: only count writable data store.
// count shared data store for each host,
// which will cause problem in calculate the total available storage among multiple hosts.
diskCapacity += datastore.getSummary().getCapacity();
}
if (diskCapacity != hostInfo.getDiskCapacity()) {
needUpdate = true;
hostInfo.setDiskCapacity(diskCapacity);
}
}
return needUpdate;
}
use of com.vmware.vim.binding.vim.host.Summary.QuickStats in project flowgate by vmware.
the class VCDataServiceTest method testFeedHostMetaData.
@Test
public void testFeedHostMetaData() {
HostSystem host = Mockito.mock(HostSystem.class);
Capability capability = Mockito.mock(Capability.class);
when(host.getCapability()).thenReturn(capability);
when(capability.isMaintenanceModeSupported()).thenReturn(true);
when(capability.isRebootSupported()).thenReturn(true);
when(capability.getMaxRunningVMs()).thenReturn(10);
when(capability.getMaxSupportedVcpus()).thenReturn(10);
when(capability.getMaxRegisteredVMs()).thenReturn(10);
RuntimeInfo runtimeInfo = Mockito.mock(RuntimeInfo.class);
when(host.getRuntime()).thenReturn(runtimeInfo);
when(runtimeInfo.getConnectionState()).thenReturn(ConnectionState.connected);
when(runtimeInfo.getPowerState()).thenReturn(PowerState.poweredOff);
Calendar time = Mockito.mock(Calendar.class);
when(runtimeInfo.getBootTime()).thenReturn(time);
Summary summary = Mockito.mock(Summary.class);
when(host.getSummary()).thenReturn(summary);
when(summary.isRebootRequired()).thenReturn(true);
QuickStats quickStats = Mockito.mock(QuickStats.class);
when(summary.getQuickStats()).thenReturn(quickStats);
when(quickStats.getUptime()).thenReturn(10);
AboutInfo aboutInfo = Mockito.mock(AboutInfo.class);
ConfigSummary configSummary = Mockito.mock(ConfigSummary.class);
when(summary.getConfig()).thenReturn(configSummary);
when(configSummary.getProduct()).thenReturn(aboutInfo);
when(aboutInfo.getBuild()).thenReturn("build");
when(aboutInfo.getFullName()).thenReturn("fullname");
when(aboutInfo.getLicenseProductName()).thenReturn("productname");
when(aboutInfo.getVersion()).thenReturn("version");
when(aboutInfo.getLicenseProductVersion()).thenReturn("productversion");
HardwareSummary hardwareSummary = Mockito.mock(HardwareSummary.class);
when(summary.getHardware()).thenReturn(hardwareSummary);
when(hardwareSummary.getModel()).thenReturn("model");
when(hardwareSummary.getVendor()).thenReturn("model");
when(hardwareSummary.getNumCpuCores()).thenReturn((short) 2);
when(hardwareSummary.getNumCpuPkgs()).thenReturn((short) 2);
when(hardwareSummary.getNumCpuThreads()).thenReturn((short) 2);
when(hardwareSummary.getCpuMhz()).thenReturn(2);
when(hardwareSummary.getMemorySize()).thenReturn(2L);
NetworkInfo networkInfo = Mockito.mock(NetworkInfo.class);
ConfigInfo configInfo = Mockito.mock(ConfigInfo.class);
when(host.getConfig()).thenReturn(configInfo);
when(configInfo.getNetwork()).thenReturn(networkInfo);
LinkSpeedDuplex linkSpeedDuplex = Mockito.mock(LinkSpeedDuplex.class);
when(linkSpeedDuplex.isDuplex()).thenReturn(true);
when(linkSpeedDuplex.getSpeedMb()).thenReturn(2);
PhysicalNic[] physicalNics = new PhysicalNic[2];
physicalNics[0] = Mockito.mock(PhysicalNic.class);
when(physicalNics[0].getMac()).thenReturn("mac");
when(physicalNics[0].getDriver()).thenReturn("driver");
when(physicalNics[0].getLinkSpeed()).thenReturn(linkSpeedDuplex);
when(physicalNics[0].getDevice()).thenReturn("device");
physicalNics[1] = Mockito.mock(PhysicalNic.class);
when(physicalNics[1].getMac()).thenReturn("mac1");
when(physicalNics[1].getDriver()).thenReturn("driver1");
when(physicalNics[1].getLinkSpeed()).thenReturn(linkSpeedDuplex);
when(physicalNics[1].getDevice()).thenReturn("device1");
when(networkInfo.getPnic()).thenReturn(physicalNics);
ConnectInfo connectInfo = Mockito.mock(ConnectInfo.class);
DatastoreInfo[] datastores = { Mockito.mock(DatastoreInfo.class), Mockito.mock(DatastoreInfo.class) };
com.vmware.vim.binding.vim.Datastore.Summary connectInfoSummary = Mockito.mock(com.vmware.vim.binding.vim.Datastore.Summary.class);
when(connectInfoSummary.getCapacity()).thenReturn(2L);
when(datastores[0].getSummary()).thenReturn(connectInfoSummary);
ManagedObjectReference mor1 = Mockito.mock(ManagedObjectReference.class);
when(datastores[1].getSummary()).thenReturn(connectInfoSummary);
when(connectInfoSummary.getDatastore()).thenReturn(mor1);
when(mor1.getValue()).thenReturn("datastoreid");
when(host.queryConnectionInfo()).thenReturn(connectInfo);
when(connectInfo.getDatastore()).thenReturn(datastores);
com.vmware.vim.binding.vim.vsan.host.ConfigInfo vsanConfigInfo = Mockito.mock(com.vmware.vim.binding.vim.vsan.host.ConfigInfo.class);
when(configInfo.getVsanHostConfig()).thenReturn(vsanConfigInfo);
when(vsanConfigInfo.getEnabled()).thenReturn(true);
when(capability.getVsanSupported()).thenReturn(true);
Collection<ClusterComputeResource> clusterComputeResources = new ArrayList<>();
ClusterComputeResource cluster = Mockito.mock(ClusterComputeResource.class);
clusterComputeResources.add(cluster);
clusterComputeResources.add(cluster);
when(vsphereClient.getAllClusterComputeResource()).thenReturn(clusterComputeResources);
ManagedObjectReference[] mors = new ManagedObjectReference[2];
mors[0] = Mockito.mock(ManagedObjectReference.class);
mors[1] = Mockito.mock(ManagedObjectReference.class);
when(mors[0].getValue()).thenReturn("hostMobId");
when(mors[1].getValue()).thenReturn("hostMobId");
when(cluster.getHost()).thenReturn(mors);
ConfigInfoEx ci = Mockito.mock(ConfigInfoEx.class);
when(cluster.getConfigurationEx()).thenReturn(ci);
when(cluster.getName()).thenReturn("cluster");
DpmConfigInfo dpmConfigInfo = Mockito.mock(DpmConfigInfo.class);
when(dpmConfigInfo.getEnabled()).thenReturn(true);
when(ci.getDpmConfigInfo()).thenReturn(dpmConfigInfo);
DrsConfigInfo drsConfigInfo = Mockito.mock(DrsConfigInfo.class);
when(drsConfigInfo.getDefaultVmBehavior()).thenReturn(DrsBehavior.fullyAutomated);
when(ci.getDrsConfig()).thenReturn(drsConfigInfo);
com.vmware.vim.binding.vim.ComputeResource.Summary computeResourceSummary = Mockito.mock(com.vmware.vim.binding.vim.ComputeResource.Summary.class);
when(computeResourceSummary.getNumEffectiveHosts()).thenReturn(2);
when(computeResourceSummary.getNumHosts()).thenReturn(2);
when(computeResourceSummary.getTotalCpu()).thenReturn(2);
when(computeResourceSummary.getNumCpuCores()).thenReturn((short) 2);
when(computeResourceSummary.getNumCpuThreads()).thenReturn((short) 2);
when(computeResourceSummary.getTotalMemory()).thenReturn(2L);
when(cluster.getSummary()).thenReturn(computeResourceSummary);
com.vmware.vim.binding.vim.vsan.cluster.ConfigInfo clusterConfigInfo = Mockito.mock(com.vmware.vim.binding.vim.vsan.cluster.ConfigInfo.class);
when(ci.getVsanConfigInfo()).thenReturn(clusterConfigInfo);
when(clusterConfigInfo.getEnabled()).thenReturn(true);
DpmHostConfigInfo[] dpmHostConfigInfos = new DpmHostConfigInfo[2];
dpmHostConfigInfos[0] = Mockito.mock(DpmHostConfigInfo.class);
dpmHostConfigInfos[1] = Mockito.mock(DpmHostConfigInfo.class);
ManagedObjectReference mor2 = Mockito.mock(ManagedObjectReference.class);
when(dpmHostConfigInfos[0].getKey()).thenReturn(mor2);
when(mor2.getValue()).thenReturn("hostMobId");
when(dpmHostConfigInfos[1].getKey()).thenReturn(mor2);
when(mor2.getValue()).thenReturn("hostMobId");
when(ci.getDpmHostConfig()).thenReturn(dpmHostConfigInfos);
ManagedObjectReference mor3 = Mockito.mock(ManagedObjectReference.class);
when(cluster._getRef()).thenReturn(mor3);
when(mor3.getValue()).thenReturn("clusterMobid");
ManagedObjectReference mor4 = Mockito.mock(ManagedObjectReference.class);
when(cluster.getParent()).thenReturn(mor4);
when(mor4.getValue()).thenReturn("InstanceId");
when(host.getName()).thenReturn("hostname");
HostInfo hostInfo = new HostInfo();
List<HostNic> hostNics = new ArrayList<HostNic>();
HostNic hostNic1 = new HostNic();
hostNic1.setDriver("driver1");
hostNic1.setMacAddress("mac1");
hostNic1.setDuplex(true);
hostNic1.setLinkSpeedMb(2);
hostNic1.setName("nic1");
HostNic hostNic2 = new HostNic();
hostNic2.setDriver("driver2");
hostNic2.setMacAddress("mac2");
hostNic2.setDuplex(true);
hostNic2.setLinkSpeedMb(2);
hostNic2.setName("nic2");
hostNics.add(hostNic1);
hostNics.add(hostNic2);
hostInfo.setHostNics(hostNics);
boolean needUpdate = service.feedHostMetaData(host, hostInfo);
TestCase.assertEquals(needUpdate, true);
}
Aggregations