Do not create alarm state if alarms creation is disabled
This commit is contained in:
parent
9e1d86d7e8
commit
abf8ff25b5
@ -0,0 +1,10 @@
|
||||
package org.thingsboard.server.common.data.exception;
|
||||
|
||||
public class ApiUsageLimitsExceededException extends RuntimeException {
|
||||
public ApiUsageLimitsExceededException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ApiUsageLimitsExceededException() {
|
||||
}
|
||||
}
|
||||
@ -34,6 +34,7 @@ import org.thingsboard.server.common.data.alarm.AlarmQuery;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmSearchStatus;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmSeverity;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmStatus;
|
||||
import org.thingsboard.server.common.data.exception.ApiUsageLimitsExceededException;
|
||||
import org.thingsboard.server.common.data.id.AlarmId;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
@ -119,7 +120,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
||||
Alarm existing = alarmDao.findLatestByOriginatorAndType(alarm.getTenantId(), alarm.getOriginator(), alarm.getType()).get();
|
||||
if (existing == null || existing.getStatus().isCleared()) {
|
||||
if (!alarmCreationEnabled) {
|
||||
throw new IllegalStateException("Alarm creation is disabled");
|
||||
throw new ApiUsageLimitsExceededException("Alarms creation is disabled");
|
||||
}
|
||||
return createAlarm(alarm);
|
||||
} else {
|
||||
|
||||
@ -29,6 +29,7 @@ import org.thingsboard.server.common.data.alarm.Alarm;
|
||||
import org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey;
|
||||
import org.thingsboard.server.common.data.device.profile.AlarmConditionKeyType;
|
||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm;
|
||||
import org.thingsboard.server.common.data.exception.ApiUsageLimitsExceededException;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
@ -261,7 +262,12 @@ class DeviceState {
|
||||
for (DeviceProfileAlarm alarm : deviceProfile.getAlarmSettings()) {
|
||||
AlarmState alarmState = alarmStates.computeIfAbsent(alarm.getId(),
|
||||
a -> new AlarmState(this.deviceProfile, deviceId, alarm, getOrInitPersistedAlarmState(alarm), dynamicPredicateValueCtx));
|
||||
stateChanged |= alarmState.process(ctx, msg, latestValues, update);
|
||||
try {
|
||||
stateChanged |= alarmState.process(ctx, msg, latestValues, update);
|
||||
} catch (ApiUsageLimitsExceededException e) {
|
||||
alarmStates.remove(alarm.getId());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user