Skip to content

Commit b99d1a1

Browse files
committed
address comments
1 parent e7d70dd commit b99d1a1

File tree

3 files changed

+48
-44
lines changed

3 files changed

+48
-44
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public Status isAgentAlive(Host agent) {
8383
return haManager.getHostStatus(agent);
8484
}
8585

86-
//TODO: check storage for HA support
8786
List<StoragePoolVO> clusterPools = _storagePoolDao.listPoolsByCluster(agent.getClusterId());
8887
boolean storageSupportHA = storageSupportHa(clusterPools);
8988
if (!storageSupportHA) {

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -89,65 +89,71 @@ protected void runHeartBeat() {
8989
Set<String> removedPools = new HashSet<>();
9090
for (String uuid : storagePool.keySet()) {
9191
HAStoragePool primaryStoragePool = storagePool.get(uuid);
92-
StoragePool storage;
9392
if (primaryStoragePool.getPool().getType() == StoragePoolType.NetworkFilesystem) {
94-
try {
95-
Connect conn = LibvirtConnection.getConnection();
96-
storage = conn.storagePoolLookupByUUIDString(uuid);
97-
if (storage == null || storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
98-
if (storage == null) {
99-
s_logger.debug(String.format("Libvirt storage pool [%s] not found, removing from HA list.", uuid));
100-
} else {
101-
s_logger.debug(String.format("Libvirt storage pool [%s] found, but not running, removing from HA list.", uuid));
102-
}
103-
104-
removedPools.add(uuid);
105-
continue;
106-
}
107-
108-
s_logger.debug(String.format("Found NFS storage pool [%s] in libvirt, continuing.", uuid));
109-
110-
} catch (LibvirtException e) {
111-
s_logger.debug(String.format("Failed to lookup libvirt storage pool [%s].", uuid), e);
112-
113-
if (e.toString().contains("pool not found")) {
114-
s_logger.debug(String.format("Removing pool [%s] from HA monitor since it was deleted.", uuid));
115-
removedPools.add(uuid);
116-
continue;
117-
}
93+
checkForNotExistingPools(removedPools, uuid);
94+
if (removedPools.contains(uuid)) {
95+
continue;
11896
}
11997
}
120-
12198
String result = null;
122-
for (int i = 1; i <= _heartBeatUpdateMaxTries; i++) {
123-
result = primaryStoragePool.getPool().createHeartBeatCommand(primaryStoragePool, hostPrivateIp, true);
124-
125-
if (result != null) {
126-
s_logger.warn(String.format("Write heartbeat for pool [%s] failed: %s; try: %s of %s.", uuid, result, i, _heartBeatUpdateMaxTries));
127-
try {
128-
Thread.sleep(_heartBeatUpdateRetrySleep);
129-
} catch (InterruptedException e) {
130-
s_logger.debug("[IGNORED] Interrupted between heartbeat retries.", e);
131-
}
132-
} else {
133-
break;
134-
}
135-
136-
}
99+
result = executePoolHeartBeatCommand(uuid, primaryStoragePool, result);
137100

138101
if (result != null && rebootHostAndAlertManagementOnHeartbeatTimeout) {
139102
s_logger.warn(String.format("Write heartbeat for pool [%s] failed: %s; stopping cloudstack-agent.", uuid, result));
140103
primaryStoragePool.getPool().createHeartBeatCommand(primaryStoragePool, null, false);;
141104
}
142105
}
143-
144106
if (!removedPools.isEmpty()) {
145107
for (String uuid : removedPools) {
146108
removeStoragePool(uuid);
147109
}
148110
}
149111
}
112+
}
150113

114+
private String executePoolHeartBeatCommand(String uuid, HAStoragePool primaryStoragePool, String result) {
115+
for (int i = 1; i <= _heartBeatUpdateMaxTries; i++) {
116+
result = primaryStoragePool.getPool().createHeartBeatCommand(primaryStoragePool, hostPrivateIp, true);
117+
118+
if (result != null) {
119+
s_logger.warn(String.format("Write heartbeat for pool [%s] failed: %s; try: %s of %s.", uuid, result, i, _heartBeatUpdateMaxTries));
120+
try {
121+
Thread.sleep(_heartBeatUpdateRetrySleep);
122+
} catch (InterruptedException e) {
123+
s_logger.debug("[IGNORED] Interrupted between heartbeat retries.", e);
124+
}
125+
} else {
126+
break;
127+
}
128+
129+
}
130+
return result;
131+
}
132+
133+
private void checkForNotExistingPools(Set<String> removedPools, String uuid) {
134+
try {
135+
Connect conn = LibvirtConnection.getConnection();
136+
StoragePool storage = conn.storagePoolLookupByUUIDString(uuid);
137+
if (storage == null || storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
138+
if (storage == null) {
139+
s_logger.debug(String.format("Libvirt storage pool [%s] not found, removing from HA list.", uuid));
140+
} else {
141+
s_logger.debug(String.format("Libvirt storage pool [%s] found, but not running, removing from HA list.", uuid));
142+
}
143+
144+
removedPools.add(uuid);
145+
}
146+
147+
s_logger.debug(String.format("Found NFS storage pool [%s] in libvirt, continuing.", uuid));
148+
149+
} catch (LibvirtException e) {
150+
s_logger.debug(String.format("Failed to lookup libvirt storage pool [%s].", uuid), e);
151+
152+
if (e.toString().contains("pool not found")) {
153+
s_logger.debug(String.format("Removing pool [%s] from HA monitor since it was deleted.", uuid));
154+
removedPools.add(uuid);
155+
}
156+
}
151157
}
152158

153159
@Override

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ private synchronized KVMStoragePool createStoragePool(String name, String host,
361361

362362
// LibvirtStorageAdaptor-specific statement
363363
if (pool.isPoolSupportHA() && primaryStorage) {
364-
//KVMHABase.HAStoragePool nfspool = new KVMHABase.HAStoragePool(pool.getUuid(), host, path, pool.getLocalPath(), PoolType.PrimaryStorage);
365364
KVMHABase.HAStoragePool storagePool = new KVMHABase.HAStoragePool(pool, host, path, PoolType.PrimaryStorage);
366365
_haMonitor.addStoragePool(storagePool);
367366
}

0 commit comments

Comments
 (0)