Search in sources :

Example 11 with ValueUnit

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());
    }
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MvcResult(org.springframework.test.web.servlet.MvcResult) Asset(com.vmware.flowgate.common.model.Asset) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) MetricData(com.vmware.flowgate.common.model.MetricData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 12 with ValueUnit

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;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit)

Example 13 with ValueUnit

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;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit)

Example 14 with ValueUnit

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());
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) Asset(com.vmware.flowgate.common.model.Asset) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 15 with ValueUnit

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;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit)

Aggregations

ValueUnit (com.vmware.flowgate.common.model.ValueUnit)63 ArrayList (java.util.ArrayList)42 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)28 HashMap (java.util.HashMap)25 MetricData (com.vmware.flowgate.common.model.MetricData)23 Test (org.junit.Test)23 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 TranslateContext (com.vmware.flowgate.common.model.TranslateContext)13 Map (java.util.Map)11 List (java.util.List)9 Asset (com.vmware.flowgate.common.model.Asset)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 WormholeException (com.vmware.flowgate.common.exception.WormholeException)3 MetricUnit (com.vmware.flowgate.common.model.ValueUnit.MetricUnit)3 PowerManageMetricsRequestBody (com.vmware.flowgate.openmanage.datamodel.PowerManageMetricsRequestBody)3 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)3 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)2 DevicePower (com.vmware.flowgate.openmanage.datamodel.DevicePower)2 Outlet (com.vmware.flowgate.poweriqworker.model.Outlet)2 Pdu (com.vmware.flowgate.poweriqworker.model.Pdu)2