Search in sources :

Example 61 with ValueUnit

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

Example 62 with ValueUnit

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

the class FilterServerEnergyConsumptionTest method testFilterServerEnergyConsumption4.

@Test
public void testFilterServerEnergyConsumption4() {
    long time = System.currentTimeMillis();
    // Sample value of Openmanage SERVER_ENERGY_CONSUMPTION metric
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setTime(time);
    valueUnit.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
    valueUnit.setExtraidentifier(String.valueOf(1302663085000l));
    valueUnit.setUnit(MetricUnit.kWh.name());
    valueUnit.setValueNum(65633);
    List<ValueUnit> valueUnits = new ArrayList<ValueUnit>();
    valueUnits.add(valueUnit);
    List<ValueUnit> results = assetService.filterServerEnergyConsumption(valueUnits, time);
    TestCase.assertEquals(0, results.size());
}
Also used : ArrayList(java.util.ArrayList) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 63 with ValueUnit

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

the class FilterServerEnergyConsumptionTest method getValueUnitsFromOpenmanage.

/**
 * @param time
 * @param duration
 * @return
 */
List<ValueUnit> getValueUnitsFromOpenmanage(long startTime, int duration) {
    // Sample values of Openmanage SERVER_ENERGY_CONSUMPTION metric
    List<ValueUnit> valueUnits = new ArrayList<>();
    ValueUnit valueUnit;
    // Every 5 min create a SERVER_ENERGY_CONSUMPTION
    int oneValuePerTime = 1000 * 5 * 60;
    int interval = duration / oneValuePerTime;
    double[] energyValues = new double[interval];
    for (int i = 0; i < interval; i++) {
        energyValues[i] = 10 * (i + 1);
    }
    for (int i = 0; i < interval; i++) {
        long tempTime = startTime + ((i + 1) * oneValuePerTime);
        valueUnit = new ValueUnit();
        valueUnit.setTime(tempTime);
        valueUnit.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
        // The startTime of SERVER_ENERGY_CONSUMPTION value from Openmanage is not change
        valueUnit.setExtraidentifier(String.valueOf(startTime));
        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