Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix outlets is null #808

Merged
merged 1 commit into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,10 @@ public List<MetricData> getMetricsByID(String assetID, Long starttime, Integer d
assetAndValueUnitsMap = getServerRawMetrics(asset, starttime, duration);
//2. Remove or filter
List<ValueUnit> serverHostUsageValueUnits = assetAndValueUnitsMap.get(assetID);
removeServerUnusedMetrics(serverHostUsageValueUnits);
filterServerEneryConsumptionMetrics(serverHostUsageValueUnits, starttime);
if(serverHostUsageValueUnits != null) {
removeServerUnusedMetrics(serverHostUsageValueUnits);
filterServerEneryConsumptionMetrics(serverHostUsageValueUnits, starttime);
}
//3. Translate
return translateToMetricDataForServer(assetAndValueUnitsMap, asset);
default:
Expand Down Expand Up @@ -1202,6 +1204,7 @@ private List<MetricData> translateToMetricDataForServer(Map<String, List<ValueUn
valueUnits.add(valueUnit);
}
}
break;
default:
valueUnits.add(valueUnit);
break;
Expand Down Expand Up @@ -1578,10 +1581,9 @@ private Map<String, Map<String, String>> getMetricDispalyNameAndFormulaMapForSer
Map<String,String> justficationfileds = server.getJustificationfields();
String allPduPortInfo = justficationfileds.get(FlowgateConstant.PDU_PORT_FOR_SERVER);
List<String> pduPorts = null;
Map<String, List<String>> pduAssetIdAndUsedOutletMap = null;
Map<String, List<String>> pduAssetIdAndUsedOutletMap = new HashMap<String, List<String>>();;
if (!StringUtils.isEmpty(allPduPortInfo)) {
pduPorts = Arrays.asList(allPduPortInfo.split(FlowgateConstant.SPILIT_FLAG));
pduAssetIdAndUsedOutletMap = new HashMap<String, List<String>>();
for (String pduPortInfo : pduPorts) {
// startport_FIELDSPLIT_endDeviceName_FIELDSPLIT_endport_FIELDSPLIT_endDeviceAssetID
// item[0] start port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3148,6 +3148,45 @@ public void testGetServerMetricsByID() {
realtimeDataRepository.deleteById(hostRealTimeData.getId());
}

@Test
public void testGetServerMetricsOutLetisNull() {
Asset asset = createAsset();
List<RealTimeData> realTimeDatas = new ArrayList<RealTimeData>();
long time = System.currentTimeMillis();
int duration = 30*60*1000;
long startTime = time - duration;
RealTimeData pduUsageMetricData = createPduAllRealTimeData(startTime);
pduUsageMetricData.setAssetID("0001bdc8b25d4c2badfd045ab61aabfa");
realTimeDatas.add(pduUsageMetricData);
realtimeDataRepository.saveAll(realTimeDatas);

asset = fillingMetricsformula(asset);
asset = assetRepository.save(asset);

List<MetricData> metricDatas =
assetService.getMetricsByID(asset.getId(), startTime, duration);
for(MetricData serverdata : metricDatas) {
String metricName = serverdata.getMetricName();
if(String.format(MetricKeyName.SERVER_CONNECTED_PDUX_POWER_LOAD, "0001bdc8b25d4c2badfd045ab61aabfa").
equals(metricName)) {
TestCase.assertEquals(0.05, serverdata.getValueNum());
}else if(String.format(MetricKeyName.SERVER_CONNECTED_PDUX_CURRENT_LOAD, "0001bdc8b25d4c2badfd045ab61aabfa").
equals(metricName)) {
TestCase.assertEquals(0.05, serverdata.getValueNum());
}else if(String.format(MetricKeyName.SERVER_CONNECTED_PDUX_TOTAL_CURRENT, "0001bdc8b25d4c2badfd045ab61aabfa").
equals(metricName)) {
TestCase.assertEquals(1.455, serverdata.getValueNum());
}else if(String.format(MetricKeyName.SERVER_CONNECTED_PDUX_TOTAL_POWER, "0001bdc8b25d4c2badfd045ab61aabfa").
equals(metricName)) {
TestCase.assertEquals(0.322, serverdata.getValueNum());
}else {
TestCase.fail("Unkown metric: "+metricName);
}
}
assetRepository.deleteById(asset.getId());
realtimeDataRepository.deleteById(pduUsageMetricData.getId());
}

@Test
public void testGetMetricsDurationAPI() throws Exception {
FieldDescriptor[] fieldpath = new FieldDescriptor[] {
Expand Down