Search in sources :

Example 1 with EsxiMetadata

use of com.vmware.flowgate.vcworker.model.EsxiMetadata in project flowgate by vmware.

the class VCDataService method feedClusterMetaData.

public boolean feedClusterMetaData(Map<String, ClusterComputeResource> clusterMap, HostSystem host, HostInfo hostInfo, String vcInstanceUUID) {
    ManagedObjectReference hostParent = host.getParent();
    if (hostParent == null || !hostParent.getType().equals(VCConstants.CLUSTERCOMPUTERESOURCE)) {
        return false;
    }
    String clusterMobId = hostParent.getValue();
    ClusterComputeResource cluster = clusterMap.get(clusterMobId);
    boolean needUpdate = false;
    EsxiMetadata oldEsxiMetadata = hostInfo.getEsxiMetadata();
    if (oldEsxiMetadata == null) {
        needUpdate = true;
        oldEsxiMetadata = new EsxiMetadata();
    }
    String hostMobId = host._getRef().getValue();
    ConfigInfoEx configInfoExtension = (ConfigInfoEx) cluster.getConfigurationEx();
    String oldEsxiMetadataClusterName = oldEsxiMetadata.getClusterName();
    String esxiMetadataClusterName = cluster.getName();
    if (!StringUtils.equals(oldEsxiMetadataClusterName, esxiMetadataClusterName)) {
        needUpdate = true;
        oldEsxiMetadata.setClusterName(esxiMetadataClusterName);
    }
    if (!configInfoExtension.getDpmConfigInfo().getEnabled().equals(oldEsxiMetadata.isClusterDPMenabled())) {
        needUpdate = true;
        oldEsxiMetadata.setClusterDPMenabled(configInfoExtension.getDpmConfigInfo().getEnabled());
    }
    String oldEsxiMetadataClusterDRSBehavior = oldEsxiMetadata.getClusterDRSBehavior();
    String esxiMetadataClusterDRSBehavior = configInfoExtension.getDrsConfig().getDefaultVmBehavior().toString();
    if (!StringUtils.equals(oldEsxiMetadataClusterDRSBehavior, esxiMetadataClusterDRSBehavior)) {
        needUpdate = true;
        oldEsxiMetadata.setClusterDRSBehavior(esxiMetadataClusterDRSBehavior);
    }
    if (cluster.getSummary().getNumEffectiveHosts() != oldEsxiMetadata.getClusterEffectiveHostsNum()) {
        needUpdate = true;
        oldEsxiMetadata.setClusterEffectiveHostsNum(cluster.getSummary().getNumEffectiveHosts());
    }
    if (cluster.getSummary().getNumHosts() != oldEsxiMetadata.getClusterHostsNum()) {
        needUpdate = true;
        oldEsxiMetadata.setClusterHostsNum(cluster.getSummary().getNumHosts());
    }
    if (cluster.getSummary().getTotalCpu() != oldEsxiMetadata.getClusterTotalCpu()) {
        needUpdate = true;
        oldEsxiMetadata.setClusterTotalCpu(cluster.getSummary().getTotalCpu());
    }
    if (cluster.getSummary().getNumCpuCores() != oldEsxiMetadata.getClusterTotalCpuCores()) {
        needUpdate = true;
        oldEsxiMetadata.setClusterTotalCpuCores(cluster.getSummary().getNumCpuCores());
    }
    if (cluster.getSummary().getNumCpuThreads() != oldEsxiMetadata.getClusterTotalCpuThreads()) {
        needUpdate = true;
        oldEsxiMetadata.setClusterTotalCpuThreads(cluster.getSummary().getNumCpuThreads());
    }
    if (cluster.getSummary().getTotalMemory() != oldEsxiMetadata.getClusterTotalMemory()) {
        needUpdate = true;
        oldEsxiMetadata.setClusterTotalMemory(cluster.getSummary().getTotalMemory());
    }
    if (!configInfoExtension.getVsanConfigInfo().getEnabled().equals(oldEsxiMetadata.isHostVSANenabled())) {
        needUpdate = true;
        oldEsxiMetadata.setClusterVSANenabled(configInfoExtension.getVsanConfigInfo().getEnabled());
    }
    DpmHostConfigInfo[] dpmHostConfigInfos = configInfoExtension.getDpmHostConfig();
    if (dpmHostConfigInfos != null && dpmHostConfigInfos.length > 0) {
        for (DpmHostConfigInfo dpmHostConfigInfo : dpmHostConfigInfos) {
            if (hostMobId.equals(dpmHostConfigInfo.getKey().getValue())) {
                if (!dpmHostConfigInfo.getEnabled().equals(oldEsxiMetadata.isHostDPMenabled())) {
                    needUpdate = true;
                    oldEsxiMetadata.setHostDPMenabled(dpmHostConfigInfo.getEnabled());
                }
            }
        }
    }
    String oldEsxiMetadataClusterMobid = oldEsxiMetadata.getClusterMobid();
    String esxiMetadataClusterMobid = cluster._getRef().getValue();
    if (!StringUtils.equals(oldEsxiMetadataClusterMobid, esxiMetadataClusterMobid)) {
        needUpdate = true;
        oldEsxiMetadata.setClusterMobid(esxiMetadataClusterMobid);
    }
    String oldEsxiMetadataInstanceId = oldEsxiMetadata.getInstanceId();
    if (!StringUtils.equals(oldEsxiMetadataInstanceId, vcInstanceUUID)) {
        needUpdate = true;
        oldEsxiMetadata.setInstanceId(vcInstanceUUID);
    }
    String oldEsxiMetadataHostName = oldEsxiMetadata.getHostName();
    String esxiMetadataHostName = host.getName();
    if (!StringUtils.equals(oldEsxiMetadataHostName, esxiMetadataHostName)) {
        needUpdate = true;
        oldEsxiMetadata.setHostName(host.getName());
    }
    if (!host.getConfig().getVsanHostConfig().getEnabled().equals(oldEsxiMetadata.isHostVSANenabled())) {
        needUpdate = true;
        oldEsxiMetadata.setHostVSANenabled(host.getConfig().getVsanHostConfig().getEnabled());
    }
    if (!host.getCapability().getVsanSupported().equals(oldEsxiMetadata.isHostVsanSupported())) {
        needUpdate = true;
        oldEsxiMetadata.setHostVsanSupported(host.getCapability().getVsanSupported());
    }
    oldEsxiMetadata.setHostMobid(hostMobId);
    hostInfo.setEsxiMetadata(oldEsxiMetadata);
    return needUpdate;
}
Also used : ClusterComputeResource(com.vmware.vim.binding.vim.ClusterComputeResource) ConfigInfoEx(com.vmware.vim.binding.vim.cluster.ConfigInfoEx) EsxiMetadata(com.vmware.flowgate.vcworker.model.EsxiMetadata) DpmHostConfigInfo(com.vmware.vim.binding.vim.cluster.DpmHostConfigInfo) ManagedObjectReference(com.vmware.vim.binding.vmodl.ManagedObjectReference)

Example 2 with EsxiMetadata

use of com.vmware.flowgate.vcworker.model.EsxiMetadata 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

EsxiMetadata (com.vmware.flowgate.vcworker.model.EsxiMetadata)2 ClusterComputeResource (com.vmware.vim.binding.vim.ClusterComputeResource)2 ConfigInfoEx (com.vmware.vim.binding.vim.cluster.ConfigInfoEx)2 DpmHostConfigInfo (com.vmware.vim.binding.vim.cluster.DpmHostConfigInfo)2 ManagedObjectReference (com.vmware.vim.binding.vmodl.ManagedObjectReference)2 HostInfo (com.vmware.flowgate.vcworker.model.HostInfo)1 HostSystem (com.vmware.vim.binding.vim.HostSystem)1 DpmConfigInfo (com.vmware.vim.binding.vim.cluster.DpmConfigInfo)1 DrsConfigInfo (com.vmware.vim.binding.vim.cluster.DrsConfigInfo)1 Capability (com.vmware.vim.binding.vim.host.Capability)1 ConfigInfo (com.vmware.vim.binding.vim.host.ConfigInfo)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1