Skip to content

Commit

Permalink
CLOUDSTACK-9350: KVM-HA- Fix CheckOnHost for Local storage
Browse files Browse the repository at this point in the history
    - Also skip HA on VMs that are using local storage
  • Loading branch information
abhinandanprateek committed Apr 29, 2016
1 parent e762e27 commit 3b89cbe
Show file tree
Hide file tree
Showing 7 changed files with 592 additions and 4 deletions.
24 changes: 23 additions & 1 deletion plugins/hypervisors/kvm/src/com/cloud/ha/KVMInvestigator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.resource.ResourceManager;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.utils.component.AdapterBase;

import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.log4j.Logger;

import javax.inject.Inject;
Expand All @@ -41,6 +45,8 @@ public class KVMInvestigator extends AdapterBase implements Investigator {
AgentManager _agentMgr;
@Inject
ResourceManager _resourceMgr;
@Inject
PrimaryDataStoreDao _storagePoolDao;

@Override
public boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) throws UnknownVM {
Expand All @@ -60,6 +66,21 @@ public Status isAgentAlive(Host agent) {
if (agent.getHypervisorType() != Hypervisor.HypervisorType.KVM && agent.getHypervisorType() != Hypervisor.HypervisorType.LXC) {
return null;
}

List<StoragePoolVO> clusterPools = _storagePoolDao.listPoolsByCluster(agent.getClusterId());
boolean hasNfs = false;
for (StoragePoolVO pool : clusterPools) {
if (pool.getPoolType() == StoragePoolType.NetworkFilesystem) {
hasNfs = true;
break;
}
}
if (!hasNfs) {
s_logger.warn(
"Agent investigation was requested on host " + agent + ", but host does not support investigation because it has no NFS storage. Skipping investigation.");
return Status.Disconnected;
}

Status hostStatus = null;
Status neighbourStatus = null;
CheckOnHostCommand cmd = new CheckOnHostCommand(agent);
Expand All @@ -78,7 +99,8 @@ public Status isAgentAlive(Host agent) {

List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(agent.getClusterId(), Status.Up);
for (HostVO neighbor : neighbors) {
if (neighbor.getId() == agent.getId() || (neighbor.getHypervisorType() != Hypervisor.HypervisorType.KVM && neighbor.getHypervisorType() != Hypervisor.HypervisorType.LXC)) {
if (neighbor.getId() == agent.getId()
|| (neighbor.getHypervisorType() != Hypervisor.HypervisorType.KVM && neighbor.getHypervisorType() != Hypervisor.HypervisorType.LXC)) {
continue;
}
s_logger.debug("Investigating host:" + agent.getId() + " via neighbouring host:" + neighbor.getId());
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@
<exclude>**/.checkstyle</exclude>
<exclude>scripts/installer/windows/acs_license.rtf</exclude>
<exclude>**/*.md</exclude>
<exclude>test/integration/component/test_host_ha.sh</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
8 changes: 8 additions & 0 deletions server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.resource.ResourceManager;
import com.cloud.server.ManagementServer;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.StorageManager;
import com.cloud.storage.dao.GuestOSCategoryDao;
Expand Down Expand Up @@ -264,6 +265,13 @@ public void scheduleRestartForVmsOnHost(final HostVO host, boolean investigate)
"Host [" + hostDesc + "] is down." + ((sb != null) ? sb.toString() : ""));

for (VMInstanceVO vm : reorderedVMList) {
ServiceOfferingVO vmOffering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
if (vmOffering.getUseLocalStorage()) {
if (s_logger.isDebugEnabled()){
s_logger.debug("Skipping HA on vm " + vm + ", because it uses local storage. Its fate is tied to the host.");
}
continue;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Notifying HA Mgr of to restart vm " + vm.getId() + "-" + vm.getInstanceName());
}
Expand Down
2 changes: 2 additions & 0 deletions server/test/com/cloud/ha/HighAvailabilityManagerImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.resource.ResourceManager;
import com.cloud.server.ManagementServer;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.StorageManager;
import com.cloud.storage.dao.GuestOSCategoryDao;
Expand Down Expand Up @@ -195,6 +196,7 @@ public void scheduleRestartForVmsOnHostNonEmptyVMList() {
Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(DataCenterVO.class));
Mockito.when(_haDao.findPreviousHA(Mockito.anyLong())).thenReturn(Arrays.asList(Mockito.mock(HaWorkVO.class)));
Mockito.when(_haDao.persist((HaWorkVO)Mockito.anyObject())).thenReturn(Mockito.mock(HaWorkVO.class));
Mockito.when(_serviceOfferingDao.findById(vm1.getServiceOfferingId())).thenReturn(Mockito.mock(ServiceOfferingVO.class));

highAvailabilityManager.scheduleRestartForVmsOnHost(hostVO, true);
}
Expand Down
Loading

0 comments on commit 3b89cbe

Please sign in to comment.