Search in sources :

Example 1 with Outlet

use of com.vmware.flowgate.poweriqworker.model.Outlet in project flowgate by vmware.

the class SyncPduAssetJobTest method getOutlets.

List<Outlet> getOutlets() {
    Outlet outlet = new Outlet();
    List<Outlet> outlets = new ArrayList<Outlet>();
    outlet.setId(12L);
    outlet.setName("Outlet1");
    outlet.setOrdinal(1L);
    outlet.setPduId(128L);
    outlet.setRatedAmps(10.2);
    OutletReading reading = new OutletReading();
    reading.setCurrent(24.2);
    reading.setApparentPower(29.0);
    reading.setVoltage(200.0);
    reading.setReadingTime("2018/10/18 05:57:26 +0300");
    reading.setActivePower(27.6);
    reading.setUnutilizedCapacity(15.2);
    outlet.setReading(reading);
    outlets.add(outlet);
    return outlets;
}
Also used : Outlet(com.vmware.flowgate.poweriqworker.model.Outlet) ArrayList(java.util.ArrayList) OutletReading(com.vmware.flowgate.poweriqworker.model.OutletReading)

Example 2 with Outlet

use of com.vmware.flowgate.poweriqworker.model.Outlet in project flowgate by vmware.

the class SyncRealTimeDataJobTest method getOutlets.

List<Outlet> getOutlets() {
    Outlet outlet = new Outlet();
    List<Outlet> outlets = new ArrayList<Outlet>();
    outlet.setId(12L);
    outlet.setName("Outlet1");
    outlet.setOrdinal(1L);
    outlet.setPduId(128L);
    outlet.setRatedAmps(10.2);
    OutletReading reading = new OutletReading();
    reading.setCurrent(24.2);
    reading.setApparentPower(29.0);
    reading.setVoltage(200.0);
    reading.setReadingTime("2018/10/18 05:57:26 +0300");
    reading.setActivePower(27.6);
    reading.setUnutilizedCapacity(15.2);
    outlet.setReading(reading);
    outlets.add(outlet);
    return outlets;
}
Also used : Outlet(com.vmware.flowgate.poweriqworker.model.Outlet) ArrayList(java.util.ArrayList) OutletReading(com.vmware.flowgate.poweriqworker.model.OutletReading)

Example 3 with Outlet

use of com.vmware.flowgate.poweriqworker.model.Outlet in project flowgate by vmware.

the class PowerIQService method generatePduOutletString.

private String generatePduOutletString(List<Outlet> pduOutlets) throws JsonProcessingException {
    List<PduOutlet> outletsSaveToFlowgate = new ArrayList<PduOutlet>();
    for (Outlet outlet : pduOutlets) {
        PduOutlet pduoutlet = new PduOutlet();
        pduoutlet.setDeviceId(outlet.getDeviceId());
        pduoutlet.setId(outlet.getId());
        pduoutlet.setName(outlet.getName());
        pduoutlet.setOrdinal(outlet.getOrdinal());
        pduoutlet.setPduId(outlet.getPduId());
        pduoutlet.setRatedAmps(outlet.getRatedAmps());
        pduoutlet.setState(outlet.getState());
        pduoutlet.setFormatedName(FlowgateConstant.OUTLET_NAME_PREFIX + outlet.getOrdinal());
        outletsSaveToFlowgate.add(pduoutlet);
    }
    return mapper.writeValueAsString(outletsSaveToFlowgate);
}
Also used : ArrayList(java.util.ArrayList) PduOutlet(com.vmware.flowgate.common.model.PduOutlet) Outlet(com.vmware.flowgate.poweriqworker.model.Outlet) PduOutlet(com.vmware.flowgate.common.model.PduOutlet)

Example 4 with Outlet

use of com.vmware.flowgate.poweriqworker.model.Outlet in project flowgate by vmware.

the class PowerIQService method getValueUnits.

