bug 5811, 8261: When delete host, send a shutdownCommand to kvm agent, then kvm agent will not automatically reconnect to mgt server

status 5811: resolved fixed
status 8261: resolved fixed
This commit is contained in:
Edison Su 2011-02-03 13:37:57 -05:00
parent 368289aa12
commit fd0752e995
4 changed files with 67 additions and 43 deletions

View File

@ -111,6 +111,7 @@ public class Agent implements HandlerFactory, IAgentControl {
AtomicInteger _inProgress = new AtomicInteger();
StartupTask _startup = null;
boolean _reconnectAllowed = true;
// for simulator use only
public Agent(IAgentShell shell) {
@ -347,6 +348,9 @@ public class Agent implements HandlerFactory, IAgentControl {
}
protected void reconnect(final Link link) {
if (!_reconnectAllowed) {
return;
}
synchronized(this) {
if (_startup != null) {
_startup.cancel();
@ -456,6 +460,12 @@ public class Agent implements HandlerFactory, IAgentControl {
} else if (cmd instanceof UpgradeCommand) {
final UpgradeCommand upgrade = (UpgradeCommand)cmd;
answer = upgradeAgent(upgrade.getUpgradeUrl(), upgrade);
} else if (cmd instanceof ShutdownCommand) {
ShutdownCommand shutdown = (ShutdownCommand)cmd;
s_logger.debug("Received shutdownCommand, due to: " + shutdown.getReason());
cancelTasks();
_reconnectAllowed = false;
answer = new Answer(cmd, true, null);
} else if(cmd instanceof AgentControlCommand) {
answer = null;
synchronized(_controlListeners) {

View File

@ -25,14 +25,17 @@ public class ShutdownCommand extends Command {
public static final String Requested = "sig.kill";
public static final String Update = "update";
public static final String Unknown = "unknown";
public static final String DeleteHost = "deleteHost";
private String reason;
private String detail;
protected ShutdownCommand() {
super();
}
public ShutdownCommand(String reason, String detail) {
super();
this.reason = reason;
this.detail = detail;
}
@ -50,6 +53,6 @@ public class ShutdownCommand extends Command {
@Override
public boolean executeInSequence() {
return false;
return true;
}
}

View File

@ -40,6 +40,7 @@ import com.cloud.agent.api.MaintainCommand;
import com.cloud.agent.api.MigrateCommand;
import com.cloud.agent.api.PingTestCommand;
import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.ShutdownCommand;
import com.cloud.agent.api.StartCommand;
import com.cloud.agent.api.StopCommand;
import com.cloud.agent.api.storage.CreateCommand;
@ -98,7 +99,7 @@ public abstract class AgentAttache {
protected boolean _maintenance;
public final static String[] s_commandsAllowedInMaintenanceMode =
new String[] { MaintainCommand.class.toString(), MigrateCommand.class.toString(), StopCommand.class.toString(), CheckVirtualMachineCommand.class.toString(), PingTestCommand.class.toString(), CheckHealthCommand.class.toString(), ReadyCommand.class.toString() };
new String[] { MaintainCommand.class.toString(), MigrateCommand.class.toString(), StopCommand.class.toString(), CheckVirtualMachineCommand.class.toString(), PingTestCommand.class.toString(), CheckHealthCommand.class.toString(), ReadyCommand.class.toString(), ShutdownCommand.class.toString() };
protected final static String[] s_commandsNotAllowedInConnectingMode =
new String[] { StartCommand.class.toString(), CreateCommand.class.toString() };
static {

View File

@ -972,47 +972,57 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory,
+ host.getGuid());
}
if (host.getType() == Type.Routing
&& host.getHypervisorType() == HypervisorType.XenServer) {
if (host.getClusterId() != null) {
List<HostVO> hosts = _hostDao.listBy(Type.Routing,
host.getClusterId(), host.getPodId(),
host.getDataCenterId());
hosts.add(host);
boolean success = true;
for (HostVO thost : hosts) {
long thostId = thost.getId();
PoolEjectCommand eject = new PoolEjectCommand(
host.getGuid());
Answer answer = easySend(thostId, eject);
if (answer != null && answer.getResult()) {
s_logger.debug("Eject Host: " + hostId + " from "
+ thostId + " Succeed");
success = true;
break;
} else {
success = false;
s_logger.debug("Eject Host: "
+ hostId
+ " from "
+ thostId
+ " failed due to "
+ (answer != null ? answer.getDetails()
: "no answer"));
}
}
if (!success) {
String msg = "Unable to eject host "
+ host.getGuid()
+ " due to there is no host up in this cluster, please execute xe pool-eject host-uuid="
+ host.getGuid() + "in this host "
+ host.getPrivateIpAddress();
s_logger.info(msg);
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST,
host.getDataCenterId(), host.getPodId(),
"Unable to eject host " + host.getGuid(), msg);
}
}
if (host.getType() == Type.Routing) {
if (host.getHypervisorType() == HypervisorType.XenServer) {
if (host.getClusterId() != null) {
List<HostVO> hosts = _hostDao.listBy(Type.Routing,
host.getClusterId(), host.getPodId(),
host.getDataCenterId());
hosts.add(host);
boolean success = true;
for (HostVO thost : hosts) {
long thostId = thost.getId();
PoolEjectCommand eject = new PoolEjectCommand(
host.getGuid());
Answer answer = easySend(thostId, eject);
if (answer != null && answer.getResult()) {
s_logger.debug("Eject Host: " + hostId + " from "
+ thostId + " Succeed");
success = true;
break;
} else {
success = false;
s_logger.debug("Eject Host: "
+ hostId
+ " from "
+ thostId
+ " failed due to "
+ (answer != null ? answer.getDetails()
: "no answer"));
}
}
if (!success) {
String msg = "Unable to eject host "
+ host.getGuid()
+ " due to there is no host up in this cluster, please execute xe pool-eject host-uuid="
+ host.getGuid() + "in this host "
+ host.getPrivateIpAddress();
s_logger.info(msg);
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST,
host.getDataCenterId(), host.getPodId(),
"Unable to eject host " + host.getGuid(), msg);
}
}
} else if (host.getHypervisorType() == HypervisorType.KVM) {
try {
ShutdownCommand cmd = new ShutdownCommand(ShutdownCommand.DeleteHost, null);
send(host.getId(), cmd);
} catch (AgentUnavailableException e) {
s_logger.debug("Sending ShutdownCommand failed: " + e.toString());
} catch (OperationTimedoutException e) {
s_logger.debug("Sending ShutdownCommand failed: " + e.toString());
}
}
}
txn.start();