Search in sources :

Example 21 with IntegrationStatus

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

the class PowerIQService method syncRealtimeData.

// Sync realtime Data logic need to refactor.
private void syncRealtimeData(FacilitySoftwareConfig powerIQ) {
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    List<Asset> allMappedPdus = Arrays.asList(restClient.getMappedAsset(AssetCategory.PDU).getBody());
    if (allMappedPdus == null || allMappedPdus.isEmpty()) {
        return;
    }
    PowerIQAPIClient client = createClient(powerIQ);
    try {
        client.testConnection();
    } catch (HttpClientErrorException e) {
        logger.error("Failed to query data from PowerIQ", e);
        IntegrationStatus integrationStatus = powerIQ.getIntegrationStatus();
        if (integrationStatus == null) {
            integrationStatus = new IntegrationStatus();
        }
        integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
        integrationStatus.setDetail(e.getMessage());
        integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
        updateIntegrationStatus(powerIQ);
        return;
    } catch (ResourceAccessException e1) {
        if (e1.getCause().getCause() instanceof ConnectException) {
            checkAndUpdateIntegrationStatus(powerIQ, e1.getMessage());
            return;
        }
    }
    Map<String, Map<String, String>> pduAssetIdAndPduInfoMap = new HashMap<String, Map<String, String>>();
    for (Asset asset : allMappedPdus) {
        String id = null;
        Map<String, String> pduInfoMap = null;
        if (asset.getJustificationfields() != null) {
            HashMap<String, String> justficationfields = asset.getJustificationfields();
            String pduInfo = justficationfields.get(FlowgateConstant.PDU);
            try {
                pduInfoMap = getInfoMap(pduInfo);
            } catch (IOException e) {
                continue;
            }
            id = pduInfoMap.get(FlowgateConstant.PDU_ID_FROM_POWERIQ);
            // Only check the pdu that belong to the current PowerIQ.
            if (!asset.getAssetSource().contains((powerIQ.getId()))) {
                continue;
            }
        }
        if (id != null) {
            pduAssetIdAndPduInfoMap.put(asset.getId(), pduInfoMap);
        }
    }
    List<RealTimeData> pduMetricRealTimeDatas = getRealTimeDatas(pduAssetIdAndPduInfoMap, client, getAdvanceSetting(powerIQ));
    if (!pduMetricRealTimeDatas.isEmpty()) {
        restClient.saveRealTimeData(pduMetricRealTimeDatas);
        logger.info("Finish sync pdu realtime data for " + powerIQ.getName());
    } else {
        logger.info("Not found any pdu realtime data from " + powerIQ.getName());
    }
    List<Asset> allMappedServers = Arrays.asList(restClient.getMappedAsset(AssetCategory.Server).getBody());
    if (allMappedServers.isEmpty()) {
        logger.info("No mapped server found. End sync RealTime data Job");
        return;
    }
    // get sensor assetIds from pdu's metricsFormular attribute
    Set<String> sensorAssetIds = getAssetIdfromformular(allMappedPdus);
    // get sensor assetIds from server's metricsFromular attribute
    Set<String> sensorAssetIdsFromServer = getAssetIdfromformular(allMappedServers);
    sensorAssetIds.addAll(sensorAssetIdsFromServer);
    if (sensorAssetIds.isEmpty()) {
        return;
    }
    // filter sensors
    List<Asset> sensorFromPowerIQ = filterAssetsBySource(powerIQ.getId(), sensorAssetIds);
    List<RealTimeData> realTimeDatas = getSensorRealTimeData(powerIQ, sensorFromPowerIQ);
    logger.info("Received new Sensor data, data item size is:" + realTimeDatas.size());
    if (realTimeDatas.isEmpty()) {
        logger.info("Not found any sensor realtime data from " + powerIQ.getName());
        return;
    }
    restClient.saveRealTimeData(realTimeDatas);
    logger.info("Finish sync sensor realtime data for " + powerIQ.getName());
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) IOException(java.io.IOException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) PowerIQAPIClient(com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient) Asset(com.vmware.flowgate.common.model.Asset) Map(java.util.Map) HashMap(java.util.HashMap) ConnectException(java.net.ConnectException)

