Search in sources :

Example 1 with RealTimeData

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

the class NlyteDataService method getRealTimeDatas.

public List<RealTimeData> getRealTimeDatas(NlyteAPIClient nlyteAPIclient, FacilitySoftwareConfig facilitySoftwareConfig, Set<String> assetIds) {
    List<RealTimeData> realTimeDatas = new ArrayList<RealTimeData>();
    for (String assetId : assetIds) {
        Asset asset = restClient.getAssetByID(assetId).getBody();
        if (asset == null || !facilitySoftwareConfig.getId().equals(asset.getAssetSource())) {
            continue;
        }
        RealTimeData realTimeData = null;
        try {
            realTimeData = generateRealTimeData(asset, nlyteAPIclient, getAdvanceSetting(facilitySoftwareConfig));
        } catch (HttpClientErrorException e) {
            logger.error("Failed to query data from Nlyte", e);
            IntegrationStatus integrationStatus = facilitySoftwareConfig.getIntegrationStatus();
            if (integrationStatus == null) {
                integrationStatus = new IntegrationStatus();
            }
            integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
            integrationStatus.setDetail(e.getMessage());
            integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
            updateIntegrationStatus(facilitySoftwareConfig);
            break;
        } catch (ResourceAccessException e1) {
            if (e1.getCause().getCause() instanceof ConnectException) {
                checkAndUpdateIntegrationStatus(facilitySoftwareConfig, e1.getMessage());
                break;
            }
        }
        if (realTimeData == null) {
            continue;
        }
        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) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) ResourceAccessException(org.springframework.web.client.ResourceAccessException) ConnectException(java.net.ConnectException)

Example 2 with RealTimeData

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

the class NlyteDataService method generateRealTimeData.

public RealTimeData generateRealTimeData(Asset asset, NlyteAPIClient nlyteAPIclient, HashMap<AdvanceSettingType, String> advanceSettingMap) {
    RealTimeData realTimeData = null;
    JsonResultForPDURealtimeValue result = nlyteAPIclient.getPowerStripsRealtimeValue(asset.getAssetNumber()).getBody();
    List<ValueUnit> valueUnits = generateValueUnits(result.getValue(), advanceSettingMap);
    if (!valueUnits.isEmpty()) {
        realTimeData = new RealTimeData();
        realTimeData.setAssetID(asset.getId());
        realTimeData.setValues(valueUnits);
        realTimeData.setTime(valueUnits.get(0).getTime());
        realTimeData.setId(realTimeData.getAssetID() + "_" + realTimeData.getTime());
    }
    return realTimeData;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) JsonResultForPDURealtimeValue(com.vmware.flowgate.nlyteworker.model.JsonResultForPDURealtimeValue)

Example 3 with RealTimeData

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

the class OpenManageJobTest method getMetricDatasSourceIsDifferent.

@Test
public void getMetricDatasSourceIsDifferent() {
    FacilitySoftwareConfig config = new FacilitySoftwareConfig();
    config.setId(createAsset().getAssetSource() + "SourceIsDifferent");
    List<RealTimeData> metricDatas = openmanageJobService.getMetricDatas(config, openManageAPIClient);
    TestCase.assertEquals(true, metricDatas.isEmpty());
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with RealTimeData

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

the class SyncSensorMetaDataJobTest method testGetSensorRealTimeData1.

@Test
public void testGetSensorRealTimeData1() {
    HashMap<String, String> justificationfields = generateExtraInfo("6566");
    Asset asset = createAsset();
    asset.setId("123o89qw4jjasd0");
    asset.setJustificationfields(justificationfields);
    Sensor sensor = createSensor();
    sensor.setId(6566);
    sensor.setName("HumiditySensor");
    sensor.setSerialNumber("8999");
    sensor.setType("HumiditySensor");
    Mockito.when(this.powerIQAPIClient.getSensorById("6566")).thenReturn(sensor);
    List<Asset> assets = new ArrayList<Asset>();
    assets.add(asset);
    List<RealTimeData> realTimeDatas = powerIQService.getSensorRealTimeData(createFacility(), assets);
    TestCase.assertEquals(0, realTimeDatas.size());
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) Sensor(com.vmware.flowgate.poweriqworker.model.Sensor) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with RealTimeData

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

the class SyncSensorMetaDataJobTest method testGetSensorRealTimeData2.

@Test
public void testGetSensorRealTimeData2() {
    HashMap<String, String> justificationfields = generateExtraInfo("6566");
    Asset asset = createAsset();
    asset.setId("123o89qw4jjasd0");
    asset.setJustificationfields(justificationfields);
    HashMap<String, String> justificationfields1 = generateExtraInfo("6567");
    Asset asset1 = createAsset();
    asset1.setId("123o89qw4jjasd1");
    asset1.setJustificationfields(justificationfields1);
    Sensor sensor = createSensor();
    SensorReading sensorReading = createReading();
    sensorReading.setUom("%");
    sensor.setId(6566);
    sensor.setName("HumiditySensor");
    sensor.setSerialNumber("8999");
    sensor.setType("HumiditySensor");
    sensor.setReading(sensorReading);
    Mockito.when(this.powerIQAPIClient.getSensorById("6566")).thenReturn(sensor);
    Sensor sensor1 = createSensor();
    SensorReading sensorReading1 = createReading();
    sensorReading1.setUom("F");
    sensor1.setId(6567);
    sensor1.setName("TemperatureSensor");
    sensor1.setSerialNumber("9000");
    sensor1.setType("TemperatureSensor");
    sensor1.setReading(sensorReading1);
    Mockito.when(this.powerIQAPIClient.getSensorById("6567")).thenReturn(sensor1);
    Set<String> assetIds = new HashSet<String>();
    assetIds.add("123o89qw4jjasd0");
    assetIds.add("123o89qw4jjasd1");
    List<Asset> assets = new ArrayList<Asset>();
    assets.add(asset);
    assets.add(asset1);
    List<RealTimeData> realTimeDatas = powerIQService.getSensorRealTimeData(createFacility(), assets);
    for (RealTimeData realtimedata : realTimeDatas) {
        if ("123o89qw4jjasd0".equals(realtimedata.getAssetID())) {
            TestCase.assertEquals((double) 100, realtimedata.getValues().get(0).getValueNum());
        } else {
            TestCase.assertEquals((double) (100 - 32) * 5 / 9, realtimedata.getValues().get(0).getValueNum());
        }
    }
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) SensorReading(com.vmware.flowgate.poweriqworker.model.SensorReading) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) Sensor(com.vmware.flowgate.poweriqworker.model.Sensor) HashSet(java.util.HashSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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