Search in sources :

Example 31 with MetricData

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

the class TranslateFunctionServiceTest method testCalculationFormulaConvert.

@Test
public void testCalculationFormulaConvert() {
    String assetId1 = "752c0c7637104a39a4242031cd48785e";
    String assetId2 = "5dab088ab8a94aa994fdf9ddd8acceb6";
    String formula = "(752c0c7637104a39a4242031cd48785e+5dab088ab8a94aa994fdf9ddd8acceb6)/2";
    long currentTimeMillis = System.currentTimeMillis();
    ValueUnit humidityValue1 = new ValueUnit();
    humidityValue1.setValueNum(20);
    humidityValue1.setTime(currentTimeMillis);
    humidityValue1.setUnit(RealtimeDataUnit.Percent.toString());
    humidityValue1.setKey(MetricName.HUMIDITY);
    ValueUnit humidityValue2 = new ValueUnit();
    humidityValue2.setValueNum(19);
    humidityValue2.setTime(currentTimeMillis);
    humidityValue2.setUnit(RealtimeDataUnit.Percent.toString());
    humidityValue2.setKey(MetricName.HUMIDITY);
    String displayName = MetricKeyName.SERVER_BACK_HUMIDITY_LOCATIONX;
    String backToName = String.format(displayName, "BACK");
    Function<TranslateContext, MetricData> function = TranslateFunctionService.convert;
    Map<String, ValueUnit> valueUnitMap = new HashMap<>();
    valueUnitMap.put(assetId1, humidityValue1);
    valueUnitMap.put(assetId2, humidityValue2);
    TranslateContext translateContext = TranslateContext.buildByValueUnitsAndDisplayNameAndFormula(valueUnitMap, backToName, formula);
    MetricData metricData = function.apply(translateContext);
    TestCase.assertEquals(backToName, metricData.getMetricName());
    TestCase.assertEquals(currentTimeMillis, metricData.getTimeStamp());
    TestCase.assertEquals(19.5, metricData.getValueNum());
    TestCase.assertEquals(ValueUnit.MetricUnit.percent.toString(), metricData.getUnit());
}
Also used : HashMap(java.util.HashMap) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) TranslateContext(com.vmware.flowgate.common.model.TranslateContext) MetricData(com.vmware.flowgate.common.model.MetricData) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 32 with MetricData

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

the class TranslateFunctionServiceTest method testExceptionConvertServerAverageUsedPowerEnergyConsumptionAverageTemperature.

@Test
public void testExceptionConvertServerAverageUsedPowerEnergyConsumptionAverageTemperature() {
    String assetId = "752c0c7637104a39a4242031cd48785e";
    long startTime = System.currentTimeMillis();
    long endTime = startTime + 30000;
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setTime(endTime);
    valueUnit.setKey(MetricName.SERVER_AVERAGE_USED_POWER);
    valueUnit.setUnit(ValueUnit.MetricUnit.kW.toString());
    valueUnit.setValueNum(0.06906666666666665);
    String displayName = MetricName.SERVER_AVERAGE_USED_POWER;
    Function<TranslateContext, MetricData> function = TranslateFunctionService.serverFormulaKeyAndFunction.get(MetricName.SERVER_AVERAGE_USED_POWER);
    Map<String, ValueUnit> valueUnitMap = new HashMap<>();
    valueUnitMap.put(assetId, valueUnit);
    TranslateContext translateContext = TranslateContext.buildByValueUnitsAndDisplayNameAndFormula(valueUnitMap, displayName, assetId);
    MetricData metricData = function.apply(translateContext);
    TestCase.assertNull(metricData);
}
Also used : HashMap(java.util.HashMap) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) TranslateContext(com.vmware.flowgate.common.model.TranslateContext) MetricData(com.vmware.flowgate.common.model.MetricData) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 33 with MetricData

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

the class TranslateFunctionServiceTest method testExceptionConvertServerPeakUsedPowerMinimumUsedPowerPeakTemperature.

@Test
public void testExceptionConvertServerPeakUsedPowerMinimumUsedPowerPeakTemperature() {
    String assetId = "752c0c7637104a39a4242031cd48785e";
    long startTime = System.currentTimeMillis();
    long endTime = startTime + 30000;
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setTime(endTime);
    valueUnit.setKey(MetricName.SERVER_PEAK_USED_POWER);
    valueUnit.setUnit(ValueUnit.MetricUnit.kW.toString());
    valueUnit.setValueNum(0.07);
    String displayName = MetricName.SERVER_PEAK_USED_POWER;
    Function<TranslateContext, MetricData> function = TranslateFunctionService.serverFormulaKeyAndFunction.get(MetricName.SERVER_PEAK_USED_POWER);
    Map<String, ValueUnit> valueUnitMap = new HashMap<>();
    valueUnitMap.put(assetId, valueUnit);
    TranslateContext translateContext = TranslateContext.buildByValueUnitsAndDisplayNameAndFormula(valueUnitMap, displayName, assetId);
    MetricData metricData = function.apply(translateContext);
    TestCase.assertNull(metricData);
    valueUnit.setExtraidentifier(String.valueOf(startTime));
    translateContext = TranslateContext.buildByValueUnitsAndDisplayNameAndFormula(valueUnitMap, displayName, assetId);
    metricData = function.apply(translateContext);
    TestCase.assertNull(metricData);
}
Also used : HashMap(java.util.HashMap) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) TranslateContext(com.vmware.flowgate.common.model.TranslateContext) MetricData(com.vmware.flowgate.common.model.MetricData) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 34 with MetricData

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

