Search in sources :

Example 1 with AdvanceSettingType

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType in project flowgate by vmware.

the class MessageProcessingTest method createFacilitySoftware.

FacilitySoftwareConfig createFacilitySoftware() {
    FacilitySoftwareConfig example = new FacilitySoftwareConfig();
    example.setId(UUID.randomUUID().toString());
    example.setName("OtherDcimSample");
    example.setUserName("administrator@vsphere.local");
    example.setPassword("Admin!23");
    example.setServerURL("https://10.160.30.134");
    example.setType(FacilitySoftwareConfig.SoftwareType.OtherDCIM);
    example.setUserId("1");
    example.setVerifyCert(false);
    example.setDescription("description");
    HashMap<AdvanceSettingType, String> advanceSetting = new HashMap<AdvanceSettingType, String>();
    example.setAdvanceSetting(advanceSetting);
    IntegrationStatus integrationStatus = new IntegrationStatus();
    integrationStatus.setDetail("");
    integrationStatus.setRetryCounter(0);
    integrationStatus.setStatus(Status.ACTIVE);
    example.setIntegrationStatus(integrationStatus);
    return example;
}
Also used : HashMap(java.util.HashMap) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AdvanceSettingType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType)

Example 2 with AdvanceSettingType

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType in project flowgate by vmware.

the class SycnRealTimeDataJobTest method testGenerateRealTimeData.

@Test
public void testGenerateRealTimeData() {
    Asset asset = createAsset();
    asset.setId("5x4ff46982db22e1b040e0f2");
    HashMap<AdvanceSettingType, String> advanceSettingMap = new HashMap<AdvanceSettingType, String>();
    advanceSettingMap.put(AdvanceSettingType.DateFormat, NlyteDataService.DateFormat);
    advanceSettingMap.put(AdvanceSettingType.TimeZone, "GMT");
    RealTimeData data = nlyteDataService.generateRealTimeData(asset, nlyteAPIClient, advanceSettingMap);
    TestCase.assertEquals("5x4ff46982db22e1b040e0f2", data.getAssetID());
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) HashMap(java.util.HashMap) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) AdvanceSettingType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with AdvanceSettingType

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType in project flowgate by vmware.

the class SycnRealTimeDataJobTest method getFacilitySoftwareByType.

public ResponseEntity<FacilitySoftwareConfig[]> getFacilitySoftwareByType() {
    HashMap<AdvanceSettingType, String> advanceSettingMap = new HashMap<AdvanceSettingType, String>();
    advanceSettingMap.put(AdvanceSettingType.DateFormat, NlyteDataService.DateFormat);
    advanceSettingMap.put(AdvanceSettingType.TimeZone, "GMT");
    FacilitySoftwareConfig[] configs = new FacilitySoftwareConfig[1];
    configs[0] = new FacilitySoftwareConfig();
    configs[0].setId("l9i8728d55368540fcba1692");
    configs[0].setType(SoftwareType.Nlyte);
    configs[0].setAdvanceSetting(advanceSettingMap);
    return new ResponseEntity<FacilitySoftwareConfig[]>(configs, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) AdvanceSettingType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType)

Example 4 with AdvanceSettingType

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType 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)

Aggregations

AdvanceSettingType (com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType)4 HashMap (java.util.HashMap)3 Asset (com.vmware.flowgate.common.model.Asset)2 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)2 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)2 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)2 WormholeException (com.vmware.flowgate.common.exception.WormholeException)1 ValueUnit (com.vmware.flowgate.common.model.ValueUnit)1 MetricUnit (com.vmware.flowgate.common.model.ValueUnit.MetricUnit)1 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)1 PowerIQAPIClient (com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient)1 Sensor (com.vmware.flowgate.poweriqworker.model.Sensor)1 SensorReading (com.vmware.flowgate.poweriqworker.model.SensorReading)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ResponseEntity (org.springframework.http.ResponseEntity)1