Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -1308,12 +1308,11 @@ private void handleShutdownHostByIpmi(ShutdownHostMsg msg, NoErrorCompletion com
Completion c = new Completion(msg, completion) {
@Override
public void success() {
changeConnectionState(HostStatusEvent.disconnected);
if (msg.isReturnEarly()) {
bus.reply(msg, reply);
} else {
submitTaskWaitHostShutdownByIpmi();
}

submitTaskWaitHostShutdownByIpmi();
completion.done();
}

Expand All @@ -1338,16 +1337,21 @@ public boolean run() {
HostVO host = dbf.findByUuid(msg.getHostUuid(), HostVO.class);

if (timeHelper.getCurrentTimeMillis() > deadline) {
reply.setError(operr(String.format("Host[%s] has not been shut down within %d seconds for an unknown reason. Please check host status in BMC[%s]", msg.getHostUuid(), timeoutInSec, host.getIpmi().getIpmiAddress())));
reply.setSuccess(false);
bus.reply(msg, reply);
if (!msg.isReturnEarly()) {
reply.setError(operr(String.format("Host[%s] has not been shut down within %d seconds for an unknown reason. Please check host status in BMC[%s]", msg.getHostUuid(), timeoutInSec, host.getIpmi().getIpmiAddress())));
reply.setSuccess(false);
bus.reply(msg, reply);
}
HostIpmiVO ipmi = host.getIpmi();
kvmHostIpmiPowerExecutor.updateIpmiPowerStatusInDB(ipmi, HostPowerStatus.POWER_ON);
return true;
}
HostPowerStatus status = kvmHostIpmiPowerExecutor.refreshHostPowerStatus(host).getIpmiPowerStatus();
if (HostPowerStatus.POWER_OFF.equals(status)) {
bus.reply(msg, reply);
if (!msg.isReturnEarly()) {
bus.reply(msg, reply);
}
changeConnectionState(HostStatusEvent.disconnected);
return true;
}
if (HostPowerStatus.POWER_ON.equals(status)) {
Expand Down Expand Up @@ -6142,13 +6146,12 @@ public void success(KVMAgentCommands.ShutdownHostResponse ret) {
return;
}

changeConnectionState(HostStatusEvent.disconnected);
if (msg.isReturnEarly()) {
bus.reply(msg, reply);
completion.done();
} else {
waitForHostShutdown(reply, completion);
}

waitForHostShutdown(reply, completion);
}

private boolean testPort() {
Expand All @@ -6174,19 +6177,24 @@ private void waitForHostShutdown(ShutdownHostReply reply, NoErrorCompletion noEr
@Override
public boolean run() {
if (isTimeout()) {
reply.setSuccess(false);
reply.setError(operr("host[%s] not shutdown in %d seconds",msg.getHostUuid(), ctimeout));
bus.reply(msg,reply);
noErrorCompletion.done();
if (!msg.isReturnEarly()) {
reply.setSuccess(false);
reply.setError(operr("host[%s] not shutdown in %d seconds", msg.getHostUuid(), ctimeout));
bus.reply(msg, reply);
noErrorCompletion.done();
}
return true;
}

if (testPort()) {
return false;
}

bus.reply(msg, reply);
noErrorCompletion.done();
if (!msg.isReturnEarly()) {
bus.reply(msg, reply);
noErrorCompletion.done();
}
changeConnectionState(HostStatusEvent.disconnected);
return true;
}

Expand Down