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