Search in sources :

Example 41 with RealTimeData

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

the class AssetControllerTest method createPduAllRealTimeData.

RealTimeData createPduAllRealTimeData(Long time) {
    RealTimeData realTimeData = new RealTimeData();
    List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
    // PDU current 1.455 = sum(OutLet-Current)
    ValueUnit pduCurrentValueUnit = new ValueUnit();
    pduCurrentValueUnit.setKey(MetricName.PDU_TOTAL_CURRENT);
    pduCurrentValueUnit.setValueNum(1.455);
    pduCurrentValueUnit.setTime(time);
    pduCurrentValueUnit.setUnit(MetricUnit.A.toString());
    valueunits.add(pduCurrentValueUnit);
    // PDU voltage 221
    ValueUnit pduVoltageValueUnit = new ValueUnit();
    pduVoltageValueUnit.setKey(MetricName.PDU_VOLTAGE);
    pduVoltageValueUnit.setValueNum(221);
    pduVoltageValueUnit.setTime(time);
    pduVoltageValueUnit.setUnit(MetricUnit.V.toString());
    valueunits.add(pduVoltageValueUnit);
    // PDU power 0.322 sum(OutLet-Power)
    ValueUnit pduPowerValueUnit = new ValueUnit();
    pduPowerValueUnit.setKey(MetricName.PDU_TOTAL_POWER);
    pduPowerValueUnit.setValueNum(0.322);
    pduPowerValueUnit.setTime(time);
    pduPowerValueUnit.setUnit(MetricUnit.kW.toString());
    valueunits.add(pduPowerValueUnit);
    // PDU powerLoad 0.05
    ValueUnit powerLoadValueUnit = new ValueUnit();
    powerLoadValueUnit.setKey(MetricName.PDU_POWER_LOAD);
    powerLoadValueUnit.setValueNum(0.05);
    powerLoadValueUnit.setTime(time);
    powerLoadValueUnit.setUnit(MetricUnit.percent.toString());
    valueunits.add(powerLoadValueUnit);
    // PDU currentLoad 0.05
    ValueUnit currentLoadValueUnit = new ValueUnit();
    currentLoadValueUnit.setKey(MetricName.PDU_CURRENT_LOAD);
    currentLoadValueUnit.setValueNum(0.05);
    currentLoadValueUnit.setTime(time);
    currentLoadValueUnit.setUnit(MetricUnit.percent.toString());
    valueunits.add(currentLoadValueUnit);
    // Outlet:1 apparent power 0.081
    ValueUnit outLetApparentPowerValueUnit = new ValueUnit();
    outLetApparentPowerValueUnit.setKey(MetricName.PDU_APPARENT_POWER);
    outLetApparentPowerValueUnit.setValueNum(0.081);
    outLetApparentPowerValueUnit.setExtraidentifier("OUTLET:1");
    outLetApparentPowerValueUnit.setTime(time);
    outLetApparentPowerValueUnit.setUnit(MetricUnit.kW.toString());
    valueunits.add(outLetApparentPowerValueUnit);
    // Outlet:1 active power 0.054
    ValueUnit valueunitActivePower = new ValueUnit();
    valueunitActivePower.setKey(MetricName.PDU_ACTIVE_POWER);
    valueunitActivePower.setUnit(MetricUnit.kW.toString());
    valueunitActivePower.setExtraidentifier("OUTLET:1");
    valueunitActivePower.setValueNum(0.054);
    valueunitActivePower.setTime(time);
    valueunits.add(valueunitActivePower);
    // Outlet:1 current 0.365
    ValueUnit currentValueUnit = new ValueUnit();
    currentValueUnit.setKey(MetricName.PDU_CURRENT);
    currentValueUnit.setValueNum(0.365);
    currentValueUnit.setExtraidentifier("OUTLET:1");
    currentValueUnit.setTime(time);
    currentValueUnit.setUnit(MetricUnit.A.toString());
    valueunits.add(currentValueUnit);
    // Outlet:1 voltage 221
    ValueUnit voltageValueUnit = new ValueUnit();
    voltageValueUnit.setKey(MetricName.PDU_VOLTAGE);
    voltageValueUnit.setValueNum(221);
    voltageValueUnit.setExtraidentifier("OUTLET:1");
    voltageValueUnit.setTime(time);
    voltageValueUnit.setUnit(MetricUnit.V.toString());
    valueunits.add(voltageValueUnit);
    // Outlet:1 freeCapacity 9.635
    ValueUnit valueunitFreeCapacity = new ValueUnit();
    valueunitFreeCapacity.setKey(MetricName.PDU_FREE_CAPACITY);
    valueunitFreeCapacity.setUnit(MetricUnit.A.toString());
    valueunitFreeCapacity.setExtraidentifier("OUTLET:1");
    valueunitFreeCapacity.setValueNum(9.635);
    valueunitFreeCapacity.setTime(time);
    valueunits.add(valueunitFreeCapacity);
    // Outlet:2 apparent power 0.241
    ValueUnit outLet2ApparentPowerValueUnit = new ValueUnit();
    outLet2ApparentPowerValueUnit.setKey(MetricName.PDU_APPARENT_POWER);
    outLet2ApparentPowerValueUnit.setValueNum(0.241);
    outLet2ApparentPowerValueUnit.setExtraidentifier("OUTLET:2");
    outLet2ApparentPowerValueUnit.setTime(time);
    outLet2ApparentPowerValueUnit.setUnit(MetricUnit.kW.toString());
    valueunits.add(outLet2ApparentPowerValueUnit);
    // Outlet:2 active power 0.2
    ValueUnit outLet2valueunitActivePower = new ValueUnit();
    outLet2valueunitActivePower.setKey(MetricName.PDU_ACTIVE_POWER);
    outLet2valueunitActivePower.setUnit(MetricUnit.kW.toString());
    outLet2valueunitActivePower.setExtraidentifier("OUTLET:2");
    outLet2valueunitActivePower.setValueNum(0.2);
    outLet2valueunitActivePower.setTime(time);
    valueunits.add(outLet2valueunitActivePower);
    // Outlet:2 current 1.09
    ValueUnit outLet2currentValueUnit = new ValueUnit();
    outLet2currentValueUnit.setKey(MetricName.PDU_CURRENT);
    outLet2currentValueUnit.setValueNum(1.09);
    outLet2currentValueUnit.setExtraidentifier("OUTLET:2");
    outLet2currentValueUnit.setTime(time);
    outLet2currentValueUnit.setUnit(MetricUnit.A.toString());
    valueunits.add(outLet2currentValueUnit);
    // Outlet:2 voltage 221
    ValueUnit outLet2voltageValueUnit = new ValueUnit();
    outLet2voltageValueUnit.setKey(MetricName.PDU_VOLTAGE);
    outLet2voltageValueUnit.setValueNum(221);
    outLet2voltageValueUnit.setExtraidentifier("OUTLET:2");
    outLet2voltageValueUnit.setTime(time);
    outLet2voltageValueUnit.setUnit(MetricUnit.V.toString());
    valueunits.add(outLet2voltageValueUnit);
    // Outlet:2 freeCapacity 8.91
    ValueUnit outLet2valueunitFreeCapacity = new ValueUnit();
    outLet2valueunitFreeCapacity.setKey(MetricName.PDU_FREE_CAPACITY);
    outLet2valueunitFreeCapacity.setUnit(MetricUnit.A.toString());
    outLet2valueunitFreeCapacity.setExtraidentifier("OUTLET:2");
    outLet2valueunitFreeCapacity.setValueNum(8.91);
    outLet2valueunitFreeCapacity.setTime(time);
    valueunits.add(outLet2valueunitFreeCapacity);
    // Inlet Pole metrics 30.545
    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(30.545);
    valueunitL1FreeCapacity.setTime(time);
    valueunits.add(valueunitL1FreeCapacity);
    // 1.455
    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(1.455);
    valueunitL1Current.setTime(time);
    valueunits.add(valueunitL1Current);
    // 221
    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(221);
    valueunitL1Voltage.setTime(time);
    valueunits.add(valueunitL1Voltage);
    realTimeData.setId(UUID.randomUUID().toString());
    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 42 with RealTimeData

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

the class AssetControllerTest method createServerPDURealTimeData.

RealTimeData createServerPDURealTimeData(long time) {
    List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
    ValueUnit totalPowerValueUnit = new ValueUnit();
    totalPowerValueUnit.setKey(MetricName.PDU_TOTAL_POWER);
    totalPowerValueUnit.setValueNum(1.033);
    totalPowerValueUnit.setTime(time);
    totalPowerValueUnit.setUnit(MetricUnit.kW.toString());
    valueunits.add(totalPowerValueUnit);
    ValueUnit totalCurrentValueUnit = new ValueUnit();
    totalCurrentValueUnit.setKey(MetricName.PDU_TOTAL_CURRENT);
    totalCurrentValueUnit.setValueNum(4.566);
    totalCurrentValueUnit.setTime(time);
    totalCurrentValueUnit.setUnit(MetricUnit.A.toString());
    valueunits.add(totalCurrentValueUnit);
    ValueUnit apparentPowerValueUnit = new ValueUnit();
    apparentPowerValueUnit.setKey(MetricName.PDU_APPARENT_POWER);
    apparentPowerValueUnit.setValueNum(1.033);
    apparentPowerValueUnit.setExtraidentifier("OUTLET:7");
    apparentPowerValueUnit.setTime(time);
    apparentPowerValueUnit.setUnit(MetricUnit.kW.toString());
    valueunits.add(apparentPowerValueUnit);
    ValueUnit currentValueUnit = new ValueUnit();
    currentValueUnit.setKey(MetricName.PDU_CURRENT);
    currentValueUnit.setValueNum(0.633);
    currentValueUnit.setExtraidentifier("OUTLET:7");
    currentValueUnit.setTime(time);
    currentValueUnit.setUnit(MetricUnit.A.toString());
    valueunits.add(currentValueUnit);
    ValueUnit voltageValueUnit = new ValueUnit();
    voltageValueUnit.setKey(MetricName.PDU_VOLTAGE);
    voltageValueUnit.setValueNum(226);
    voltageValueUnit.setExtraidentifier("OUTLET:7");
    voltageValueUnit.setTime(time);
    voltageValueUnit.setUnit(MetricUnit.V.toString());
    valueunits.add(voltageValueUnit);
    ValueUnit powerLoadValueUnit = new ValueUnit();
    powerLoadValueUnit.setKey(MetricName.PDU_POWER_LOAD);
    powerLoadValueUnit.setValueNum(0.134);
    powerLoadValueUnit.setTime(time);
    powerLoadValueUnit.setUnit(MetricUnit.percent.toString());
    valueunits.add(powerLoadValueUnit);
    ValueUnit currentLoadValueUnit = new ValueUnit();
    currentLoadValueUnit.setKey(MetricName.PDU_CURRENT_LOAD);
    currentLoadValueUnit.setValueNum(0.1427);
    currentLoadValueUnit.setTime(time);
    currentLoadValueUnit.setUnit(MetricUnit.percent.toString());
    valueunits.add(currentLoadValueUnit);
    RealTimeData realTimeData = new RealTimeData();
    realTimeData.setId(UUID.randomUUID().toString());
    realTimeData.setAssetID("0001bdc8b25d4c2badfd045ab61aabfa");
    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 43 with RealTimeData

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

the class AssetControllerTest method createServerHostRealTimeData.

RealTimeData createServerHostRealTimeData(long time) {
    double[] storageIORateUsageValues = { 330, 98, 57, 852, 224, 95, 209, 66, 56, 798, 236, 81, 213, 63, 61 };
    double[] memoryUsageValues = { 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22 };
    double[] cpuUsedInMhzValues = { 746, 570, 552, 844, 651, 566, 552, 569, 538, 836, 655, 565, 571, 551, 570 };
    double[] cpuUsageValues = { 4.67, 3.57, 3.46, 5.28, 4.08, 3.55, 3.45, 3.56, 3.37, 5.23, 4.1, 3.53, 3.57, 3.45, 3.57 };
    double[] activeMemoryValues = { 1561416, 1561416, 2065824, 2065824, 2065824, 2065428, 2065428, 2065428, 1729924, 1729924, 1729924, 1561072, 1561072, 1561072, 2063852 };
    double[] sharedMemoryValues = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 };
    double[] consumedMemoryValues = { 18291220, 18291236, 18291236, 18291236, 18291252, 18291252, 18291252, 18291156, 18291156, 18291200, 18291060, 18291172, 18291172, 18291188, 18291188 };
    double[] swapMemoryValues = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    double[] balloonMemoryValues = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    double[] networkUtilizationValues = { 146, 18, 15, 16, 16, 12, 9, 16, 10, 16, 17, 12, 12, 19, 29 };
    double[] powerValues = { 0.069, 0.069, 0.069, 0.069, 0.07, 0.069, 0.069, 0.069, 0.069, 0.069, 0.069, 0.069, 0.069, 0.069, 0.069 };
    double[] energyValues = { 0.00038805555555555555, 0.0003833333333333333, 0.0003833333333333333, 0.0003869444444444444, 0.00038888888888888887, 0.00038805555555555555, 0.0003833333333333333, 0.0003833333333333333, 0.0003833333333333333, 0.00038555555555555554, 0.00038805555555555555, 0.0003833333333333333, 0.0003833333333333333, 0.0003833333333333333, 0.00038555555555555554 };
    List<ValueUnit> valueUnits = new ArrayList<>();
    ValueUnit valueUnit;
    long startTime = 0;
    long endTime = 0;
    long maxValueTime = 0;
    long minValueTime = 0;
    for (int i = 0; i < 15; i++) {
        long tempTime = time + ((i + 1) * 20000);
        if (i == 0) {
            startTime = tempTime;
            minValueTime = tempTime;
        }
        if (i == 14) {
            endTime = tempTime;
        }
        if (i == 4) {
            maxValueTime = tempTime;
        }
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_STORAGEIORATEUSAGE);
        valueUnit.setUnit(MetricUnit.kBps.name());
        valueUnit.setValueNum(storageIORateUsageValues[i]);
        valueUnits.add(valueUnit);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_MEMORYUSAGE);
        valueUnit.setUnit(MetricUnit.percent.name());
        valueUnit.setValueNum(memoryUsageValues[i]);
        valueUnits.add(valueUnit);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_CPUUSEDINMHZ);
        valueUnit.setUnit(MetricUnit.Mhz.name());
        valueUnit.setValueNum(cpuUsedInMhzValues[i]);
        valueUnits.add(valueUnit);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_CPUUSAGE);
        valueUnit.setUnit(MetricUnit.percent.name());
        valueUnit.setValueNum(cpuUsageValues[i]);
        valueUnits.add(valueUnit);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_ACTIVEMEMORY);
        valueUnit.setUnit(MetricUnit.kB.name());
        valueUnit.setValueNum(activeMemoryValues[i]);
        valueUnits.add(valueUnit);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_SHAREDMEMORY);
        valueUnit.setUnit(MetricUnit.kB.name());
        valueUnit.setValueNum(sharedMemoryValues[i]);
        valueUnits.add(valueUnit);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_CONSUMEDMEMORY);
        valueUnit.setUnit(MetricUnit.kB.name());
        valueUnit.setValueNum(consumedMemoryValues[i]);
        valueUnits.add(valueUnit);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_SWAPMEMORY);
        valueUnit.setUnit(MetricUnit.kB.name());
        valueUnit.setValueNum(swapMemoryValues[i]);
        valueUnits.add(valueUnit);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_BALLOONMEMORY);
        valueUnit.setUnit(MetricUnit.kB.name());
        valueUnit.setValueNum(balloonMemoryValues[i]);
        valueUnits.add(valueUnit);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_NETWORKUTILIZATION);
        valueUnit.setUnit(MetricUnit.kBps.name());
        valueUnit.setValueNum(networkUtilizationValues[i]);
        valueUnits.add(valueUnit);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_POWER);
        valueUnit.setUnit(MetricUnit.kW.name());
        valueUnit.setValueNum(powerValues[i]);
        valueUnits.add(valueUnit);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
        valueUnit.setExtraidentifier(String.valueOf(tempTime - 20000));
        valueUnit.setUnit(MetricUnit.kWh.name());
        valueUnit.setValueNum(energyValues[i]);
        valueUnits.add(valueUnit);
    }
    valueUnit = new ValueUnit();
    valueUnit.setTime(endTime);
    valueUnit.setExtraidentifier(startTime + FlowgateConstant.SEPARATOR + minValueTime);
    valueUnit.setKey(MetricName.SERVER_MINIMUM_USED_POWER);
    valueUnit.setUnit(MetricUnit.kW.toString());
    valueUnit.setValueNum(0.069);
    valueUnits.add(valueUnit);
    valueUnit = new ValueUnit();
    valueUnit.setTime(endTime);
    valueUnit.setExtraidentifier(startTime + FlowgateConstant.SEPARATOR + maxValueTime);
    valueUnit.setKey(MetricName.SERVER_PEAK_USED_POWER);
    valueUnit.setUnit(MetricUnit.kW.toString());
    valueUnit.setValueNum(0.07);
    valueUnits.add(valueUnit);
    valueUnit = new ValueUnit();
    valueUnit.setTime(endTime);
    valueUnit.setExtraidentifier(String.valueOf(startTime));
    valueUnit.setKey(MetricName.SERVER_AVERAGE_USED_POWER);
    valueUnit.setUnit(MetricUnit.kW.toString());
    valueUnit.setValueNum(0.06906666666666665);
    valueUnits.add(valueUnit);
    valueUnit = new ValueUnit();
    valueUnit.setTime(time);
    valueUnit.setKey(MetricName.SERVER_POWER);
    valueUnit.setUnit(MetricUnit.kW.toString());
    valueUnit.setValueNum(0.56);
    valueUnits.add(valueUnit);
    String sinceTime = String.valueOf(time - 900000l);
    valueUnit = new ValueUnit();
    String minimumPowerTime = String.valueOf(time - 30000l);
    valueUnit.setTime(time);
    valueUnit.setExtraidentifier(sinceTime + FlowgateConstant.SEPARATOR + minimumPowerTime);
    valueUnit.setKey(MetricName.SERVER_MINIMUM_USED_POWER);
    valueUnit.setUnit(MetricUnit.kW.toString());
    valueUnit.setValueNum(0.5);
    valueUnits.add(valueUnit);
    valueUnit = new ValueUnit();
    String peakPowerTime = String.valueOf(time - 60000l);
    valueUnit.setTime(time);
    valueUnit.setExtraidentifier(sinceTime + FlowgateConstant.SEPARATOR + peakPowerTime);
    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.setExtraidentifier(sinceTime);
    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);
    valueUnit = new ValueUnit();
    valueUnit.setTime(time);
    valueUnit.setExtraidentifier(sinceTime);
    valueUnit.setKey(MetricName.SERVER_AVERAGE_TEMPERATURE);
    valueUnit.setUnit(MetricUnit.C.toString());
    valueUnit.setValueNum(24);
    valueUnits.add(valueUnit);
    valueUnit = new ValueUnit();
    valueUnit.setTime(time);
    String peakTemperatureTime = String.valueOf(time - 60000l);
    valueUnit.setExtraidentifier(sinceTime + FlowgateConstant.SEPARATOR + peakTemperatureTime);
    valueUnit.setKey(MetricName.SERVER_PEAK_TEMPERATURE);
    valueUnit.setUnit(MetricUnit.C.toString());
    valueUnit.setValueNum(30);
    valueUnits.add(valueUnit);
    RealTimeData realTimeData = new RealTimeData();
    realTimeData.setId(UUID.randomUUID().toString());
    realTimeData.setAssetID("0001bdc8b25d4c2badfd045ab61aabfa");
    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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 44 with RealTimeData

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

