use of com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient in project flowgate by vmware.
the class PowerIQService method removeSensorMetaData.
public void removeSensorMetaData(FacilitySoftwareConfig powerIQ) {
PowerIQAPIClient client = createClient(powerIQ);
restClient.setServiceKey(serviceKeyConfig.getServiceKey());
List<Asset> sensors = restClient.getAllAssetsBySourceAndType(powerIQ.getId(), AssetCategory.Sensors);
List<Asset> servers = restClient.getAllAssetsByType(AssetCategory.Server);
long currentTime = System.currentTimeMillis();
String expiredTimeRangeValue = template.opsForValue().get(EventMessageUtil.EXPIREDTIMERANGE);
long expiredTimeRange = 0l;
if (expiredTimeRangeValue != null) {
expiredTimeRange = Long.valueOf(expiredTimeRangeValue);
} else {
expiredTimeRange = FlowgateConstant.DEFAULTEXPIREDTIMERANGE;
}
for (Asset sensor : sensors) {
if (!sensor.isExpired(currentTime, expiredTimeRange)) {
continue;
}
Sensor sensorFromPowerIQ = client.getSensorById(String.valueOf(sensor.getAssetNumber()));
if (sensorFromPowerIQ == null) {
List<Asset> needToupdate = updateServer(servers, sensor.getId());
restClient.saveAssets(needToupdate);
restClient.removeAssetByID(sensor.getId());
} else {
sensor.setLastupdate(currentTime);
restClient.saveAssets(sensor);
}
}
}
use of com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient in project flowgate by vmware.
the class PowerIQService method syncPowerIQAssetsMetaData.
public void syncPowerIQAssetsMetaData(FacilitySoftwareConfig powerIQ) {
PowerIQAPIClient client = createClient(powerIQ);
restClient.setServiceKey(serviceKeyConfig.getServiceKey());
try {
client.testConnection();
} catch (ResourceAccessException e1) {
if (e1.getCause().getCause() instanceof ConnectException) {
checkAndUpdateIntegrationStatus(powerIQ, e1.getMessage());
return;
}
} 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;
}
LocationInfo location = getLocationInfo(client);
List<Asset> pdusFromFlowgate = restClient.getAllAssetsBySourceAndType(powerIQ.getId(), AssetCategory.PDU);
Map<String, Asset> pduIDAndAssetMap = getPDUIDAndAssetMap(pdusFromFlowgate);
boolean hasNewPduToSave = savePduAssetsToFlowgate(pduIDAndAssetMap, powerIQ.getId(), client, location);
logger.info("Finish sync PDU metadata for " + powerIQ.getName());
Map<String, Asset> exsitingSensorAssets = getAssetsFromWormhole(powerIQ.getId());
saveSensorAssetsToFlowgate(exsitingSensorAssets, client, powerIQ.getId(), location);
logger.info("Finish sync Sensor metadata for: " + powerIQ.getName());
if (hasNewPduToSave) {
try {
EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.AggregateAndCleanPowerIQPDU, "");
String jobmessage = EventMessageUtil.convertEventMessageAsString(eventMessage);
publisher.publish(EventMessageUtil.AggregatorTopic, jobmessage);
logger.info("Send aggregate Pdu data command");
} catch (IOException e) {
logger.error("Failed to Send aggregate pdu data command", e);
}
}
}
use of com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient 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.poweriqworker.client.PowerIQAPIClient 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;
}
Aggregations