public List<ValueUnit> getValueUnits(Map<String, String> pduInfoFromPowerIQ, PowerIQAPIClient client, HashMap<AdvanceSettingType, String> advanceSettingMap) {
    List<ValueUnit> values = new ArrayList<ValueUnit>();
    Long pduId = Long.parseLong(pduInfoFromPowerIQ.get(FlowgateConstant.PDU_ID_FROM_POWERIQ));
    List<Outlet> outlets = client.getOutlets(pduId);
    Pdu pdu = client.getPduByID(pduId);
    if (outlets.isEmpty() && pdu.getReading() == null) {
        return values;
    }
    String dateFormat = advanceSettingMap.get(AdvanceSettingType.DateFormat);
    String timezone = advanceSettingMap.get(AdvanceSettingType.TimeZone);
    String PDU_AMPS_UNIT = advanceSettingMap.get(AdvanceSettingType.PDU_AMPS_UNIT);
    String PDU_POWER_UNIT = advanceSettingMap.get(AdvanceSettingType.PDU_POWER_UNIT);
    String PDU_VOLT_UNIT = advanceSettingMap.get(AdvanceSettingType.PDU_VOLT_UNIT);
    if (PDU_AMPS_UNIT == null) {
        // By default the Current unit in powerIQ is Amps.
        PDU_AMPS_UNIT = POWERIQ_CURRENT_UNIT;
    }
    if (PDU_POWER_UNIT == null) {
        // By default the active_power unit in powerIQ is watt.
        PDU_POWER_UNIT = POWERIQ_POWER_UNIT;
    }
    if (PDU_VOLT_UNIT == null) {
        // By default the voltage unit in powerIQ is volt.
        PDU_VOLT_UNIT = POWERIQ_VOLTAGE_UNIT;
    }
    double inlteTotalPower = 0.0;
    double inletTotalCurrent = 0.0;
    double inletVoltage = 0.0;
    Reading pduReading = pdu.getReading();
    List<InletReading> inletReadings = null;
    List<InletPoleReading> inletPoleReadings = null;
    if (pduReading != null) {
        inletReadings = pduReading.getInletReadings();
        inletPoleReadings = pduReading.getInletPoleReadings();
    }
    if (inletReadings != null && !inletReadings.isEmpty()) {
        String time = null;
        for (InletReading inletReading : inletReadings) {
            time = inletReading.getReadingTime();
            if (time != null) {
                break;
            }
        }
        long valueTime = -1;
        if (time != null) {
            valueTime = WormholeDateFormat.getLongTime(time, dateFormat, timezone);
        }
        if (valueTime == -1) {
            logger.error("Failed to translate the time string: " + time + ".And the dateformat is " + dateFormat);
        } else {
            for (InletReading reading : inletReadings) {
                String extraIdentifier = FlowgateConstant.INLET_NAME_PREFIX + reading.getInletOrdinal();
                Double voltage = reading.getVoltage();
                if (voltage != null) {
                    ValueUnit voltageValue = new ValueUnit();
                    voltageValue.setExtraidentifier(extraIdentifier);
                    voltageValue.setKey(MetricName.PDU_VOLTAGE);
                    voltageValue.setTime(valueTime);
                    voltageValue.setValueNum(voltageValue.translateUnit(voltage, MetricUnit.valueOf(PDU_VOLT_UNIT), MetricUnit.V));
                    voltageValue.setUnit(MetricUnit.V.toString());
                    values.add(voltageValue);
                    inletVoltage = voltageValue.getValueNum();
                }
                Double current = reading.getCurrent();
                if (current != null) {
                    ValueUnit currentValue = new ValueUnit();
                    currentValue.setExtraidentifier(extraIdentifier);
                    currentValue.setKey(MetricName.PDU_CURRENT);
                    currentValue.setTime(valueTime);
                    currentValue.setValueNum(currentValue.translateUnit(current, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
                    currentValue.setUnit(MetricUnit.A.toString());
                    values.add(currentValue);
                    inletTotalCurrent += currentValue.getValueNum();
                }
                Double activePower = reading.getActivePower();
                if (activePower != null) {
                    ValueUnit activePowerValue = new ValueUnit();
                    activePowerValue.setExtraidentifier(extraIdentifier);
                    activePowerValue.setKey(MetricName.PDU_ACTIVE_POWER);
                    activePowerValue.setTime(valueTime);
                    activePowerValue.setValueNum(activePowerValue.translateUnit(activePower, MetricUnit.valueOf(PDU_POWER_UNIT), MetricUnit.kW));
                    activePowerValue.setUnit(MetricUnit.kW.toString());
                    values.add(activePowerValue);
                }
                Double apparentPower = reading.getApparentPower();
                if (apparentPower != null) {
                    ValueUnit apparentPowerValue = new ValueUnit();
                    apparentPowerValue.setExtraidentifier(extraIdentifier);
                    apparentPowerValue.setKey(MetricName.PDU_APPARENT_POWER);
                    apparentPowerValue.setTime(valueTime);
                    apparentPowerValue.setValueNum(apparentPowerValue.translateUnit(apparentPower, MetricUnit.valueOf(PDU_POWER_UNIT), MetricUnit.kW));
                    apparentPowerValue.setUnit(MetricUnit.kW.toString());
                    values.add(apparentPowerValue);
                    inlteTotalPower += apparentPowerValue.getValueNum();
                }
                Double freeCapacity = reading.getUnutilizedCapacity();
                if (freeCapacity != null) {
                    ValueUnit freeCapacityValue = new ValueUnit();
                    freeCapacityValue.setExtraidentifier(extraIdentifier);
                    freeCapacityValue.setKey(MetricName.PDU_FREE_CAPACITY);
                    freeCapacityValue.setTime(valueTime);
                    freeCapacityValue.setValueNum(freeCapacityValue.translateUnit(freeCapacity, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
                    freeCapacityValue.setUnit(MetricUnit.A.toString());
                    values.add(freeCapacityValue);
                }
            }
            ValueUnit total_current = new ValueUnit();
            total_current.setKey(MetricName.PDU_TOTAL_CURRENT);
            total_current.setTime(valueTime);
            total_current.setUnit(MetricUnit.A.toString());
            total_current.setValueNum(inletTotalCurrent);
            values.add(total_current);
            ValueUnit total_power = new ValueUnit();
            total_power.setKey(MetricName.PDU_TOTAL_POWER);
            total_power.setTime(valueTime);
            total_power.setUnit(MetricUnit.kW.toString());
            total_power.setValueNum(inlteTotalPower);
            values.add(total_power);
        }
    }
    if (inletPoleReadings != null && !inletPoleReadings.isEmpty()) {
        String inletPoleReadingTime = null;
        for (InletPoleReading inletPoleReading : inletPoleReadings) {
            inletPoleReadingTime = inletPoleReading.getReadingTime();
            if (inletPoleReadingTime != null) {
                break;
            }
        }
        long valueTime = -1;
        if (inletPoleReadingTime != null) {
            valueTime = WormholeDateFormat.getLongTime(inletPoleReadingTime, dateFormat, timezone);
        }
        if (valueTime == -1) {
            logger.error("Failed to translate the time string: " + inletPoleReadingTime + ".And the dateformat is " + dateFormat);
        } else {
            for (InletPoleReading reading : inletPoleReadings) {
                String extraIdentifier = FlowgateConstant.INLET_NAME_PREFIX + reading.getInletOrdinal() + FlowgateConstant.INLET_POLE_NAME_PREFIX + reading.getInletPoleOrdinal();
                Double currentValue = reading.getCurrent();
                if (currentValue != null) {
                    ValueUnit current = new ValueUnit();
                    current.setExtraidentifier(extraIdentifier);
                    current.setKey(MetricName.PDU_CURRENT);
                    current.setTime(valueTime);
                    current.setValueNum(current.translateUnit(currentValue, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
                    current.setUnit(MetricUnit.A.toString());
                    values.add(current);
                }
                Double voltageValue = reading.getVoltage();
                if (voltageValue != null) {
                    ValueUnit voltage = new ValueUnit();
                    voltage.setExtraidentifier(extraIdentifier);
                    voltage.setKey(MetricName.PDU_VOLTAGE);
                    voltage.setTime(valueTime);
                    voltage.setValueNum(voltage.translateUnit(voltageValue, MetricUnit.valueOf(PDU_VOLT_UNIT), MetricUnit.V));
                    voltage.setUnit(MetricUnit.V.toString());
                    values.add(voltage);
                }
                Double freeCapacityValue = reading.getUnutilizedCapacity();
                if (freeCapacityValue != null) {
                    ValueUnit freeCapacity = new ValueUnit();
                    freeCapacity.setExtraidentifier(extraIdentifier);
                    freeCapacity.setKey(MetricName.PDU_FREE_CAPACITY);
                    freeCapacity.setTime(valueTime);
                    freeCapacity.setValueNum(freeCapacity.translateUnit(freeCapacityValue, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
                    freeCapacity.setUnit(MetricUnit.A.toString());
                    values.add(freeCapacity);
                }
            }
        }
    }
    if (!outlets.isEmpty()) {
        String time = null;
        for (Outlet outlet : outlets) {
            time = outlet.getReading().getReadingTime();
            if (time != null) {
                break;
            }
        }
        long valueTime = -1;
        if (time != null) {
            valueTime = WormholeDateFormat.getLongTime(time, dateFormat, timezone);
        }
        if (valueTime == -1) {
            logger.error("Failed to translate the time string: " + time + ".And the dateformat is " + dateFormat);
        } else {
            double totalOutletCurrentUsed = 0.0;
            double totalOutletPowerUsed = 0.0;
            for (Outlet outlet : outlets) {
                OutletReading reading = outlet.getReading();
                String extraIdentifier = FlowgateConstant.OUTLET_NAME_PREFIX + outlet.getOrdinal();
                Double voltage = reading.getVoltage();
                if (voltage != null) {
                    ValueUnit voltageValue = new ValueUnit();
                    voltageValue.setExtraidentifier(extraIdentifier);
                    voltageValue.setKey(MetricName.PDU_VOLTAGE);
                    voltageValue.setTime(valueTime);
                    voltageValue.setValueNum(voltageValue.translateUnit(voltage, MetricUnit.valueOf(PDU_VOLT_UNIT), MetricUnit.V));
                    voltageValue.setUnit(MetricUnit.V.toString());
                    values.add(voltageValue);
                }
                Double current = reading.getCurrent();
                if (current != null) {
                    ValueUnit currentValue = new ValueUnit();
                    currentValue.setExtraidentifier(extraIdentifier);
                    currentValue.setKey(MetricName.PDU_CURRENT);
                    currentValue.setTime(valueTime);
                    currentValue.setValueNum(currentValue.translateUnit(current, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
                    currentValue.setUnit(MetricUnit.A.toString());
                    values.add(currentValue);
                    totalOutletCurrentUsed += currentValue.getValueNum();
                }
                Double active_power = reading.getActivePower();
                if (active_power != null) {
                    ValueUnit activePowerValue = new ValueUnit();
                    activePowerValue.setExtraidentifier(extraIdentifier);
                    activePowerValue.setKey(MetricName.PDU_ACTIVE_POWER);
                    activePowerValue.setTime(valueTime);
                    activePowerValue.setValueNum(activePowerValue.translateUnit(active_power, MetricUnit.valueOf(PDU_POWER_UNIT), MetricUnit.kW));
                    activePowerValue.setUnit(MetricUnit.kW.toString());
                    values.add(activePowerValue);
                }
                Double apparent_power = reading.getApparentPower();
                if (apparent_power != null) {
                    ValueUnit apparentPowerValue = new ValueUnit();
                    apparentPowerValue.setExtraidentifier(extraIdentifier);
                    apparentPowerValue.setKey(MetricName.PDU_APPARENT_POWER);
                    apparentPowerValue.setTime(valueTime);
                    apparentPowerValue.setValueNum(apparentPowerValue.translateUnit(apparent_power, MetricUnit.valueOf(PDU_POWER_UNIT), MetricUnit.kW));
                    apparentPowerValue.setUnit(MetricUnit.kW.toString());
                    values.add(apparentPowerValue);
                    totalOutletPowerUsed += apparentPowerValue.getValueNum();
                }
                Double freeCapacity = reading.getUnutilizedCapacity();
                if (freeCapacity != null) {
                    ValueUnit freeCapacityValue = new ValueUnit();
                    freeCapacityValue.setExtraidentifier(extraIdentifier);
                    freeCapacityValue.setKey(MetricName.PDU_FREE_CAPACITY);
                    freeCapacityValue.setTime(valueTime);
                    freeCapacityValue.setValueNum(freeCapacityValue.translateUnit(freeCapacity, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
                    freeCapacityValue.setUnit(MetricUnit.A.toString());
                    values.add(freeCapacityValue);
                }
            }
            String rate_current = pduInfoFromPowerIQ.get(FlowgateConstant.PDU_RATE_AMPS);
            DecimalFormat df = new DecimalFormat("#.0000");
            if (totalOutletCurrentUsed == 0.0) {
                totalOutletCurrentUsed = inletTotalCurrent;
            }
            if (rate_current != null) {
                Double rate_current_value = Double.parseDouble(rate_current);
                ValueUnit current_load = new ValueUnit();
                current_load.setKey(MetricName.PDU_CURRENT_LOAD);
                current_load.setTime(valueTime);
                current_load.setUnit(MetricUnit.percent.toString());
                current_load.setValueNum(Double.parseDouble(df.format(totalOutletCurrentUsed / rate_current_value)));
                values.add(current_load);
            }
            String real_rate_power = getRealRatePower(inletVoltage, pduInfoFromPowerIQ);
            if (totalOutletPowerUsed == 0.0) {
                totalOutletPowerUsed = inlteTotalPower;
            }
            if (real_rate_power != null) {
                Double rate_power_value = Double.parseDouble(real_rate_power);
                ValueUnit power_load = new ValueUnit();
                power_load.setKey(MetricName.PDU_POWER_LOAD);
                power_load.setTime(valueTime);
                power_load.setUnit(MetricUnit.percent.toString());
                power_load.setValueNum(Double.parseDouble(df.format(totalOutletPowerUsed / rate_power_value)));
                values.add(power_load);
            }
        }
    }
    return values;
}
Also used : Pdu(com.vmware.flowgate.poweriqworker.model.Pdu) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) InletReading(com.vmware.flowgate.poweriqworker.model.InletReading) OutletReading(com.vmware.flowgate.poweriqworker.model.OutletReading) InletPoleReading(com.vmware.flowgate.poweriqworker.model.InletPoleReading) Reading(com.vmware.flowgate.poweriqworker.model.Reading) SensorReading(com.vmware.flowgate.poweriqworker.model.SensorReading) PduOutlet(com.vmware.flowgate.common.model.PduOutlet) Outlet(com.vmware.flowgate.poweriqworker.model.Outlet) InletReading(com.vmware.flowgate.poweriqworker.model.InletReading) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) InletPoleReading(com.vmware.flowgate.poweriqworker.model.InletPoleReading) OutletReading(com.vmware.flowgate.poweriqworker.model.OutletReading)

Example 5 with Outlet

use of com.vmware.flowgate.poweriqworker.model.Outlet in project flowgate by vmware.

the class PowerIQService method savePduAssetsToFlowgate.

public boolean savePduAssetsToFlowgate(Map<String, Asset> existedPduAssets, String assetSource, PowerIQAPIClient client, LocationInfo location) {
    int limit = 100;
    int offset = 0;
    List<Pdu> pdus = null;
    List<Asset> assetsNeedToSave = null;
    boolean triggerPDUAggregation = false;
    while ((pdus = client.getPdus(limit, offset)) != null) {
        if (pdus.isEmpty()) {
            break;
        }
        assetsNeedToSave = new ArrayList<Asset>();
        for (Pdu pdu : pdus) {
            List<Outlet> outlets = client.getOutlets(pdu.getId());
            List<Inlet> inlets = client.getInlets(pdu.getId());
            Asset asset = fillLocation(pdu.getParent(), location);
            String outletString = null;
            String inletString = null;
            try {
                outletString = generatePduOutletString(outlets);
                inletString = generatePduInletString(inlets);
            } catch (JsonProcessingException e) {
                logger.info(String.format("Sync pdu metadata error", e.getCause()));
            }
            Map<String, String> pduInfo = generatePduRateInfoMap(pdu);
            Asset existedPduAsset = existedPduAssets.get(String.valueOf(pdu.getId()));
            if (existedPduAsset != null) {
                boolean isAddAssetsNeedToSave = false;
                existedPduAsset.setLastupdate(System.currentTimeMillis());
                if (!StringUtils.equals(existedPduAsset.getAssetName(), pdu.getName())) {
                    existedPduAsset.setAssetName(pdu.getName());
                    isAddAssetsNeedToSave = true;
                }
                if (StringUtils.isBlank(existedPduAsset.getSerialnumber())) {
                    existedPduAsset.setSerialnumber(pdu.getSerialNumber());
                    isAddAssetsNeedToSave = true;
                }
                HashMap<String, String> oldJustficationfields = existedPduAsset.getJustificationfields();
                String oldPduInfo = oldJustficationfields.get(FlowgateConstant.PDU);
                Map<String, String> oldPduMap = null;
                try {
                    oldPduMap = getInfoMap(oldPduInfo);
                } catch (IOException e) {
                    logger.error("Sync pdu metadata error", e.getCause());
                    continue;
                }
                if (outletString != null && !StringUtils.equals(oldPduMap.get(FlowgateConstant.PDU_OUTLETS_FROM_POWERIQ), outletString)) {
                    oldPduMap.put(FlowgateConstant.PDU_OUTLETS_FROM_POWERIQ, outletString);
                    isAddAssetsNeedToSave = true;
                }
                if (inlets != null && !StringUtils.equals(oldPduMap.get(FlowgateConstant.PDU_INLETS_FROM_POWERIQ), inletString)) {
                    oldPduMap.put(FlowgateConstant.PDU_INLETS_FROM_POWERIQ, inletString);
                    isAddAssetsNeedToSave = true;
                }
                if (StringUtils.isBlank(oldPduMap.get(FlowgateConstant.PDU_RATE_AMPS))) {
                    oldPduMap.put(FlowgateConstant.PDU_RATE_AMPS, pduInfo.get(FlowgateConstant.PDU_RATE_AMPS));
                    isAddAssetsNeedToSave = true;
                }
                if (StringUtils.isBlank(oldPduMap.get(FlowgateConstant.PDU_MIN_RATE_POWER))) {
                    oldPduMap.put(FlowgateConstant.PDU_MIN_RATE_POWER, pduInfo.get(FlowgateConstant.PDU_MIN_RATE_POWER));
                    isAddAssetsNeedToSave = true;
                }
                if (StringUtils.isBlank(oldPduMap.get(FlowgateConstant.PDU_MAX_RATE_POWER))) {
                    oldPduMap.put(FlowgateConstant.PDU_MAX_RATE_POWER, pduInfo.get(FlowgateConstant.PDU_MAX_RATE_POWER));
                    isAddAssetsNeedToSave = true;
                }
                if (StringUtils.isBlank(oldPduMap.get(FlowgateConstant.PDU_MIN_RATE_VOLTS))) {
                    oldPduMap.put(FlowgateConstant.PDU_MIN_RATE_VOLTS, pduInfo.get(FlowgateConstant.PDU_MIN_RATE_VOLTS));
                    isAddAssetsNeedToSave = true;
                }
                if (StringUtils.isBlank(oldPduMap.get(FlowgateConstant.PDU_MAX_RATE_VOLTS))) {
                    oldPduMap.put(FlowgateConstant.PDU_MAX_RATE_VOLTS, pduInfo.get(FlowgateConstant.PDU_MAX_RATE_VOLTS));
                    isAddAssetsNeedToSave = true;
                }
                if (StringUtils.isBlank(oldPduMap.get(FlowgateConstant.PDU_PHASE))) {
                    oldPduMap.put(FlowgateConstant.PDU_PHASE, pduInfo.get(FlowgateConstant.PDU_PHASE));
                    isAddAssetsNeedToSave = true;
                }
                try {
                    String newPduInfo = mapper.writeValueAsString(oldPduMap);
                    oldJustficationfields.put(FlowgateConstant.PDU, newPduInfo);
                    existedPduAsset.setJustificationfields(oldJustficationfields);
                } catch (JsonProcessingException e) {
                    logger.error("Sync pdu metadata error", e.getCause());
                }
                String[] assetSources = existedPduAsset.getAssetSource().split(FlowgateConstant.SPILIT_FLAG);
                if (assetSources.length == 1) {
                    // So far this asset source is only have powerIQ
                    if (!StringUtils.equals(existedPduAsset.getRow(), asset.getRow()) || !StringUtils.equals(existedPduAsset.getRoom(), asset.getRoom()) || !StringUtils.equals(existedPduAsset.getFloor(), asset.getFloor()) || !StringUtils.equals(existedPduAsset.getCity(), asset.getCity()) || !StringUtils.equals(existedPduAsset.getCountry(), asset.getCountry()) || !StringUtils.equals(existedPduAsset.getExtraLocation(), asset.getExtraLocation())) {
                        existedPduAsset.setRow(asset.getRow());
                        existedPduAsset.setRoom(asset.getRoom());
                        existedPduAsset.setFloor(asset.getFloor());
                        existedPduAsset.setCity(asset.getCity());
                        existedPduAsset.setCountry(asset.getCountry());
                        existedPduAsset.setExtraLocation(asset.getExtraLocation());
                        isAddAssetsNeedToSave = true;
                    }
                }
                // save
                if (isAddAssetsNeedToSave) {
                    assetsNeedToSave.add(existedPduAsset);
                }
            } else {
                asset.setAssetName(pdu.getName());
                asset.setSerialnumber(pdu.getSerialNumber());
                asset.setAssetSource(assetSource);
                asset.setCategory(AssetCategory.PDU);
                asset.setCreated(System.currentTimeMillis());
                if (outletString != null) {
                    pduInfo.put(FlowgateConstant.PDU_OUTLETS_FROM_POWERIQ, outletString);
                }
                if (inletString != null) {
                    pduInfo.put(FlowgateConstant.PDU_INLETS_FROM_POWERIQ, inletString);
                }
                pduInfo.put(FlowgateConstant.PDU_ID_FROM_POWERIQ, String.valueOf(pdu.getId()));
                String pduInfoString = null;
                try {
                    pduInfoString = mapper.writeValueAsString(pduInfo);
                } catch (JsonProcessingException e) {
                    logger.info(String.format("Sync pdu metadata error", e.getCause()));
                }
                if (pduInfoString != null) {
                    HashMap<String, String> justfacationfields = new HashMap<String, String>();
                    justfacationfields.put(FlowgateConstant.PDU, pduInfoString);
                    asset.setJustificationfields(justfacationfields);
                }
                // save asset
                ResponseEntity<Void> responseEntity = restClient.saveAssets(asset);
                if (responseEntity.getStatusCode().is2xxSuccessful()) {
                    String assetId = getAssetIdByResponseEntity(responseEntity);
                    asset.setId(assetId);
                    Map<String, String> metricsFormulas = new HashMap<>(1);
                    metricsFormulas.put(FlowgateConstant.PDU, asset.metricsFormulaToString(generatePredefinedMetricFormulas(assetId)));
                    asset.setMetricsformulars(metricsFormulas);
                    // save asset formulas
                    restClient.saveAssets(asset);
                }
                triggerPDUAggregation = true;
            }
        }
        if (assetsNeedToSave.size() > 0) {
            restClient.saveAssets(assetsNeedToSave);
        }
        offset += limit;
    }
    return triggerPDUAggregation;
}
Also used : Pdu(com.vmware.flowgate.poweriqworker.model.Pdu) HashMap(java.util.HashMap) IOException(java.io.IOException) PduInlet(com.vmware.flowgate.common.model.PduInlet) Inlet(com.vmware.flowgate.poweriqworker.model.Inlet) PduOutlet(com.vmware.flowgate.common.model.PduOutlet) Outlet(com.vmware.flowgate.poweriqworker.model.Outlet) Asset(com.vmware.flowgate.common.model.Asset) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

Outlet (com.vmware.flowgate.poweriqworker.model.Outlet)6 ArrayList (java.util.ArrayList)4 PduOutlet (com.vmware.flowgate.common.model.PduOutlet)3 OutletReading (com.vmware.flowgate.poweriqworker.model.OutletReading)3 Pdu (com.vmware.flowgate.poweriqworker.model.Pdu)3 ValueUnit (com.vmware.flowgate.common.model.ValueUnit)2 HashMap (java.util.HashMap)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Asset (com.vmware.flowgate.common.model.Asset)1 PduInlet (com.vmware.flowgate.common.model.PduInlet)1 Inlet (com.vmware.flowgate.poweriqworker.model.Inlet)1 InletPoleReading (com.vmware.flowgate.poweriqworker.model.InletPoleReading)1 InletReading (com.vmware.flowgate.poweriqworker.model.InletReading)1 Reading (com.vmware.flowgate.poweriqworker.model.Reading)1 SensorReading (com.vmware.flowgate.poweriqworker.model.SensorReading)1 IOException (java.io.IOException)1 DecimalFormat (java.text.DecimalFormat)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1