Skip to content

Commit d55d453

Browse files
committed
CLOUDSTACK-8530: KVM hosts without active agents should be in Disconnected state
KVM hosts which are actuall up, but if their agents are shutdown should be put in disconnected state. This would avoid getting the VMs HA'd and other commands such as deploying a VM will exclude that host and save us from errors. The improvement is that, we first try to contact the KVM host itself. If it fails we assume that it's disconnected, and then ask its KVM neighbours if they can check its status. If all of the KVM neighbours tell us that it's Down and we're unable to reach the KVM host, then the host is possibly down. In case any of the KVM neighbours tell us that it's Up but we're unable to reach the KVM host then we can be sure that the agent is offline but the host is running. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> This closes apache#340
1 parent 19cc5eb commit d55d453

1 file changed

Lines changed: 33 additions & 10 deletions

File tree

‎plugins/hypervisors/kvm/src/com/cloud/ha/KVMInvestigator.java‎

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818
*/
1919
package com.cloud.ha;
2020

21-
import java.util.List;
22-
23-
import javax.ejb.Local;
24-
import javax.inject.Inject;
25-
26-
import org.apache.log4j.Logger;
27-
2821
import com.cloud.agent.AgentManager;
2922
import com.cloud.agent.api.Answer;
3023
import com.cloud.agent.api.CheckOnHostCommand;
@@ -35,6 +28,11 @@
3528
import com.cloud.hypervisor.Hypervisor;
3629
import com.cloud.resource.ResourceManager;
3730
import com.cloud.utils.component.AdapterBase;
31+
import org.apache.log4j.Logger;
32+
33+
import javax.ejb.Local;
34+
import javax.inject.Inject;
35+
import java.util.List;
3836

3937
@Local(value = Investigator.class)
4038
public class KVMInvestigator extends AdapterBase implements Investigator {
@@ -60,22 +58,47 @@ public Status isAgentAlive(Host agent) {
6058
if (agent.getHypervisorType() != Hypervisor.HypervisorType.KVM && agent.getHypervisorType() != Hypervisor.HypervisorType.LXC) {
6159
return null;
6260
}
61+
Status hostStatus = null;
62+
Status neighbourStatus = null;
6363
CheckOnHostCommand cmd = new CheckOnHostCommand(agent);
64+
65+
try {
66+
Answer answer = _agentMgr.easySend(agent.getId(), cmd);
67+
if (answer != null) {
68+
hostStatus = answer.getResult() ? Status.Down : Status.Up;
69+
}
70+
} catch (Exception e) {
71+
s_logger.debug("Failed to send command to host: " + agent.getId());
72+
}
73+
if (hostStatus == null) {
74+
hostStatus = Status.Disconnected;
75+
}
76+
6477
List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(agent.getClusterId(), Status.Up);
6578
for (HostVO neighbor : neighbors) {
6679
if (neighbor.getId() == agent.getId() || (neighbor.getHypervisorType() != Hypervisor.HypervisorType.KVM && neighbor.getHypervisorType() != Hypervisor.HypervisorType.LXC)) {
6780
continue;
6881
}
82+
s_logger.debug("Investigating host:" + agent.getId() + " via neighbouring host:" + neighbor.getId());
6983
try {
7084
Answer answer = _agentMgr.easySend(neighbor.getId(), cmd);
7185
if (answer != null) {
72-
return answer.getResult() ? Status.Down : Status.Up;
86+
neighbourStatus = answer.getResult() ? Status.Down : Status.Up;
87+
s_logger.debug("Neighbouring host:" + neighbor.getId() + " returned status:" + neighbourStatus + " for the investigated host:" + agent.getId());
88+
if (neighbourStatus == Status.Up) {
89+
break;
90+
}
7391
}
7492
} catch (Exception e) {
7593
s_logger.debug("Failed to send command to host: " + neighbor.getId());
7694
}
7795
}
78-
79-
return null;
96+
if (neighbourStatus == Status.Up && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) {
97+
hostStatus = Status.Disconnected;
98+
}
99+
if (neighbourStatus == Status.Down && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) {
100+
hostStatus = Status.Down;
101+
}
102+
return hostStatus;
80103
}
81104
}

0 commit comments

Comments
 (0)