the class AssetControllerTest method getPduMetricsDataById.

@Test
public void getPduMetricsDataById() 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) };
    List<RealTimeData> realTimeDatas = new ArrayList<RealTimeData>();
    Long currentTime = System.currentTimeMillis();
    RealTimeData pduRealTimeData = createPduRealTimeData(currentTime);
    pduRealTimeData.setAssetID("00040717c4154b5b924ced78eafcea7a");
    RealTimeData sensorRealTimeData = createSensorRealtimeData(currentTime);
    sensorRealTimeData.setAssetID("00027ca37b004a9890d1bf20349d5ac1");
    realTimeDatas.add(pduRealTimeData);
    realTimeDatas.add(sensorRealTimeData);
    Iterable<RealTimeData> result = realtimeDataRepository.saveAll(realTimeDatas);
    Asset asset = createAsset();
    Map<String, String> formulas = new HashMap<String, String>();
    Map<String, Map<String, String>> sensorMetricFormulas = new HashMap<String, Map<String, String>>();
    Map<String, String> tempSensor = new HashMap<String, String>();
    tempSensor.put("INLET", "00027ca37b004a9890d1bf20349d5ac1");
    sensorMetricFormulas.put(MetricName.PDU_TEMPERATURE, tempSensor);
    Map<String, String> humiditySensor = new HashMap<String, String>();
    humiditySensor.put("OUTLET", "00027ca37b004a9890d1bf20349d5ac1");
    sensorMetricFormulas.put(MetricName.PDU_HUMIDITY, humiditySensor);
    String sensorFormulaInfo = null;
    try {
        sensorFormulaInfo = mapper.writeValueAsString(sensorMetricFormulas);
    } catch (JsonProcessingException e) {
        TestCase.fail(e.getMessage());
    }
    formulas.put(FlowgateConstant.SENSOR, sensorFormulaInfo);
    asset.setCategory(AssetCategory.PDU);
    asset.setMetricsformulars(formulas);
    asset.setId("00040717c4154b5b924ced78eafcea7a");
    asset = assetRepository.save(asset);
    MvcResult result1 = this.mockMvc.perform(get("/v1/assets/pdu/{assetId}/realtimedata", asset.getId()).param("starttime", String.valueOf(currentTime)).param("duration", "300000")).andDo(document("assets-getPduMetricsData-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 = result1.getResponse().getContentAsString();
    MetricData[] datas = mapper.readValue(res, MetricData[].class);
    try {
        for (MetricData pduMetricdata : datas) {
            String metricName = pduMetricdata.getMetricName();
            if (String.format(MetricName.PDU_XLET_ACTIVE_POWER, "OUTLET:7").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 0.2);
            } else if (String.format(MetricName.PDU_XLET_APPARENT_POWER, "OUTLET:7").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 1.033);
            } else if (String.format(MetricName.PDU_XLET_CURRENT, "OUTLET:7").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 0.633);
            } else if (String.format(MetricName.PDU_XLET_FREE_CAPACITY, "OUTLET:7").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 20.0);
            } else if (String.format(MetricName.PDU_XLET_VOLTAGE, "OUTLET:7").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 226.0);
            } else if (String.format(MetricKeyName.PDU_HUMIDITY_LOCATIONX, "OUTLET").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 20.0);
            } else if (String.format(MetricKeyName.PDU_TEMPERATURE_LOCATIONX, "INLET").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 32.0);
            } else if (MetricName.PDU_CURRENT_LOAD.equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 0.1427);
            } else if (MetricName.PDU_POWER_LOAD.equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 0.134);
            } else if (MetricName.PDU_TOTAL_CURRENT.equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 4.566);
            } else if (MetricName.PDU_TOTAL_POWER.equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 1.033);
            } else if (String.format(MetricName.PDU_INLET_XPOLE_CURRENT, "INLET:1", "L1").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 6.0);
            } else if (String.format(MetricName.PDU_INLET_XPOLE_FREE_CAPACITY, "INLET:1", "L1").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 34.0);
            } else if (String.format(MetricName.PDU_INLET_XPOLE_VOLTAGE, "INLET:1", "L1").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 220.0);
            } else if (String.format(MetricName.PDU_INLET_XPOLE_CURRENT, "INLET:2", "L1").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 6.0);
            } else if (String.format(MetricName.PDU_INLET_XPOLE_FREE_CAPACITY, "INLET:2", "L1").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 24.0);
            } else if (String.format(MetricName.PDU_INLET_XPOLE_VOLTAGE, "INLET:2", "L1").equals(metricName)) {
                TestCase.assertEquals(pduMetricdata.getValueNum(), 240.0);
            } else {
                TestCase.fail("Unkown metric");
            }
        }
    } finally {
        assetRepository.deleteById(asset.getId());
        realtimeDataRepository.deleteById(pduRealTimeData.getId());
        realtimeDataRepository.deleteById(sensorRealTimeData.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) FieldDescriptor(org.springframework.restdocs.payload.FieldDescriptor) Asset(com.vmware.flowgate.common.model.Asset) Map(java.util.Map) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) MetricData(com.vmware.flowgate.common.model.MetricData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 45 with RealTimeData

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

the class AssetControllerTest method testGetMetricDataForOther.

@Test
public void testGetMetricDataForOther() {
    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);
    List<MetricData> metricDatas = assetService.getMetricsByID(sensorId, startTime, duration);
    TestCase.assertEquals(2, metricDatas.size());
    for (MetricData sensordata : metricDatas) {
        long metricTime = sensordata.getTimeStamp();
        if (metricTime == startTime) {
            TestCase.assertEquals(32.0, sensordata.getValueNum());
        } else if (metricTime == startTime + 5 * 60 * 1000) {
            TestCase.assertEquals(25.0, sensordata.getValueNum());
        } else {
            TestCase.fail();
        }
    }
    assetRepository.deleteById(sensorId);
    realtimeDataRepository.deleteById(tempRealTimeData.getId());
    realtimeDataRepository.deleteById(realTimeData.getId());
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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)

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