Search in sources :

Example 46 with RealTimeData

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

the class AssetService method getValueUnitsByAssetID.

private List<ValueUnit> getValueUnitsByAssetID(String assetID, long starttime, int duration) {
    List<RealTimeData> realtimeDatas = realtimeDataRepository.getDataByIDAndTimeRange(assetID, starttime, duration);
    List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
    if (realtimeDatas.isEmpty()) {
        return valueunits;
    }
    for (RealTimeData realTimeData : realtimeDatas) {
        for (ValueUnit value : realTimeData.getValues()) {
            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 47 with RealTimeData

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

the class AssetService method getServerMetricsDataById.

public List<MetricData> getServerMetricsDataById(String assetID, long starttime, int duration) {
    Optional<Asset> serverAssetOptional = assetRepository.findById(assetID);
    if (!serverAssetOptional.isPresent()) {
        throw WormholeRequestException.NotFound("asset", "id", assetID);
    }
    Asset server = serverAssetOptional.get();
    List<MetricData> result = new ArrayList<MetricData>();
    Map<String, String> metricFormula = server.getMetricsformulars();
    if (metricFormula == null || metricFormula.isEmpty()) {
        return result;
    }
    result.addAll(getServerHostMetric(server, starttime, duration));
    Map<String, String> justficationfileds = server.getJustificationfields();
    String allPduPortInfo = justficationfileds.get(FlowgateConstant.PDU_PORT_FOR_SERVER);
    List<String> pduPorts = null;
    Map<String, String> pduAssetIdAndUsedOutletMap = null;
    if (!StringUtils.isEmpty(allPduPortInfo)) {
        pduPorts = Arrays.asList(allPduPortInfo.split(FlowgateConstant.SPILIT_FLAG));
        pduAssetIdAndUsedOutletMap = new HashMap<String, String>();
        for (String pduPortInfo : pduPorts) {
            // startport_FIELDSPLIT_endDeviceName_FIELDSPLIT_endport_FIELDSPLIT_endDeviceAssetID
            // item[0] start port
            // item[1] device name
            // item[2] end port
            // itme[3] assetid
            String[] items = pduPortInfo.split(FlowgateConstant.SEPARATOR);
            pduAssetIdAndUsedOutletMap.put(items[3], items[2]);
        }
    }
    String pduFormulasInfo = metricFormula.get(FlowgateConstant.PDU);
    if (pduFormulasInfo != null) {
        Map<String, Map<String, String>> pduMetrics = server.metricsFormulaToMap(pduFormulasInfo, new TypeReference<Map<String, Map<String, String>>>() {
        });
        List<String> metricNames = new ArrayList<String>();
        metricNames.add(MetricName.PDU_TOTAL_POWER);
        metricNames.add(MetricName.PDU_APPARENT_POWER);
        metricNames.add(MetricName.PDU_CURRENT);
        metricNames.add(MetricName.PDU_VOLTAGE);
        metricNames.add(MetricName.PDU_POWER_LOAD);
        metricNames.add(MetricName.PDU_CURRENT_LOAD);
        for (String pduId : pduMetrics.keySet()) {
            List<RealTimeData> realtimedatas = realtimeDataRepository.getDataByIDAndTimeRange(pduId, starttime, duration);
            List<ValueUnit> valueUnits = getValueUnits(realtimedatas, metricNames);
            String outlet = UnknownOulet;
            if (pduAssetIdAndUsedOutletMap != null) {
                outlet = pduAssetIdAndUsedOutletMap.get(pduId);
            }
            result.addAll(generateServerPduMetricData(valueUnits, pduId, outlet));
        }
    }
    String sensorFormulasInfo = metricFormula.get(FlowgateConstant.SENSOR);
    if (sensorFormulasInfo != null) {
        Map<String, Map<String, String>> sensorFormulars = server.metricsFormulaToMap(sensorFormulasInfo, new TypeReference<Map<String, Map<String, String>>>() {
        });
        Map<String, List<RealTimeData>> assetIdAndRealtimeDataMap = new HashMap<String, List<RealTimeData>>();
        for (Map.Entry<String, Map<String, String>> sensorFormula : sensorFormulars.entrySet()) {
            Map<String, String> locationAndIdMap = sensorFormula.getValue();
            String metricName = sensorFormula.getKey();
            List<ValueUnit> valueUnits = generateSensorValueUnit(assetIdAndRealtimeDataMap, starttime, duration, locationAndIdMap, metricName);
            result.addAll(generateServerSensorMetricData(valueUnits, metricName));
        }
    }
    return result;
}
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) Map(java.util.Map) HashMap(java.util.HashMap) MetricData(com.vmware.flowgate.common.model.MetricData)

Example 48 with RealTimeData

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

the class AssetService method getOtherMetricsDataById.

private List<MetricData> getOtherMetricsDataById(String assetID, Long starttime, Integer duration) {
    List<MetricData> metricDataList = new ArrayList<>();
    List<RealTimeData> realTimeData = realtimeDataRepository.getDataByIDAndTimeRange(assetID, starttime, duration);
    if (realTimeData == null || realTimeData.isEmpty()) {
        return metricDataList;
    }
    RealTimeData latestData = findLatestData(realTimeData);
    List<ValueUnit> latestDataValues = latestData.getValues();
    if (latestDataValues == null || latestDataValues.isEmpty()) {
        return metricDataList;
    }
    metricDataList.addAll(generateOtherMetricData(latestDataValues));
    return metricDataList;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) MetricData(com.vmware.flowgate.common.model.MetricData)

Example 49 with RealTimeData

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

the class AssetService method getServerHostMetric.

private List<MetricData> getServerHostMetric(Asset server, long starttime, int duration) {
    List<MetricData> metricDataList = Lists.newArrayList();
    String hostMetricsFormulaString = server.getMetricsformulars().get(FlowgateConstant.HOST_METRICS);
    if (StringUtils.isBlank(hostMetricsFormulaString)) {
        return metricDataList;
    }
    Map<String, String> hostMetricsFormula = server.metricsFormulaToMap(hostMetricsFormulaString, new TypeReference<Map<String, String>>() {
    });
    if (hostMetricsFormula == null || hostMetricsFormula.isEmpty()) {
        return metricDataList;
    }
    Map<String, List<String>> assetIdAndMetricsNameList = Maps.newHashMap();
    for (Map.Entry<String, String> itemEntry : hostMetricsFormula.entrySet()) {
        List<String> metricsNameList = assetIdAndMetricsNameList.computeIfAbsent(itemEntry.getValue(), k -> Lists.newArrayList());
        metricsNameList.add(itemEntry.getKey());
    }
    Map<String, List<RealTimeData>> realtimeDataMap = Maps.newHashMap();
    for (Map.Entry<String, List<String>> entry : assetIdAndMetricsNameList.entrySet()) {
        realtimeDataMap.put(entry.getKey(), realtimeDataRepository.getDataByIDAndTimeRange(entry.getKey(), 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_ENERGY_CONSUMPTION);
    specialMetricNames.add(MetricName.SERVER_AVERAGE_TEMPERATURE);
    specialMetricNames.add(MetricName.SERVER_PEAK_TEMPERATURE);
    MetricData metricData;
    for (Map.Entry<String, List<RealTimeData>> realtimeDataEntry : realtimeDataMap.entrySet()) {
        List<String> metricsNameList = assetIdAndMetricsNameList.get(realtimeDataEntry.getKey());
        for (RealTimeData realTimeData : realtimeDataEntry.getValue()) {
            for (ValueUnit valueUnit : realTimeData.getValues()) {
                if (metricsNameList.contains(valueUnit.getKey())) {
                    metricData = new MetricData();
                    long timestamp = 0l;
                    String metricName = valueUnit.getKey();
                    String extraInfo = valueUnit.getExtraidentifier();
                    if (extraInfo == null && specialMetricNames.contains(metricName)) {
                        logger.error("The value of {} is invalid,RealtimeData Id: {}", metricName, realTimeData.getId());
                        continue;
                    }
                    switch(metricName) {
                        case MetricName.SERVER_AVERAGE_USED_POWER:
                            // Time of AvgPower is since time
                            timestamp = Long.valueOf(extraInfo);
                            break;
                        case MetricName.SERVER_PEAK_USED_POWER:
                            String[] sinceTimeAndPeakTime = extraInfo.split(FlowgateConstant.SEPARATOR);
                            if (sinceTimeAndPeakTime.length < TIMESTAMPARRAYLENGTH) {
                                logger.error("The extraInfo of {} is invalid,RealtimeData Id: {}", metricName, realTimeData.getId());
                                continue;
                            }
                            // Time of PeakPower is peakPower time
                            timestamp = Long.valueOf(sinceTimeAndPeakTime[1]);
                            break;
                        case MetricName.SERVER_MINIMUM_USED_POWER:
                            String[] sinceTimeAndMinimumTime = extraInfo.split(FlowgateConstant.SEPARATOR);
                            if (sinceTimeAndMinimumTime.length < TIMESTAMPARRAYLENGTH) {
                                logger.error("The extraInfo of {} is invalid,RealtimeData Id: {}", metricName, realTimeData.getId());
                                continue;
                            }
                            // Time of MinimumPower is minimumPower time
                            timestamp = Long.valueOf(sinceTimeAndMinimumTime[1]);
                            break;
                        case MetricName.SERVER_ENERGY_CONSUMPTION:
                            // Time of energy consumption is since time
                            timestamp = Long.valueOf(extraInfo);
                            break;
                        case MetricName.SERVER_AVERAGE_TEMPERATURE:
                            // Time of average temperature is since time
                            timestamp = Long.valueOf(extraInfo);
                            break;
                        case MetricName.SERVER_PEAK_TEMPERATURE:
                            // Time of energy consumption is since time
                            String[] temperatureSinceTimeAndPeakTime = extraInfo.split(FlowgateConstant.SEPARATOR);
                            if (temperatureSinceTimeAndPeakTime.length < TIMESTAMPARRAYLENGTH) {
                                logger.error("The extraInfo of {} is invalid,RealtimeData Id: {}", metricName, realTimeData.getId());
                                continue;
                            }
                            // Time of PeakTemperature is peak time
                            timestamp = Long.valueOf(temperatureSinceTimeAndPeakTime[1]);
                            break;
                        default:
                            // Time of other host metric is valueUnit current time
                            timestamp = valueUnit.getTime();
                            break;
                    }
                    metricData.setMetricName(valueUnit.getKey());
                    metricData.setTimeStamp(timestamp);
                    metricData.setValue(valueUnit.getValue());
                    metricData.setValueNum(valueUnit.getValueNum());
                    // This kind of logic will be deprecated in next version
                    String unit = databaseUnitAndOutputUnitMap.get(valueUnit.getUnit());
                    if (unit == null) {
                        unit = valueUnit.getUnit();
                    }
                    metricData.setUnit(unit);
                    metricDataList.add(metricData);
                }
            }
        }
    }
    return metricDataList;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) 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) HashSet(java.util.HashSet)

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