use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetControllerTest method testGetMetricsDurationAPI.
@Test
public void testGetMetricsDurationAPI() throws Exception {
FieldDescriptor[] fieldpath = new FieldDescriptor[] { fieldWithPath("metricName").description("metric name").type(JsonFieldType.STRING), fieldWithPath("valueNum").description("valueNum.").type(JsonFieldType.NUMBER), fieldWithPath("value").description("value").type(JsonFieldType.NULL), fieldWithPath("unit").description("metric unit").type(JsonFieldType.STRING), fieldWithPath("timeStamp").description("timeStamp").type(JsonFieldType.NUMBER) };
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");
RealTimeData tempRealTimeData = createTemperatureSensorRealtimeData(startTime, "00027ca37b004a9890d1bf20349d5ac1");
RealTimeData humdityRealTimeData = createHumiditySensorRealtimeData(startTime, "34527ca37b004a9890d1bf20349d5ac1");
RealTimeData backTemperature = createBackTemperatureSensorRealtimeData(startTime, "968765a37b004a9890d1bf20349d5ac1");
RealTimeData backHumidity = createBackHumiditySensorRealtimeData(startTime, "486970a37b004a9890d1bf20349d5ac1");
RealTimeData hostRealTimeData = createServerHostRealTimeData(startTime);
hostRealTimeData.setAssetID(asset.getId());
realTimeDatas.add(hostRealTimeData);
realTimeDatas.add(humdityRealTimeData);
realTimeDatas.add(tempRealTimeData);
realTimeDatas.add(backHumidity);
realTimeDatas.add(backTemperature);
realTimeDatas.add(pduUsageMetricData);
realtimeDataRepository.saveAll(realTimeDatas);
asset = fillingMetricsformula(asset);
HashMap<String, String> justificationfields = new HashMap<>();
justificationfields.put(FlowgateConstant.PDU_PORT_FOR_SERVER, "power-2_FIELDSPLIT_CAN1-MDF-R01-PDU-BUILDING_FIELDSPLIT_OUTLET:1_FIELDSPLIT_0001bdc8b25d4c2badfd045ab61aabfa");
asset.setJustificationfields(justificationfields);
asset = assetRepository.save(asset);
MvcResult result = this.mockMvc.perform(get("/v1/assets/{assetId}/metrics", asset.getId()).param("starttime", String.valueOf(startTime)).param("duration", String.valueOf(duration))).andDo(document("assets-getAllMetricsDataInDuration-Server-example", pathParameters(parameterWithName("assetId").description("The id of asset,generated by flowgate.")), requestParameters(parameterWithName("starttime").description("Start time of you want to query.Default value: the system current time in Millis").optional(), parameterWithName("duration").description("Duration of you want to query.Default value: 300000 ms").optional()), responseFields(fieldWithPath("[]").description("An array of realTimeDatas")).andWithPrefix("[].", fieldpath))).andReturn();
String res = result.getResponse().getContentAsString();
MetricData[] metricDatas = mapper.readValue(res, MetricData[].class);
Set<String> specialMetricNames = new HashSet<String>();
specialMetricNames.add(MetricName.SERVER_AVERAGE_USED_POWER);
specialMetricNames.add(MetricName.SERVER_PEAK_USED_POWER);
specialMetricNames.add(MetricName.SERVER_MINIMUM_USED_POWER);
specialMetricNames.add(MetricName.SERVER_AVERAGE_TEMPERATURE);
specialMetricNames.add(MetricName.SERVER_PEAK_TEMPERATURE);
for (MetricData serverdata : metricDatas) {
String metricName = serverdata.getMetricName();
if (String.format(MetricKeyName.SERVER_CONNECTED_PDUX_OUTLETX_CURRENT, "0001bdc8b25d4c2badfd045ab61aabfa", "OUTLET:1").equals(metricName)) {
TestCase.assertEquals(0.365, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_CONNECTED_PDUX_OUTLETX_POWER, "0001bdc8b25d4c2badfd045ab61aabfa", "OUTLET:1").equals(metricName)) {
TestCase.assertEquals(0.081, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_CONNECTED_PDUX_OUTLETX_VOLTAGE, "0001bdc8b25d4c2badfd045ab61aabfa", "OUTLET:1").equals(metricName)) {
TestCase.assertEquals(221.0, serverdata.getValueNum());
} else 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 if (String.format(MetricKeyName.SERVER_BACK_HUMIDITY_LOCATIONX, "OUTLET").equals(metricName)) {
TestCase.assertEquals(19.0, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_BACK_TEMPREATURE_LOCATIONX, "OUTLET").equals(metricName)) {
TestCase.assertEquals(25.0, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_FRONT_HUMIDITY_LOCATIONX, "INLET").equals(metricName)) {
TestCase.assertEquals(serverdata.getValueNum(), 20.0);
} else if (String.format(MetricKeyName.SERVER_FRONT_TEMPERATURE_LOCATIONX, "INLET").equals(metricName)) {
TestCase.assertEquals(serverdata.getValueNum(), 32.0);
} else if (MetricName.SERVER_VOLTAGE.equals(metricName)) {
TestCase.assertEquals(221.0, serverdata.getValueNum());
} else if (MetricName.SERVER_STORAGEUSAGE.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 240000) {
TestCase.assertEquals(65.0, serverdata.getValueNum());
}
} else if (MetricName.SERVER_MEMORYUSAGE.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(87.22, serverdata.getValueNum());
}
} else if (MetricName.SERVER_CPUUSEDINMHZ.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(746.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_CPUUSAGE.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(4.67, serverdata.getValueNum());
}
} else if (MetricName.SERVER_ACTIVEMEMORY.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(1561416.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_SHAREDMEMORY.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(8.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_CONSUMEDMEMORY.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(18291220.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_SWAPMEMORY.equals(metricName)) {
TestCase.assertEquals(0.00, serverdata.getValueNum());
} else if (MetricName.SERVER_BALLOONMEMORY.equals(metricName)) {
TestCase.assertEquals(0.0, serverdata.getValueNum());
} else if (MetricName.SERVER_NETWORKUTILIZATION.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(146.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_STORAGEIORATEUSAGE.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(330.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_POWER.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(0.069, serverdata.getValueNum());
}
} else if (MetricName.SERVER_ENERGY_CONSUMPTION.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime) {
TestCase.assertEquals(0.00038805555555555555, serverdata.getValueNum());
}
} else if (specialMetricNames.contains(metricName)) {
TestCase.fail("Duration API not support this metric " + metricName);
}
}
assetRepository.deleteById(asset.getId());
realtimeDataRepository.deleteById(pduUsageMetricData.getId());
realtimeDataRepository.deleteById(tempRealTimeData.getId());
realtimeDataRepository.deleteById(humdityRealTimeData.getId());
realtimeDataRepository.deleteById(backHumidity.getId());
realtimeDataRepository.deleteById(backTemperature.getId());
realtimeDataRepository.deleteById(hostRealTimeData.getId());
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetService method getPduMetricsDataById.
public List<MetricData> getPduMetricsDataById(String assetID, long starttime, int duration) {
Optional<Asset> pduAssetOptional = assetRepository.findById(assetID);
if (!pduAssetOptional.isPresent()) {
return null;
}
List<RealTimeData> pduMetricsRealtimeDatas = realtimeDataRepository.getDataByIDAndTimeRange(assetID, starttime, duration);
List<ValueUnit> valueunits = new ArrayList<>();
List<String> metricNames = new ArrayList<String>();
metricNames.add(MetricName.PDU_TOTAL_POWER);
metricNames.add(MetricName.PDU_APPARENT_POWER);
metricNames.add(MetricName.PDU_ACTIVE_POWER);
metricNames.add(MetricName.PDU_CURRENT);
metricNames.add(MetricName.PDU_VOLTAGE);
metricNames.add(MetricName.PDU_FREE_CAPACITY);
metricNames.add(MetricName.PDU_POWER_LOAD);
metricNames.add(MetricName.PDU_CURRENT_LOAD);
// pdu metrics data,such as power/current/voltage
valueunits.addAll(getValueUnits(pduMetricsRealtimeDatas, metricNames));
Asset pdu = pduAssetOptional.get();
// sensor metrics data, such as temperature or humidity
Map<String, String> formulars = pdu.getMetricsformulars();
String sensorFormulasInfo = formulars.get(FlowgateConstant.SENSOR);
Map<String, Map<String, String>> sensorFormulasMap = null;
if (sensorFormulasInfo != null) {
sensorFormulasMap = pdu.metricsFormulaToMap(sensorFormulasInfo, new TypeReference<Map<String, Map<String, String>>>() {
});
}
if (sensorFormulasMap != null) {
Map<String, List<RealTimeData>> assetIdAndRealtimeDataMap = new HashMap<String, List<RealTimeData>>();
Map<String, String> humidityLocationAndIdMap = sensorFormulasMap.get(MetricName.PDU_HUMIDITY);
if (humidityLocationAndIdMap != null && !humidityLocationAndIdMap.isEmpty()) {
valueunits.addAll(generateSensorValueUnit(assetIdAndRealtimeDataMap, starttime, duration, humidityLocationAndIdMap, MetricName.PDU_HUMIDITY));
}
Map<String, String> temperatureLocationAndIdMap = sensorFormulasMap.get(MetricName.PDU_TEMPERATURE);
if (temperatureLocationAndIdMap != null && !temperatureLocationAndIdMap.isEmpty()) {
valueunits.addAll(generateSensorValueUnit(assetIdAndRealtimeDataMap, starttime, duration, temperatureLocationAndIdMap, MetricName.PDU_TEMPERATURE));
}
}
return generateMetricsDataForPDU(valueunits);
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetService method generateSensorValueUnit.
private List<ValueUnit> generateSensorValueUnit(Map<String, List<RealTimeData>> assetIdAndRealtimeDataMap, long starttime, int duration, Map<String, String> locationAndIdMap, String metricName) {
List<ValueUnit> valueunits = new ArrayList<>();
for (Map.Entry<String, String> locationInfoAndId : locationAndIdMap.entrySet()) {
String formula = locationInfoAndId.getValue();
String location = locationInfoAndId.getKey();
String[] ids = formula.split("\\+|-|\\*|/|\\(|\\)");
for (String assetId : ids) {
List<RealTimeData> realtimeDatas = null;
if (!assetIdAndRealtimeDataMap.containsKey(assetId)) {
realtimeDatas = realtimeDataRepository.getDataByIDAndTimeRange(assetId, starttime, duration);
assetIdAndRealtimeDataMap.put(assetId, realtimeDatas);
}
realtimeDatas = assetIdAndRealtimeDataMap.get(assetId);
if (realtimeDatas == null || realtimeDatas.isEmpty()) {
continue;
}
RealTimeData realTimeData = findLatestData(realtimeDatas);
for (ValueUnit value : realTimeData.getValues()) {
if (value.getKey().equals(metricNameMap.get(metricName))) {
if (location.indexOf(FlowgateConstant.SEPARATOR) > -1) {
location = location.replace(FlowgateConstant.SEPARATOR, FlowgateConstant.UNDERLINE);
}
value.setExtraidentifier(location);
valueunits.add(value);
}
}
}
}
return valueunits;
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetService method getValueUnits.
private List<ValueUnit> getValueUnits(List<RealTimeData> realtimeDatas, List<String> metricsName) {
List<ValueUnit> valueunits = new ArrayList<>();
if (realtimeDatas == null || realtimeDatas.isEmpty()) {
return valueunits;
}
RealTimeData realTimeData = findLatestData(realtimeDatas);
for (ValueUnit value : realTimeData.getValues()) {
if (metricsName.contains(value.getKey())) {
valueunits.add(value);
}
}
return valueunits;
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testGenerateRealTimeData.
@Test
public void testGenerateRealTimeData() {
Asset asset = createAsset();
asset.setId("5x4ff46982db22e1b040e0f2");
HashMap<AdvanceSettingType, String> advanceSettingMap = new HashMap<AdvanceSettingType, String>();
advanceSettingMap.put(AdvanceSettingType.DateFormat, NlyteDataService.DateFormat);
advanceSettingMap.put(AdvanceSettingType.TimeZone, "GMT");
RealTimeData data = nlyteDataService.generateRealTimeData(asset, nlyteAPIClient, advanceSettingMap);
TestCase.assertEquals("5x4ff46982db22e1b040e0f2", data.getAssetID());
}
Aggregations