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);
}
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());
}
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);
}
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;
}
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;
}
Aggregations