use of com.xensource.xenapi.Session in project cloudstack by apache.
the class XenServerConnectionPool method connect.
public Connection connect(String hostUuid, String poolUuid, String ipAddress, String username, Queue<String> password, int wait) {
XenServerConnection mConn = null;
if (hostUuid == null || poolUuid == null || ipAddress == null || username == null || password == null) {
String msg = "Connect some parameter are null hostUuid:" + hostUuid + " ,poolUuid:" + poolUuid + " ,ipAddress:" + ipAddress;
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
synchronized (poolUuid.intern()) {
mConn = getConnect(poolUuid);
if (mConn != null) {
try {
Host host = Host.getByUuid(mConn, hostUuid);
if (!host.getEnabled(mConn)) {
String msg = "Cannot connect this host " + ipAddress + " due to the host is not enabled";
s_logger.debug(msg);
if (mConn.getIp().equalsIgnoreCase(ipAddress)) {
removeConnect(poolUuid);
mConn = null;
}
throw new CloudRuntimeException(msg);
}
return mConn;
} catch (CloudRuntimeException e) {
throw e;
} catch (Exception e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("connect through IP(" + mConn.getIp() + " for pool(" + poolUuid + ") is broken due to " + e.toString());
}
removeConnect(poolUuid);
mConn = null;
}
}
if (mConn == null) {
try {
Connection conn = new Connection(getURL(ipAddress), 5, _connWait);
Session sess = loginWithPassword(conn, username, password, APIVersion.latest().toString());
Host host = sess.getThisHost(conn);
Boolean hostenabled = host.getEnabled(conn);
if (sess != null) {
try {
Session.logout(conn);
} catch (Exception e) {
s_logger.debug("Caught exception during logout", e);
}
conn.dispose();
}
if (!hostenabled) {
String msg = "Unable to create master connection, due to master Host " + ipAddress + " is not enabled";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
mConn = new XenServerConnection(getURL(ipAddress), ipAddress, username, password, _retries, _interval, wait, _connWait);
loginWithPassword(mConn, username, password, APIVersion.latest().toString());
} catch (Types.HostIsSlave e) {
String maddress = e.masterIPAddress;
mConn = new XenServerConnection(getURL(maddress), maddress, username, password, _retries, _interval, wait, _connWait);
try {
Session session = loginWithPassword(mConn, username, password, APIVersion.latest().toString());
Host host = session.getThisHost(mConn);
if (!host.getEnabled(mConn)) {
String msg = "Unable to create master connection, due to master Host " + maddress + " is not enabled";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
} catch (Exception e1) {
String msg = "Unable to create master connection to host(" + maddress + ") , due to " + e1.toString();
s_logger.debug(msg);
throw new CloudRuntimeException(msg, e1);
}
} catch (CloudRuntimeException e) {
throw e;
} catch (Exception e) {
String msg = "Unable to create master connection to host(" + ipAddress + ") , due to " + e.toString();
s_logger.debug(msg);
throw new CloudRuntimeException(msg, e);
}
addConnect(poolUuid, mConn);
}
}
return mConn;
}
use of com.xensource.xenapi.Session in project cosmic by MissionCriticalCloud.
the class XenServerConnectionPool method slaveLocalLoginWithPassword.
protected Session slaveLocalLoginWithPassword(final Connection conn, final String username, final Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException {
Session s = null;
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
s = Session.slaveLocalLoginWithPassword(conn, username, password.peek());
logged_in = true;
} catch (final BadServerResponse e) {
logged_in = false;
ex = e;
} catch (final XenAPIException e) {
logged_in = false;
ex = e;
} catch (final XmlRpcException e) {
logged_in = false;
ex = e;
}
if (logged_in && conn != null) {
break;
} else {
if (password.size() > 1) {
password.remove();
continue;
} else {
// the last password did not work leave it and flag error
if (ex instanceof BadServerResponse) {
throw (BadServerResponse) ex;
} else if (ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
} else if (ex instanceof Types.SessionAuthenticationFailed) {
throw (Types.SessionAuthenticationFailed) ex;
} else if (ex instanceof XenAPIException) {
throw (XenAPIException) ex;
}
break;
}
}
}
return s;
}
use of com.xensource.xenapi.Session in project cosmic by MissionCriticalCloud.
the class XenServerConnectionPool method connect.
public Connection connect(final String hostUuid, final String poolUuid, final String ipAddress, final String username, final Queue<String> password, final int wait) {
XenServerConnection mConn = null;
if (hostUuid == null || poolUuid == null || ipAddress == null || username == null || password == null) {
final String msg = "Connect some parameter are null hostUuid:" + hostUuid + " ,poolUuid:" + poolUuid + " ,ipAddress:" + ipAddress;
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
synchronized (poolUuid.intern()) {
mConn = getConnect(poolUuid);
if (mConn != null) {
try {
final Host host = Host.getByUuid(mConn, hostUuid);
if (!host.getEnabled(mConn)) {
final String msg = "Cannot connect this host " + ipAddress + " due to the host is not enabled";
s_logger.debug(msg);
if (mConn.getIp().equalsIgnoreCase(ipAddress)) {
removeConnect(poolUuid);
mConn = null;
}
throw new CloudRuntimeException(msg);
}
return mConn;
} catch (final CloudRuntimeException e) {
throw e;
} catch (final Exception e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("connect through IP(" + mConn.getIp() + " for pool(" + poolUuid + ") is broken due to " + e.toString());
}
removeConnect(poolUuid);
mConn = null;
}
}
if (mConn == null) {
try {
final Connection conn = new Connection(getURL(ipAddress), 5, _connWait);
final Session sess = loginWithPassword(conn, username, password, APIVersion.latest().toString());
final Host host = sess.getThisHost(conn);
final Boolean hostenabled = host.getEnabled(conn);
if (sess != null) {
try {
Session.logout(conn);
} catch (final Exception e) {
s_logger.debug("Caught exception during logout", e);
}
conn.dispose();
}
if (!hostenabled) {
final String msg = "Unable to create master connection, due to master Host " + ipAddress + " is not enabled";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
mConn = new XenServerConnection(getURL(ipAddress), ipAddress, username, password, _retries, _interval, wait, _connWait);
loginWithPassword(mConn, username, password, APIVersion.latest().toString());
} catch (final Types.HostIsSlave e) {
final String maddress = e.masterIPAddress;
mConn = new XenServerConnection(getURL(maddress), maddress, username, password, _retries, _interval, wait, _connWait);
try {
final Session session = loginWithPassword(mConn, username, password, APIVersion.latest().toString());
final Host host = session.getThisHost(mConn);
if (!host.getEnabled(mConn)) {
final String msg = "Unable to create master connection, due to master Host " + maddress + " is not enabled";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
} catch (final Exception e1) {
final String msg = "Unable to create master connection to host(" + maddress + ") , due to " + e1.toString();
s_logger.debug(msg);
throw new CloudRuntimeException(msg, e1);
}
} catch (final CloudRuntimeException e) {
throw e;
} catch (final Exception e) {
final String msg = "Unable to create master connection to host(" + ipAddress + ") , due to " + e.toString();
s_logger.debug(msg);
throw new CloudRuntimeException(msg, e);
}
addConnect(poolUuid, mConn);
}
}
return mConn;
}
use of com.xensource.xenapi.Session in project cosmic by MissionCriticalCloud.
the class XenServerConnectionPool method loginWithPassword.
protected Session loginWithPassword(final Connection conn, final String username, final Queue<String> password, final String version) throws BadServerResponse, XenAPIException, XmlRpcException {
Session s = null;
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
s = Session.loginWithPassword(conn, username, password.peek(), APIVersion.latest().toString());
logged_in = true;
} catch (final BadServerResponse e) {
logged_in = false;
ex = e;
} catch (final XenAPIException e) {
logged_in = false;
ex = e;
} catch (final XmlRpcException e) {
logged_in = false;
ex = e;
}
if (logged_in && conn != null) {
break;
} else {
if (password.size() > 1) {
password.remove();
continue;
} else {
// the last password did not work leave it and flag error
if (ex instanceof BadServerResponse) {
throw (BadServerResponse) ex;
} else if (ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
} else if (ex instanceof Types.SessionAuthenticationFailed) {
throw (Types.SessionAuthenticationFailed) ex;
} else if (ex instanceof XenAPIException) {
throw (XenAPIException) ex;
}
}
}
}
return s;
}
use of com.xensource.xenapi.Session in project cloudstack by apache.
the class XenServerConnectionPool method slaveLocalLoginWithPassword.
protected Session slaveLocalLoginWithPassword(Connection conn, String username, Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException {
Session s = null;
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
s = Session.slaveLocalLoginWithPassword(conn, username, password.peek());
logged_in = true;
} catch (BadServerResponse e) {
logged_in = false;
ex = e;
} catch (XenAPIException e) {
logged_in = false;
ex = e;
} catch (XmlRpcException e) {
logged_in = false;
ex = e;
}
if (logged_in && conn != null) {
break;
} else {
if (password.size() > 1) {
password.remove();
continue;
} else {
// the last password did not work leave it and flag error
if (ex instanceof BadServerResponse) {
throw (BadServerResponse) ex;
} else if (ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
} else if (ex instanceof Types.SessionAuthenticationFailed) {
throw (Types.SessionAuthenticationFailed) ex;
} else if (ex instanceof XenAPIException) {
throw (XenAPIException) ex;
}
break;
}
}
}
return s;
}
Aggregations