Example 22 with IntegrationStatus

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

the class PowerIQService method getSensorRealTimeData.

public List<RealTimeData> getSensorRealTimeData(FacilitySoftwareConfig powerIQ, List<Asset> assets) {
    HashMap<AdvanceSettingType, String> advanceSetting = getAdvanceSetting(powerIQ);
    List<RealTimeData> realtimeDatas = new ArrayList<RealTimeData>();
    String dateFormat = advanceSetting.get(AdvanceSettingType.DateFormat);
    String timezone = advanceSetting.get(AdvanceSettingType.TimeZone);
    String temperature = advanceSetting.get(AdvanceSettingType.TEMPERATURE_UNIT);
    String humidity = advanceSetting.get(AdvanceSettingType.HUMIDITY_UNIT);
    PowerIQAPIClient powerIQAPIClient = createClient(powerIQ);
    for (Asset asset : assets) {
        HashMap<String, String> sensorExtraInfo = asset.getJustificationfields();
        String sensorInfo = sensorExtraInfo.get(FlowgateConstant.SENSOR);
        Map<String, String> sensorInfoMap = null;
        try {
            sensorInfoMap = getInfoMap(sensorInfo);
        } catch (IOException e2) {
            continue;
        }
        String sensorId = sensorInfoMap.get(FlowgateConstant.SENSOR_ID_FROM_POWERIQ);
        Sensor sensor = null;
        try {
            sensor = powerIQAPIClient.getSensorById(sensorId);
        } catch (HttpClientErrorException e) {
            logger.error("Failed to query data from PowerIQ", e);
            IntegrationStatus integrationStatus = powerIQ.getIntegrationStatus();
            if (integrationStatus == null) {
                integrationStatus = new IntegrationStatus();
            }
            integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
            integrationStatus.setDetail(e.getMessage());
            integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
            updateIntegrationStatus(powerIQ);
            break;
        } catch (ResourceAccessException e1) {
            if (e1.getCause().getCause() instanceof ConnectException) {
                checkAndUpdateIntegrationStatus(powerIQ, e1.getMessage());
                break;
            }
            break;
        }
        SensorReading reading = sensor.getReading();
        if (reading == null || reading.getId() == 0) {
            continue;
        }
        RealTimeData realTimeData = new RealTimeData();
        String valueDateTime = reading.getReadingTime();
        long recordedTime = WormholeDateFormat.getLongTime(valueDateTime, dateFormat, timezone);
        if (recordedTime == -1) {
            logger.error("Failed to translate the time string: " + valueDateTime + ".And the dateformat is " + dateFormat);
            continue;
        }
        List<ValueUnit> values = new ArrayList<ValueUnit>();
        ValueUnit value = new ValueUnit();
        value.setTime(recordedTime);
        value.setKey(sensorAndMetricMap.get(sensor.getType()));
        String unit = reading.getUom();
        MetricUnit sourceUnit = null, targetUnit = null;
        switch(sensorAndMetricMap.get(sensor.getType())) {
            case MetricName.HUMIDITY:
                if (unit != null && !unit.isEmpty()) {
                    if (unit.equals("%")) {
                        sourceUnit = MetricUnit.percent;
                    } else {
                        sourceUnit = MetricUnit.valueOf(unit);
                    }
                } else {
                    if (humidity.equals("%")) {
                        sourceUnit = MetricUnit.percent;
                    } else {
                        sourceUnit = MetricUnit.valueOf(humidity);
                    }
                }
                targetUnit = MetricUnit.percent;
                break;
            case MetricName.TEMPERATURE:
                if (unit != null && !unit.isEmpty()) {
                    sourceUnit = MetricUnit.valueOf(unit.toUpperCase());
                } else {
                    sourceUnit = MetricUnit.valueOf(temperature.toUpperCase());
                }
                targetUnit = MetricUnit.C;
                break;
            default:
                break;
        }
        Double metricsValue = reading.getValue();
        if (metricsValue == null) {
            continue;
        }
        try {
            value.setValueNum(value.translateUnit(metricsValue, sourceUnit, targetUnit));
        } catch (WormholeException e) {
            logger.error("Cannot translate Unit", e);
        }
        if (targetUnit.toString().equals(MetricUnit.percent.toString())) {
            value.setUnit("%");
        } else {
            value.setUnit(targetUnit.toString());
        }
        values.add(value);
        realTimeData.setAssetID(asset.getId());
        realTimeData.setTime(recordedTime);
        realTimeData.setValues(values);
        realTimeData.setId(asset.getId() + "_" + recordedTime);
        realtimeDatas.add(realTimeData);
    }
    return realtimeDatas;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) ArrayList(java.util.ArrayList) WormholeException(com.vmware.flowgate.common.exception.WormholeException) IOException(java.io.IOException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) SensorReading(com.vmware.flowgate.poweriqworker.model.SensorReading) PowerIQAPIClient(com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient) Asset(com.vmware.flowgate.common.model.Asset) MetricUnit(com.vmware.flowgate.common.model.ValueUnit.MetricUnit) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) AdvanceSettingType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType) Sensor(com.vmware.flowgate.poweriqworker.model.Sensor) ConnectException(java.net.ConnectException)

