use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class PowerIQService method getSensorRealTimeData.
public List<RealTimeData> getSensorRealTimeData(FacilitySoftwareConfig powerIQ, List<Asset> assets) {
HashMap<AdvanceSettingType, String> advanceSetting = getAdvanceSetting(powerIQ);
List<RealTimeData> realtimeDatas = new ArrayList<RealTimeData>();
String dateFormat = advanceSetting.get(AdvanceSettingType.DateFormat);
String timezone = advanceSetting.get(AdvanceSettingType.TimeZone);
String temperature = advanceSetting.get(AdvanceSettingType.TEMPERATURE_UNIT);
String humidity = advanceSetting.get(AdvanceSettingType.HUMIDITY_UNIT);
PowerIQAPIClient powerIQAPIClient = createClient(powerIQ);
for (Asset asset : assets) {
HashMap<String, String> sensorExtraInfo = asset.getJustificationfields();
String sensorInfo = sensorExtraInfo.get(FlowgateConstant.SENSOR);
Map<String, String> sensorInfoMap = null;
try {
sensorInfoMap = getInfoMap(sensorInfo);
} catch (IOException e2) {
continue;
}
String sensorId = sensorInfoMap.get(FlowgateConstant.SENSOR_ID_FROM_POWERIQ);
Sensor sensor = null;
try {
sensor = powerIQAPIClient.getSensorById(sensorId);
} catch (HttpClientErrorException e) {
logger.error("Failed to query data from PowerIQ", e);
IntegrationStatus integrationStatus = powerIQ.getIntegrationStatus();
if (integrationStatus == null) {
integrationStatus = new IntegrationStatus();
}
integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
integrationStatus.setDetail(e.getMessage());
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
updateIntegrationStatus(powerIQ);
break;
} catch (ResourceAccessException e1) {
if (e1.getCause().getCause() instanceof ConnectException) {
checkAndUpdateIntegrationStatus(powerIQ, e1.getMessage());
break;
}
break;
}
SensorReading reading = sensor.getReading();
if (reading == null || reading.getId() == 0) {
continue;
}
RealTimeData realTimeData = new RealTimeData();
String valueDateTime = reading.getReadingTime();
long recordedTime = WormholeDateFormat.getLongTime(valueDateTime, dateFormat, timezone);
if (recordedTime == -1) {
logger.error("Failed to translate the time string: " + valueDateTime + ".And the dateformat is " + dateFormat);
continue;
}
List<ValueUnit> values = new ArrayList<ValueUnit>();
ValueUnit value = new ValueUnit();
value.setTime(recordedTime);
value.setKey(sensorAndMetricMap.get(sensor.getType()));
String unit = reading.getUom();
MetricUnit sourceUnit = null, targetUnit = null;
switch(sensorAndMetricMap.get(sensor.getType())) {
case MetricName.HUMIDITY:
if (unit != null && !unit.isEmpty()) {
if (unit.equals("%")) {
sourceUnit = MetricUnit.percent;
} else {
sourceUnit = MetricUnit.valueOf(unit);
}
} else {
if (humidity.equals("%")) {
sourceUnit = MetricUnit.percent;
} else {
sourceUnit = MetricUnit.valueOf(humidity);
}
}
targetUnit = MetricUnit.percent;
break;
case MetricName.TEMPERATURE:
if (unit != null && !unit.isEmpty()) {
sourceUnit = MetricUnit.valueOf(unit.toUpperCase());
} else {
sourceUnit = MetricUnit.valueOf(temperature.toUpperCase());
}
targetUnit = MetricUnit.C;
break;
default:
break;
}
Double metricsValue = reading.getValue();
if (metricsValue == null) {
continue;
}
try {
value.setValueNum(value.translateUnit(metricsValue, sourceUnit, targetUnit));
} catch (WormholeException e) {
logger.error("Cannot translate Unit", e);
}
if (targetUnit.toString().equals(MetricUnit.percent.toString())) {
value.setUnit("%");
} else {
value.setUnit(targetUnit.toString());
}
values.add(value);
realTimeData.setAssetID(asset.getId());
realTimeData.setTime(recordedTime);
realTimeData.setValues(values);
realTimeData.setId(asset.getId() + "_" + recordedTime);
realtimeDatas.add(realTimeData);
}
return realtimeDatas;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class OpenManageJobService method getMetricDatas.
/**
*Example of Temperature
* "@odata.context": "/api/$metadata#DeviceService.TemperatureResponseModel",
* "@odata.type": "#DeviceService.TemperatureResponseModel",
* "@odata.id": "/api/DeviceService/Devices(10074)/Temperature",
* "peakTemperatureUnit": "celsius",
* "avgTemperatureUnit": "celsius",
* "DateFormat": "CIM",
* "instantaneousTemperatureUnit": "celsius",
* "startTime": "20210201050207.000000-360",
* "avgTemperatureTimeStamp": "20210202093523.806515-360",
* "avgTemperature": "21",
* "instantaneousTemperature": "23",
* "peakTemperature": "27",
* "peakTemperatureTimeStamp": "20210201050207.000000-360"
* @param integration
* @param client
* @return
*/
public List<RealTimeData> getMetricDatas(FacilitySoftwareConfig integration, OpenManageAPIClient client) {
List<RealTimeData> metricDatas = new ArrayList<RealTimeData>();
Map<String, String> assetIdAndOpenmanageDeviceIdMap = getMappedAssetIDMap(integration.getId());
if (assetIdAndOpenmanageDeviceIdMap.isEmpty()) {
return metricDatas;
}
Plugin powerManage = null;
CommonResult<Plugin> plugins = client.getCommonResult(Plugin.class);
for (Plugin plugin : plugins.getValue()) {
if (PowerManager.equals(plugin.getName()) && plugin.isInstalled() && plugin.isEnabled()) {
powerManage = plugin;
break;
}
}
for (Map.Entry<String, String> map : assetIdAndOpenmanageDeviceIdMap.entrySet()) {
String deviceId = map.getValue();
String assetId = map.getKey();
Map<String, ValueUnit> metricNameAndValueUnitMap = getMetricsData(deviceId, client, powerManage);
RealTimeData metricData = null;
if (!metricNameAndValueUnitMap.isEmpty()) {
metricData = new RealTimeData();
List<ValueUnit> valueUnits = new ArrayList<ValueUnit>(metricNameAndValueUnitMap.values());
long currentTime = valueUnits.get(0).getTime();
metricData.setAssetID(assetId);
metricData.setTime(currentTime);
metricData.setValues(valueUnits);
metricData.setId(assetId + currentTime);
metricDatas.add(metricData);
}
}
return metricDatas;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class OpenManageJobTest method getMetricDatas.
@Test
public void getMetricDatas() {
Mockito.when(this.openManageAPIClient.getCommonResult(Plugin.class)).thenReturn(getCommonResult());
Mockito.when(this.openManageAPIClient.getDevicePowerMetrics("10074")).thenReturn(getPowerMetricsData());
Mockito.when(this.openManageAPIClient.getDeviceTemperatureMetrics("10074")).thenReturn(getDeviceTemperature());
Mockito.when(this.openManageAPIClient.getMetricsFromPowerManage(any(PowerManageMetricsRequestBody.class))).thenReturn(getDeviceMetricsResult());
Mockito.when(this.openManageAPIClient.getCommonResult(PowerSetting.class)).thenReturn(getPowerSettings());
FacilitySoftwareConfig config = new FacilitySoftwareConfig();
config.setId(createAsset().getAssetSource());
List<RealTimeData> metricDatas = openmanageJobService.getMetricDatas(config, openManageAPIClient);
for (RealTimeData data : metricDatas) {
if ("assetid1611766210404".equals(data.getId())) {
// power metrics
List<ValueUnit> values = data.getValues();
for (ValueUnit value : values) {
switch(value.getKey()) {
case MetricName.SERVER_AVERAGE_USED_POWER:
TestCase.assertEquals(0.074, value.getValueNum());
break;
// use powerManager value to override it
case MetricName.SERVER_POWER:
TestCase.assertEquals(0.072, value.getValueNum());
break;
case MetricName.SERVER_MINIMUM_USED_POWER:
TestCase.assertEquals(0.07, value.getValueNum());
break;
case MetricName.SERVER_PEAK_USED_POWER:
TestCase.assertEquals(0.08, value.getValueNum());
break;
case MetricName.SERVER_ENERGY_CONSUMPTION:
TestCase.assertEquals(800.0, value.getValueNum());
break;
case MetricName.SERVER_AVERAGE_TEMPERATURE:
TestCase.assertEquals(22.0, value.getValueNum());
break;
case MetricName.SERVER_TEMPERATURE:
TestCase.assertEquals(24.0, value.getValueNum());
break;
case MetricName.SERVER_PEAK_TEMPERATURE:
TestCase.assertEquals(30.0, value.getValueNum());
break;
case MetricName.SERVER_FRONT_TEMPERATURE:
TestCase.assertEquals(24.0, value.getValueNum());
break;
default:
TestCase.fail();
break;
}
}
} else {
TestCase.fail();
}
}
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class OpenManageJobTest method getMetricDatasTestNA.
@Test
public void getMetricDatasTestNA() {
Mockito.when(this.openManageAPIClient.getCommonResult(Plugin.class)).thenReturn(getCommonResult());
DevicePower powerMetrics = getPowerMetricsData();
powerMetrics.setMinimumPower("N/A");
Mockito.when(this.openManageAPIClient.getDevicePowerMetrics("10074")).thenReturn(powerMetrics);
Mockito.when(this.openManageAPIClient.getDeviceTemperatureMetrics("10074")).thenReturn(getDeviceTemperature());
Mockito.when(this.openManageAPIClient.getMetricsFromPowerManage(any(PowerManageMetricsRequestBody.class))).thenReturn(getDeviceMetricsResult());
Mockito.when(this.openManageAPIClient.getCommonResult(PowerSetting.class)).thenReturn(getPowerSettings());
FacilitySoftwareConfig config = new FacilitySoftwareConfig();
config.setId(createAsset().getAssetSource());
List<RealTimeData> metricDatas = openmanageJobService.getMetricDatas(config, openManageAPIClient);
for (RealTimeData data : metricDatas) {
if ("assetid1611766210404".equals(data.getId())) {
// power metrics
List<ValueUnit> values = data.getValues();
for (ValueUnit value : values) {
switch(value.getKey()) {
case MetricName.SERVER_AVERAGE_USED_POWER:
TestCase.assertEquals(0.074, value.getValueNum());
break;
// use powerManager value to override it
case MetricName.SERVER_POWER:
TestCase.assertEquals(0.072, value.getValueNum());
break;
case MetricName.SERVER_MINIMUM_USED_POWER:
TestCase.fail("Should not contain the " + MetricName.SERVER_MINIMUM_USED_POWER);
break;
case MetricName.SERVER_PEAK_USED_POWER:
TestCase.assertEquals(0.08, value.getValueNum());
break;
case MetricName.SERVER_ENERGY_CONSUMPTION:
TestCase.assertEquals(800.0, value.getValueNum());
break;
case MetricName.SERVER_AVERAGE_TEMPERATURE:
TestCase.assertEquals(22.0, value.getValueNum());
break;
case MetricName.SERVER_TEMPERATURE:
TestCase.assertEquals(24.0, value.getValueNum());
break;
case MetricName.SERVER_PEAK_TEMPERATURE:
TestCase.assertEquals(30.0, value.getValueNum());
break;
case MetricName.SERVER_FRONT_TEMPERATURE:
TestCase.assertEquals(24.0, value.getValueNum());
break;
default:
TestCase.fail();
break;
}
}
} else {
TestCase.fail();
}
}
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class VCDataService method getMinMaxAvgValueUnit.
public List<ValueUnit> getMinMaxAvgValueUnit(List<ValueUnit> valueUnits) {
List<ValueUnit> statisticsValueUnit = new ArrayList<>(3);
if (valueUnits == null || valueUnits.isEmpty()) {
return statisticsValueUnit;
}
ValueUnit firstValueUnit = valueUnits.get(0);
ValueUnit minValueUnit = new ValueUnit();
minValueUnit.setUnit(firstValueUnit.getUnit());
minValueUnit.setValueNum(firstValueUnit.getValueNum());
minValueUnit.setTime(firstValueUnit.getTime());
ValueUnit maxValueUnit = new ValueUnit();
maxValueUnit.setUnit(firstValueUnit.getUnit());
maxValueUnit.setValueNum(firstValueUnit.getValueNum());
maxValueUnit.setTime(firstValueUnit.getTime());
ValueUnit averageValueUnit = new ValueUnit();
averageValueUnit.setUnit(firstValueUnit.getUnit());
if (MetricName.SERVER_POWER.equals(firstValueUnit.getKey())) {
minValueUnit.setKey(MetricName.SERVER_MINIMUM_USED_POWER);
maxValueUnit.setKey(MetricName.SERVER_PEAK_USED_POWER);
averageValueUnit.setKey(MetricName.SERVER_AVERAGE_USED_POWER);
} else {
return statisticsValueUnit;
}
double sum = 0.0d;
long startTime = Long.MAX_VALUE;
long endTime = Long.MIN_VALUE;
for (ValueUnit value : valueUnits) {
double valueNum = value.getValueNum();
long time = value.getTime();
sum += valueNum;
if (valueNum < minValueUnit.getValueNum()) {
minValueUnit.setValueNum(valueNum);
minValueUnit.setTime(time);
}
if (valueNum > maxValueUnit.getValueNum()) {
maxValueUnit.setValueNum(valueNum);
maxValueUnit.setTime(time);
}
startTime = Math.min(time, startTime);
endTime = Math.max(time, endTime);
}
// Record the since time and peak power time, for example 1612417403074_FIELDSPLIT_1612415606985
minValueUnit.setExtraidentifier(startTime + FlowgateConstant.SEPARATOR + minValueUnit.getTime());
minValueUnit.setTime(endTime);
maxValueUnit.setExtraidentifier(startTime + FlowgateConstant.SEPARATOR + maxValueUnit.getTime());
maxValueUnit.setTime(endTime);
averageValueUnit.setValueNum(sum / valueUnits.size());
averageValueUnit.setExtraidentifier(String.valueOf(startTime));
averageValueUnit.setTime(endTime);
statisticsValueUnit.add(minValueUnit);
statisticsValueUnit.add(maxValueUnit);
statisticsValueUnit.add(averageValueUnit);
return statisticsValueUnit;
}
Aggregations