use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetControllerTest method testGetHostSpecialMetricsExample.
@Test
public void testGetHostSpecialMetricsExample() throws Exception {
Asset asset = createAsset();
List<RealTimeData> realTimeDatas = new ArrayList<RealTimeData>();
Long time = System.currentTimeMillis();
List<ValueUnit> valueUnits = new ArrayList<ValueUnit>();
ValueUnit valueUnit = new ValueUnit();
String sinceTime = String.valueOf(time - 900000l);
valueUnit = new ValueUnit();
valueUnit.setTime(time);
valueUnit.setExtraidentifier(sinceTime + FlowgateConstant.SEPARATOR);
valueUnit.setKey(MetricName.SERVER_MINIMUM_USED_POWER);
valueUnit.setUnit(MetricUnit.kW.toString());
valueUnit.setValueNum(0.5);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(time);
valueUnit.setExtraidentifier(sinceTime + FlowgateConstant.SEPARATOR);
valueUnit.setKey(MetricName.SERVER_PEAK_USED_POWER);
valueUnit.setUnit(MetricUnit.kW.toString());
valueUnit.setValueNum(0.8);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(time);
valueUnit.setKey(MetricName.SERVER_AVERAGE_USED_POWER);
valueUnit.setUnit(MetricUnit.kW.toString());
valueUnit.setValueNum(0.6);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(time);
valueUnit.setExtraidentifier(sinceTime);
valueUnit.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
valueUnit.setUnit(MetricUnit.kWh.toString());
valueUnit.setValueNum(356);
valueUnits.add(valueUnit);
RealTimeData hostRealTimeData = new RealTimeData();
hostRealTimeData.setValues(valueUnits);
hostRealTimeData.setTime(time);
hostRealTimeData.setId("00027ca37b004a9890d1bf20349d5ac99");
hostRealTimeData.setAssetID(asset.getId());
realTimeDatas.add(hostRealTimeData);
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:7_FIELDSPLIT_0001bdc8b25d4c2badfd045ab61aabfa");
asset.setJustificationfields(justificationfields);
asset = assetRepository.save(asset);
MvcResult result1 = this.mockMvc.perform(get("/v1/assets/{assetId}/realtimedata", asset.getId()).param("starttime", String.valueOf(time)).param("duration", "300000")).andReturn();
String res = result1.getResponse().getContentAsString();
MetricData[] datas = mapper.readValue(res, MetricData[].class);
// In mock metrics data, SERVER_MINIMUM_USED_POWER/SERVER_PEAK_USED_POWER/SERVER_AVERAGE_USED_POWER is invalid
try {
for (MetricData serverdata : datas) {
String metricName = serverdata.getMetricName();
if (MetricName.SERVER_ENERGY_CONSUMPTION.equals(metricName)) {
TestCase.assertEquals(serverdata.getValueNum(), 356.00);
} else {
TestCase.fail("Unknown metric :" + metricName);
}
}
} finally {
assetRepository.deleteById(asset.getId());
realtimeDataRepository.deleteById(hostRealTimeData.getId());
}
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetControllerTest method createTemperatureSensorRealtimeData.
RealTimeData createTemperatureSensorRealtimeData(long time, String sensorAssetId) {
List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
ValueUnit tempValue = new ValueUnit();
tempValue.setValueNum(32);
tempValue.setTime(time);
tempValue.setUnit(MetricUnit.C.toString());
tempValue.setKey(MetricName.TEMPERATURE);
valueunits.add(tempValue);
RealTimeData realTimeData = new RealTimeData();
realTimeData.setId(UUID.randomUUID().toString());
realTimeData.setAssetID(sensorAssetId);
realTimeData.setValues(valueunits);
realTimeData.setTime(time);
return realTimeData;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetControllerTest method createSensorRealtimeData.
RealTimeData createSensorRealtimeData(long time) {
List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
ValueUnit tempValue = new ValueUnit();
tempValue.setValueNum(32);
tempValue.setTime(time);
tempValue.setUnit(MetricUnit.C.toString());
tempValue.setKey(MetricName.TEMPERATURE);
valueunits.add(tempValue);
ValueUnit humidityValue = new ValueUnit();
humidityValue.setValueNum(20);
humidityValue.setTime(time);
humidityValue.setUnit(MetricUnit.percent.toString());
humidityValue.setKey(MetricName.HUMIDITY);
valueunits.add(humidityValue);
RealTimeData realTimeData = new RealTimeData();
realTimeData.setId(UUID.randomUUID().toString());
realTimeData.setAssetID("00027ca37b004a9890d1bf20349d5ac1");
realTimeData.setValues(valueunits);
realTimeData.setTime(time);
return realTimeData;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetControllerTest method insertRealtimeDataExample.
@Test
public void insertRealtimeDataExample() throws JsonProcessingException, Exception {
Asset asset = createAsset();
asset = assetRepository.save(asset);
long time = System.currentTimeMillis();
RealTimeData realtimedata = createServerPDURealTimeData(time);
List<ValueUnit> valueunits = realtimedata.getValues();
valueunits.addAll(createServerHostRealTimeData(time).getValues());
ValueUnit tempValue = new ValueUnit();
tempValue.setValueNum(32);
tempValue.setTime(time);
tempValue.setUnit(MetricUnit.C.toString());
tempValue.setKey(MetricName.TEMPERATURE);
valueunits.add(tempValue);
ValueUnit humidityValue = new ValueUnit();
humidityValue.setValueNum(20);
humidityValue.setTime(time);
humidityValue.setUnit("%");
humidityValue.setKey(MetricName.HUMIDITY);
valueunits.add(humidityValue);
realtimedata.setId(UUID.randomUUID().toString());
realtimedata.setAssetID(asset.getId());
realtimeDataRepository.save(realtimedata);
this.mockMvc.perform(post("/v1/assets/" + asset.getId() + "/sensordata").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(realtimedata))).andExpect(status().isOk()).andDo(document("assets-insertRealtimeData-example", requestFields(fieldWithPath("id").description("ID of the realtime, created by flowgate"), fieldWithPath("assetID").description("ID of the asset, created by flowgate"), subsectionWithPath("values").description("A list of sensor data. eg. Humidity , Electric... ").type(ValueUnit[].class), fieldWithPath("time").description("The time of generate sensor data."))));
assetRepository.deleteById(asset.getId());
realtimeDataRepository.deleteById(realtimedata.getId());
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetControllerTest method createBackHumiditySensorRealtimeData.
RealTimeData createBackHumiditySensorRealtimeData(long time, String sensorAssetId) {
List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
ValueUnit humidityValue = new ValueUnit();
humidityValue.setValueNum(19);
humidityValue.setTime(time);
humidityValue.setUnit(MetricUnit.percent.toString());
humidityValue.setKey(MetricName.HUMIDITY);
valueunits.add(humidityValue);
RealTimeData realTimeData = new RealTimeData();
realTimeData.setId(UUID.randomUUID().toString());
realTimeData.setAssetID(sensorAssetId);
realTimeData.setValues(valueunits);
realTimeData.setTime(time);
return realTimeData;
}
Aggregations