Search in sources :

Example 1 with ValueUnit

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

the class TranslateFunctionServiceTest method testConvertServerAverageUsedPowerEnergyConsumptionAverageTemperature.

@Test
public void testConvertServerAverageUsedPowerEnergyConsumptionAverageTemperature() {
    String assetId = "752c0c7637104a39a4242031cd48785e";
    long startTime = System.currentTimeMillis();
    long endTime = startTime + 30000;
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setTime(endTime);
    valueUnit.setExtraidentifier(String.valueOf(startTime));
    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.assertEquals(valueUnit.getKey(), metricData.getMetricName());
    TestCase.assertEquals(startTime, 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 2 with ValueUnit

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

the class TranslateFunctionServiceTest method testServerConvertValue.

@Test
public void testServerConvertValue() {
    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.setValue("value");
    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("value", metricData.getValue());
    TestCase.assertEquals(0.0, 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 3 with ValueUnit

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

the class TranslateFunctionServiceTest method testConvertServerPeakUsedPowerMinimumUsedPowerPeakTemperature.

@Test
public void testConvertServerPeakUsedPowerMinimumUsedPowerPeakTemperature() {
    String assetId = "752c0c7637104a39a4242031cd48785e";
    long startTime = System.currentTimeMillis();
    long maxValueTime = startTime + 2000;
    long endTime = startTime + 30000;
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setTime(endTime);
    valueUnit.setExtraidentifier(startTime + FlowgateConstant.SEPARATOR + maxValueTime);
    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.assertEquals(valueUnit.getKey(), metricData.getMetricName());
    TestCase.assertEquals(maxValueTime, 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 4 with ValueUnit

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

the class FilterServerEnergyConsumptionTest method testFilterServerEnergyConsumption2.

@Test
public void testFilterServerEnergyConsumption2() {
    long time = System.currentTimeMillis();
    int duration = 30 * 60 * 1000;
    int vcduration = 20 * 60 * 1000;
    // The vc-worker miss 10 min datas
    List<ValueUnit> valueUnits = getValueUnitsFromVC(time, vcduration);
    valueUnits.addAll(getValueUnitsFromOpenmanage(time, duration));
    List<ValueUnit> results = assetService.filterServerEnergyConsumption(valueUnits, 1618204305000l);
    TestCase.assertEquals(1, results.size());
    for (ValueUnit value : results) {
        TestCase.assertEquals(60.0, value.getValueNum());
    }
}
Also used : ValueUnit(com.vmware.flowgate.common.model.ValueUnit) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with ValueUnit

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

the class FilterServerEnergyConsumptionTest method getValueUnitsFromVC.

List<ValueUnit> getValueUnitsFromVC(long time, int duration) {
    List<ValueUnit> valueUnits = new ArrayList<>();
    ValueUnit valueUnit;
    int oneValuePerTime = 1000 * 20;
    int interval = duration / oneValuePerTime;
    double[] energyValues = new double[interval];
    for (int i = 0; i < interval; i++) {
        energyValues[i] = 0.001 * (i + 1);
    }
    for (int i = 0; i < interval; i++) {
        long tempTime = time + ((i + 1) * oneValuePerTime);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
        valueUnit.setExtraidentifier(String.valueOf(tempTime - oneValuePerTime));
        valueUnit.setUnit(MetricUnit.kWh.name());
        valueUnit.setValueNum(energyValues[i]);
        valueUnits.add(valueUnit);
    }
    return valueUnits;
}
Also used : ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit)

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