Skip to content

Commit e51e340

Browse files
committed
improvements for extension alert
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 017a003 commit e51e340

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/manager/ExtensionsManagerImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ protected Map<String, String> getFilteredExternalDetails(Map<String, String> det
408408
protected void sendExtensionPathNotReadyAlert(Extension extension) {
409409
String msg = String.format("Path for %s not ready across management servers",
410410
extension);
411+
if (!Extension.State.Enabled.equals(extension.getState())) {
412+
logger.warn(msg);
413+
return;
414+
}
411415
alertManager.sendAlert(AlertManager.AlertType.ALERT_TYPE_EXTENSION_PATH_NOT_READY, 0L, 0L, msg, msg);
412416
}
413417

framework/extensions/src/test/java/org/apache/cloudstack/framework/extensions/manager/ExtensionsManagerImplTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,21 @@ public void getFilteredExternalDetailsReturnsFilteredMap() {
347347
@Test
348348
public void sendExtensionPathNotReadyAlertCallsAlertManager() {
349349
Extension ext = mock(Extension.class);
350+
when(ext.getState()).thenReturn(Extension.State.Enabled);
350351
extensionsManager.sendExtensionPathNotReadyAlert(ext);
351352
verify(alertManager, atLeastOnce()).sendAlert(eq(AlertManager.AlertType.ALERT_TYPE_EXTENSION_PATH_NOT_READY),
352353
anyLong(), anyLong(), anyString(), anyString());
353354
}
354355

356+
@Test
357+
public void sendExtensionPathNotReadyAlertDoesNotCallsAlertManager() {
358+
Extension ext = mock(Extension.class);
359+
when(ext.getState()).thenReturn(Extension.State.Disabled);
360+
extensionsManager.sendExtensionPathNotReadyAlert(ext);
361+
verify(alertManager, never()).sendAlert(eq(AlertManager.AlertType.ALERT_TYPE_EXTENSION_PATH_NOT_READY),
362+
anyLong(), anyLong(), anyString(), anyString());
363+
}
364+
355365
@Test
356366
public void updateExtensionPathReadyUpdatesWhenStateDiffers() {
357367
Extension ext = mock(Extension.class);

server/src/main/java/com/cloud/alert/AlertManagerImpl.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
import javax.mail.MessagingException;
3838
import javax.naming.ConfigurationException;
3939

40-
import com.cloud.dc.DataCenter;
41-
import com.cloud.dc.Pod;
42-
import com.cloud.org.Cluster;
4340
import org.apache.cloudstack.framework.config.ConfigDepot;
4441
import org.apache.cloudstack.framework.config.ConfigKey;
4542
import org.apache.cloudstack.framework.config.Configurable;
@@ -52,8 +49,9 @@
5249
import org.apache.cloudstack.utils.mailing.SMTPMailSender;
5350
import org.apache.commons.lang3.ArrayUtils;
5451
import org.apache.commons.lang3.math.NumberUtils;
55-
import org.apache.logging.log4j.Logger;
5652
import org.apache.logging.log4j.LogManager;
53+
import org.apache.logging.log4j.Logger;
54+
import org.jetbrains.annotations.Nullable;
5755

5856
import com.cloud.alert.dao.AlertDao;
5957
import com.cloud.api.ApiDBUtils;
@@ -66,9 +64,11 @@
6664
import com.cloud.configuration.Config;
6765
import com.cloud.configuration.ConfigurationManager;
6866
import com.cloud.dc.ClusterVO;
67+
import com.cloud.dc.DataCenter;
6968
import com.cloud.dc.DataCenter.NetworkType;
7069
import com.cloud.dc.DataCenterVO;
7170
import com.cloud.dc.HostPodVO;
71+
import com.cloud.dc.Pod;
7272
import com.cloud.dc.Vlan.VlanType;
7373
import com.cloud.dc.dao.ClusterDao;
7474
import com.cloud.dc.dao.DataCenterDao;
@@ -82,14 +82,17 @@
8282
import com.cloud.host.dao.HostDao;
8383
import com.cloud.network.Ipv6Service;
8484
import com.cloud.network.dao.IPAddressDao;
85+
import com.cloud.org.Cluster;
8586
import com.cloud.org.Grouping.AllocationState;
8687
import com.cloud.resource.ResourceManager;
8788
import com.cloud.storage.StorageManager;
8889
import com.cloud.utils.Pair;
8990
import com.cloud.utils.component.ManagerBase;
9091
import com.cloud.utils.concurrency.NamedThreadFactory;
9192
import com.cloud.utils.db.SearchCriteria;
92-
import org.jetbrains.annotations.Nullable;
93+
import com.cloud.utils.db.Transaction;
94+
import com.cloud.utils.db.TransactionCallbackNoReturn;
95+
import com.cloud.utils.db.TransactionStatus;
9396

9497
public class AlertManagerImpl extends ManagerBase implements AlertManager, Configurable {
9598
protected Logger logger = LogManager.getLogger(AlertManagerImpl.class.getName());
@@ -105,7 +108,8 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
105108
, AlertType.ALERT_TYPE_UPLOAD_FAILED
106109
, AlertType.ALERT_TYPE_OOBM_AUTH_ERROR
107110
, AlertType.ALERT_TYPE_HA_ACTION
108-
, AlertType.ALERT_TYPE_CA_CERT);
111+
, AlertType.ALERT_TYPE_CA_CERT
112+
, AlertType.ALERT_TYPE_EXTENSION_PATH_NOT_READY);
109113

110114
private static final long INITIAL_CAPACITY_CHECK_DELAY = 30L * 1000L; // Thirty seconds expressed in milliseconds.
111115

@@ -290,8 +294,13 @@ protected void recalculateHostCapacities() {
290294
Math.min(CapacityManager.CapacityCalculateWorkers.value(), hostIds.size())));
291295
for (Long hostId : hostIds) {
292296
futures.put(hostId, executorService.submit(() -> {
293-
final HostVO host = hostDao.findById(hostId);
294-
_capacityMgr.updateCapacityForHost(host);
297+
Transaction.execute(new TransactionCallbackNoReturn() {
298+
@Override
299+
public void doInTransactionWithoutResult(TransactionStatus status) {
300+
final HostVO host = hostDao.findById(hostId);
301+
_capacityMgr.updateCapacityForHost(host);
302+
}
303+
});
295304
return null;
296305
}));
297306
}
@@ -316,13 +325,18 @@ protected void recalculateStorageCapacities() {
316325
Math.min(CapacityManager.CapacityCalculateWorkers.value(), storagePoolIds.size())));
317326
for (Long poolId: storagePoolIds) {
318327
futures.put(poolId, executorService.submit(() -> {
319-
final StoragePoolVO pool = _storagePoolDao.findById(poolId);
320-
long disk = _capacityMgr.getAllocatedPoolCapacity(pool, null);
321-
if (pool.isShared()) {
322-
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, disk);
323-
} else {
324-
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, disk);
325-
}
328+
Transaction.execute(new TransactionCallbackNoReturn() {
329+
@Override
330+
public void doInTransactionWithoutResult(TransactionStatus status) {
331+
final StoragePoolVO pool = _storagePoolDao.findById(poolId);
332+
long disk = _capacityMgr.getAllocatedPoolCapacity(pool, null);
333+
if (pool.isShared()) {
334+
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, disk);
335+
} else {
336+
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, disk);
337+
}
338+
}
339+
});
326340
return null;
327341
}));
328342
}

0 commit comments

Comments
 (0)