Search in sources :

Example 16 with ValueUnit

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

the class AssetService method getPduMetricsDataById.

public List<MetricData> getPduMetricsDataById(String assetID, long starttime, int duration) {
    Optional<Asset> pduAssetOptional = assetRepository.findById(assetID);
    if (!pduAssetOptional.isPresent()) {
        return null;
    }
    List<RealTimeData> pduMetricsRealtimeDatas = realtimeDataRepository.getDataByIDAndTimeRange(assetID, starttime, duration);
    List<ValueUnit> valueunits = new ArrayList<>();
    List<String> metricNames = new ArrayList<String>();
    metricNames.add(MetricName.PDU_TOTAL_POWER);
    metricNames.add(MetricName.PDU_APPARENT_POWER);
    metricNames.add(MetricName.PDU_ACTIVE_POWER);
    metricNames.add(MetricName.PDU_CURRENT);
    metricNames.add(MetricName.PDU_VOLTAGE);
    metricNames.add(MetricName.PDU_FREE_CAPACITY);
    metricNames.add(MetricName.PDU_POWER_LOAD);
    metricNames.add(MetricName.PDU_CURRENT_LOAD);
    // pdu metrics data,such as power/current/voltage
    valueunits.addAll(getValueUnits(pduMetricsRealtimeDatas, metricNames));
    Asset pdu = pduAssetOptional.get();
    // sensor metrics data, such as temperature or humidity
    Map<String, String> formulars = pdu.getMetricsformulars();
    String sensorFormulasInfo = formulars.get(FlowgateConstant.SENSOR);
    Map<String, Map<String, String>> sensorFormulasMap = null;
    if (sensorFormulasInfo != null) {
        sensorFormulasMap = pdu.metricsFormulaToMap(sensorFormulasInfo, new TypeReference<Map<String, Map<String, String>>>() {
        });
    }
    if (sensorFormulasMap != null) {
        Map<String, List<RealTimeData>> assetIdAndRealtimeDataMap = new HashMap<String, List<RealTimeData>>();
        Map<String, String> humidityLocationAndIdMap = sensorFormulasMap.get(MetricName.PDU_HUMIDITY);
        if (humidityLocationAndIdMap != null && !humidityLocationAndIdMap.isEmpty()) {
            valueunits.addAll(generateSensorValueUnit(assetIdAndRealtimeDataMap, starttime, duration, humidityLocationAndIdMap, MetricName.PDU_HUMIDITY));
        }
        Map<String, String> temperatureLocationAndIdMap = sensorFormulasMap.get(MetricName.PDU_TEMPERATURE);
        if (temperatureLocationAndIdMap != null && !temperatureLocationAndIdMap.isEmpty()) {
            valueunits.addAll(generateSensorValueUnit(assetIdAndRealtimeDataMap, starttime, duration, temperatureLocationAndIdMap, MetricName.PDU_TEMPERATURE));
        }
    }
    return generateMetricsDataForPDU(valueunits);
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) List(java.util.List) ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) HashMap(java.util.HashMap)

Example 17 with ValueUnit

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

the class AssetService method generateServerPduMetricData.

