Search in sources :

Example 56 with ValueUnit

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

the class TranslateFunctionServiceTest method testServerConvert.

@Test
public void testServerConvert() {
    String assetId = "752c0c7637104a39a4242031cd48785e";
    long currentTimeMillis = System.currentTimeMillis();
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setTime(currentTimeMillis);
    valueUnit.setKey(MetricName.SERVER_CPUUSAGE);
    valueUnit.setUnit(ValueUnit.MetricUnit.percent.name());
    valueUnit.setValueNum(4.67);
    String displayName = MetricName.SERVER_CPUUSAGE;
    Function<TranslateContext, MetricData> function = TranslateFunctionService.convert;
    Map<String, ValueUnit> valueUnitMap = new HashMap<>();
    valueUnitMap.put(assetId, valueUnit);
    TranslateContext translateContext = TranslateContext.buildByValueUnitsAndDisplayNameAndFormula(valueUnitMap, displayName, assetId);
    MetricData metricData = function.apply(translateContext);
    TestCase.assertEquals(valueUnit.getKey(), 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 57 with ValueUnit

use of com.vmware.flowgate.common.model.ValueUnit 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 58 with ValueUnit

use of com.vmware.flowgate.common.model.ValueUnit 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 59 with ValueUnit

use of com.vmware.flowgate.common.model.ValueUnit 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 60 with ValueUnit

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

Aggregations

ValueUnit (com.vmware.flowgate.common.model.ValueUnit)63 ArrayList (java.util.ArrayList)42 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)28 HashMap (java.util.HashMap)25 MetricData (com.vmware.flowgate.common.model.MetricData)23 Test (org.junit.Test)23 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 TranslateContext (com.vmware.flowgate.common.model.TranslateContext)13 Map (java.util.Map)11 List (java.util.List)9 Asset (com.vmware.flowgate.common.model.Asset)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 WormholeException (com.vmware.flowgate.common.exception.WormholeException)3 MetricUnit (com.vmware.flowgate.common.model.ValueUnit.MetricUnit)3 PowerManageMetricsRequestBody (com.vmware.flowgate.openmanage.datamodel.PowerManageMetricsRequestBody)3 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)3 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)2 DevicePower (com.vmware.flowgate.openmanage.datamodel.DevicePower)2 Outlet (com.vmware.flowgate.poweriqworker.model.Outlet)2 Pdu (com.vmware.flowgate.poweriqworker.model.Pdu)2