use of com.vmware.flowgate.common.exception.WormholeException in project flowgate by vmware.
the class AuthVcUser method authenticateUser.
public void authenticateUser(String name, String password) throws URISyntaxException, InvalidLogin, InvalidLocale, SSLException {
Client vmomiClient = null;
SessionManager sessionManager = null;
try {
URI uri = new URI(serviceUrl);
HttpConfiguration httpConfig = new HttpConfigurationImpl();
httpConfig.setThumbprintVerifier(getThumbprintVerifier());
HttpClientConfiguration clientConfig = HttpClientConfiguration.Factory.newInstance();
// set customized SSL protocols
// TlsClientConfiguration tlsClientConfiguration = new TlsClientConfiguration();
httpConfig.setEnabledProtocols(new String[] { "TLSv1.1", "TLSv1.2" });
clientConfig.setHttpConfiguration(httpConfig);
vmomiClient = Client.Factory.createClient(uri, version, clientConfig);
ManagedObjectReference svcRef = new ManagedObjectReference();
svcRef.setType("ServiceInstance");
svcRef.setValue("ServiceInstance");
if (name == null || name.isEmpty()) {
// VC session token auth
vmomiClient.getBinding().setSession(vmomiClient.getBinding().createSession(password));
}
ServiceInstance instance = vmomiClient.createStub(ServiceInstance.class, svcRef);
ServiceInstanceContent instanceContent = instance.retrieveContent();
sessionManager = vmomiClient.createStub(SessionManager.class, instanceContent.getSessionManager());
if (name != null && !name.isEmpty()) {
// username/passowrd auth
sessionManager.login(name, password, sessionManager.getDefaultLocale());
sessionManager.logout();
} else {
// VC session token auth
UserSession session = sessionManager.getCurrentSession();
if (session == null) {
throw new WormholeException("invalid vc session.");
} else {
logger.info(session.getUserName() + " is authenticated");
}
}
} finally {
if (vmomiClient != null) {
vmomiClient.shutdown();
}
}
}
use of com.vmware.flowgate.common.exception.WormholeException in project flowgate by vmware.
the class NlyteDataService method generateValueUnits.
public List<ValueUnit> generateValueUnits(List<PowerStripsRealtimeValue> values, HashMap<AdvanceSettingType, String> advanceSettingMap) {
List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
long currenttime = System.currentTimeMillis();
String dateFormat = advanceSettingMap.get(AdvanceSettingType.DateFormat);
String timezone = advanceSettingMap.get(AdvanceSettingType.TimeZone);
String current = advanceSettingMap.get(AdvanceSettingType.PDU_AMPS_UNIT);
String power = advanceSettingMap.get(AdvanceSettingType.PDU_POWER_UNIT);
String voltage = advanceSettingMap.get(AdvanceSettingType.PDU_VOLT_UNIT);
for (PowerStripsRealtimeValue value : values) {
String valueDateTime = value.getRecordedDateTime();
long recordedTime = WormholeDateFormat.getLongTime(valueDateTime, dateFormat, timezone);
if (recordedTime > currenttime || recordedTime == -1) {
logger.error("Failed to translate the time string: " + valueDateTime);
continue;
}
if (sensorValueTypeMap.containsKey(value.getName())) {
ValueUnit valueunit = new ValueUnit();
valueunit.setKey(sensorValueTypeMap.get(value.getName()));
String unit = value.getUnit();
MetricUnit targetUnit = null, sourceUnit = null;
switch(sensorValueTypeMap.get(value.getName())) {
case MetricName.PDU_TOTAL_CURRENT:
if (unit != null && !unit.isEmpty()) {
sourceUnit = MetricUnit.valueOf(unit.toUpperCase());
} else {
sourceUnit = MetricUnit.valueOf(current.toUpperCase());
}
targetUnit = MetricUnit.A;
break;
case MetricName.PDU_TOTAL_POWER:
if (unit != null && !unit.isEmpty()) {
sourceUnit = MetricUnit.valueOf(unit.toUpperCase());
} else {
sourceUnit = MetricUnit.valueOf(power.toUpperCase());
}
targetUnit = MetricUnit.kW;
break;
case MetricName.PDU_VOLTAGE:
if (unit != null && !unit.isEmpty()) {
sourceUnit = MetricUnit.valueOf(unit.toUpperCase());
} else {
sourceUnit = MetricUnit.valueOf(voltage.toUpperCase());
}
targetUnit = MetricUnit.V;
break;
default:
break;
}
valueunit.setUnit(targetUnit.toString());
try {
valueunit.setValueNum(valueunit.translateUnit(value.getValue(), sourceUnit, targetUnit));
} catch (WormholeException e) {
logger.error("Cannot translate Unit", e);
}
valueunit.setTime(recordedTime);
valueunits.add(valueunit);
} else {
continue;
}
}
return valueunits;
}
use of com.vmware.flowgate.common.exception.WormholeException 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.exception.WormholeException in project flowgate by vmware.
the class EncryptionGuard method decode.
/**
* Decrypt the encrypted text against given secret key.
*
* @param encodedText
* the encrypted string
* @return the clear string, or null if encrypted string is null
* @throws WormholeException
* if input arguments is null
*/
public static String decode(String encodedText) throws GeneralSecurityException, UnsupportedEncodingException {
if (encodedText == null) {
return null;
}
if (encodedText.length() < SALT_SIZE) {
throw new WormholeException("This encodedText is invalid");
// throw EncryptionException.SHORT_ENCRYPTED_STRING(encodedText);
}
String initKey = FlowgateKeystore.getEncryptKey();
Key key = new SecretKeySpec(initKey.getBytes(), "AES");
encodedText.substring(0, SALT_SIZE);
String encryptedText = encodedText.substring(SALT_SIZE);
byte[] encryptedBytes = Base64.getDecoder().decode(encryptedText);
Cipher cipher = getCiperInternal(Cipher.DECRYPT_MODE, key);
byte[] outputBytes = cipher.doFinal(encryptedBytes);
String outputText = new String(outputBytes, UTF8_ENCODING);
return outputText.substring(SALT_SIZE);
}
Aggregations