CLOUDSTACK-4643

put host maintenance mode will not change XS master,
when you delete a host, and this host is master, master will be designated by CS
This commit is contained in:
Anthony Xu 2013-09-11 15:43:42 -07:00
parent 6b2bc93206
commit 4adf13192f
2 changed files with 53 additions and 98 deletions

View File

@ -1818,37 +1818,19 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
protected MaintainAnswer execute(MaintainCommand cmd) {
Connection conn = getConnection();
try {
Pool pool = Pool.getByUuid(conn, _host.pool);
Pool.Record poolr = pool.getRecord(conn);
Host.Record hostr = poolr.master.getRecord(conn);
if (!_host.uuid.equals(hostr.uuid)) {
s_logger.debug("Not the master node so just return ok: " + _host.ip);
return new MaintainAnswer(cmd);
}
Map<Host, Host.Record> hostMap = Host.getAllRecords(conn);
if (hostMap.size() == 1) {
s_logger.debug("There is the last host in pool " + poolr.uuid );
return new MaintainAnswer(cmd);
}
Host newMaster = null;
Host.Record newMasterRecord = null;
for (Map.Entry<Host, Host.Record> entry : hostMap.entrySet()) {
if (!_host.uuid.equals(entry.getValue().uuid)) {
newMaster = entry.getKey();
newMasterRecord = entry.getValue();
s_logger.debug("New master for the XenPool is " + newMasterRecord.uuid + " : " + newMasterRecord.address);
try {
_connPool.switchMaster(_host.ip, _host.pool, conn, newMaster, _username, _password, _wait);
return new MaintainAnswer(cmd, "New Master is " + newMasterRecord.address);
} catch (XenAPIException e) {
s_logger.warn("Unable to switch the new master to " + newMasterRecord.uuid + ": " + newMasterRecord.address + " Trying again...");
} catch (XmlRpcException e) {
s_logger.warn("Unable to switch the new master to " + newMasterRecord.uuid + ": " + newMasterRecord.address + " Trying again...");
}
Host host = Host.getByUuid(conn, _host.uuid);
// remove all tags cloud stack
Host.Record hr = host.getRecord(conn);
Iterator<String> it = hr.tags.iterator();
while (it.hasNext()) {
String tag = it.next();
if (tag.contains("cloud")) {
it.remove();
}
}
return new MaintainAnswer(cmd, false, "Unable to find an appropriate host to set as the new master");
host.setTags(conn, hr.tags);
return new MaintainAnswer(cmd);
} catch (XenAPIException e) {
s_logger.warn("Unable to put server in maintainence mode", e);
return new MaintainAnswer(cmd, false, e.getMessage());
@ -7739,37 +7721,58 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
Connection conn = getConnection();
String hostuuid = cmd.getHostuuid();
try {
Map<Host, Host.Record> hostrs = Host.getAllRecords(conn);
boolean found = false;
for( Host.Record hr : hostrs.values() ) {
if( hr.uuid.equals(hostuuid)) {
found = true;
}
}
if( ! found) {
Host host = Host.getByUuid(conn, hostuuid);
if( isRefNull(host) ) {
s_logger.debug("host " + hostuuid + " has already been ejected from pool " + _host.pool);
return new Answer(cmd);
}
Pool pool = Pool.getAll(conn).iterator().next();
Pool.Record poolr = pool.getRecord(conn);
Host.Record masterRec = poolr.master.getRecord(conn);
if (hostuuid.equals(masterRec.uuid)) {
s_logger.debug("This is last host to eject, so don't need to eject: " + hostuuid);
return new Answer(cmd);
}
Host host = Host.getByUuid(conn, hostuuid);
// remove all tags cloud stack add before eject
Host.Record hr = host.getRecord(conn);
Iterator<String> it = hr.tags.iterator();
while (it.hasNext()) {
String tag = it.next();
if (tag.startsWith("vmops-version-")) {
if (tag.contains("cloud")) {
it.remove();
}
}
host.setTags(conn, hr.tags);
Pool pool = Pool.getByUuid(conn, _host.pool);
Pool.Record poolr = pool.getRecord(conn);
Host.Record hostr = poolr.master.getRecord(conn);
if (_host.uuid.equals(hostr.uuid)) {
boolean mastermigrated = false;
Map<Host, Host.Record> hostMap = Host.getAllRecords(conn);
if (hostMap.size() != 1) {
Host newMaster = null;
Host.Record newMasterRecord = null;
for (Map.Entry<Host, Host.Record> entry : hostMap.entrySet()) {
if (_host.uuid.equals(entry.getValue().uuid)) {
continue;
}
newMaster = entry.getKey();
newMasterRecord = entry.getValue();
s_logger.debug("New master for the XenPool is " + newMasterRecord.uuid + " : " + newMasterRecord.address);
try {
_connPool.switchMaster(_host.ip, _host.pool, conn, newMaster, _username, _password, _wait);
mastermigrated = true;
break;
} catch (Exception e) {
s_logger.warn("Unable to switch the new master to " + newMasterRecord.uuid + ": " + newMasterRecord.address + " due to " + e.toString());
}
}
} else {
s_logger.debug("This is last host to eject, so don't need to eject: " + hostuuid);
return new Answer(cmd);
}
if ( !mastermigrated ) {
String msg = "this host is master, and cannot designate a new master";
s_logger.debug(msg);
return new Answer(cmd, false, msg);
}
}
// eject from pool
try {
Pool.eject(conn, host);
@ -7783,12 +7786,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
host.destroy(conn);
}
return new Answer(cmd);
} catch (XenAPIException e) {
String msg = "XenAPIException Unable to destroy host " + _host.uuid + " in xenserver database due to " + e.toString();
s_logger.warn(msg, e);
return new Answer(cmd, false, msg);
} catch (Exception e) {
String msg = "Exception Unable to destroy host " + _host.uuid + " in xenserver database due to " + e.getMessage();
String msg = "Exception Unable to destroy host " + _host.uuid + " in xenserver database due to " + e.toString();
s_logger.warn(msg, e);
return new Answer(cmd, false, msg);
}

View File

@ -18,14 +18,9 @@ package com.cloud.hypervisor.xen.resource;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
@ -37,21 +32,14 @@ import com.cloud.agent.api.FenceAnswer;
import com.cloud.agent.api.FenceCommand;
import com.cloud.agent.api.NetworkUsageAnswer;
import com.cloud.agent.api.NetworkUsageCommand;
import com.cloud.agent.api.PoolEjectCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.resource.ServerResource;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
import com.xensource.xenapi.Bond;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.Network;
import com.xensource.xenapi.PBD;
import com.xensource.xenapi.PIF;
import com.xensource.xenapi.SR;
import com.xensource.xenapi.Types;
import com.xensource.xenapi.Types.IpConfigurationMode;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.VLAN;
@ -65,8 +53,6 @@ public class XenServer56Resource extends CitrixResourceBase {
public Answer executeRequest(Command cmd) {
if (cmd instanceof FenceCommand) {
return execute((FenceCommand) cmd);
} else if (cmd instanceof PoolEjectCommand) {
return execute((PoolEjectCommand) cmd);
} else if (cmd instanceof NetworkUsageCommand) {
return execute((NetworkUsageCommand) cmd);
} else {
@ -226,36 +212,6 @@ public class XenServer56Resource extends CitrixResourceBase {
}
}
@Override
protected Answer execute(PoolEjectCommand cmd) {
Connection conn = getConnection();
String hostuuid = cmd.getHostuuid();
try {
Host host = Host.getByUuid(conn, hostuuid);
// remove all tags cloud stack add before eject
Host.Record hr = host.getRecord(conn);
Iterator<String> it = hr.tags.iterator();
while (it.hasNext()) {
String tag = it.next();
if (tag.contains("cloud-heartbeat-")) {
it.remove();
}
}
return super.execute(cmd);
} catch (XenAPIException e) {
String msg = "Unable to eject host " + _host.uuid + " due to " + e.toString();
s_logger.warn(msg, e);
return new Answer(cmd, false, msg);
} catch (Exception e) {
s_logger.warn("Unable to eject host " + _host.uuid, e);
String msg = "Unable to eject host " + _host.uuid + " due to " + e.getMessage();
s_logger.warn(msg, e);
return new Answer(cmd, false, msg);
}
}
protected FenceAnswer execute(FenceCommand cmd) {
Connection conn = getConnection();
try {