Example 23 with IntegrationStatus

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

the class NlyteDataService method syncMappedData.

private void syncMappedData(FacilitySoftwareConfig nlyte) {
    NlyteAPIClient nlyteAPIclient = new NlyteAPIClient(nlyte);
    HandleAssetUtil assetUtil = new HandleAssetUtil();
    List<NlyteAsset> nlyteAssets = null;
    try {
        nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Server);
    } catch (HttpClientErrorException e) {
        logger.error("Failed to query data from Nlyte", e);
        IntegrationStatus integrationStatus = nlyte.getIntegrationStatus();
        if (integrationStatus == null) {
            integrationStatus = new IntegrationStatus();
        }
        integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
        integrationStatus.setDetail(e.getMessage());
        integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
        updateIntegrationStatus(nlyte);
        return;
    } catch (ResourceAccessException e1) {
        if (e1.getCause().getCause() instanceof ConnectException) {
            checkAndUpdateIntegrationStatus(nlyte, e1.getMessage());
            return;
        }
    }
    HashMap<Integer, LocationGroup> locationMap = assetUtil.initLocationGroupMap(nlyteAPIclient);
    HashMap<Integer, Material> materialMap = assetUtil.initServerMaterialsMap(nlyteAPIclient);
    HashMap<Integer, Manufacturer> manufacturerMap = assetUtil.initManufacturersMap(nlyteAPIclient);
    saveAssetForMappedData(nlyte.getId(), nlyteAssets, locationMap, materialMap, manufacturerMap, AssetCategory.Server);
    HashMap<Integer, Material> pduMaterialMap = new HashMap<Integer, Material>();
    nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.PDU);
    List<Material> powerStripMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.powerStripMaterial);
    for (Material material : powerStripMaterials) {
        material.setMaterialType(AssetCategory.PDU);
        pduMaterialMap.put(material.getMaterialID(), material);
    }
    saveAssetForMappedData(nlyte.getId(), nlyteAssets, locationMap, pduMaterialMap, manufacturerMap, AssetCategory.PDU);
    HashMap<Integer, Material> networksMaterialMap = new HashMap<Integer, Material>();
    nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Networks);
    List<Material> networkMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.networkMaterials);
    for (Material material : networkMaterials) {
        material.setMaterialType(AssetCategory.Networks);
        networksMaterialMap.put(material.getMaterialID(), material);
    }
    saveAssetForMappedData(nlyte.getId(), nlyteAssets, locationMap, networksMaterialMap, manufacturerMap, AssetCategory.Networks);
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Material(com.vmware.flowgate.nlyteworker.model.Material) ResourceAccessException(org.springframework.web.client.ResourceAccessException) NlyteAPIClient(com.vmware.flowgate.nlyteworker.restclient.NlyteAPIClient) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) Manufacturer(com.vmware.flowgate.nlyteworker.model.Manufacturer) LocationGroup(com.vmware.flowgate.nlyteworker.model.LocationGroup) ConnectException(java.net.ConnectException)

