Search in sources :

Example 6 with RealTimeData

use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.

the class AssetControllerTest method testGetServerMetricsByID.

@Test
public void testGetServerMetricsByID() {
    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);
    List<MetricData> metricDatas = assetService.getMetricsByID(asset.getId(), startTime, duration);
    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());
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Asset(com.vmware.flowgate.common.model.Asset) MetricData(com.vmware.flowgate.common.model.MetricData) HashSet(java.util.HashSet) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 7 with RealTimeData

use of com.vmware.flowgate.common.model.RealTimeData 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 8 with RealTimeData

use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.

the class AssetControllerTest method testRealtimedataNotDataExample.

@Test
public void testRealtimedataNotDataExample() throws Exception {
    Asset asset = createAsset();
    fillingMetricsformula(asset);
    asset.setId("00027ca37b004a9890d1bf20349d5ac1");
    asset.setCategory(AssetCategory.Sensors);
    asset = assetRepository.save(asset);
    List<RealTimeData> realTimeDatas = new ArrayList<>();
    long currentTime = System.currentTimeMillis();
    RealTimeData sensorRealTimeData = createSensorRealtimeData(currentTime);
    sensorRealTimeData.setAssetID("00027ca37b004a9890d1bf20349d5ac1");
    sensorRealTimeData.setValues(new ArrayList<>());
    realTimeDatas.add(sensorRealTimeData);
    realtimeDataRepository.saveAll(realTimeDatas);
    try {
        MvcResult result = this.mockMvc.perform(get("/v1/assets/" + asset.getId() + "/realtimedata")).andExpect(status().isOk()).andReturn();
        MetricData[] datas = getMetricDataByJsonString(result.getResponse().getContentAsString());
        TestCase.assertEquals(0, datas.length);
        MvcResult result1 = this.mockMvc.perform(get("/v1/assets/" + asset.getId() + "/realtimedata").param("starttime", String.valueOf(currentTime)).param("duration", "300000")).andExpect(status().isOk()).andReturn();
        MetricData[] datas1 = getMetricDataByJsonString(result1.getResponse().getContentAsString());
        TestCase.assertEquals(0, datas1.length);
        MvcResult result2 = this.mockMvc.perform(get("/v1/assets/" + asset.getId() + "/realtimedata").param("starttime", String.valueOf(currentTime + 30000000)).param("duration", "1")).andExpect(status().isOk()).andReturn();
        MetricData[] data2 = getMetricDataByJsonString(result2.getResponse().getContentAsString());
        TestCase.assertEquals(0, data2.length);
        asset.setCategory(AssetCategory.Server);
        asset = assetRepository.save(asset);
        MvcResult result3 = this.mockMvc.perform(get("/v1/assets/" + asset.getId() + "/realtimedata").param("starttime", String.valueOf(currentTime + 30000000)).param("duration", "1")).andExpect(status().isOk()).andReturn();
        asset.setCategory(AssetCategory.PDU);
        asset = assetRepository.save(asset);
        MvcResult result4 = this.mockMvc.perform(get("/v1/assets/" + asset.getId() + "/realtimedata").param("starttime", String.valueOf(currentTime + 30000000)).param("duration", "1")).andExpect(status().isOk()).andReturn();
    } finally {
        assetRepository.deleteById(asset.getId());
        realtimeDataRepository.deleteById(sensorRealTimeData.getId());
    }
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) MvcResult(org.springframework.test.web.servlet.MvcResult) MetricData(com.vmware.flowgate.common.model.MetricData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 9 with RealTimeData

use of com.vmware.flowgate.common.model.RealTimeData 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 10 with RealTimeData

use of com.vmware.flowgate.common.model.RealTimeData 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)

Aggregations

RealTimeData (com.vmware.flowgate.common.model.RealTimeData)49 ArrayList (java.util.ArrayList)37 ValueUnit (com.vmware.flowgate.common.model.ValueUnit)28 Test (org.junit.Test)24 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)24 Asset (com.vmware.flowgate.common.model.Asset)23 MetricData (com.vmware.flowgate.common.model.MetricData)16 HashMap (java.util.HashMap)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 Map (java.util.Map)8 MvcResult (org.springframework.test.web.servlet.MvcResult)8 HashSet (java.util.HashSet)6 FieldDescriptor (org.springframework.restdocs.payload.FieldDescriptor)5 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)4 Sensor (com.vmware.flowgate.poweriqworker.model.Sensor)4 ConnectException (java.net.ConnectException)4 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)4 ResourceAccessException (org.springframework.web.client.ResourceAccessException)4 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)3 SensorReading (com.vmware.flowgate.poweriqworker.model.SensorReading)3