Search in sources :

Example 11 with HostSystem

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

the class VCDataServiceTest method testSyncCustomerAttrsData.

@Test
public void testSyncCustomerAttrsData() throws Exception {
    String assetId = "QONVN1098G1NVN01NG01";
    String vcMobID = "host-11";
    SDDCSoftwareConfig sddcSoftwareConfig = new SDDCSoftwareConfig();
    sddcSoftwareConfig.setType(SDDCSoftwareConfig.SoftwareType.VCENTER);
    sddcSoftwareConfig.setServerURL("https://1.1.1.1");
    sddcSoftwareConfig.setPassword("ASDFGAGAHAHwegqhwrjw");
    sddcSoftwareConfig.setVerifyCert(false);
    EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.VCenter, EventMessageUtil.VCENTER_SyncCustomerAttrsData, mapper.writeValueAsString(sddcSoftwareConfig));
    ListOperations<String, String> listOperations = Mockito.mock(ListOperations.class);
    doReturn(listOperations).when(template).opsForList();
    doReturn(mapper.writeValueAsString(eventMessage), null).when(listOperations).rightPop(EventMessageUtil.vcJobList);
    doReturn(vsphereClient).when(service).connectVsphere(any());
    ServerMapping serverMapping = new ServerMapping();
    serverMapping.setVcMobID(vcMobID);
    serverMapping.setVcHostName("server-1");
    serverMapping.setAsset(assetId);
    ServerMapping[] serverMappings = { serverMapping };
    doReturn(new ResponseEntity<>(serverMappings, HttpStatus.OK)).when(restClient).getServerMappingsByVC(any());
    Collection<HostSystem> hostSystems = new ArrayList<>();
    HostSystem hostSystem = mock(HostSystem.class);
    ManagedObjectReference managedObjectReference = mock(ManagedObjectReference.class);
    hostSystems.add(hostSystem);
    doReturn(managedObjectReference).when(hostSystem)._getRef();
    doReturn("server-1").when(hostSystem).getName();
    doReturn(vcMobID).when(managedObjectReference).getValue();
    doReturn(hostSystems).when(vsphereClient).getAllHost();
    Asset asset = new Asset();
    asset.setId(assetId);
    Map<String, String> metricsFormulas = new HashMap<>();
    Map<String, String> hostMetricsFormula = new HashMap<>();
    hostMetricsFormula.put(MetricName.SERVER_TEMPERATURE, asset.getId());
    hostMetricsFormula.put(MetricName.SERVER_PEAK_TEMPERATURE, asset.getId());
    hostMetricsFormula.put(MetricName.SERVER_AVERAGE_TEMPERATURE, asset.getId());
    hostMetricsFormula.put(MetricName.SERVER_ENERGY_CONSUMPTION, asset.getId());
    hostMetricsFormula.put(MetricName.SERVER_POWER, asset.getId());
    hostMetricsFormula.put(MetricName.SERVER_AVERAGE_USED_POWER, asset.getId());
    hostMetricsFormula.put(MetricName.SERVER_PEAK_USED_POWER, asset.getId());
    hostMetricsFormula.put(MetricName.SERVER_MINIMUM_USED_POWER, asset.getId());
    metricsFormulas.put(FlowgateConstant.HOST_METRICS, asset.metricsFormulaToString(hostMetricsFormula));
    asset.setMetricsformulars(metricsFormulas);
    Asset[] assets = { asset };
    doReturn(new ResponseEntity<>(assets, HttpStatus.OK)).when(restClient).getAssetsByVCID(any());
    doReturn(new ResponseEntity<Void>(HttpStatus.OK)).when(restClient).saveAssets(any(Asset.class));
    service.executeAsync(EventMessageUtil.createEventMessage(EventType.VCenter, EventMessageUtil.VCENTER_SyncData, null));
}
Also used : 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) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) HostSystem(com.vmware.vim.binding.vim.HostSystem) Asset(com.vmware.flowgate.common.model.Asset) ManagedObjectReference(com.vmware.vim.binding.vmodl.ManagedObjectReference) Test(org.junit.Test)

Example 12 with HostSystem

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

the class VCDataServiceTest method testFeedClusterMetaData.