Example 24 with IntegrationStatus

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

the class NlyteDataService method checkAndUpdateIntegrationStatus.

public void checkAndUpdateIntegrationStatus(FacilitySoftwareConfig nlyte, String message) {
    IntegrationStatus integrationStatus = nlyte.getIntegrationStatus();
    if (integrationStatus == null) {
        integrationStatus = new IntegrationStatus();
    }
    int timesOftry = integrationStatus.getRetryCounter();
    timesOftry++;
    if (timesOftry < FlowgateConstant.MAXNUMBEROFRETRIES) {
        integrationStatus.setRetryCounter(timesOftry);
    } else {
        integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
        integrationStatus.setDetail(message);
        integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
        logger.error("Failed to query data from Nlyte,error message is " + message);
    }
    nlyte.setIntegrationStatus(integrationStatus);
    updateIntegrationStatus(nlyte);
}
Also used : IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus)

Example 25 with IntegrationStatus

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

the class InfobloxClientTest method getInfobloxFacilitySoftware.

private FacilitySoftwareConfig[] getInfobloxFacilitySoftware() {
    FacilitySoftwareConfig[] facilitySoftwareConfigs = new FacilitySoftwareConfig[1];
    FacilitySoftwareConfig facilitySoftwareConfig = new FacilitySoftwareConfig();
    facilitySoftwareConfig.setPassword("O75xginpkAD748w=Lc20CrTzd1lEpvDTdJqH5IXBZTb5gYp7P8awDAs19F0=");
    facilitySoftwareConfig.setServerURL("https://10.161.71.133");
    facilitySoftwareConfig.setName("infoblox-1");
    facilitySoftwareConfig.setVerifyCert(false);
    IntegrationStatus integrationStatus = new IntegrationStatus();
    integrationStatus.setRetryCounter(0);
    integrationStatus.setDetail("");
    integrationStatus.setStatus(IntegrationStatus.Status.ACTIVE);
    facilitySoftwareConfig.setIntegrationStatus(integrationStatus);
    facilitySoftwareConfig.setUserName("admin");
    facilitySoftwareConfig.setType(FacilitySoftwareConfig.SoftwareType.InfoBlox);
    facilitySoftwareConfig.setUserId("e1edfv8953002379827896a1aaiqoose");
    facilitySoftwareConfigs[0] = facilitySoftwareConfig;
    return facilitySoftwareConfigs;
}
Also used : IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig)

Aggregations

IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)31 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)12 Asset (com.vmware.flowgate.common.model.Asset)10 ConnectException (java.net.ConnectException)10 IOException (java.io.IOException)8 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)7 HashMap (java.util.HashMap)7 ResourceAccessException (org.springframework.web.client.ResourceAccessException)7 ArrayList (java.util.ArrayList)5 AssetIPMapping (com.vmware.flowgate.common.model.AssetIPMapping)3 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)3 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)3 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)3 PowerIQAPIClient (com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 AdvanceSettingType (com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType)2 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)2 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)2 LocationGroup (com.vmware.flowgate.nlyteworker.model.LocationGroup)2 Manufacturer (com.vmware.flowgate.nlyteworker.model.Manufacturer)2