Search in sources :

Example 6 with ValueUnit

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

the class FilterServerEnergyConsumptionTest method testFilterServerEnergyConsumption.

/**
 * The since time(from open manage) early with the start time(API parameter)
 */
@Test
public void testFilterServerEnergyConsumption() {
    long time = System.currentTimeMillis();
    int duration = 5 * 60 * 1000;
    List<ValueUnit> valueUnits = getValueUnitsFromVC(time, duration);
    // Sample value of Openmanage SERVER_ENERGY_CONSUMPTION metric
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setTime(time);
    valueUnit.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
    valueUnit.setExtraidentifier(String.valueOf(1302663085000l));
    valueUnit.setUnit(MetricUnit.kWh.name());
    valueUnit.setValueNum(65633);
    valueUnits.add(valueUnit);
    List<ValueUnit> results = assetService.filterServerEnergyConsumption(valueUnits, time);
    TestCase.assertEquals(15, results.size());
    DecimalFormat df = new DecimalFormat("#.0000");
    for (ValueUnit valueunit : results) {
        Long sinceTime = Long.parseLong(valueunit.getExtraidentifier());
        String valueString = df.format(valueunit.getValueNum());
        Double value = Double.valueOf(valueString);
        if (sinceTime == time) {
            TestCase.assertEquals(0.001, value);
        } else if (sinceTime == time + 20000) {
            TestCase.assertEquals(0.002, value);
        } else if (sinceTime == time + 40000) {
            TestCase.assertEquals(0.003, value);
        } else if (sinceTime == time + 60000) {
            TestCase.assertEquals(0.004, value);
        } else if (sinceTime == time + 80000) {
            TestCase.assertEquals(0.005, value);
        } else if (sinceTime == time + 100000) {
            TestCase.assertEquals(0.006, value);
        } else if (sinceTime == time + 120000) {
            TestCase.assertEquals(0.007, value);
        } else if (sinceTime == time + 140000) {
            TestCase.assertEquals(0.008, value);
        } else if (sinceTime == time + 160000) {
            TestCase.assertEquals(0.009, value);
        } else if (sinceTime == time + 180000) {
            TestCase.assertEquals(0.01, value);
        } else if (sinceTime == time + 200000) {
            TestCase.assertEquals(0.011, value);
        } else if (sinceTime == time + 220000) {
            TestCase.assertEquals(0.012, value);
        } else if (sinceTime == time + 240000) {
            TestCase.assertEquals(0.013, value);
        } else if (sinceTime == time + 260000) {
            TestCase.assertEquals(0.014, value);
        } else if (sinceTime == time + 280000) {
            TestCase.assertEquals(0.015, value);
        }
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with ValueUnit

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

the class FilterServerEnergyConsumptionTest method testFilterServerEnergyConsumption1.

/**
 * We want to cover the combination with the longest time in a specified time period.
 * If the coverage time is the same, take the combination with the least number of combinations
 */
@Test
public void testFilterServerEnergyConsumption1() {
    long time = System.currentTimeMillis();
    int duration = 30 * 60 * 1000;
    int vcduration = 30 * 60 * 1000;
    List<ValueUnit> valueUnits = getValueUnitsFromVC(time, vcduration);
    valueUnits.addAll(getValueUnitsFromOpenmanage(time, duration));
    // Sample value of Openmanage SERVER_ENERGY_CONSUMPTION metric
    List<ValueUnit> results = assetService.filterServerEnergyConsumption(valueUnits, 1618204305000l);
    TestCase.assertEquals(1, results.size());
    for (ValueUnit value : results) {
        TestCase.assertEquals(60.0, value.getValueNum());
    }
}
Also used : ValueUnit(com.vmware.flowgate.common.model.ValueUnit) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with ValueUnit

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

the class NlyteDataService method generateRealTimeData.

public RealTimeData generateRealTimeData(Asset asset, NlyteAPIClient nlyteAPIclient, HashMap<AdvanceSettingType, String> advanceSettingMap) {
    RealTimeData realTimeData = null;
    JsonResultForPDURealtimeValue result = nlyteAPIclient.getPowerStripsRealtimeValue(asset.getAssetNumber()).getBody();
    List<ValueUnit> valueUnits = generateValueUnits(result.getValue(), advanceSettingMap);
    if (!valueUnits.isEmpty()) {
        realTimeData = new RealTimeData();
        realTimeData.setAssetID(asset.getId());
        realTimeData.setValues(valueUnits);
        realTimeData.setTime(valueUnits.get(0).getTime());
        realTimeData.setId(realTimeData.getAssetID() + "_" + realTimeData.getTime());
    }
    return realTimeData;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) JsonResultForPDURealtimeValue(com.vmware.flowgate.nlyteworker.model.JsonResultForPDURealtimeValue)

Example 9 with ValueUnit

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

the class OpenManageJobService method getMetricsData.

private Map<String, ValueUnit> getMetricsData(String deviceId, OpenManageAPIClient client, Plugin powerManage) {
    DevicePower powerMetricsData = client.getDevicePowerMetrics(deviceId);
    long currentTime = 0;
    Map<String, ValueUnit> metricNameAndValueUnitMap = new HashMap<String, ValueUnit>();
    // Power metrics data from the Openmanage base API
    if (powerMetricsData != null && CIM.equals(powerMetricsData.getDateFormat())) {
        String power = powerMetricsData.getPower();
        if (!NULLVALUE.equals(power)) {
            ValueUnit instantPower = new ValueUnit();
            currentTime = WormholeDateFormat.cimDateToMilliseconds(powerMetricsData.getInstantaneousHeadroomTimeStamp());
            instantPower.setKey(MetricName.SERVER_POWER);
            instantPower.setTime(currentTime);
            instantPower.setUnit(MetricUnit.kW.name());
            instantPower.setValueNum(instantPower.translateUnit(Double.valueOf(power), metricUnitMap.get(powerMetricsData.getPowerUnit()), MetricUnit.kW));
            metricNameAndValueUnitMap.put(MetricName.SERVER_POWER, instantPower);
        }
        long sinceTime = WormholeDateFormat.cimDateToMilliseconds(powerMetricsData.getSince());
        String energyConsumption = powerMetricsData.getSystemEnergyConsumption();
        if (!NULLVALUE.equals(energyConsumption)) {
            long systemEnergyConsumptionTime = WormholeDateFormat.cimDateToMilliseconds(powerMetricsData.getSystemEnergyConsumptionTimeStamp());
            ValueUnit systemEnergyConsumption = new ValueUnit();
            systemEnergyConsumption.setTime(systemEnergyConsumptionTime);
            systemEnergyConsumption.setExtraidentifier(String.valueOf(sinceTime));
            systemEnergyConsumption.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
            systemEnergyConsumption.setUnit(MetricUnit.kWh.name());
            systemEnergyConsumption.setValueNum(systemEnergyConsumption.translateUnit(Double.valueOf(energyConsumption), metricUnitMap.get(powerMetricsData.getSystemEnergyConsumptionUnit()), MetricUnit.kWh));
            metricNameAndValueUnitMap.put(MetricName.SERVER_ENERGY_CONSUMPTION, systemEnergyConsumption);
        }
        String avgValue = powerMetricsData.getAvgPower();
        if (!NULLVALUE.equals(avgValue)) {
            ValueUnit avgPower = new ValueUnit();
            avgPower.setTime(currentTime);
            avgPower.setExtraidentifier(String.valueOf(sinceTime));
            avgPower.setKey(MetricName.SERVER_AVERAGE_USED_POWER);
            avgPower.setUnit(MetricUnit.kW.name());
            avgPower.setValueNum(avgPower.translateUnit(Double.valueOf(avgValue), metricUnitMap.get(powerMetricsData.getAvgPowerUnit()), MetricUnit.kW));
            metricNameAndValueUnitMap.put(MetricName.SERVER_AVERAGE_USED_POWER, avgPower);
        }
        String peakValue = powerMetricsData.getPeakPower();
        if (!NULLVALUE.equals(peakValue)) {
            ValueUnit peakPower = new ValueUnit();
            peakPower.setTime(currentTime);
            long peakPowerTime = WormholeDateFormat.cimDateToMilliseconds(powerMetricsData.getPeakPowerTimeStamp());
            String sinceAndPeakTime = String.valueOf(sinceTime) + FlowgateConstant.SEPARATOR + String.valueOf(peakPowerTime);
            // Record the since time and peak power time, for example  1612417403074_FIELDSPLIT_1612415606985
            peakPower.setExtraidentifier(sinceAndPeakTime);
            peakPower.setKey(MetricName.SERVER_PEAK_USED_POWER);
            peakPower.setUnit(MetricUnit.kW.name());
            peakPower.setValueNum(peakPower.translateUnit(Double.valueOf(peakValue), metricUnitMap.get(powerMetricsData.getPeakPowerUnit()), MetricUnit.kW));
            metricNameAndValueUnitMap.put(MetricName.SERVER_PEAK_USED_POWER, peakPower);
        }
        String minimumValue = powerMetricsData.getMinimumPower();
        if (!NULLVALUE.equals(minimumValue)) {
            ValueUnit minimumPower = new ValueUnit();
            minimumPower.setTime(currentTime);
            long minimumTime = WormholeDateFormat.cimDateToMilliseconds(powerMetricsData.getMinimumPowerTimeStamp());
            String sinceAndMinimum = String.valueOf(sinceTime) + FlowgateConstant.SEPARATOR + String.valueOf(minimumTime);
            minimumPower.setExtraidentifier(sinceAndMinimum);
            minimumPower.setKey(MetricName.SERVER_MINIMUM_USED_POWER);
            minimumPower.setUnit(MetricUnit.kW.name());
            minimumPower.setValueNum(minimumPower.translateUnit(Double.valueOf(minimumValue), metricUnitMap.get(powerMetricsData.getPeakPowerUnit()), MetricUnit.kW));
            metricNameAndValueUnitMap.put(MetricName.SERVER_MINIMUM_USED_POWER, minimumPower);
        }
    }
    // Temperature metrics data from the Openmanage base API
    DeviceTemperature temperatureMetrics = client.getDeviceTemperatureMetrics(deviceId);
    if (temperatureMetrics != null && CIM.equals(temperatureMetrics.getDateFormat())) {
        String temperatureValue = temperatureMetrics.getInstantaneousTemperature();
        if (!NULLVALUE.equals(temperatureValue)) {
            ValueUnit temperature = new ValueUnit();
            temperature.setKey(MetricName.SERVER_TEMPERATURE);
            temperature.setTime(currentTime);
            temperature.setUnit(MetricUnit.C.name());
            temperature.setValueNum(temperature.translateUnit(Double.valueOf(temperatureValue), metricUnitMap.get(temperatureMetrics.getInstantaneousTemperatureUnit()), MetricUnit.C));
            metricNameAndValueUnitMap.put(MetricName.SERVER_TEMPERATURE, temperature);
        }
        long startTime = WormholeDateFormat.cimDateToMilliseconds(temperatureMetrics.getStartTime());
        String avgValue = temperatureMetrics.getAvgTemperature();
        if (!NULLVALUE.equals(avgValue)) {
            ValueUnit avgTemperature = new ValueUnit();
            avgTemperature.setKey(MetricName.SERVER_AVERAGE_TEMPERATURE);
            avgTemperature.setExtraidentifier(String.valueOf(startTime));
            avgTemperature.setTime(currentTime);
            avgTemperature.setUnit(MetricUnit.C.name());
            avgTemperature.setValueNum(avgTemperature.translateUnit(Double.valueOf(avgValue), metricUnitMap.get(temperatureMetrics.getAvgTemperatureUnit()), MetricUnit.C));
            metricNameAndValueUnitMap.put(MetricName.SERVER_AVERAGE_TEMPERATURE, avgTemperature);
        }
        String peakValue = temperatureMetrics.getPeakTemperature();
        if (!NULLVALUE.equals(peakValue)) {
            ValueUnit peakTemperature = new ValueUnit();
            peakTemperature.setKey(MetricName.SERVER_PEAK_TEMPERATURE);
            long peakTime = WormholeDateFormat.cimDateToMilliseconds(temperatureMetrics.getPeakTemperatureTimeStamp());
            String startAndPeakTime = String.valueOf(startTime) + FlowgateConstant.SEPARATOR + String.valueOf(peakTime);
            peakTemperature.setExtraidentifier(startAndPeakTime);
            peakTemperature.setTime(currentTime);
            peakTemperature.setUnit(MetricUnit.C.name());
            peakTemperature.setValueNum(peakTemperature.translateUnit(Double.valueOf(peakValue), metricUnitMap.get(temperatureMetrics.getPeakTemperatureUnit()), MetricUnit.C));
            metricNameAndValueUnitMap.put(MetricName.SERVER_PEAK_TEMPERATURE, peakTemperature);
        }
    }
    // get metrics form power Manage plugin
    if (powerManage != null && powerManagerEnable) {
        String pluginId = powerManage.getId();
        PowerManageMetricsRequestBody body = new PowerManageMetricsRequestBody();
        body.setPluginId(pluginId);
        body.setEntityType(EntityType.Device.getValue());
        body.setEntityId(Integer.valueOf(deviceId));
        List<Integer> metricTypes = new ArrayList<Integer>();
        metricTypes.add(MetricType.INSTANT_POWER.getValue());
        // Inlet temperature
        metricTypes.add(MetricType.INSTANT_TEMP.getValue());
        body.setMetricTypes(metricTypes);
        body.setDuration(Duration.Recent.getValue());
        body.setSortOrder(SortOrder.Ascending.getValue());
        DeviceMetricsResult metrics = null;
        try {
            metrics = client.getMetricsFromPowerManage(body);
        } catch (HttpClientErrorException e) {
            logger.error("Not found any metrics data.", e);
            return metricNameAndValueUnitMap;
        }
        List<DeviceMetric> metricValues = metrics.getValue();
        if (metricValues.isEmpty()) {
            return metricNameAndValueUnitMap;
        }
        Map<Integer, String> metricTypeMap = new HashMap<Integer, String>();
        metricTypeMap.put(MetricType.INSTANT_POWER.getValue(), MetricName.SERVER_TOTAL_POWER);
        metricTypeMap.put(MetricType.INSTANT_TEMP.getValue(), MetricName.SERVER_FRONT_TEMPERATURE);
        CommonResult<PowerSetting> powerSettings = client.getCommonResult(PowerSetting.class);
        Map<Integer, Integer> powerSettingTypeAndValueMap = new HashMap<Integer, Integer>();
        for (PowerSetting powerSetting : powerSettings.getValue()) {
            powerSettingTypeAndValueMap.put(powerSetting.getId(), powerSetting.getValue());
        }
        for (DeviceMetric metric : metricValues) {
            if (MetricType.INSTANT_POWER.getValue() == metric.getType()) {
                ValueUnit instantPower = new ValueUnit();
                instantPower.setKey(MetricName.SERVER_POWER);
                instantPower.setTime(currentTime);
                instantPower.setUnit(MetricUnit.kW.name());
                int unitValue = powerSettingTypeAndValueMap.get(PowerSettingType.PowerUnit.getValue());
                // PowerUnit1 : watt
                // PowerUnit2 : BtuPerHr
                MetricUnit powerSourceUnit = metricUnitMap.get(PowerSettingType.PowerUnit.name() + unitValue);
                instantPower.setValueNum(instantPower.translateUnit(metric.getValue(), powerSourceUnit, MetricUnit.kW));
                metricNameAndValueUnitMap.put(MetricName.SERVER_POWER, instantPower);
            } else if (MetricType.INSTANT_TEMP.getValue() == metric.getType()) {
                ValueUnit inletTemperature = new ValueUnit();
                inletTemperature.setKey(MetricName.SERVER_FRONT_TEMPERATURE);
                inletTemperature.setTime(currentTime);
                inletTemperature.setUnit(MetricUnit.C.name());
                int unitValue = powerSettingTypeAndValueMap.get(PowerSettingType.TemperatureUnit.getValue());
                MetricUnit temperatureSourceUnit = metricUnitMap.get(PowerSettingType.TemperatureUnit.name() + unitValue);
                inletTemperature.setValueNum(inletTemperature.translateUnit(metric.getValue(), temperatureSourceUnit, MetricUnit.C));
                metricNameAndValueUnitMap.put(MetricName.SERVER_FRONT_TEMPERATURE, inletTemperature);
            }
        }
    }
    return metricNameAndValueUnitMap;
}
Also used : DeviceTemperature(com.vmware.flowgate.openmanage.datamodel.DeviceTemperature) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) PowerSetting(com.vmware.flowgate.openmanage.datamodel.PowerSetting) PowerManageMetricsRequestBody(com.vmware.flowgate.openmanage.datamodel.PowerManageMetricsRequestBody) ArrayList(java.util.ArrayList) DeviceMetric(com.vmware.flowgate.openmanage.datamodel.DeviceMetric) DeviceMetricsResult(com.vmware.flowgate.openmanage.datamodel.DeviceMetricsResult) DevicePower(com.vmware.flowgate.openmanage.datamodel.DevicePower) MetricUnit(com.vmware.flowgate.common.model.ValueUnit.MetricUnit) ValueUnit(com.vmware.flowgate.common.model.ValueUnit)

Example 10 with ValueUnit

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

the class SyncRealTimeDataJobTest method testGetValueUnits3.

@Test
public void testGetValueUnits3() {
    Mockito.when(this.powerIQAPIClient.getPduByID(128L)).thenReturn(createPdu());
    Mockito.when(this.powerIQAPIClient.getOutlets(128L)).thenReturn(getOutlets());
    Map<String, String> pduInfoMap = new HashMap<String, String>();
    pduInfoMap.put(FlowgateConstant.PDU_ID_FROM_POWERIQ, "128");
    List<ValueUnit> valueUnits = powerIQService.getValueUnits(pduInfoMap, powerIQAPIClient, createAdvanceSettingMap());
    TestCase.assertEquals(21, valueUnits.size());
    for (ValueUnit valueunit : valueUnits) {
        String extraidentifier = valueunit.getExtraidentifier();
        String inlet1InletPoleExtraIdentifier = FlowgateConstant.INLET_NAME_PREFIX + 1 + FlowgateConstant.INLET_POLE_NAME_PREFIX;
        if (extraidentifier != null) {
            if (extraidentifier.equals(FlowgateConstant.INLET_NAME_PREFIX + 1)) {
                switch(valueunit.getKey()) {
                    case MetricName.PDU_ACTIVE_POWER:
                        TestCase.assertEquals(getInlets().get(0).getReading().getActivePower() / 1000, valueunit.getValueNum());
                        break;
                    case MetricName.PDU_VOLTAGE:
                        TestCase.assertEquals(getInlets().get(0).getReading().getVoltage(), valueunit.getValueNum());
                        break;
                    case MetricName.PDU_CURRENT:
                        TestCase.assertEquals(getInlets().get(0).getReading().getCurrent(), valueunit.getValueNum());
                        break;
                    default:
                        break;
                }
            } else if (valueunit.getExtraidentifier().equals(FlowgateConstant.OUTLET_NAME_PREFIX + 1)) {
                switch(valueunit.getKey()) {
                    case MetricName.PDU_ACTIVE_POWER:
                        TestCase.assertEquals(getOutlets().get(0).getReading().getActivePower() / 1000, valueunit.getValueNum());
                        break;
                    case MetricName.PDU_VOLTAGE:
                        TestCase.assertEquals(getOutlets().get(0).getReading().getVoltage(), valueunit.getValueNum());
                        break;
                    case MetricName.PDU_CURRENT:
                        TestCase.assertEquals(getOutlets().get(0).getReading().getCurrent(), valueunit.getValueNum());
                        break;
                    default:
                        break;
                }
            } else if (valueunit.getExtraidentifier().equals(inlet1InletPoleExtraIdentifier + 1)) {
                switch(valueunit.getKey()) {
                    case MetricName.PDU_FREE_CAPACITY:
                        TestCase.assertEquals(7.38, valueunit.getValueNum());
                        break;
                    case MetricName.PDU_VOLTAGE:
                        TestCase.assertEquals(122.1, valueunit.getValueNum());
                        break;
                    case MetricName.PDU_CURRENT:
                        TestCase.assertEquals(1.62, valueunit.getValueNum());
                        break;
                    default:
                        break;
                }
            } else if (valueunit.getExtraidentifier().equals(inlet1InletPoleExtraIdentifier + 2)) {
                switch(valueunit.getKey()) {
                    case MetricName.PDU_FREE_CAPACITY:
                        TestCase.assertEquals(5.38, valueunit.getValueNum());
                        break;
                    case MetricName.PDU_VOLTAGE:
                        TestCase.assertEquals(112.1, valueunit.getValueNum());
                        break;
                    case MetricName.PDU_CURRENT:
                        TestCase.assertEquals(3.62, valueunit.getValueNum());
                        break;
                    default:
                        break;
                }
            } else if (valueunit.getExtraidentifier().equals(inlet1InletPoleExtraIdentifier + 3)) {
                switch(valueunit.getKey()) {
                    case MetricName.PDU_FREE_CAPACITY:
                        TestCase.assertEquals(8.38, valueunit.getValueNum());
                        break;
                    case MetricName.PDU_VOLTAGE:
                        TestCase.assertEquals(102.1, valueunit.getValueNum());
                        break;
                    case MetricName.PDU_CURRENT:
                        TestCase.assertEquals(0.62, valueunit.getValueNum());
                        break;
                    default:
                        break;
                }
            } else {
                TestCase.fail();
            }
        } else {
            switch(valueunit.getKey()) {
                case MetricName.PDU_TOTAL_POWER:
                    TestCase.assertEquals(getInlets().get(0).getReading().getApparentPower() / 1000, valueunit.getValueNum());
                    break;
                case MetricName.PDU_TOTAL_CURRENT:
                    TestCase.assertEquals(getInlets().get(0).getReading().getCurrent(), valueunit.getValueNum());
                    break;
                default:
                    TestCase.fail();
                    break;
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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