Search in sources :

Example 16 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class VCDataServiceTest method testQueryHostMetaDataForclustersIsNull.

@Test
public void testQueryHostMetaDataForclustersIsNull() 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);
    when(vsphereClient.getAllClusterComputeResource()).thenReturn(null);
    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 : 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 17 with Asset

use of com.vmware.flowgate.common.model.Asset 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 18 with Asset

use of com.vmware.flowgate.common.model.Asset 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 19 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class NlyteDataService method removePduFromServer.

public List<Asset> removePduFromServer(List<Asset> servers, String pduId) {
    List<Asset> needToUpdate = new ArrayList<Asset>();
    for (Asset server : servers) {
        boolean changed = false;
        HashMap<String, String> serverJustficationfields = server.getJustificationfields();
        Set<String> pduDevices = new HashSet<String>();
        String pduPortString = serverJustficationfields.get(FlowgateConstant.PDU_PORT_FOR_SERVER);
        if (pduPortString != null) {
            String[] pduPorts = pduPortString.split(FlowgateConstant.SPILIT_FLAG);
            for (String pduport : pduPorts) {
                if (!pduport.contains(pduId)) {
                    pduDevices.add(pduport);
                    changed = true;
                }
            }
            if (changed) {
                pduPortString = String.join(FlowgateConstant.SPILIT_FLAG, pduDevices);
                serverJustficationfields.put(FlowgateConstant.PDU_PORT_FOR_SERVER, pduPortString);
                server.setJustificationfields(serverJustficationfields);
            }
        }
        List<String> pduIds = server.getPdus();
        Iterator<String> pduite = pduIds.iterator();
        while (pduite.hasNext()) {
            String pduid = pduite.next();
            if (pduid.equals(pduId)) {
                pduite.remove();
                changed = true;
            }
        }
        server.setPdus(pduIds);
        Map<String, String> formulars = server.getMetricsformulars();
        if (formulars == null || formulars.isEmpty()) {
            continue;
        }
        Map<String, Map<String, String>> pduFormulas = server.metricsFormulaToMap(formulars.get(FlowgateConstant.PDU), new TypeReference<Map<String, Map<String, String>>>() {
        });
        if (pduFormulas == null || pduFormulas.isEmpty()) {
            continue;
        }
        Iterator<Map.Entry<String, Map<String, String>>> ite = pduFormulas.entrySet().iterator();
        while (ite.hasNext()) {
            Map.Entry<String, Map<String, String>> map = ite.next();
            String pduAssetID = map.getKey();
            if (pduAssetID.equals(pduId)) {
                changed = true;
                ite.remove();
            }
        }
        formulars.put(FlowgateConstant.PDU, server.metricsFormulaToString(pduFormulas));
        server.setMetricsformulars(formulars);
        if (changed) {
            needToUpdate.add(server);
        }
    }
    return needToUpdate;
}
Also used : ArrayList(java.util.ArrayList) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 20 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class HandleAssetUtil method generateAssetsMap.

/**
 * @return
 */
public Map<Long, Asset> generateAssetsMap(List<Asset> assets) {
    Map<Long, Asset> assetFromWormholeMap = null;
    if (assets == null || assets.isEmpty()) {
        return null;
    }
    assetFromWormholeMap = new HashMap<Long, Asset>();
    for (Asset asset : assets) {
        assetFromWormholeMap.put(asset.getAssetNumber(), asset);
    }
    return assetFromWormholeMap;
}
Also used : NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset)

Aggregations

Asset (com.vmware.flowgate.common.model.Asset)173 Test (org.junit.Test)96 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)90 HashMap (java.util.HashMap)86 ArrayList (java.util.ArrayList)82 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)36 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)35 Map (java.util.Map)34 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)31 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)23 IOException (java.io.IOException)23 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)22 MetricData (com.vmware.flowgate.common.model.MetricData)16 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)16 HashSet (java.util.HashSet)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)13 List (java.util.List)12 MvcResult (org.springframework.test.web.servlet.MvcResult)12 TypeReference (com.fasterxml.jackson.core.type.TypeReference)10