use of com.emc.cloud.platform.clientlib.ClientGeneralException in project coprhd-controller by CoprHD.
the class UCSMServiceImpl method bindSPToComputeElement.
@Override
public LsServer bindSPToComputeElement(String ucsmURL, String username, String password, String serviceProfileDn, String computeElementDn, StringBuilder errorMessage) throws ClientGeneralException {
ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
ConfigConfMo bindSPToCEConfigConfMo = new ConfigConfMo();
bindSPToCEConfigConfMo.setInHierarchical(Boolean.toString(true));
// bindSPToCEConfigConfMo.
com.emc.cloud.platform.ucs.in.model.LsServer lsServer = new com.emc.cloud.platform.ucs.in.model.LsServer();
lsServer.setDn(serviceProfileDn);
LsBinding lsBinding = new LsBinding();
lsBinding.setPnDn(computeElementDn);
lsServer.getContent().add(factory.createLsBinding(lsBinding));
ConfigConfig configConfig = new ConfigConfig();
configConfig.setManagedObject(factory.createLsServer(lsServer));
bindSPToCEConfigConfMo.getContent().add(factory.createConfigConfMoInConfig(configConfig));
LsServer returnedLsServer = pushLsServer(computeSession, factory, bindSPToCEConfigConfMo, errorMessage);
if ((returnedLsServer == null) || returnedLsServer.getAssignState().equals(ASSOC_STATE_UNASSOCIATED)) {
throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, new String[] { "Failed to bind ServiceProfile " + serviceProfileDn + " to ComputeElement '" + computeElementDn + "' on LsServer : " + serviceProfileDn });
}
return returnedLsServer;
}
use of com.emc.cloud.platform.clientlib.ClientGeneralException in project coprhd-controller by CoprHD.
the class UCSMSession method decryptAndRetrieveSessionCache.
public ComputeSessionCache decryptAndRetrieveSessionCache() throws ClientGeneralException {
Object zkdata = null;
ComputeSessionCache cache = null;
try {
LOGGER.debug("Attempt to fetch session info for {}", hostAddress);
try {
zkdata = distributedDataManager.getData(getNodePath(), false);
} catch (Exception e) {
throw new ClientGeneralException(ClientMessageKeys.DISTRIBUTED_DATA_CACHE_ERROR, e);
}
if (zkdata != null) {
cache = (ComputeSessionCache) zkdata;
}
try {
if (cache != null && cache.getSessionId() != null) {
cache.setSessionId(encryptionProvider.decrypt(Base64.decodeBase64(cache.getSessionId())));
}
} catch (Exception e) {
throw new ClientGeneralException(ClientMessageKeys.DATA_ENCRYPTION_ERROR, e);
}
} catch (Exception e) {
LOGGER.warn(e.getMessage());
}
return cache;
}
use of com.emc.cloud.platform.clientlib.ClientGeneralException in project coprhd-controller by CoprHD.
the class UCSMSession method getLock.
private InterProcessReadWriteLock getLock() throws ClientGeneralException {
try {
if (lock == null) {
String lockName = ComputeSessionUtil.Constants.COMPUTE_SESSION_BASE_PATH.toString() + "-" + hostAddress;
lock = coordinator.getReadWriteLock(lockName);
}
} catch (Exception e) {
throw new ClientGeneralException(ClientMessageKeys.DISTRIBUTED_LOCK_ERROR, e);
}
return lock;
}
use of com.emc.cloud.platform.clientlib.ClientGeneralException in project coprhd-controller by CoprHD.
the class UCSMSession method relogin.
private void relogin() throws ClientGeneralException {
try {
writeLock();
LOGGER.info("Attempt to login {}", hostAddress);
// recheck login status
if (isSessionValid()) {
LOGGER.debug("After rechecking. Re-login session not required for {}", hostAddress);
return;
}
ComputeSessionCache cache = null;
AaaLogin aaaLogin = new AaaLogin();
aaaLogin.setInName(username);
aaaLogin.setInPassword(password);
Object response = ucsmTransportWrapper.execute(serviceURI, objectFactory.createAaaLogin(aaaLogin), Object.class);
Assert.notNull(response, "Authentication Call resulted in Null Response");
Assert.isTrue(response instanceof com.emc.cloud.platform.ucs.out.model.AaaLogin, "Invalid Response Type!");
com.emc.cloud.platform.ucs.out.model.AaaLogin loginResponse = (com.emc.cloud.platform.ucs.out.model.AaaLogin) response;
if (loginResponse != null && loginResponse.getOutCookie() != null && !loginResponse.getOutCookie().isEmpty()) {
cache = new ComputeSessionCache(loginResponse.getOutCookie(), System.currentTimeMillis(), parseNumber(loginResponse.getOutRefreshPeriod()).longValue(), oneWayHash);
encryptAndUpdateSessionCache(cache);
} else {
throw new ClientGeneralException(ClientMessageKeys.UNAUTHORIZED, new String[] { serviceURI, "", "Unable to authenticate username/credentials pair" });
}
} finally {
writeUnlock();
}
}
use of com.emc.cloud.platform.clientlib.ClientGeneralException in project coprhd-controller by CoprHD.
the class UCSMHttpTransportWrapper method postEntity.
public <T> T postEntity(String serviceURI, JAXBElement<T> jaxbElement, Class<T> returnType) throws ClientGeneralException {
URL ucsmURL = null;
ClientHttpRequest httpRequest = null;
try {
ucsmURL = new URL(serviceURI);
} catch (MalformedURLException ex) {
throw new ClientGeneralException(ClientMessageKeys.MALFORMED_URL);
}
if (ucsmURL.getProtocol().equalsIgnoreCase("https")) {
httpRequest = ucsSSLTransportRequestFactory.create();
} else {
httpRequest = ucsTransportRequestFactory.create();
}
T result = null;
try {
result = httpRequest.httpPostXMLObject(serviceURI, jaxbElement, returnType);
} catch (ClientGeneralException e) {
LOGGER.info(e.getLocalizedMessage(), e);
throw e;
}
return result;
}
Aggregations