use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetControllerTest method testRealtimedataOtherExample.
@Test
public void testRealtimedataOtherExample() throws Exception {
Asset sensor = createSensor();
assetRepository.save(sensor);
String sensorId = sensor.getId();
long time = System.currentTimeMillis();
int duration = 30 * 60 * 1000;
long startTime = time - duration;
List<RealTimeData> realTimeDatas = new ArrayList<>();
RealTimeData tempRealTimeData = createTemperatureSensorRealtimeData(startTime, sensorId);
realTimeDatas.add(tempRealTimeData);
List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
ValueUnit tempValue = new ValueUnit();
tempValue.setValueNum(25);
tempValue.setTime(startTime + 5 * 60 * 1000);
tempValue.setUnit(MetricUnit.C.toString());
tempValue.setKey(MetricName.TEMPERATURE);
valueunits.add(tempValue);
RealTimeData realTimeData = new RealTimeData();
realTimeData.setId(UUID.randomUUID().toString());
realTimeData.setAssetID(sensorId);
realTimeData.setValues(valueunits);
realTimeData.setTime(startTime + 5 * 60 * 1000);
realTimeDatas.add(realTimeData);
realtimeDataRepository.saveAll(realTimeDatas);
MvcResult result1 = this.mockMvc.perform(get("/v1/assets/" + sensor.getId() + "/realtimedata").param("starttime", String.valueOf(startTime)).param("duration", String.valueOf(duration))).andReturn();
String res = result1.getResponse().getContentAsString();
MetricData[] metricDatas = mapper.readValue(res, MetricData[].class);
TestCase.assertEquals(1, metricDatas.length);
try {
for (MetricData sensordata : metricDatas) {
long metricTime = sensordata.getTimeStamp();
if (metricTime == startTime + 5 * 60 * 1000) {
TestCase.assertEquals(25.0, sensordata.getValueNum());
} else {
TestCase.fail();
}
}
} finally {
assetRepository.deleteById(sensorId);
realtimeDataRepository.deleteById(tempRealTimeData.getId());
realtimeDataRepository.deleteById(realTimeData.getId());
}
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetControllerTest method createHumiditySensorRealtimeData.
RealTimeData createHumiditySensorRealtimeData(long time, String sensorAssetId) {
List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
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(sensorAssetId);
realTimeData.setValues(valueunits);
realTimeData.setTime(time);
return realTimeData;
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetControllerTest method createPduRealTimeData.
RealTimeData createPduRealTimeData(Long time) {
RealTimeData realTimeData = createServerPDURealTimeData(time);
List<ValueUnit> valueunits = realTimeData.getValues();
ValueUnit valueunitActivePower = new ValueUnit();
valueunitActivePower.setKey(MetricName.PDU_ACTIVE_POWER);
valueunitActivePower.setUnit(MetricUnit.kW.toString());
valueunitActivePower.setExtraidentifier("OUTLET:7");
valueunitActivePower.setValueNum(0.2);
valueunitActivePower.setTime(time);
valueunits.add(valueunitActivePower);
ValueUnit valueunitFreeCapacity = new ValueUnit();
valueunitFreeCapacity.setKey(MetricName.PDU_FREE_CAPACITY);
valueunitFreeCapacity.setUnit(MetricUnit.A.toString());
valueunitFreeCapacity.setExtraidentifier("OUTLET:7");
valueunitFreeCapacity.setValueNum(20);
valueunitFreeCapacity.setTime(time);
valueunits.add(valueunitFreeCapacity);
ValueUnit valueunitL1FreeCapacity = new ValueUnit();
valueunitL1FreeCapacity.setKey(MetricName.PDU_FREE_CAPACITY);
valueunitL1FreeCapacity.setUnit(MetricUnit.A.toString());
valueunitL1FreeCapacity.setExtraidentifier("INLET:1" + FlowgateConstant.INLET_POLE_NAME_PREFIX + 1);
valueunitL1FreeCapacity.setValueNum(34);
valueunitL1FreeCapacity.setTime(time);
valueunits.add(valueunitL1FreeCapacity);
ValueUnit valueunitL1Current = new ValueUnit();
valueunitL1Current.setKey(MetricName.PDU_CURRENT);
valueunitL1Current.setUnit(MetricUnit.A.toString());
valueunitL1Current.setExtraidentifier("INLET:1" + FlowgateConstant.INLET_POLE_NAME_PREFIX + 1);
valueunitL1Current.setValueNum(6);
valueunitL1Current.setTime(time);
valueunits.add(valueunitL1Current);
ValueUnit valueunitL1Voltage = new ValueUnit();
valueunitL1Voltage.setKey(MetricName.PDU_VOLTAGE);
valueunitL1Voltage.setUnit(MetricUnit.V.toString());
valueunitL1Voltage.setExtraidentifier("INLET:1" + FlowgateConstant.INLET_POLE_NAME_PREFIX + 1);
valueunitL1Voltage.setValueNum(220);
valueunitL1Voltage.setTime(time);
valueunits.add(valueunitL1Voltage);
ValueUnit valueunit1L1FreeCapacity = new ValueUnit();
valueunit1L1FreeCapacity.setKey(MetricName.PDU_FREE_CAPACITY);
valueunit1L1FreeCapacity.setUnit(MetricUnit.A.toString());
valueunit1L1FreeCapacity.setExtraidentifier("INLET:2" + FlowgateConstant.INLET_POLE_NAME_PREFIX + 1);
valueunit1L1FreeCapacity.setValueNum(24);
valueunit1L1FreeCapacity.setTime(time);
valueunits.add(valueunit1L1FreeCapacity);
ValueUnit valueunit1L1Current = new ValueUnit();
valueunit1L1Current.setKey(MetricName.PDU_CURRENT);
valueunit1L1Current.setUnit(MetricUnit.A.toString());
valueunit1L1Current.setExtraidentifier("INLET:2" + FlowgateConstant.INLET_POLE_NAME_PREFIX + 1);
valueunit1L1Current.setValueNum(6);
valueunit1L1Current.setTime(time);
valueunits.add(valueunit1L1Current);
ValueUnit valueunit1L1Voltage = new ValueUnit();
valueunit1L1Voltage.setKey(MetricName.PDU_VOLTAGE);
valueunit1L1Voltage.setUnit(MetricUnit.V.toString());
valueunit1L1Voltage.setExtraidentifier("INLET:2" + FlowgateConstant.INLET_POLE_NAME_PREFIX + 1);
valueunit1L1Voltage.setValueNum(240);
valueunit1L1Voltage.setTime(time);
valueunits.add(valueunit1L1Voltage);
realTimeData.setId(UUID.randomUUID().toString());
realTimeData.setValues(valueunits);
realTimeData.setTime(time);
return realTimeData;
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetControllerTest method realTimeDatabatchCreationExample.
@Test
public void realTimeDatabatchCreationExample() throws JsonProcessingException, Exception {
List<RealTimeData> realtimedatas = new ArrayList<RealTimeData>();
long currentTime = System.currentTimeMillis();
RealTimeData realtimedata1 = createServerPDURealTimeData(currentTime);
List<ValueUnit> valueunits = realtimedata1.getValues();
ValueUnit tempValue = new ValueUnit();
tempValue.setValueNum(32);
tempValue.setTime(currentTime);
tempValue.setUnit(MetricUnit.C.toString());
tempValue.setKey(MetricName.TEMPERATURE);
valueunits.add(tempValue);
ValueUnit humidityValue = new ValueUnit();
humidityValue.setValueNum(20);
humidityValue.setTime(currentTime);
humidityValue.setUnit("%");
humidityValue.setKey(MetricName.HUMIDITY);
valueunits.add(humidityValue);
realtimedata1.setAssetID("assetid1");
realtimedatas.add(realtimedata1);
RealTimeData realtimedata2 = createServerPDURealTimeData(currentTime);
realtimedata2.setAssetID("assetid2");
realtimedatas.add(realtimedata2);
FieldDescriptor[] fieldpath = new FieldDescriptor[] { fieldWithPath("id").description("ID of the RealTimeData"), fieldWithPath("assetID").description("ID of the asset, created by flowgate"), fieldWithPath("values").description("List of ValueUnit"), fieldWithPath("time").description("Create time of ValueUnit"), subsectionWithPath("values").description("A list of sensor data. eg. Humidity , Electric... ").type(ValueUnit[].class) };
this.mockMvc.perform(post("/v1/assets/sensordata/batchoperation").contentType(MediaType.APPLICATION_JSON_VALUE).content(objectMapper.writeValueAsString(realtimedatas))).andExpect(status().isCreated()).andDo(document("assets-realTimeDatabatchCreation-example", requestFields(fieldWithPath("[]").description("An array of RealTimeData")).andWithPrefix("[].", fieldpath)));
realtimeDataRepository.deleteById(realtimedata1.getId());
realtimeDataRepository.deleteById(realtimedata2.getId());
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetControllerTest method testGetServerMetricsByIDHostUsageFormulaIsNull.
@Test
public void testGetServerMetricsByIDHostUsageFormulaIsNull() {
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");
realTimeDatas.add(humdityRealTimeData);
realTimeDatas.add(tempRealTimeData);
realTimeDatas.add(backHumidity);
realTimeDatas.add(backTemperature);
realTimeDatas.add(pduUsageMetricData);
realtimeDataRepository.saveAll(realTimeDatas);
asset = fillingMetricsformula(asset);
Map<String, String> metricFormula = asset.getMetricsformulars();
metricFormula.remove(FlowgateConstant.HOST_METRICS);
asset.setMetricsformulars(metricFormula);
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);
List<MetricData> metricDatas = assetService.getMetricsByID(asset.getId(), startTime, duration);
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());
}
}
assetRepository.deleteById(asset.getId());
realtimeDataRepository.deleteById(pduUsageMetricData.getId());
realtimeDataRepository.deleteById(tempRealTimeData.getId());
realtimeDataRepository.deleteById(humdityRealTimeData.getId());
realtimeDataRepository.deleteById(backHumidity.getId());
realtimeDataRepository.deleteById(backTemperature.getId());
}
Aggregations