@Test
public void testFeedClusterMetaData() {
    HostSystem host = Mockito.mock(HostSystem.class);
    HostInfo hostInfo = new HostInfo();
    EsxiMetadata esxiMetadata = new EsxiMetadata();
    esxiMetadata.setClusterDPMenabled(true);
    esxiMetadata.setClusterDRSBehavior("clusterDRSBehavior");
    esxiMetadata.setClusterEffectiveHostsNum(2);
    esxiMetadata.setClusterHostsNum(2);
    esxiMetadata.setClusterMobid("clusterMobid");
    esxiMetadata.setClusterName("cluster");
    esxiMetadata.setClusterTotalCpu(2);
    esxiMetadata.setClusterTotalCpuCores(2);
    esxiMetadata.setClusterTotalCpuThreads(2);
    esxiMetadata.setClusterTotalMemory(2);
    esxiMetadata.setClusterVSANenabled(true);
    esxiMetadata.setHostDPMenabled(true);
    esxiMetadata.setHostMobid("hostMobid");
    esxiMetadata.setHostName("hostName");
    esxiMetadata.setHostVSANenabled(true);
    esxiMetadata.setHostVsanSupported(true);
    esxiMetadata.setInstanceId("instanceId");
    hostInfo.setEsxiMetadata(esxiMetadata);
    ManagedObjectReference mor = Mockito.mock(ManagedObjectReference.class);
    when(host.getParent()).thenReturn(mor);
    when(mor.getValue()).thenReturn("cluster");
    when(mor.getType()).thenReturn("ClusterComputeResource");
    when(host._getRef()).thenReturn(mor);
    when(mor.getValue()).thenReturn("hostMobId");
    HashMap<String, ClusterComputeResource> clusterMap = Mockito.mock(HashMap.class);
    ClusterComputeResource cluster = Mockito.mock(ClusterComputeResource.class);
    when(clusterMap.get(anyString())).thenReturn(cluster);
    clusterMap.put("cluster", cluster);
    ConfigInfoEx ci = Mockito.mock(ConfigInfoEx.class);
    when(cluster.getConfigurationEx()).thenReturn(ci);
    when(cluster.getName()).thenReturn("cluster");
    DpmConfigInfo dci = Mockito.mock(DpmConfigInfo.class);
    when(ci.getDpmConfigInfo()).thenReturn(dci);
    when(dci.getEnabled()).thenReturn(true);
    DrsConfigInfo drsCI = Mockito.mock(DrsConfigInfo.class);
    when(ci.getDrsConfig()).thenReturn(drsCI);
    when(drsCI.getDefaultVmBehavior()).thenReturn(DrsBehavior.fullyAutomated);
    com.vmware.vim.binding.vim.ComputeResource.Summary summary = Mockito.mock(com.vmware.vim.binding.vim.ComputeResource.Summary.class);
    when(cluster.getSummary()).thenReturn(summary);
    when(summary.getNumEffectiveHosts()).thenReturn(2);
    when(summary.getNumHosts()).thenReturn(2);
    when(summary.getNumCpuCores()).thenReturn((short) 2);
    when(summary.getTotalMemory()).thenReturn(2L);
    when(summary.getNumCpuThreads()).thenReturn((short) 2);
    when(summary.getTotalCpu()).thenReturn(2);
    com.vmware.vim.binding.vim.vsan.cluster.ConfigInfo configInfo = Mockito.mock(com.vmware.vim.binding.vim.vsan.cluster.ConfigInfo.class);
    when(ci.getVsanConfigInfo()).thenReturn(configInfo);
    when(configInfo.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[0].getEnabled()).thenReturn(true);
    when(dpmHostConfigInfos[1].getKey()).thenReturn(mor2);
    when(mor2.getValue()).thenReturn("hostMobId");
    when(dpmHostConfigInfos[1].getEnabled()).thenReturn(true);
    when(ci.getDpmHostConfig()).thenReturn(dpmHostConfigInfos);
    ManagedObjectReference mor3 = Mockito.mock(ManagedObjectReference.class);
    when(cluster._getRef()).thenReturn(mor3);
    when(mor3.getValue()).thenReturn("cluster");
    ManagedObjectReference mor4 = Mockito.mock(ManagedObjectReference.class);
    when(cluster.getParent()).thenReturn(mor4);
    when(mor4.getValue()).thenReturn("clusterInstance");
    when(host.getName()).thenReturn("host");
    ConfigInfo configInfo1 = Mockito.mock(ConfigInfo.class);
    when(host.getConfig()).thenReturn(configInfo1);
    com.vmware.vim.binding.vim.vsan.host.ConfigInfo hostConfig = Mockito.mock(com.vmware.vim.binding.vim.vsan.host.ConfigInfo.class);
    when(configInfo1.getVsanHostConfig()).thenReturn(hostConfig);
    when(hostConfig.getEnabled()).thenReturn(true);
    Capability hostCapability = Mockito.mock(Capability.class);
    when(host.getCapability()).thenReturn(hostCapability);
    when(hostCapability.getVsanSupported()).thenReturn(true);
    boolean needUpdate = service.feedClusterMetaData(clusterMap, host, hostInfo, "vcInstanceUUID");
    TestCase.assertEquals(needUpdate, true);
}
Also used : ConfigInfoEx(com.vmware.vim.binding.vim.cluster.ConfigInfoEx) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HostSystem(com.vmware.vim.binding.vim.HostSystem) ClusterComputeResource(com.vmware.vim.binding.vim.ClusterComputeResource) Capability(com.vmware.vim.binding.vim.host.Capability) ClusterComputeResource(com.vmware.vim.binding.vim.ClusterComputeResource) EsxiMetadata(com.vmware.flowgate.vcworker.model.EsxiMetadata) 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) HostInfo(com.vmware.flowgate.vcworker.model.HostInfo) 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