the class TranslateFunctionServiceTest method testConvertByExtraIdentifier.

@Test
public void testConvertByExtraIdentifier() {
    String assetId = "752c0c7637104a39a4242031cd48785e";
    long currentTimeMillis = System.currentTimeMillis();
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setKey(MetricName.PDU_ACTIVE_POWER);
    valueUnit.setUnit(ValueUnit.MetricUnit.kW.toString());
    valueUnit.setExtraidentifier("OUTLET:7");
    valueUnit.setValueNum(0.2);
    valueUnit.setTime(currentTimeMillis);
    String displayName = MetricName.PDU_XLET_ACTIVE_POWER;
    Function<TranslateContext, MetricData> function = TranslateFunctionService.pduFormulaKeyAndFunction.get(MetricName.PDU_XLET_ACTIVE_POWER);
    Map<String, ValueUnit> valueUnitMap = new HashMap<>();
    valueUnitMap.put(assetId, valueUnit);
    TranslateContext translateContext = TranslateContext.buildByValueUnitsAndDisplayNameAndFormula(valueUnitMap, displayName, assetId);
    MetricData metricData = function.apply(translateContext);
    TestCase.assertEquals(String.format(displayName, valueUnit.getExtraidentifier()), metricData.getMetricName());
    TestCase.assertEquals(valueUnit.getTime(), metricData.getTimeStamp());
    TestCase.assertEquals(valueUnit.getValueNum(), metricData.getValueNum());
    TestCase.assertEquals(valueUnit.getUnit(), metricData.getUnit());
}
Also used : HashMap(java.util.HashMap) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) TranslateContext(com.vmware.flowgate.common.model.TranslateContext) MetricData(com.vmware.flowgate.common.model.MetricData) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 35 with MetricData

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

the class TranslateFunctionServiceTest method testConvertPduCurrentVoltageFreeCapacityByExtraIdentifier.

@Test
public void testConvertPduCurrentVoltageFreeCapacityByExtraIdentifier() {
    String assetId = "752c0c7637104a39a4242031cd48785e";
    long currentTimeMillis = System.currentTimeMillis();
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setKey(MetricName.PDU_CURRENT);
    valueUnit.setUnit(ValueUnit.MetricUnit.A.toString());
    valueUnit.setExtraidentifier("INLET:1|L1");
    valueUnit.setValueNum(6);
    valueUnit.setTime(currentTimeMillis);
    String displayName = MetricName.PDU_INLET_XPOLE_CURRENT;
    Function<TranslateContext, MetricData> function = TranslateFunctionService.pduFormulaKeyAndFunction.get(MetricName.PDU_INLET_XPOLE_CURRENT);
    Map<String, ValueUnit> valueUnitMap = new HashMap<>();
    valueUnitMap.put(assetId, valueUnit);
    TranslateContext translateContext = TranslateContext.buildByValueUnitsAndDisplayNameAndFormula(valueUnitMap, displayName, assetId);
    MetricData metricData = function.apply(translateContext);
    TestCase.assertEquals("INLET:1|L1|Current", metricData.getMetricName());
    TestCase.assertEquals(valueUnit.getTime(), metricData.getTimeStamp());
    TestCase.assertEquals(valueUnit.getValueNum(), metricData.getValueNum());
    TestCase.assertEquals(valueUnit.getUnit(), metricData.getUnit());
}
Also used : HashMap(java.util.HashMap) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) TranslateContext(com.vmware.flowgate.common.model.TranslateContext) MetricData(com.vmware.flowgate.common.model.MetricData) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MetricData (com.vmware.flowgate.common.model.MetricData)35 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)24 ValueUnit (com.vmware.flowgate.common.model.ValueUnit)23 Test (org.junit.Test)23 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)23 Asset (com.vmware.flowgate.common.model.Asset)16 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)16 TranslateContext (com.vmware.flowgate.common.model.TranslateContext)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 MvcResult (org.springframework.test.web.servlet.MvcResult)8 Map (java.util.Map)7 List (java.util.List)6 FieldDescriptor (org.springframework.restdocs.payload.FieldDescriptor)4 HashSet (java.util.HashSet)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AssetIPMapping (com.vmware.flowgate.common.model.AssetIPMapping)1 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)1 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)1 MetricClient (com.vmware.flowgate.vroworker.vro.MetricClient)1