Search in sources :

Example 21 with ValueUnit

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

the class AssetService method generateSensorValueUnit.

private List<ValueUnit> generateSensorValueUnit(Map<String, List<RealTimeData>> assetIdAndRealtimeDataMap, long starttime, int duration, Map<String, String> locationAndIdMap, String metricName) {
    List<ValueUnit> valueunits = new ArrayList<>();
    for (Map.Entry<String, String> locationInfoAndId : locationAndIdMap.entrySet()) {
        String formula = locationInfoAndId.getValue();
        String location = locationInfoAndId.getKey();
        String[] ids = formula.split("\\+|-|\\*|/|\\(|\\)");
        for (String assetId : ids) {
            List<RealTimeData> realtimeDatas = null;
            if (!assetIdAndRealtimeDataMap.containsKey(assetId)) {
                realtimeDatas = realtimeDataRepository.getDataByIDAndTimeRange(assetId, starttime, duration);
                assetIdAndRealtimeDataMap.put(assetId, realtimeDatas);
            }
            realtimeDatas = assetIdAndRealtimeDataMap.get(assetId);
            if (realtimeDatas == null || realtimeDatas.isEmpty()) {
                continue;
            }
            RealTimeData realTimeData = findLatestData(realtimeDatas);
            for (ValueUnit value : realTimeData.getValues()) {
                if (value.getKey().equals(metricNameMap.get(metricName))) {
                    if (location.indexOf(FlowgateConstant.SEPARATOR) > -1) {
                        location = location.replace(FlowgateConstant.SEPARATOR, FlowgateConstant.UNDERLINE);
                    }
                    value.setExtraidentifier(location);
                    valueunits.add(value);
                }
            }
        }
    }
    return valueunits;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) Map(java.util.Map) HashMap(java.util.HashMap)

Example 22 with ValueUnit

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

the class AssetService method generateOtherMetricData.

private List<MetricData> generateOtherMetricData(List<ValueUnit> valueUnits) {
    List<MetricData> result = new ArrayList<>();
    if (valueUnits == null || valueUnits.isEmpty()) {
        return result;
    }
    MetricData data;
    for (ValueUnit value : valueUnits) {
        data = new MetricData();
        data.setTimeStamp(value.getTime());
        data.setValueNum(value.getValueNum());
        data.setValue(value.getValue());
        data.setMetricName(value.getKey());
        String unit = databaseUnitAndOutputUnitMap.get(value.getUnit());
        if (unit == null) {
            unit = value.getUnit();
        }
        data.setUnit(unit);
        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 23 with ValueUnit

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

the class AssetService method translateToMetricDataForOtherAsset.

private List<MetricData> translateToMetricDataForOtherAsset(Map<String, List<ValueUnit>> assetAndValueUnitsMap, Asset asset) {
    List<MetricData> metricDatas = new ArrayList<MetricData>();
    Map<String, Map<String, String>> displayNameAndFormulasMap = getMetricDispalyNameAndFormulaMap(asset);
    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>> entry : displayNameAndFormulasMap.entrySet()) {
        String displayName = entry.getKey();
        Map<String, String> formulaMap = entry.getValue();
        for (Map.Entry<String, String> formulaEntry : formulaMap.entrySet()) {
            String valueUnitName = formulaEntry.getKey();
            String formula = formulaEntry.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;
                    }
                    valueUnits.add(valueUnit);
                }
                if (valueUnits.isEmpty()) {
                    continue;
                }
                Collections.sort(valueUnits, comparator);
                idAndValues.put(id, valueUnits);
            }
            if (idAndValues.isEmpty()) {
                continue;
            }
            Function<TranslateContext, MetricData> function = TranslateFunctionService.convert;
            String formulaKey = displayNameAndFormulaKeyMap.get(displayName);
            if (TranslateFunctionService.defaultFormulaKeyAndFunction.containsKey(formulaKey)) {
                function = TranslateFunctionService.defaultFormulaKeyAndFunction.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 24 with ValueUnit

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

the class AssetService method getValueUnits.

private List<ValueUnit> getValueUnits(List<RealTimeData> realtimeDatas, List<String> metricsName) {
    List<ValueUnit> valueunits = new ArrayList<>();
    if (realtimeDatas == null || realtimeDatas.isEmpty()) {
        return valueunits;
    }
    RealTimeData realTimeData = findLatestData(realtimeDatas);
    for (ValueUnit value : realTimeData.getValues()) {
        if (metricsName.contains(value.getKey())) {
            valueunits.add(value);
        }
    }
    return valueunits;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit)

Example 25 with ValueUnit

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

the class AssetService method convertValueUnitToMetricData.

/**
 * Sample of TranslateContext
 * {
 *    DisplayName:"Temperature|%S",
 *    Formulas:"23551d6dacf2432c8a3edbc6bbc922cd + 123456",
 *    valueData:[{id,valueUnit}]
 * }
 * One displayName may correspond to one or multiple values
 * When the API of get-latest-data use the method, One MetricName correspond one value
 * When the API of get-duration-data use the method, One MetricName correspond multiple values
 * @param displayName
 * @param formula
 * @param idAndValues
 * @return
 */
private List<MetricData> convertValueUnitToMetricData(String displayName, Function<TranslateContext, MetricData> function, String formula, Map<String, List<ValueUnit>> idAndValues) {
    List<ValueUnit> valueUnits = idAndValues.get(idAndValues.keySet().iterator().next());
    Map<String, ValueUnit> idAndValueUnitMap = null;
    // Assuming the collection length is the same
    List<MetricData> metricDatas = new ArrayList<MetricData>();
    for (int i = 0; i < valueUnits.size(); i++) {
        // Sample data: <id1, valueUnit1>,<id2, valueUnit1>
        idAndValueUnitMap = new HashMap<String, ValueUnit>();
        TranslateContext translateContext = new TranslateContext();
        for (Map.Entry<String, List<ValueUnit>> valuesEntry : idAndValues.entrySet()) {
            String id = valuesEntry.getKey();
            ValueUnit value = valuesEntry.getValue().get(i);
            idAndValueUnitMap.put(id, value);
        }
        translateContext.setDisplayName(displayName);
        translateContext.setFormula(formula);
        translateContext.setValueUnits(idAndValueUnitMap);
        MetricData metricData = function.apply(translateContext);
        if (metricData != null) {
            metricDatas.add(metricData);
        }
    }
    return metricDatas;
}
Also used : 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)

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