Search in sources :

Example 6 with HostSystem

use of com.vmware.vim.binding.vim.HostSystem in project flowgate by vmware.

the class VCDataServiceTest method testFeedHostUsageData.

@Test
public void testFeedHostUsageData() {
    Asset hostMappingAsset = Mockito.mock(Asset.class);
    HostSystem host = Mockito.mock(HostSystem.class);
    when(hostMappingAsset.getId()).thenReturn("hostid");
    PerformanceManager performanceManager = Mockito.mock(PerformanceManager.class);
    when(vsphereClient.getPerformanceManager()).thenReturn(performanceManager);
    CounterInfo[] counterInfos = new CounterInfo[4];
    counterInfos[0] = Mockito.mock(CounterInfo.class);
    when(counterInfos[0].getKey()).thenReturn(1);
    ElementDescription edGroup = Mockito.mock(ElementDescription.class);
    when(counterInfos[0].getGroupInfo()).thenReturn(edGroup);
    when(edGroup.getKey()).thenReturn(VCConstants.HOST_CPU_GROUP);
    ElementDescription edName = Mockito.mock(ElementDescription.class);
    when(counterInfos[0].getNameInfo()).thenReturn(edName);
    when(edName.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
    counterInfos[1] = Mockito.mock(CounterInfo.class);
    when(counterInfos[1].getKey()).thenReturn(2);
    ElementDescription edGroup1 = Mockito.mock(ElementDescription.class);
    when(counterInfos[1].getGroupInfo()).thenReturn(edGroup1);
    when(edGroup1.getKey()).thenReturn(VCConstants.HOST_MEMORY_GROUP);
    ElementDescription edName1 = Mockito.mock(ElementDescription.class);
    when(counterInfos[1].getNameInfo()).thenReturn(edName1);
    when(edName1.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
    counterInfos[2] = Mockito.mock(CounterInfo.class);
    when(counterInfos[2].getKey()).thenReturn(3);
    ElementDescription edGroup2 = Mockito.mock(ElementDescription.class);
    when(counterInfos[2].getGroupInfo()).thenReturn(edGroup2);
    when(edGroup2.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
    ElementDescription edName2 = Mockito.mock(ElementDescription.class);
    when(counterInfos[2].getNameInfo()).thenReturn(edName2);
    when(edName2.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_ENERGY);
    counterInfos[3] = Mockito.mock(CounterInfo.class);
    when(counterInfos[3].getKey()).thenReturn(4);
    ElementDescription edGroup3 = Mockito.mock(ElementDescription.class);
    when(counterInfos[3].getGroupInfo()).thenReturn(edGroup3);
    when(edGroup3.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
    ElementDescription edName3 = Mockito.mock(ElementDescription.class);
    when(counterInfos[3].getNameInfo()).thenReturn(edName3);
    when(edName3.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_POWER);
    when(performanceManager.getPerfCounter()).thenReturn(counterInfos);
    MetricId[] metrics = new MetricId[4];
    metrics[0] = Mockito.mock(MetricId.class);
    metrics[1] = Mockito.mock(MetricId.class);
    metrics[2] = Mockito.mock(MetricId.class);
    metrics[3] = Mockito.mock(MetricId.class);
    when(metrics[0].getCounterId()).thenReturn(1);
    when(metrics[1].getCounterId()).thenReturn(2);
    when(metrics[2].getCounterId()).thenReturn(3);
    when(metrics[3].getCounterId()).thenReturn(4);
    when(metrics[0].getInstance()).thenReturn(null);
    when(metrics[1].getInstance()).thenReturn(null);
    when(metrics[2].getInstance()).thenReturn(null);
    when(metrics[3].getInstance()).thenReturn(null);
    when(performanceManager.queryAvailableMetric(host._getRef(), null, null, new Integer(20))).thenReturn(metrics);
    ProviderSummary summary = Mockito.mock(ProviderSummary.class);
    when(summary.getRefreshRate()).thenReturn(1);
    when(performanceManager.queryProviderSummary(host._getRef())).thenReturn(summary);
    EntityMetric[] metricBase = new EntityMetric[4];
    metricBase[0] = Mockito.mock(EntityMetric.class);
    long[] values = { 1L, 2L, 3L, 4L };
    IntSeries[] metricSerieses1 = new IntSeries[4];
    metricSerieses1[0] = Mockito.mock(IntSeries.class);
    MetricId metricID = Mockito.mock(MetricId.class);
    when(metricSerieses1[0].getId()).thenReturn(metricID);
    when(metricID.getCounterId()).thenReturn(1);
    IntSeries intSeries1 = Mockito.mock(IntSeries.class);
    intSeries1 = metricSerieses1[0];
    when((intSeries1.getValue())).thenReturn(values);
    when(metricID.getCounterId()).thenReturn(1);
    metricSerieses1[1] = Mockito.mock(IntSeries.class);
    when(metricSerieses1[1].getId()).thenReturn(metricID);
    when(metricID.getCounterId()).thenReturn(1);
    IntSeries intSeries2 = Mockito.mock(IntSeries.class);
    intSeries2 = metricSerieses1[1];
    when(intSeries2.getValue()).thenReturn(values);
    MetricId metricID2 = Mockito.mock(MetricId.class);
    metricSerieses1[2] = Mockito.mock(IntSeries.class);
    when(metricSerieses1[2].getId()).thenReturn(metricID2);
    when(metricID2.getCounterId()).thenReturn(3);
    IntSeries intSeries3 = Mockito.mock(IntSeries.class);
    intSeries3 = metricSerieses1[2];
    when(intSeries3.getValue()).thenReturn(values);
    MetricId metricID3 = Mockito.mock(MetricId.class);
    metricSerieses1[3] = Mockito.mock(IntSeries.class);
    when(metricSerieses1[3].getId()).thenReturn(metricID3);
    when(metricID3.getCounterId()).thenReturn(4);
    IntSeries intSeries4 = Mockito.mock(IntSeries.class);
    intSeries4 = metricSerieses1[3];
    when(intSeries4.getValue()).thenReturn(values);
    when(metricBase[0].getValue()).thenReturn(metricSerieses1);
    SampleInfo[] sampleInfos1 = new SampleInfo[4];
    sampleInfos1[0] = Mockito.mock(SampleInfo.class);
    Calendar time = Calendar.getInstance();
    when(sampleInfos1[0].getTimestamp()).thenReturn(time);
    sampleInfos1[1] = Mockito.mock(SampleInfo.class);
    when(sampleInfos1[1].getTimestamp()).thenReturn(time);
    sampleInfos1[2] = Mockito.mock(SampleInfo.class);
    when(sampleInfos1[2].getTimestamp()).thenReturn(time);
    sampleInfos1[3] = Mockito.mock(SampleInfo.class);
    when(sampleInfos1[3].getTimestamp()).thenReturn(time);
    when(metricBase[0].getSampleInfo()).thenReturn(sampleInfos1);
    metricBase[1] = Mockito.mock(EntityMetric.class);
    when(metricBase[1].getValue()).thenReturn(metricSerieses1);
    when(metricBase[1].getSampleInfo()).thenReturn(sampleInfos1);
    metricBase[2] = Mockito.mock(EntityMetric.class);
    when(metricBase[2].getValue()).thenReturn(metricSerieses1);
    when(metricBase[2].getSampleInfo()).thenReturn(sampleInfos1);
    metricBase[3] = Mockito.mock(EntityMetric.class);
    when(metricBase[3].getValue()).thenReturn(metricSerieses1);
    when(metricBase[3].getSampleInfo()).thenReturn(sampleInfos1);
    when(performanceManager.queryStats(any())).thenReturn(metricBase);
    service.feedHostUsageData(vsphereClient, hostMappingAsset.getId(), host._getRef());
}
Also used : Calendar(java.util.Calendar) SampleInfo(com.vmware.vim.binding.vim.PerformanceManager.SampleInfo) MetricId(com.vmware.vim.binding.vim.PerformanceManager.MetricId) PerformanceManager(com.vmware.vim.binding.vim.PerformanceManager) EntityMetric(com.vmware.vim.binding.vim.PerformanceManager.EntityMetric) HostSystem(com.vmware.vim.binding.vim.HostSystem) IntSeries(com.vmware.vim.binding.vim.PerformanceManager.IntSeries) Asset(com.vmware.flowgate.common.model.Asset) CounterInfo(com.vmware.vim.binding.vim.PerformanceManager.CounterInfo) ProviderSummary(com.vmware.vim.binding.vim.PerformanceManager.ProviderSummary) ElementDescription(com.vmware.vim.binding.vim.ElementDescription) Test(org.junit.Test)

Example 7 with HostSystem

use of com.vmware.vim.binding.vim.HostSystem in project flowgate by vmware.

the class VCDataServiceTest method testQueryHostMetaData.

@Test
public void testQueryHostMetaData() throws Exception {
    SDDCSoftwareConfig vc = Mockito.mock(SDDCSoftwareConfig.class);
    HashMap<String, ServerMapping> serverMappingMap = new HashMap<String, ServerMapping>();
    ServerMapping mapping1 = new ServerMapping();
    mapping1.setVcMobID("vc1");
    mapping1.setAsset("asset1");
    serverMappingMap.put(mapping1.getVcMobID(), mapping1);
    ServerMapping mapping2 = new ServerMapping();
    mapping2.setVcMobID("vc2");
    mapping2.setAsset("asset2");
    serverMappingMap.put(mapping2.getVcMobID(), mapping2);
    doReturn(serverMappingMap).when(service).getVaildServerMapping(any());
    doReturn(vsphereClient).when(service).connectVsphere(any());
    HostSystem host1 = Mockito.mock(HostSystem.class);
    HostSystem host2 = Mockito.mock(HostSystem.class);
    Collection<HostSystem> hosts = new ArrayList<>();
    hosts.add(host1);
    hosts.add(host2);
    when(vsphereClient.getAllHost()).thenReturn(hosts);
    Collection<ClusterComputeResource> clusterComputeResources = new ArrayList<>();
    ClusterComputeResource cluster = Mockito.mock(ClusterComputeResource.class);
    clusterComputeResources.add(cluster);
    clusterComputeResources.add(cluster);
    when(vsphereClient.getAllClusterComputeResource()).thenReturn(clusterComputeResources);
    ManagedObjectReference mor1 = Mockito.mock(ManagedObjectReference.class);
    ManagedObjectReference mor2 = Mockito.mock(ManagedObjectReference.class);
    when(host1._getRef()).thenReturn(mor1);
    when(mor1.getValue()).thenReturn("vc1");
    when(host2._getRef()).thenReturn(mor2);
    when(mor2.getValue()).thenReturn("vc2");
    Asset asset = new Asset();
    asset.setId("asset1");
    HashMap<String, String> hostJustification = new HashMap<String, String>();
    HostInfo hostInfo = new HostInfo();
    String vcHostObjStr = mapper.writeValueAsString(hostInfo);
    hostJustification.put(FlowgateConstant.HOST_METADATA, vcHostObjStr);
    asset.setJustificationfields(hostJustification);
    ResponseEntity<Asset> assets = Mockito.mock(ResponseEntity.class);
    when(restClient.getAssetByID(anyString())).thenReturn(assets);
    when(assets.getBody()).thenReturn(asset);
    doReturn(true).when(service).feedHostMetaData(any(), any());
    doReturn(true).when(service).feedClusterMetaData(any(), any(), any(), anyString());
    service.queryHostMetaData(vc);
}
Also used : ClusterComputeResource(com.vmware.vim.binding.vim.ClusterComputeResource) HashMap(java.util.HashMap) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) HostSystem(com.vmware.vim.binding.vim.HostSystem) Asset(com.vmware.flowgate.common.model.Asset) HostInfo(com.vmware.flowgate.vcworker.model.HostInfo) ManagedObjectReference(com.vmware.vim.binding.vmodl.ManagedObjectReference) Test(org.junit.Test)

Example 8 with HostSystem

use of com.vmware.vim.binding.vim.HostSystem in project flowgate by vmware.

the class VCDataService method queryHostMetrics.

public void queryHostMetrics(SDDCSoftwareConfig vc) {
    Map<String, ServerMapping> serverMappingMap = getVaildServerMapping(vc);
    if (serverMappingMap == null || serverMappingMap.isEmpty()) {
        logger.info("No serverMapping found for vc {}", vc.getName());
        return;
    }
    try (VsphereClient vsphereClient = connectVsphere(vc)) {
        Collection<HostSystem> hosts = vsphereClient.getAllHost();
        if (hosts == null || hosts.isEmpty()) {
            logger.error("vsphere: {} get hosts is null", vc.getName());
            return;
        }
        for (HostSystem host : hosts) {
            String mobId = host._getRef().getValue();
            if (serverMappingMap.containsKey(mobId)) {
                ServerMapping serverMapping = serverMappingMap.get(mobId);
                String assetId = serverMapping.getAsset();
                Asset hostMappingAsset = restClient.getAssetByID(assetId).getBody();
                if (hostMappingAsset == null) {
                    logger.error("The asset {} doesn't exist in serverMapping {}.", assetId, serverMapping.getId());
                    continue;
                }
                feedHostUsageData(vsphereClient, assetId, host._getRef());
            }
        }
    } catch (ConnectionException connectionException) {
        checkAndUpdateIntegrationStatus(vc, connectionException.getMessage());
        return;
    } catch (ExecutionException executionException) {
        if (executionException.getCause() instanceof InvalidLogin) {
            logger.error("Failed to login {}: {}", vc.getServerURL(), executionException);
            checkAndUpdateIntegrationStatus(vc, "Invalid username or password.");
            return;
        }
    } catch (Exception exception) {
        logger.error("Failed to sync the host metrics to VC ", exception);
        return;
    }
}
Also used : ServerMapping(com.vmware.flowgate.common.model.ServerMapping) VsphereClient(com.vmware.flowgate.vcworker.client.VsphereClient) HostSystem(com.vmware.vim.binding.vim.HostSystem) InvalidLogin(com.vmware.vim.binding.vim.fault.InvalidLogin) Asset(com.vmware.flowgate.common.model.Asset) ExecutionException(java.util.concurrent.ExecutionException) ConnectionException(com.vmware.vim.vmomi.client.exception.ConnectionException) ConnectionException(com.vmware.vim.vmomi.client.exception.ConnectionException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ExecutionException(java.util.concurrent.ExecutionException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException)

Example 9 with HostSystem

use of com.vmware.vim.binding.vim.HostSystem 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);
}
Also used : DatastoreInfo(com.vmware.vim.binding.vim.host.ConnectInfo.DatastoreInfo) ConfigInfoEx(com.vmware.vim.binding.vim.cluster.ConfigInfoEx) ArrayList(java.util.ArrayList) LinkSpeedDuplex(com.vmware.vim.binding.vim.host.PhysicalNic.LinkSpeedDuplex) HardwareSummary(com.vmware.vim.binding.vim.host.Summary.HardwareSummary) QuickStats(com.vmware.vim.binding.vim.host.Summary.QuickStats) HostNic(com.vmware.flowgate.vcworker.model.HostNic) HostSystem(com.vmware.vim.binding.vim.HostSystem) ClusterComputeResource(com.vmware.vim.binding.vim.ClusterComputeResource) Capability(com.vmware.vim.binding.vim.host.Capability) RuntimeInfo(com.vmware.vim.binding.vim.host.RuntimeInfo) NetworkInfo(com.vmware.vim.binding.vim.host.NetworkInfo) PhysicalNic(com.vmware.vim.binding.vim.host.PhysicalNic) Calendar(java.util.Calendar) ConfigSummary(com.vmware.vim.binding.vim.host.Summary.ConfigSummary) AboutInfo(com.vmware.vim.binding.vim.AboutInfo) ClusterComputeResource(com.vmware.vim.binding.vim.ClusterComputeResource) DpmConfigInfo(com.vmware.vim.binding.vim.cluster.DpmConfigInfo) DpmHostConfigInfo(com.vmware.vim.binding.vim.cluster.DpmHostConfigInfo) ConfigInfo(com.vmware.vim.binding.vim.host.ConfigInfo) DrsConfigInfo(com.vmware.vim.binding.vim.cluster.DrsConfigInfo) DpmHostConfigInfo(com.vmware.vim.binding.vim.cluster.DpmHostConfigInfo) DpmConfigInfo(com.vmware.vim.binding.vim.cluster.DpmConfigInfo) DrsConfigInfo(com.vmware.vim.binding.vim.cluster.DrsConfigInfo) ConfigSummary(com.vmware.vim.binding.vim.host.Summary.ConfigSummary) HardwareSummary(com.vmware.vim.binding.vim.host.Summary.HardwareSummary) ProviderSummary(com.vmware.vim.binding.vim.PerformanceManager.ProviderSummary) Summary(com.vmware.vim.binding.vim.host.Summary) HostInfo(com.vmware.flowgate.vcworker.model.HostInfo) ConnectInfo(com.vmware.vim.binding.vim.host.ConnectInfo) ManagedObjectReference(com.vmware.vim.binding.vmodl.ManagedObjectReference) Test(org.junit.Test)

Example 10 with HostSystem

use of com.vmware.vim.binding.vim.HostSystem in project flowgate by vmware.

the class VCDataServiceTest method testFeedHostUsageDataNotAvailableMetricId.

@Test
public void testFeedHostUsageDataNotAvailableMetricId() {
    PerformanceManager performanceManager = Mockito.mock(PerformanceManager.class);
    when(vsphereClient.getPerformanceManager()).thenReturn(performanceManager);
    CounterInfo[] counterInfos = new CounterInfo[4];
    counterInfos[0] = Mockito.mock(CounterInfo.class);
    when(counterInfos[0].getKey()).thenReturn(1);
    ElementDescription edGroup = Mockito.mock(ElementDescription.class);
    when(counterInfos[0].getGroupInfo()).thenReturn(edGroup);
    when(edGroup.getKey()).thenReturn(VCConstants.HOST_CPU_GROUP);
    ElementDescription edName = Mockito.mock(ElementDescription.class);
    when(counterInfos[0].getNameInfo()).thenReturn(edName);
    when(edName.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
    counterInfos[1] = Mockito.mock(CounterInfo.class);
    when(counterInfos[1].getKey()).thenReturn(2);
    ElementDescription edGroup1 = Mockito.mock(ElementDescription.class);
    when(counterInfos[1].getGroupInfo()).thenReturn(edGroup1);
    when(edGroup1.getKey()).thenReturn(VCConstants.HOST_MEMORY_GROUP);
    ElementDescription edName1 = Mockito.mock(ElementDescription.class);
    when(counterInfos[1].getNameInfo()).thenReturn(edName1);
    when(edName1.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
    counterInfos[2] = Mockito.mock(CounterInfo.class);
    when(counterInfos[2].getKey()).thenReturn(3);
    ElementDescription edGroup2 = Mockito.mock(ElementDescription.class);
    when(counterInfos[2].getGroupInfo()).thenReturn(edGroup2);
    when(edGroup2.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
    ElementDescription edName2 = Mockito.mock(ElementDescription.class);
    when(counterInfos[2].getNameInfo()).thenReturn(edName2);
    when(edName2.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_ENERGY);
    counterInfos[3] = Mockito.mock(CounterInfo.class);
    when(counterInfos[3].getKey()).thenReturn(4);
    ElementDescription edGroup3 = Mockito.mock(ElementDescription.class);
    when(counterInfos[3].getGroupInfo()).thenReturn(edGroup3);
    when(edGroup3.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
    ElementDescription edName3 = Mockito.mock(ElementDescription.class);
    when(counterInfos[3].getNameInfo()).thenReturn(edName3);
    when(edName3.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_POWER);
    when(performanceManager.getPerfCounter()).thenReturn(counterInfos);
    HostSystem host = Mockito.mock(HostSystem.class);
    ManagedObjectReference managedObjectReference = host._getRef();
    when(performanceManager.queryAvailableMetric(managedObjectReference, null, null, new Integer(20))).thenReturn(null);
    service.feedHostUsageData(vsphereClient, "avbaebhqw9", managedObjectReference);
}
Also used : PerformanceManager(com.vmware.vim.binding.vim.PerformanceManager) HostSystem(com.vmware.vim.binding.vim.HostSystem) CounterInfo(com.vmware.vim.binding.vim.PerformanceManager.CounterInfo) ElementDescription(com.vmware.vim.binding.vim.ElementDescription) ManagedObjectReference(com.vmware.vim.binding.vmodl.ManagedObjectReference) Test(org.junit.Test)

Aggregations

HostSystem (com.vmware.vim.binding.vim.HostSystem)12 Asset (com.vmware.flowgate.common.model.Asset)9 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)8 Test (org.junit.Test)8 ManagedObjectReference (com.vmware.vim.binding.vmodl.ManagedObjectReference)7 ArrayList (java.util.ArrayList)7 HostInfo (com.vmware.flowgate.vcworker.model.HostInfo)5 HashMap (java.util.HashMap)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)4 ClusterComputeResource (com.vmware.vim.binding.vim.ClusterComputeResource)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 VsphereClient (com.vmware.flowgate.vcworker.client.VsphereClient)3 InvalidLogin (com.vmware.vim.binding.vim.fault.InvalidLogin)3 ConnectionException (com.vmware.vim.vmomi.client.exception.ConnectionException)3 IOException (java.io.IOException)3 ElementDescription (com.vmware.vim.binding.vim.ElementDescription)2 PerformanceManager (com.vmware.vim.binding.vim.PerformanceManager)2 CounterInfo (com.vmware.vim.binding.vim.PerformanceManager.CounterInfo)2 ProviderSummary (com.vmware.vim.binding.vim.PerformanceManager.ProviderSummary)2