Search in sources :

Example 1 with Inlet

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

the class SyncPduAssetJobTest method getInlets.

List<Inlet> getInlets() {
    Inlet inlet = new Inlet();
    List<Inlet> inlets = new ArrayList<Inlet>();
    inlet.setId(23L);
    inlet.setOrdinal(1);
    inlet.setPduId(128L);
    inlet.setPueIt(true);
    inlet.setPueTotal(true);
    inlet.setSource(true);
    InletReading inletReading = new InletReading();
    inletReading.setCurrent(1.2);
    inletReading.setApparentPower(20.0);
    inletReading.setVoltage(200.0);
    inletReading.setReadingTime("2018/10/18 05:57:26 +0300");
    inletReading.setActivePower(26.6);
    inletReading.setUnutilizedCapacity(15.2);
    inlet.setReading(inletReading);
    inlets.add(inlet);
    return inlets;
}
Also used : ArrayList(java.util.ArrayList) InletReading(com.vmware.flowgate.poweriqworker.model.InletReading) Inlet(com.vmware.flowgate.poweriqworker.model.Inlet)

Example 2 with Inlet

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

the class PowerIQService method generatePduInletString.

private String generatePduInletString(List<Inlet> pduInlets) throws JsonProcessingException {
    List<PduInlet> pduInletsSaveToFlowgate = new ArrayList<PduInlet>();
    for (Inlet inlet : pduInlets) {
        PduInlet pduInlet = new PduInlet();
        pduInlet.setId(inlet.getId());
        pduInlet.setOrdinal(inlet.getOrdinal());
        pduInlet.setPduId(inlet.getPduId());
        pduInlet.setPowerSource(inlet.isSource());
        pduInlet.setPueIt(inlet.isPueIt());
        pduInlet.setPueTotal(inlet.isPueTotal());
        pduInlet.setRatedAmps(inlet.getRatedAmps());
        pduInlet.setFormatedName(FlowgateConstant.INLET_NAME_PREFIX + inlet.getOrdinal());
        pduInletsSaveToFlowgate.add(pduInlet);
    }
    return mapper.writeValueAsString(pduInletsSaveToFlowgate);
}
Also used : ArrayList(java.util.ArrayList) PduInlet(com.vmware.flowgate.common.model.PduInlet) PduInlet(com.vmware.flowgate.common.model.PduInlet) Inlet(com.vmware.flowgate.poweriqworker.model.Inlet)

Example 3 with Inlet

use of com.vmware.flowgate.poweriqworker.model.Inlet 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)

Example 4 with Inlet

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

the class SyncRealTimeDataJobTest method getInlets.

List<Inlet> getInlets() {
    Inlet inlet = new Inlet();
    List<Inlet> inlets = new ArrayList<Inlet>();
    inlet.setId(23L);
    inlet.setOrdinal(1);
    inlet.setPduId(128L);
    inlet.setPueIt(true);
    inlet.setPueTotal(true);
    inlet.setSource(true);
    InletReading inletReading = new InletReading();
    inletReading.setCurrent(1.2);
    inletReading.setApparentPower(20.0);
    inletReading.setVoltage(200.0);
    inletReading.setReadingTime("2018/10/18 05:57:26 +0300");
    inletReading.setActivePower(26.6);
    inletReading.setUnutilizedCapacity(15.2);
    inlet.setReading(inletReading);
    inlets.add(inlet);
    return inlets;
}
Also used : ArrayList(java.util.ArrayList) InletReading(com.vmware.flowgate.poweriqworker.model.InletReading) Inlet(com.vmware.flowgate.poweriqworker.model.Inlet)

Aggregations

Inlet (com.vmware.flowgate.poweriqworker.model.Inlet)4 ArrayList (java.util.ArrayList)3 PduInlet (com.vmware.flowgate.common.model.PduInlet)2 InletReading (com.vmware.flowgate.poweriqworker.model.InletReading)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Asset (com.vmware.flowgate.common.model.Asset)1 PduOutlet (com.vmware.flowgate.common.model.PduOutlet)1 Outlet (com.vmware.flowgate.poweriqworker.model.Outlet)1 Pdu (com.vmware.flowgate.poweriqworker.model.Pdu)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1