Skip to content

Commit 43d485c

Browse files
author
Anthony Xu
committed
Revert "CLOUDSTACK-5923: CS doesn't do master switch for XS any more, CS will depend on XS HA to do master switch, XS HA needs to be enabled."
This reverts commit af5f3d5.
1 parent aa6f4dc commit 43d485c

3 files changed

Lines changed: 464 additions & 46 deletions

File tree

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long p
188188
String hostIp = ia.getHostAddress();
189189
Queue<String> pass=new LinkedList<String>();
190190
pass.add(password);
191-
conn = _connPool.getConnect(hostIp, username, pass);
191+
String masterIp = _connPool.getMasterIp(hostIp, username, pass);
192+
conn = _connPool.masterConnect(masterIp, username, pass);
192193
if (conn == null) {
193194
String msg = "Unable to get a connection to " + url;
194195
s_logger.debug(msg);
@@ -391,7 +392,7 @@ protected boolean addHostsToPool(Connection conn, String hostIp, Long clusterId)
391392
password = host.getDetail("password");
392393
pass.add(password);
393394
String address = host.getPrivateIpAddress();
394-
Connection hostConn = _connPool.getConnect(address, username, pass);
395+
Connection hostConn = _connPool.slaveConnect(address, username, pass);
395396
if (hostConn == null) {
396397
continue;
397398
}
@@ -405,7 +406,7 @@ protected boolean addHostsToPool(Connection conn, String hostIp, Long clusterId)
405406
s_logger.warn("Can not get master ip address from host " + address);
406407
} finally {
407408
try{
408-
Session.logout(hostConn);
409+
Session.localLogout(hostConn);
409410
} catch (Exception e ) {
410411
}
411412
hostConn.dispose();

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,23 @@ protected boolean pingdomr(Connection conn, String host, String port) {
430430
}
431431

432432
protected boolean pingXenServer() {
433-
Connection conn = getConnection();
433+
Session slaveSession = null;
434+
Connection slaveConn = null;
434435
try {
435-
callHostPlugin(conn, "echo", "main");
436+
URL slaveUrl = null;
437+
slaveUrl = _connPool.getURL(_host.ip);
438+
slaveConn = new Connection(slaveUrl, 10);
439+
slaveSession = _connPool.slaveLocalLoginWithPassword(slaveConn, _username, _password);
436440
return true;
437441
} catch (Exception e) {
438-
s_logger.debug("cannot ping host " + _host.ip + " due to " + e.toString(), e);
442+
} finally {
443+
if( slaveSession != null ){
444+
try{
445+
Session.localLogout(slaveConn);
446+
} catch (Exception e) {
447+
}
448+
slaveConn.dispose();
449+
}
439450
}
440451
return false;
441452
}
@@ -6053,9 +6064,9 @@ protected StorageSubsystemCommandHandler getStorageHandler() {
60536064
}
60546065

60556066
private void CheckXenHostInfo() throws ConfigurationException {
6056-
Connection conn = _connPool.getConnect(_host.ip, _username, _password);
6067+
Connection conn = _connPool.slaveConnect(_host.ip, _username, _password);
60576068
if( conn == null ) {
6058-
throw new ConfigurationException("Can not create connection to " + _host.ip);
6069+
throw new ConfigurationException("Can not create slave connection to " + _host.ip);
60596070
}
60606071
try {
60616072
Host.Record hostRec = null;
@@ -6075,7 +6086,7 @@ private void CheckXenHostInfo() throws ConfigurationException {
60756086
}
60766087
} finally {
60776088
try {
6078-
Session.logout(conn);
6089+
Session.localLogout(conn);
60796090
} catch (Exception e) {
60806091
}
60816092
}
@@ -7371,11 +7382,35 @@ protected Answer execute(PoolEjectCommand cmd) {
73717382

73727383
Host.Record hostr = poolr.master.getRecord(conn);
73737384
if (_host.uuid.equals(hostr.uuid)) {
7385+
boolean mastermigrated = false;
73747386
Map<Host, Host.Record> hostMap = Host.getAllRecords(conn);
7375-
if (hostMap.size() > 1) {
7376-
String msg = "This host is XS master, please designate a new XS master throught XenCenter before you delete this host from CS";
7387+
if (hostMap.size() != 1) {
7388+
Host newMaster = null;
7389+
Host.Record newMasterRecord = null;
7390+
for (Map.Entry<Host, Host.Record> entry : hostMap.entrySet()) {
7391+
if (_host.uuid.equals(entry.getValue().uuid)) {
7392+
continue;
7393+
}
7394+
newMaster = entry.getKey();
7395+
newMasterRecord = entry.getValue();
7396+
s_logger.debug("New master for the XenPool is " + newMasterRecord.uuid + " : " + newMasterRecord.address);
7397+
try {
7398+
_connPool.switchMaster(_host.ip, _host.pool, conn, newMaster, _username, _password, _wait);
7399+
mastermigrated = true;
7400+
break;
7401+
} catch (Exception e) {
7402+
s_logger.warn("Unable to switch the new master to " + newMasterRecord.uuid + ": " + newMasterRecord.address + " due to " + e.toString());
7403+
}
7404+
}
7405+
} else {
7406+
s_logger.debug("This is last host to eject, so don't need to eject: " + hostuuid);
7407+
return new Answer(cmd);
7408+
}
7409+
if ( !mastermigrated ) {
7410+
String msg = "this host is master, and cannot designate a new master";
73777411
s_logger.debug(msg);
73787412
return new Answer(cmd, false, msg);
7413+
73797414
}
73807415
}
73817416

0 commit comments

Comments
 (0)