private List<MetricData> generateServerPduMetricData(List<ValueUnit> valueUnits, String pduAssetId, String outLet) {
    List<MetricData> result = new ArrayList<MetricData>();
    Double serverVoltage = null;
    long serverVoltageReadTime = 0;
    for (ValueUnit value : valueUnits) {
        MetricData data = new MetricData();
        data.setTimeStamp(value.getTime());
        data.setValueNum(value.getValueNum());
        String unit = databaseUnitAndOutputUnitMap.get(value.getUnit());
        if (unit == null) {
            unit = value.getUnit();
        }
        data.setUnit(unit);
        switch(value.getKey()) {
            case MetricName.PDU_TOTAL_POWER:
                data.setMetricName(String.format(MetricKeyName.SERVER_CONNECTED_PDUX_TOTAL_POWER, pduAssetId));
                result.add(data);
                break;
            case MetricName.PDU_APPARENT_POWER:
                String outlet_pdu_power_extraidentifier = value.getExtraidentifier();
                if (outLet.equals(outlet_pdu_power_extraidentifier)) {
                    data.setMetricName(String.format(MetricKeyName.SERVER_CONNECTED_PDUX_OUTLETX_POWER, pduAssetId, value.getExtraidentifier()));
                    result.add(data);
                }
                break;
            case MetricName.PDU_CURRENT:
                String outlet_pdu_current_extraidentifier = value.getExtraidentifier();
                if (outlet_pdu_current_extraidentifier == null) {
                    data.setMetricName(String.format(MetricKeyName.SERVER_CONNECTED_PDUX_TOTAL_CURRENT, pduAssetId));
                    result.add(data);
                } else if (outLet.equals(outlet_pdu_current_extraidentifier)) {
                    data.setMetricName(String.format(MetricKeyName.SERVER_CONNECTED_PDUX_OUTLETX_CURRENT, pduAssetId, value.getExtraidentifier()));
                    result.add(data);
                }
                break;
            case MetricName.PDU_VOLTAGE:
                String extraidentifier = value.getExtraidentifier();
                serverVoltageReadTime = data.getTimeStamp();
                // some pdus without outlet metrics,but have inlet metrics
                if (serverVoltage == null) {
                    serverVoltage = data.getValueNum();
                }
                if (outLet.equals(extraidentifier)) {
                    data.setMetricName(String.format(MetricKeyName.SERVER_CONNECTED_PDUX_OUTLETX_VOLTAGE, pduAssetId, value.getExtraidentifier()));
                    result.add(data);
                    serverVoltage = data.getValueNum();
                }
                break;
            case MetricName.PDU_POWER_LOAD:
                data.setMetricName(String.format(MetricKeyName.SERVER_CONNECTED_PDUX_POWER_LOAD, pduAssetId));
                result.add(data);
                break;
            case MetricName.PDU_CURRENT_LOAD:
                data.setMetricName(String.format(MetricKeyName.SERVER_CONNECTED_PDUX_CURRENT_LOAD, pduAssetId));
                result.add(data);
                break;
            default:
                break;
        }
    }
    if (serverVoltage != null) {
        MetricData data = new MetricData();
        data.setMetricName(MetricName.SERVER_VOLTAGE);
        data.setTimeStamp(serverVoltageReadTime);
        data.setValueNum(serverVoltage);
        data.setUnit(MetricUnit.V.toString());
        result.add(data);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) MetricData(com.vmware.flowgate.common.model.MetricData)

Example 18 with ValueUnit

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

the class AssetService method findLatestMetricDataByAssetValueUnitMap.

private Map<String, List<ValueUnit>> findLatestMetricDataByAssetValueUnitMap(Map<String, List<ValueUnit>> assetValueUnitMap) {
    Map<String, List<ValueUnit>> latestAssetValueUnitsMap = new HashMap<>();
    if (assetValueUnitMap == null || assetValueUnitMap.isEmpty()) {
        return latestAssetValueUnitsMap;
    }
    Map<String, Long> intervalMetricNames = new HashMap<>();
    intervalMetricNames.put(MetricName.SERVER_AVERAGE_USED_POWER, 0L);
    intervalMetricNames.put(MetricName.SERVER_AVERAGE_TEMPERATURE, 0L);
    intervalMetricNames.put(MetricName.SERVER_ENERGY_CONSUMPTION, 0L);
    Set<String> peakMetricNames = new HashSet<>();
    peakMetricNames.add(MetricName.SERVER_PEAK_USED_POWER);
    peakMetricNames.add(MetricName.SERVER_PEAK_TEMPERATURE);
    Set<String> minimumMetricNames = new HashSet<>();
    minimumMetricNames.add(MetricName.SERVER_MINIMUM_USED_POWER);
    for (Map.Entry<String, List<ValueUnit>> entry : assetValueUnitMap.entrySet()) {
        Map<String, ValueUnit> latestValueUnitMap = new HashMap<>();
        for (ValueUnit valueUnit : entry.getValue()) {
            ValueUnit latestValueUnit;
            if (intervalMetricNames.containsKey(valueUnit.getKey()) || peakMetricNames.contains(valueUnit.getKey()) || minimumMetricNames.contains(valueUnit.getKey())) {
                latestValueUnit = latestValueUnitMap.get(valueUnit.getKey());
                if (latestValueUnit == null) {
                    latestValueUnitMap.put(valueUnit.getKey(), valueUnit);
                    continue;
                }
                if (intervalMetricNames.containsKey(valueUnit.getKey())) {
                    long maxInterval = intervalMetricNames.get(valueUnit.getKey());
                    long currentInterval = valueUnit.getTime() - Long.parseLong(valueUnit.getExtraidentifier());
                    if (currentInterval > maxInterval) {
                        intervalMetricNames.put(valueUnit.getKey(), currentInterval);
                        latestValueUnitMap.put(valueUnit.getKey(), valueUnit);
                    }
                } else if (peakMetricNames.contains(valueUnit.getKey())) {
                    if (valueUnit.getValueNum() > latestValueUnit.getValueNum()) {
                        latestValueUnitMap.put(valueUnit.getKey(), valueUnit);
                    }
                } else if (minimumMetricNames.contains(valueUnit.getKey())) {
                    if (valueUnit.getValueNum() < latestValueUnit.getValueNum()) {
                        latestValueUnitMap.put(valueUnit.getKey(), valueUnit);
                    }
                }
            } else {
                String key = valueUnit.getKey();
                String extraIdentifier = valueUnit.getExtraidentifier();
                latestValueUnit = latestValueUnitMap.get(key + extraIdentifier);
                if (latestValueUnit == null) {
                    latestValueUnitMap.put(key + extraIdentifier, valueUnit);
                    continue;
                }
                if (valueUnit.getTime() > latestValueUnit.getTime()) {
                    latestValueUnitMap.put(key + extraIdentifier, valueUnit);
                }
            }
        }
        latestAssetValueUnitsMap.put(entry.getKey(), new ArrayList<>(latestValueUnitMap.values()));
    }
    return latestAssetValueUnitsMap;
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 19 with ValueUnit

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

the class AssetService method translateToMetricDataForPDU.

private List<MetricData> translateToMetricDataForPDU(Map<String, List<ValueUnit>> assetAndValueUnitsMap, Asset pdu) {
    List<MetricData> metricDatas = new ArrayList<MetricData>();
    Map<String, Map<String, String>> displayNameAndFormulasMap = getMetricDispalyNameAndFormulaMapForPDU(pdu);
    if (displayNameAndFormulasMap.isEmpty() || !displayNameAndFormulasMap.containsKey(DISPLAYNAMEANDFORMULANAMEMAPKEY)) {
        return metricDatas;
    }
    // The displayNameAndFormulaKeyMap use to find a method to translate the valueUnit to MetricData
    Map<String, String> displayNameAndFormulaKeyMap = displayNameAndFormulasMap.get(DISPLAYNAMEANDFORMULANAMEMAPKEY);
    displayNameAndFormulasMap.remove(DISPLAYNAMEANDFORMULANAMEMAPKEY);
    CompareValueUnitByTime comparator = new CompareValueUnitByTime();
    for (Map.Entry<String, Map<String, String>> displayNameAndFormulaEntry : displayNameAndFormulasMap.entrySet()) {
        String displayName = displayNameAndFormulaEntry.getKey();
        // Key:MetricName Value:Formula
        Map<String, String> valueUnitNameAndFormulaMap = displayNameAndFormulaEntry.getValue();
        for (Map.Entry<String, String> valueUnitNameAndFormula : valueUnitNameAndFormulaMap.entrySet()) {
            String valueUnitName = valueUnitNameAndFormula.getKey();
            String formula = valueUnitNameAndFormula.getValue();
            String[] ids = formula.split("\\+|-|\\*|/|\\(|\\)");
            Map<String, List<ValueUnit>> idAndValues = new HashMap<>();
            for (String id : ids) {
                List<ValueUnit> valueUnits = new ArrayList<ValueUnit>();
                for (ValueUnit valueUnit : assetAndValueUnitsMap.get(id)) {
                    if (!valueUnitName.equals(valueUnit.getKey())) {
                        continue;
                    }
                    String extraidentifier = valueUnit.getExtraidentifier();
                    String[] extraInfo = null;
                    if (extraidentifier != null) {
                        extraInfo = extraidentifier.split("\\" + FlowgateConstant.INLET_POLE_NAME_PREFIX);
                    }
                    switch(displayName) {
                        // Current
                        case MetricName.PDU_CURRENT:
                        case MetricName.PDU_VOLTAGE:
                            if (extraidentifier == null) {
                                valueUnits.add(valueUnit);
                            }
                            break;
                        // %s|%s|Current
                        case MetricName.PDU_INLET_XPOLE_CURRENT:
                        case MetricName.PDU_INLET_XPOLE_VOLTAGE:
                        case MetricName.PDU_INLET_XPOLE_FREE_CAPACITY:
                            if (extraInfo != null && extraInfo.length == 2) {
                                valueUnits.add(valueUnit);
                            }
                            break;
                        // %s|Current
                        case MetricName.PDU_XLET_CURRENT:
                        case MetricName.PDU_XLET_VOLTAGE:
                        case MetricName.PDU_XLET_FREE_CAPACITY:
                            if (extraInfo != null && extraInfo.length == 1) {
                                valueUnits.add(valueUnit);
                            }
                            break;
                        default:
                            valueUnits.add(valueUnit);
                            break;
                    }
                }
                if (valueUnits.isEmpty()) {
                    continue;
                }
                Collections.sort(valueUnits, comparator);
                idAndValues.put(id, valueUnits);
            }
            if (!idAndValues.isEmpty()) {
                Function<TranslateContext, MetricData> function = TranslateFunctionService.convert;
                String formulaKey = displayNameAndFormulaKeyMap.get(displayName);
                if (TranslateFunctionService.pduFormulaKeyAndFunction.containsKey(formulaKey)) {
                    function = TranslateFunctionService.pduFormulaKeyAndFunction.get(formulaKey);
                }
                metricDatas.addAll(convertValueUnitToMetricData(displayName, function, formula, idAndValues));
            }
        }
    }
    return metricDatas;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TranslateContext(com.vmware.flowgate.common.model.TranslateContext) List(java.util.List) ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) Map(java.util.Map) HashMap(java.util.HashMap) MetricData(com.vmware.flowgate.common.model.MetricData)

Example 20 with ValueUnit

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

the class AssetService method generateServerSensorMetricData.

private List<MetricData> generateServerSensorMetricData(List<ValueUnit> valueUnits, String metricName) {
    List<MetricData> result = new ArrayList<MetricData>();
    if (valueUnits == null || valueUnits.isEmpty()) {
        return result;
    }
    for (ValueUnit value : valueUnits) {
        MetricData data = new MetricData();
        data.setTimeStamp(value.getTime());
        data.setValueNum(value.getValueNum());
        String unit = databaseUnitAndOutputUnitMap.get(value.getUnit());
        if (unit == null) {
            unit = value.getUnit();
        }
        data.setUnit(unit);
        switch(value.getKey()) {
            case MetricName.HUMIDITY:
                switch(metricName) {
                    case MetricName.SERVER_BACK_HUMIDITY:
                        data.setMetricName(String.format(MetricKeyName.SERVER_BACK_HUMIDITY_LOCATIONX, value.getExtraidentifier()));
                        result.add(data);
                        break;
                    case MetricName.SERVER_FRONT_HUMIDITY:
                        data.setMetricName(String.format(MetricKeyName.SERVER_FRONT_HUMIDITY_LOCATIONX, value.getExtraidentifier()));
                        result.add(data);
                        break;
                    default:
                        break;
                }
                break;
            case MetricName.TEMPERATURE:
                switch(metricName) {
                    case MetricName.SERVER_BACK_TEMPREATURE:
                        data.setMetricName(String.format(MetricKeyName.SERVER_BACK_TEMPREATURE_LOCATIONX, value.getExtraidentifier()));
                        result.add(data);
                        break;
                    case MetricName.SERVER_FRONT_TEMPERATURE:
                        data.setMetricName(String.format(MetricKeyName.SERVER_FRONT_TEMPERATURE_LOCATIONX, value.getExtraidentifier()));
                        result.add(data);
                        break;
                    default:
                        break;
                }
                break;
            default:
                break;
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) MetricData(com.vmware.flowgate.common.model.MetricData)

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