Skip to content

Commit fd0752e

Browse files
committed
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
1 parent 368289a commit fd0752e

4 files changed

Lines changed: 67 additions & 43 deletions

File tree

agent/src/com/cloud/agent/Agent.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public int value() {
111111
AtomicInteger _inProgress = new AtomicInteger();
112112

113113
StartupTask _startup = null;
114+
boolean _reconnectAllowed = true;
114115

115116
// for simulator use only
116117
public Agent(IAgentShell shell) {
@@ -347,6 +348,9 @@ public Task create(Task.Type type, Link link, byte[] data) {
347348
}
348349

349350
protected void reconnect(final Link link) {
351+
if (!_reconnectAllowed) {
352+
return;
353+
}
350354
synchronized(this) {
351355
if (_startup != null) {
352356
_startup.cancel();
@@ -456,6 +460,12 @@ protected void processRequest(final Request request, final Link link) {
456460
} else if (cmd instanceof UpgradeCommand) {
457461
final UpgradeCommand upgrade = (UpgradeCommand)cmd;
458462
answer = upgradeAgent(upgrade.getUpgradeUrl(), upgrade);
463+
} else if (cmd instanceof ShutdownCommand) {
464+
ShutdownCommand shutdown = (ShutdownCommand)cmd;
465+
s_logger.debug("Received shutdownCommand, due to: " + shutdown.getReason());
466+
cancelTasks();
467+
_reconnectAllowed = false;
468+
answer = new Answer(cmd, true, null);
459469
} else if(cmd instanceof AgentControlCommand) {
460470
answer = null;
461471
synchronized(_controlListeners) {

api/src/com/cloud/agent/api/ShutdownCommand.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ public class ShutdownCommand extends Command {
2525
public static final String Requested = "sig.kill";
2626
public static final String Update = "update";
2727
public static final String Unknown = "unknown";
28+
public static final String DeleteHost = "deleteHost";
2829

2930
private String reason;
3031
private String detail;
3132

3233
protected ShutdownCommand() {
34+
super();
3335
}
3436

3537
public ShutdownCommand(String reason, String detail) {
38+
super();
3639
this.reason = reason;
3740
this.detail = detail;
3841
}
@@ -50,6 +53,6 @@ public String getDetail() {
5053

5154
@Override
5255
public boolean executeInSequence() {
53-
return false;
56+
return true;
5457
}
5558
}

server/src/com/cloud/agent/manager/AgentAttache.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.cloud.agent.api.MigrateCommand;
4141
import com.cloud.agent.api.PingTestCommand;
4242
import com.cloud.agent.api.ReadyCommand;
43+
import com.cloud.agent.api.ShutdownCommand;
4344
import com.cloud.agent.api.StartCommand;
4445
import com.cloud.agent.api.StopCommand;
4546
import com.cloud.agent.api.storage.CreateCommand;
@@ -98,7 +99,7 @@ public int compare(Object o1, Object o2) {
9899
protected boolean _maintenance;
99100

100101
public final static String[] s_commandsAllowedInMaintenanceMode =
101-
new String[] { MaintainCommand.class.toString(), MigrateCommand.class.toString(), StopCommand.class.toString(), CheckVirtualMachineCommand.class.toString(), PingTestCommand.class.toString(), CheckHealthCommand.class.toString(), ReadyCommand.class.toString() };
102+
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() };
102103
protected final static String[] s_commandsNotAllowedInConnectingMode =
103104
new String[] { StartCommand.class.toString(), CreateCommand.class.toString() };
104105
static {

server/src/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -972,47 +972,57 @@ public boolean deleteHost(long hostId) {
972972
+ host.getGuid());
973973
}
974974

975-
if (host.getType() == Type.Routing
976-
&& host.getHypervisorType() == HypervisorType.XenServer) {
977-
if (host.getClusterId() != null) {
978-
List<HostVO> hosts = _hostDao.listBy(Type.Routing,
979-
host.getClusterId(), host.getPodId(),
980-
host.getDataCenterId());
981-
hosts.add(host);
982-
boolean success = true;
983-
for (HostVO thost : hosts) {
984-
long thostId = thost.getId();
985-
PoolEjectCommand eject = new PoolEjectCommand(
986-
host.getGuid());
987-
Answer answer = easySend(thostId, eject);
988-
if (answer != null && answer.getResult()) {
989-
s_logger.debug("Eject Host: " + hostId + " from "
990-
+ thostId + " Succeed");
991-
success = true;
992-
break;
993-
} else {
994-
success = false;
995-
s_logger.debug("Eject Host: "
996-
+ hostId
997-
+ " from "
998-
+ thostId
999-
+ " failed due to "
1000-
+ (answer != null ? answer.getDetails()
1001-
: "no answer"));
1002-
}
1003-
}
1004-
if (!success) {
1005-
String msg = "Unable to eject host "
1006-
+ host.getGuid()
1007-
+ " due to there is no host up in this cluster, please execute xe pool-eject host-uuid="
1008-
+ host.getGuid() + "in this host "
1009-
+ host.getPrivateIpAddress();
1010-
s_logger.info(msg);
1011-
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST,
1012-
host.getDataCenterId(), host.getPodId(),
1013-
"Unable to eject host " + host.getGuid(), msg);
1014-
}
1015-
}
975+
if (host.getType() == Type.Routing) {
976+
if (host.getHypervisorType() == HypervisorType.XenServer) {
977+
if (host.getClusterId() != null) {
978+
List<HostVO> hosts = _hostDao.listBy(Type.Routing,
979+
host.getClusterId(), host.getPodId(),
980+
host.getDataCenterId());
981+
hosts.add(host);
982+
boolean success = true;
983+
for (HostVO thost : hosts) {
984+
long thostId = thost.getId();
985+
PoolEjectCommand eject = new PoolEjectCommand(
986+
host.getGuid());
987+
Answer answer = easySend(thostId, eject);
988+
if (answer != null && answer.getResult()) {
989+
s_logger.debug("Eject Host: " + hostId + " from "
990+
+ thostId + " Succeed");
991+
success = true;
992+
break;
993+
} else {
994+
success = false;
995+
s_logger.debug("Eject Host: "
996+
+ hostId
997+
+ " from "
998+
+ thostId
999+
+ " failed due to "
1000+
+ (answer != null ? answer.getDetails()
1001+
: "no answer"));
1002+
}
1003+
}
1004+
if (!success) {
1005+
String msg = "Unable to eject host "
1006+
+ host.getGuid()
1007+
+ " due to there is no host up in this cluster, please execute xe pool-eject host-uuid="
1008+
+ host.getGuid() + "in this host "
1009+
+ host.getPrivateIpAddress();
1010+
s_logger.info(msg);
1011+
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST,
1012+
host.getDataCenterId(), host.getPodId(),
1013+
"Unable to eject host " + host.getGuid(), msg);
1014+
}
1015+
}
1016+
} else if (host.getHypervisorType() == HypervisorType.KVM) {
1017+
try {
1018+
ShutdownCommand cmd = new ShutdownCommand(ShutdownCommand.DeleteHost, null);
1019+
send(host.getId(), cmd);
1020+
} catch (AgentUnavailableException e) {
1021+
s_logger.debug("Sending ShutdownCommand failed: " + e.toString());
1022+
} catch (OperationTimedoutException e) {
1023+
s_logger.debug("Sending ShutdownCommand failed: " + e.toString());
1024+
}
1025+
}
10161026
}
10171027
txn.start();
10181028

0 commit comments

Comments
 (0)