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());
}
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());
}
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;
}
Aggregations