use of com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType in project flowgate by vmware.
the class MessageProcessingTest method createFacilitySoftware.
FacilitySoftwareConfig createFacilitySoftware() {
FacilitySoftwareConfig example = new FacilitySoftwareConfig();
example.setId(UUID.randomUUID().toString());
example.setName("OtherDcimSample");
example.setUserName("administrator@vsphere.local");
example.setPassword("Admin!23");
example.setServerURL("https://10.160.30.134");
example.setType(FacilitySoftwareConfig.SoftwareType.OtherDCIM);
example.setUserId("1");
example.setVerifyCert(false);
example.setDescription("description");
HashMap<AdvanceSettingType, String> advanceSetting = new HashMap<AdvanceSettingType, String>();
example.setAdvanceSetting(advanceSetting);
IntegrationStatus integrationStatus = new IntegrationStatus();
integrationStatus.setDetail("");
integrationStatus.setRetryCounter(0);
integrationStatus.setStatus(Status.ACTIVE);
example.setIntegrationStatus(integrationStatus);
return example;
}
use of com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testGenerateRealTimeData.
@Test
public void testGenerateRealTimeData() {
Asset asset = createAsset();
asset.setId("5x4ff46982db22e1b040e0f2");
HashMap<AdvanceSettingType, String> advanceSettingMap = new HashMap<AdvanceSettingType, String>();
advanceSettingMap.put(AdvanceSettingType.DateFormat, NlyteDataService.DateFormat);
advanceSettingMap.put(AdvanceSettingType.TimeZone, "GMT");
RealTimeData data = nlyteDataService.generateRealTimeData(asset, nlyteAPIClient, advanceSettingMap);
TestCase.assertEquals("5x4ff46982db22e1b040e0f2", data.getAssetID());
}
use of com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType in project flowgate by vmware.
the class SycnRealTimeDataJobTest method getFacilitySoftwareByType.
public ResponseEntity<FacilitySoftwareConfig[]> getFacilitySoftwareByType() {
HashMap<AdvanceSettingType, String> advanceSettingMap = new HashMap<AdvanceSettingType, String>();
advanceSettingMap.put(AdvanceSettingType.DateFormat, NlyteDataService.DateFormat);
advanceSettingMap.put(AdvanceSettingType.TimeZone, "GMT");
FacilitySoftwareConfig[] configs = new FacilitySoftwareConfig[1];
configs[0] = new FacilitySoftwareConfig();
configs[0].setId("l9i8728d55368540fcba1692");
configs[0].setType(SoftwareType.Nlyte);
configs[0].setAdvanceSetting(advanceSettingMap);
return new ResponseEntity<FacilitySoftwareConfig[]>(configs, HttpStatus.OK);
}
use of com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType 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