Skip to content

Commit 865330d

Browse files
committed
CLOUDSTACK-5610: Host doesn't go to Down/Alert state even though it is powered off. VM
deployment fails because of that as cloudstack tries to deploy it on a host which is ctually down. An investigator wasn't present for hyper-v; so cloudstack wasn't able to determine the status of the host. Wrote an investigator for hyper-v which checks with other hosts in the cluster for the status of the host being investigated.
1 parent 4d9b95e commit 865330d

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

plugins/hypervisors/hyperv/resources/META-INF/cloudstack/hyperv-compute/spring-hyperv-compute-context.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@
2020
<bean id="HypervGuru" class="com.cloud.hypervisor.hyperv.guru.HypervGuru">
2121
<property name="name" value="HypervGuru" />
2222
</bean>
23-
23+
<bean id="HypervInvestigator" class="com.cloud.ha.HypervInvestigator">
24+
<property name="name" value="HypervInvestigator" />
25+
</bean>
2426
</beans>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.cloud.ha;
20+
21+
import com.cloud.agent.AgentManager;
22+
import com.cloud.agent.api.Answer;
23+
import com.cloud.agent.api.CheckOnHostCommand;
24+
import com.cloud.host.Host;
25+
import com.cloud.host.HostVO;
26+
import com.cloud.host.Status;
27+
import com.cloud.host.dao.HostDao;
28+
import com.cloud.hypervisor.Hypervisor;
29+
import com.cloud.resource.ResourceManager;
30+
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;
36+
37+
@Local(value=Investigator.class)
38+
public class HypervInvestigator extends AdapterBase implements Investigator {
39+
private final static Logger s_logger = Logger.getLogger(HypervInvestigator.class);
40+
@Inject HostDao _hostDao;
41+
@Inject AgentManager _agentMgr;
42+
@Inject ResourceManager _resourceMgr;
43+
44+
@Override
45+
public Boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) {
46+
Status status = isAgentAlive(host);
47+
if (status == null) {
48+
return null;
49+
}
50+
return status == Status.Up ? true : null;
51+
}
52+
53+
@Override
54+
public Status isAgentAlive(Host agent) {
55+
if (agent.getHypervisorType() != Hypervisor.HypervisorType.Hyperv) {
56+
return null;
57+
}
58+
CheckOnHostCommand cmd = new CheckOnHostCommand(agent);
59+
List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(agent.getClusterId(), Status.Up);
60+
for (HostVO neighbor : neighbors) {
61+
if (neighbor.getId() == agent.getId() || neighbor.getHypervisorType() != Hypervisor.HypervisorType.Hyperv) {
62+
continue;
63+
}
64+
65+
try {
66+
Answer answer = _agentMgr.easySend(neighbor.getId(), cmd);
67+
if (answer != null) {
68+
return answer.getResult() ? Status.Down : Status.Up;
69+
}
70+
} catch (Exception e) {
71+
s_logger.debug("Failed to send command to host: " + neighbor.getId());
72+
}
73+
}
74+
75+
return null;
76+
}
77+
}

0 commit comments

Comments
 (0)