use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testGetRealTimeDatas.
@Test
public void testGetRealTimeDatas() {
Set<String> assetIds = new HashSet<String>();
assetIds.add("5x4ff46982db22e1b040e0f2");
FacilitySoftwareConfig config = getFacilitySoftwareByType().getBody()[0];
List<RealTimeData> realTimeDatas = nlyteDataService.getRealTimeDatas(nlyteAPIClient, config, assetIds);
TestCase.assertEquals(1, realTimeDatas.size());
TestCase.assertEquals("5x4ff46982db22e1b040e0f2", realTimeDatas.get(0).getAssetID());
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class PowerIQService method getRealTimeDatas.
public List<RealTimeData> getRealTimeDatas(Map<String, Map<String, String>> pduAssetIdAndPduInfoMap, PowerIQAPIClient client, HashMap<AdvanceSettingType, String> advanceSettingMap) {
List<RealTimeData> realTimeDatas = new ArrayList<RealTimeData>();
if (pduAssetIdAndPduInfoMap == null || pduAssetIdAndPduInfoMap.isEmpty()) {
return realTimeDatas;
}
try {
for (Map.Entry<String, Map<String, String>> map : pduAssetIdAndPduInfoMap.entrySet()) {
List<ValueUnit> values = getValueUnits(map.getValue(), client, advanceSettingMap);
if (!values.isEmpty()) {
RealTimeData realTimeData = new RealTimeData();
realTimeData.setAssetID(map.getKey());
realTimeData.setValues(values);
realTimeData.setTime(values.get(0).getTime());
// this will remove the duplicated items.
realTimeData.setId(map.getKey() + "_" + realTimeData.getTime());
realTimeDatas.add(realTimeData);
} else {
continue;
}
}
} catch (Exception e) {
logger.error("An exception occurred in the method of getRealTimeDatas from SyncPowerIQRealTimeDataJob", e);
}
return realTimeDatas;
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class PowerIQService method syncRealtimeData.
// Sync realtime Data logic need to refactor.
private void syncRealtimeData(FacilitySoftwareConfig powerIQ) {
restClient.setServiceKey(serviceKeyConfig.getServiceKey());
List<Asset> allMappedPdus = Arrays.asList(restClient.getMappedAsset(AssetCategory.PDU).getBody());
if (allMappedPdus == null || allMappedPdus.isEmpty()) {
return;
}
PowerIQAPIClient client = createClient(powerIQ);
try {
client.testConnection();
} 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);
return;
} catch (ResourceAccessException e1) {
if (e1.getCause().getCause() instanceof ConnectException) {
checkAndUpdateIntegrationStatus(powerIQ, e1.getMessage());
return;
}
}
Map<String, Map<String, String>> pduAssetIdAndPduInfoMap = new HashMap<String, Map<String, String>>();
for (Asset asset : allMappedPdus) {
String id = null;
Map<String, String> pduInfoMap = null;
if (asset.getJustificationfields() != null) {
HashMap<String, String> justficationfields = asset.getJustificationfields();
String pduInfo = justficationfields.get(FlowgateConstant.PDU);
try {
pduInfoMap = getInfoMap(pduInfo);
} catch (IOException e) {
continue;
}
id = pduInfoMap.get(FlowgateConstant.PDU_ID_FROM_POWERIQ);
// Only check the pdu that belong to the current PowerIQ.
if (!asset.getAssetSource().contains((powerIQ.getId()))) {
continue;
}
}
if (id != null) {
pduAssetIdAndPduInfoMap.put(asset.getId(), pduInfoMap);
}
}
List<RealTimeData> pduMetricRealTimeDatas = getRealTimeDatas(pduAssetIdAndPduInfoMap, client, getAdvanceSetting(powerIQ));
if (!pduMetricRealTimeDatas.isEmpty()) {
restClient.saveRealTimeData(pduMetricRealTimeDatas);
logger.info("Finish sync pdu realtime data for " + powerIQ.getName());
} else {
logger.info("Not found any pdu realtime data from " + powerIQ.getName());
}
List<Asset> allMappedServers = Arrays.asList(restClient.getMappedAsset(AssetCategory.Server).getBody());
if (allMappedServers.isEmpty()) {
logger.info("No mapped server found. End sync RealTime data Job");
return;
}
// get sensor assetIds from pdu's metricsFormular attribute
Set<String> sensorAssetIds = getAssetIdfromformular(allMappedPdus);
// get sensor assetIds from server's metricsFromular attribute
Set<String> sensorAssetIdsFromServer = getAssetIdfromformular(allMappedServers);
sensorAssetIds.addAll(sensorAssetIdsFromServer);
if (sensorAssetIds.isEmpty()) {
return;
}
// filter sensors
List<Asset> sensorFromPowerIQ = filterAssetsBySource(powerIQ.getId(), sensorAssetIds);
List<RealTimeData> realTimeDatas = getSensorRealTimeData(powerIQ, sensorFromPowerIQ);
logger.info("Received new Sensor data, data item size is:" + realTimeDatas.size());
if (realTimeDatas.isEmpty()) {
logger.info("Not found any sensor realtime data from " + powerIQ.getName());
return;
}
restClient.saveRealTimeData(realTimeDatas);
logger.info("Finish sync sensor realtime data for " + powerIQ.getName());
}
use of com.vmware.flowgate.common.model.RealTimeData 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.RealTimeData 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;
}
Aggregations