Revert the AlarmInfo items. We will update the assignee via separate message
This commit is contained in:
commit
04eb8c989a
@ -98,17 +98,17 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
|
|||||||
@Override
|
@Override
|
||||||
public Alarm assign(Alarm alarm, User user, UserId assigneeId) {
|
public Alarm assign(Alarm alarm, User user, UserId assigneeId) {
|
||||||
long assignTs = System.currentTimeMillis();
|
long assignTs = System.currentTimeMillis();
|
||||||
Alarm assignedAlarm = alarmSubscriptionService.assignAlarm(alarm.getTenantId(), alarm.getId(), assigneeId, assignTs);
|
AlarmOperationResult operationResult = alarmSubscriptionService.assignAlarm(alarm.getTenantId(), alarm.getId(), assigneeId, assignTs);
|
||||||
notificationEntityService.notifyCreateOrUpdateAlarm(assignedAlarm, ActionType.ALARM_ASSIGN, user);
|
notificationEntityService.notifyCreateOrUpdateAlarm(operationResult.getAlarm(), ActionType.ALARM_ASSIGN, user);
|
||||||
return assignedAlarm;
|
return operationResult.getAlarm();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Alarm unassign(Alarm alarm, User user) {
|
public Alarm unassign(Alarm alarm, User user) {
|
||||||
long assignTs = System.currentTimeMillis();
|
long assignTs = System.currentTimeMillis();
|
||||||
Alarm unassignedAlarm = alarmSubscriptionService.unassignAlarm(alarm.getTenantId(), alarm.getId(), assignTs);
|
AlarmOperationResult operationResult = alarmSubscriptionService.unassignAlarm(alarm.getTenantId(), alarm.getId(), assignTs);
|
||||||
notificationEntityService.notifyCreateOrUpdateAlarm(unassignedAlarm, ActionType.ALARM_UNASSIGN, user);
|
notificationEntityService.notifyCreateOrUpdateAlarm(operationResult.getAlarm(), ActionType.ALARM_UNASSIGN, user);
|
||||||
return unassignedAlarm;
|
return operationResult.getAlarm();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -503,13 +503,13 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore
|
|||||||
subscriptionManagerService.onAlarmUpdate(
|
subscriptionManagerService.onAlarmUpdate(
|
||||||
TenantId.fromUUID(new UUID(proto.getTenantIdMSB(), proto.getTenantIdLSB())),
|
TenantId.fromUUID(new UUID(proto.getTenantIdMSB(), proto.getTenantIdLSB())),
|
||||||
TbSubscriptionUtils.toEntityId(proto.getEntityType(), proto.getEntityIdMSB(), proto.getEntityIdLSB()),
|
TbSubscriptionUtils.toEntityId(proto.getEntityType(), proto.getEntityIdMSB(), proto.getEntityIdLSB()),
|
||||||
JacksonUtil.fromString(proto.getAlarm(), AlarmInfo.class),callback);
|
JacksonUtil.fromString(proto.getAlarm(), Alarm.class),callback);
|
||||||
} else if (msg.hasAlarmDelete()) {
|
} else if (msg.hasAlarmDelete()) {
|
||||||
TbAlarmDeleteProto proto = msg.getAlarmDelete();
|
TbAlarmDeleteProto proto = msg.getAlarmDelete();
|
||||||
subscriptionManagerService.onAlarmDeleted(
|
subscriptionManagerService.onAlarmDeleted(
|
||||||
TenantId.fromUUID(new UUID(proto.getTenantIdMSB(), proto.getTenantIdLSB())),
|
TenantId.fromUUID(new UUID(proto.getTenantIdMSB(), proto.getTenantIdLSB())),
|
||||||
TbSubscriptionUtils.toEntityId(proto.getEntityType(), proto.getEntityIdMSB(), proto.getEntityIdLSB()),
|
TbSubscriptionUtils.toEntityId(proto.getEntityType(), proto.getEntityIdMSB(), proto.getEntityIdLSB()),
|
||||||
JacksonUtil.fromString(proto.getAlarm(), AlarmInfo.class), callback);
|
JacksonUtil.fromString(proto.getAlarm(), Alarm.class), callback);
|
||||||
} else {
|
} else {
|
||||||
throwNotHandled(msg, callback);
|
throwNotHandled(msg, callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -293,7 +293,7 @@ public class DefaultSubscriptionManagerService extends TbApplicationEventListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAlarmUpdate(TenantId tenantId, EntityId entityId, AlarmInfo alarmInfo, TbCallback callback) {
|
public void onAlarmUpdate(TenantId tenantId, EntityId entityId, Alarm alarm, TbCallback callback) {
|
||||||
onLocalAlarmSubUpdate(entityId,
|
onLocalAlarmSubUpdate(entityId,
|
||||||
s -> {
|
s -> {
|
||||||
if (TbSubscriptionType.ALARMS.equals(s.getType())) {
|
if (TbSubscriptionType.ALARMS.equals(s.getType())) {
|
||||||
@ -302,15 +302,15 @@ public class DefaultSubscriptionManagerService extends TbApplicationEventListene
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
s -> alarmInfo.getCreatedTime() >= s.getTs() || alarmInfo.getAssignTs() >= s.getTs(),
|
s -> alarm.getCreatedTime() >= s.getTs() || alarm.getAssignTs() >= s.getTs(),
|
||||||
s -> alarmInfo,
|
s -> alarm,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
callback.onSuccess();
|
callback.onSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAlarmDeleted(TenantId tenantId, EntityId entityId, AlarmInfo alarmInfo, TbCallback callback) {
|
public void onAlarmDeleted(TenantId tenantId, EntityId entityId, Alarm alarmInfo, TbCallback callback) {
|
||||||
onLocalAlarmSubUpdate(entityId,
|
onLocalAlarmSubUpdate(entityId,
|
||||||
s -> {
|
s -> {
|
||||||
if (TbSubscriptionType.ALARMS.equals(s.getType())) {
|
if (TbSubscriptionType.ALARMS.equals(s.getType())) {
|
||||||
@ -415,19 +415,19 @@ public class DefaultSubscriptionManagerService extends TbApplicationEventListene
|
|||||||
private void onLocalAlarmSubUpdate(EntityId entityId,
|
private void onLocalAlarmSubUpdate(EntityId entityId,
|
||||||
Function<TbSubscription, TbAlarmsSubscription> castFunction,
|
Function<TbSubscription, TbAlarmsSubscription> castFunction,
|
||||||
Predicate<TbAlarmsSubscription> filterFunction,
|
Predicate<TbAlarmsSubscription> filterFunction,
|
||||||
Function<TbAlarmsSubscription, AlarmInfo> processFunction,
|
Function<TbAlarmsSubscription, Alarm> processFunction,
|
||||||
boolean deleted) {
|
boolean deleted) {
|
||||||
Set<TbSubscription> entitySubscriptions = subscriptionsByEntityId.get(entityId);
|
Set<TbSubscription> entitySubscriptions = subscriptionsByEntityId.get(entityId);
|
||||||
if (entitySubscriptions != null) {
|
if (entitySubscriptions != null) {
|
||||||
entitySubscriptions.stream().map(castFunction).filter(Objects::nonNull).filter(filterFunction).forEach(s -> {
|
entitySubscriptions.stream().map(castFunction).filter(Objects::nonNull).filter(filterFunction).forEach(s -> {
|
||||||
AlarmInfo alarmInfo = processFunction.apply(s);
|
Alarm alarm = processFunction.apply(s);
|
||||||
if (alarmInfo != null) {
|
if (alarm != null) {
|
||||||
if (serviceId.equals(s.getServiceId())) {
|
if (serviceId.equals(s.getServiceId())) {
|
||||||
AlarmSubscriptionUpdate update = new AlarmSubscriptionUpdate(s.getSubscriptionId(), alarmInfo, deleted);
|
AlarmSubscriptionUpdate update = new AlarmSubscriptionUpdate(s.getSubscriptionId(), alarm, deleted);
|
||||||
localSubscriptionService.onSubscriptionUpdate(s.getSessionId(), update, TbCallback.EMPTY);
|
localSubscriptionService.onSubscriptionUpdate(s.getSessionId(), update, TbCallback.EMPTY);
|
||||||
} else {
|
} else {
|
||||||
TopicPartitionInfo tpi = notificationsTopicService.getNotificationsTopic(ServiceType.TB_CORE, s.getServiceId());
|
TopicPartitionInfo tpi = notificationsTopicService.getNotificationsTopic(ServiceType.TB_CORE, s.getServiceId());
|
||||||
toCoreNotificationsProducer.send(tpi, toProto(s, alarmInfo, deleted), null);
|
toCoreNotificationsProducer.send(tpi, toProto(s, alarm, deleted), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -564,12 +564,12 @@ public class DefaultSubscriptionManagerService extends TbApplicationEventListene
|
|||||||
return new TbProtoQueueMsg<>(subscription.getEntityId().getId(), toCoreMsg);
|
return new TbProtoQueueMsg<>(subscription.getEntityId().getId(), toCoreMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TbProtoQueueMsg<ToCoreNotificationMsg> toProto(TbSubscription subscription, AlarmInfo alarmInfo, boolean deleted) {
|
private TbProtoQueueMsg<ToCoreNotificationMsg> toProto(TbSubscription subscription, Alarm alarm, boolean deleted) {
|
||||||
TbAlarmSubscriptionUpdateProto.Builder builder = TbAlarmSubscriptionUpdateProto.newBuilder();
|
TbAlarmSubscriptionUpdateProto.Builder builder = TbAlarmSubscriptionUpdateProto.newBuilder();
|
||||||
|
|
||||||
builder.setSessionId(subscription.getSessionId());
|
builder.setSessionId(subscription.getSessionId());
|
||||||
builder.setSubscriptionId(subscription.getSubscriptionId());
|
builder.setSubscriptionId(subscription.getSubscriptionId());
|
||||||
builder.setAlarm(JacksonUtil.toString(alarmInfo));
|
builder.setAlarm(JacksonUtil.toString(alarm));
|
||||||
builder.setDeleted(deleted);
|
builder.setDeleted(deleted);
|
||||||
|
|
||||||
ToCoreNotificationMsg toCoreMsg = ToCoreNotificationMsg.newBuilder().setToLocalSubscriptionServiceMsg(
|
ToCoreNotificationMsg toCoreMsg = ToCoreNotificationMsg.newBuilder().setToLocalSubscriptionServiceMsg(
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
package org.thingsboard.server.service.subscription;
|
package org.thingsboard.server.service.subscription;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.thingsboard.server.common.data.alarm.Alarm;
|
||||||
import org.thingsboard.server.common.data.alarm.AlarmInfo;
|
import org.thingsboard.server.common.data.alarm.AlarmInfo;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
@ -42,9 +43,9 @@ public interface SubscriptionManagerService extends ApplicationListener<Partitio
|
|||||||
|
|
||||||
void onTimeSeriesDelete(TenantId tenantId, EntityId entityId, List<String> keys, TbCallback callback);
|
void onTimeSeriesDelete(TenantId tenantId, EntityId entityId, List<String> keys, TbCallback callback);
|
||||||
|
|
||||||
void onAlarmUpdate(TenantId tenantId, EntityId entityId, AlarmInfo alarmInfo, TbCallback callback);
|
void onAlarmUpdate(TenantId tenantId, EntityId entityId, Alarm alarm, TbCallback callback);
|
||||||
|
|
||||||
void onAlarmDeleted(TenantId tenantId, EntityId entityId, AlarmInfo alarmInfo, TbCallback callback);
|
void onAlarmDeleted(TenantId tenantId, EntityId entityId, Alarm alarm, TbCallback callback);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -211,8 +211,8 @@ public class TbAlarmDataSubCtx extends TbAbstractDataSubCtx<AlarmDataQuery> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendWsMsg(String sessionId, AlarmSubscriptionUpdate subscriptionUpdate) {
|
private void sendWsMsg(String sessionId, AlarmSubscriptionUpdate subscriptionUpdate) {
|
||||||
AlarmInfo alarmInfo = subscriptionUpdate.getAlarm();
|
Alarm alarm = subscriptionUpdate.getAlarm();
|
||||||
AlarmId alarmId = alarmInfo.getId();
|
AlarmId alarmId = alarm.getId();
|
||||||
if (subscriptionUpdate.isAlarmDeleted()) {
|
if (subscriptionUpdate.isAlarmDeleted()) {
|
||||||
Alarm deleted = alarmsMap.remove(alarmId);
|
Alarm deleted = alarmsMap.remove(alarmId);
|
||||||
if (deleted != null) {
|
if (deleted != null) {
|
||||||
@ -221,10 +221,10 @@ public class TbAlarmDataSubCtx extends TbAbstractDataSubCtx<AlarmDataQuery> {
|
|||||||
} else {
|
} else {
|
||||||
AlarmData current = alarmsMap.get(alarmId);
|
AlarmData current = alarmsMap.get(alarmId);
|
||||||
boolean onCurrentPage = current != null;
|
boolean onCurrentPage = current != null;
|
||||||
boolean matchesFilter = filter(alarmInfo);
|
boolean matchesFilter = filter(alarm);
|
||||||
if (onCurrentPage) {
|
if (onCurrentPage) {
|
||||||
if (matchesFilter) {
|
if (matchesFilter) {
|
||||||
AlarmData updated = new AlarmData(alarmInfo, current.getEntityId());
|
AlarmData updated = current.update(alarm);
|
||||||
updated.getLatest().putAll(current.getLatest());
|
updated.getLatest().putAll(current.getLatest());
|
||||||
alarmsMap.put(alarmId, updated);
|
alarmsMap.put(alarmId, updated);
|
||||||
sendWsMsg(new AlarmDataUpdate(cmdId, null, Collections.singletonList(updated), maxEntitiesPerAlarmSubscription, data.getTotalElements()));
|
sendWsMsg(new AlarmDataUpdate(cmdId, null, Collections.singletonList(updated), maxEntitiesPerAlarmSubscription, data.getTotalElements()));
|
||||||
|
|||||||
@ -190,8 +190,8 @@ public class TbSubscriptionUtils {
|
|||||||
if (proto.getErrorCode() > 0) {
|
if (proto.getErrorCode() > 0) {
|
||||||
return new AlarmSubscriptionUpdate(proto.getSubscriptionId(), SubscriptionErrorCode.forCode(proto.getErrorCode()), proto.getErrorMsg());
|
return new AlarmSubscriptionUpdate(proto.getSubscriptionId(), SubscriptionErrorCode.forCode(proto.getErrorCode()), proto.getErrorMsg());
|
||||||
} else {
|
} else {
|
||||||
AlarmInfo alarmInfo = JacksonUtil.fromString(proto.getAlarm(), AlarmInfo.class);
|
Alarm alarm = JacksonUtil.fromString(proto.getAlarm(), Alarm.class);
|
||||||
return new AlarmSubscriptionUpdate(proto.getSubscriptionId(), alarmInfo);
|
return new AlarmSubscriptionUpdate(proto.getSubscriptionId(), alarm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,27 +317,27 @@ public class TbSubscriptionUtils {
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ToCoreMsg toAlarmUpdateProto(TenantId tenantId, EntityId entityId, AlarmInfo alarmInfo) {
|
public static ToCoreMsg toAlarmUpdateProto(TenantId tenantId, EntityId entityId, Alarm alarm) {
|
||||||
TbAlarmUpdateProto.Builder builder = TbAlarmUpdateProto.newBuilder();
|
TbAlarmUpdateProto.Builder builder = TbAlarmUpdateProto.newBuilder();
|
||||||
builder.setEntityType(entityId.getEntityType().name());
|
builder.setEntityType(entityId.getEntityType().name());
|
||||||
builder.setEntityIdMSB(entityId.getId().getMostSignificantBits());
|
builder.setEntityIdMSB(entityId.getId().getMostSignificantBits());
|
||||||
builder.setEntityIdLSB(entityId.getId().getLeastSignificantBits());
|
builder.setEntityIdLSB(entityId.getId().getLeastSignificantBits());
|
||||||
builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits());
|
builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits());
|
||||||
builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits());
|
builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits());
|
||||||
builder.setAlarm(JacksonUtil.toString(alarmInfo));
|
builder.setAlarm(JacksonUtil.toString(alarm));
|
||||||
SubscriptionMgrMsgProto.Builder msgBuilder = SubscriptionMgrMsgProto.newBuilder();
|
SubscriptionMgrMsgProto.Builder msgBuilder = SubscriptionMgrMsgProto.newBuilder();
|
||||||
msgBuilder.setAlarmUpdate(builder);
|
msgBuilder.setAlarmUpdate(builder);
|
||||||
return ToCoreMsg.newBuilder().setToSubscriptionMgrMsg(msgBuilder.build()).build();
|
return ToCoreMsg.newBuilder().setToSubscriptionMgrMsg(msgBuilder.build()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ToCoreMsg toAlarmDeletedProto(TenantId tenantId, EntityId entityId, AlarmInfo alarmInfo) {
|
public static ToCoreMsg toAlarmDeletedProto(TenantId tenantId, EntityId entityId, Alarm alarm) {
|
||||||
TbAlarmDeleteProto.Builder builder = TbAlarmDeleteProto.newBuilder();
|
TbAlarmDeleteProto.Builder builder = TbAlarmDeleteProto.newBuilder();
|
||||||
builder.setEntityType(entityId.getEntityType().name());
|
builder.setEntityType(entityId.getEntityType().name());
|
||||||
builder.setEntityIdMSB(entityId.getId().getMostSignificantBits());
|
builder.setEntityIdMSB(entityId.getId().getMostSignificantBits());
|
||||||
builder.setEntityIdLSB(entityId.getId().getLeastSignificantBits());
|
builder.setEntityIdLSB(entityId.getId().getLeastSignificantBits());
|
||||||
builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits());
|
builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits());
|
||||||
builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits());
|
builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits());
|
||||||
builder.setAlarm(JacksonUtil.toString(alarmInfo));
|
builder.setAlarm(JacksonUtil.toString(alarm));
|
||||||
SubscriptionMgrMsgProto.Builder msgBuilder = SubscriptionMgrMsgProto.newBuilder();
|
SubscriptionMgrMsgProto.Builder msgBuilder = SubscriptionMgrMsgProto.newBuilder();
|
||||||
msgBuilder.setAlarmDelete(builder);
|
msgBuilder.setAlarmDelete(builder);
|
||||||
return ToCoreMsg.newBuilder().setToSubscriptionMgrMsg(msgBuilder.build()).build();
|
return ToCoreMsg.newBuilder().setToSubscriptionMgrMsg(msgBuilder.build()).build();
|
||||||
|
|||||||
@ -94,16 +94,16 @@ public class DefaultAlarmSubscriptionService extends AbstractSubscriptionService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AlarmInfo createOrUpdateAlarm(Alarm alarm) {
|
public Alarm createOrUpdateAlarm(Alarm alarm) {
|
||||||
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm, apiUsageStateService.getApiUsageState(alarm.getTenantId()).isAlarmCreationEnabled());
|
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm, apiUsageStateService.getApiUsageState(alarm.getTenantId()).isAlarmCreationEnabled());
|
||||||
if (result.isSuccessful()) {
|
if (result.isSuccessful()) {
|
||||||
onAlarmUpdated(result);
|
onAlarmUpdated(result);
|
||||||
AlarmSeverity oldSeverity = result.getOldSeverity();
|
AlarmSeverity oldSeverity = result.getOldSeverity();
|
||||||
if (oldSeverity != null && !oldSeverity.equals(result.getAlarmInfo().getSeverity())) {
|
if (oldSeverity != null && !oldSeverity.equals(result.getAlarm().getSeverity())) {
|
||||||
AlarmComment alarmComment = AlarmComment.builder()
|
AlarmComment alarmComment = AlarmComment.builder()
|
||||||
.alarmId(alarm.getId())
|
.alarmId(alarm.getId())
|
||||||
.type(AlarmCommentType.SYSTEM)
|
.type(AlarmCommentType.SYSTEM)
|
||||||
.comment(JacksonUtil.newObjectNode().put("text", String.format("Alarm severity was updated from %s to %s", oldSeverity, result.getAlarmInfo().getSeverity())))
|
.comment(JacksonUtil.newObjectNode().put("text", String.format("Alarm severity was updated from %s to %s", oldSeverity, result.getAlarm().getSeverity())))
|
||||||
.build();
|
.build();
|
||||||
alarmCommentService.createOrUpdateAlarmComment(alarm.getTenantId(), alarmComment);
|
alarmCommentService.createOrUpdateAlarmComment(alarm.getTenantId(), alarmComment);
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ public class DefaultAlarmSubscriptionService extends AbstractSubscriptionService
|
|||||||
if (result.isCreated()) {
|
if (result.isCreated()) {
|
||||||
apiUsageClient.report(alarm.getTenantId(), null, ApiUsageRecordKey.CREATED_ALARMS_COUNT);
|
apiUsageClient.report(alarm.getTenantId(), null, ApiUsageRecordKey.CREATED_ALARMS_COUNT);
|
||||||
}
|
}
|
||||||
return result.getAlarmInfo();
|
return result.getAlarm();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -142,25 +142,25 @@ public class DefaultAlarmSubscriptionService extends AbstractSubscriptionService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AlarmInfo assignAlarm(TenantId tenantId, AlarmId alarmId, UserId assigneeId, long assignTs) {
|
public AlarmOperationResult assignAlarm(TenantId tenantId, AlarmId alarmId, UserId assigneeId, long assignTs) {
|
||||||
AlarmOperationResult result = alarmService.assignAlarm(tenantId, alarmId, assigneeId, assignTs);
|
AlarmOperationResult result = alarmService.assignAlarm(tenantId, alarmId, assigneeId, assignTs);
|
||||||
if (result.isSuccessful()) {
|
if (result.isSuccessful()) {
|
||||||
onAlarmUpdated(result);
|
onAlarmUpdated(result);
|
||||||
} else {
|
} else {
|
||||||
log.warn("Failed to assign alarm!");
|
log.warn("[{}][{}] Failed to assign alarm.", tenantId, alarmId);
|
||||||
}
|
}
|
||||||
return result.getAlarmInfo();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AlarmInfo unassignAlarm(TenantId tenantId, AlarmId alarmId, long assignTs) {
|
public AlarmOperationResult unassignAlarm(TenantId tenantId, AlarmId alarmId, long assignTs) {
|
||||||
AlarmOperationResult result = alarmService.unassignAlarm(tenantId, alarmId, assignTs);
|
AlarmOperationResult result = alarmService.unassignAlarm(tenantId, alarmId, assignTs);
|
||||||
if (result.isSuccessful()) {
|
if (result.isSuccessful()) {
|
||||||
onAlarmUpdated(result);
|
onAlarmUpdated(result);
|
||||||
} else {
|
} else {
|
||||||
log.warn("Failed to unassign alarm!");
|
log.warn("[{}][{}] Failed to unassign alarm.", tenantId, alarmId);
|
||||||
}
|
}
|
||||||
return result.getAlarmInfo();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -205,18 +205,18 @@ public class DefaultAlarmSubscriptionService extends AbstractSubscriptionService
|
|||||||
|
|
||||||
private void onAlarmUpdated(AlarmOperationResult result) {
|
private void onAlarmUpdated(AlarmOperationResult result) {
|
||||||
wsCallBackExecutor.submit(() -> {
|
wsCallBackExecutor.submit(() -> {
|
||||||
AlarmInfo alarmInfo = result.getAlarmInfo();
|
Alarm alarm = result.getAlarm();
|
||||||
TenantId tenantId = alarmInfo.getTenantId();
|
TenantId tenantId = alarm.getTenantId();
|
||||||
for (EntityId entityId : result.getPropagatedEntitiesList()) {
|
for (EntityId entityId : result.getPropagatedEntitiesList()) {
|
||||||
TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, entityId);
|
TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, entityId);
|
||||||
if (currentPartitions.contains(tpi)) {
|
if (currentPartitions.contains(tpi)) {
|
||||||
if (subscriptionManagerService.isPresent()) {
|
if (subscriptionManagerService.isPresent()) {
|
||||||
subscriptionManagerService.get().onAlarmUpdate(tenantId, entityId, alarmInfo, TbCallback.EMPTY);
|
subscriptionManagerService.get().onAlarmUpdate(tenantId, entityId, alarm, TbCallback.EMPTY);
|
||||||
} else {
|
} else {
|
||||||
log.warn("Possible misconfiguration because subscriptionManagerService is null!");
|
log.warn("Possible misconfiguration because subscriptionManagerService is null!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TransportProtos.ToCoreMsg toCoreMsg = TbSubscriptionUtils.toAlarmUpdateProto(tenantId, entityId, alarmInfo);
|
TransportProtos.ToCoreMsg toCoreMsg = TbSubscriptionUtils.toAlarmUpdateProto(tenantId, entityId, alarm);
|
||||||
clusterService.pushMsgToCore(tpi, entityId.getId(), toCoreMsg, null);
|
clusterService.pushMsgToCore(tpi, entityId.getId(), toCoreMsg, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,18 +225,18 @@ public class DefaultAlarmSubscriptionService extends AbstractSubscriptionService
|
|||||||
|
|
||||||
private void onAlarmDeleted(AlarmOperationResult result) {
|
private void onAlarmDeleted(AlarmOperationResult result) {
|
||||||
wsCallBackExecutor.submit(() -> {
|
wsCallBackExecutor.submit(() -> {
|
||||||
AlarmInfo alarmInfo = result.getAlarmInfo();
|
Alarm alarm = result.getAlarm();
|
||||||
TenantId tenantId = alarmInfo.getTenantId();
|
TenantId tenantId = alarm.getTenantId();
|
||||||
for (EntityId entityId : result.getPropagatedEntitiesList()) {
|
for (EntityId entityId : result.getPropagatedEntitiesList()) {
|
||||||
TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, entityId);
|
TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, entityId);
|
||||||
if (currentPartitions.contains(tpi)) {
|
if (currentPartitions.contains(tpi)) {
|
||||||
if (subscriptionManagerService.isPresent()) {
|
if (subscriptionManagerService.isPresent()) {
|
||||||
subscriptionManagerService.get().onAlarmDeleted(tenantId, entityId, alarmInfo, TbCallback.EMPTY);
|
subscriptionManagerService.get().onAlarmDeleted(tenantId, entityId, alarm, TbCallback.EMPTY);
|
||||||
} else {
|
} else {
|
||||||
log.warn("Possible misconfiguration because subscriptionManagerService is null!");
|
log.warn("Possible misconfiguration because subscriptionManagerService is null!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TransportProtos.ToCoreMsg toCoreMsg = TbSubscriptionUtils.toAlarmDeletedProto(tenantId, entityId, alarmInfo);
|
TransportProtos.ToCoreMsg toCoreMsg = TbSubscriptionUtils.toAlarmDeletedProto(tenantId, entityId, alarm);
|
||||||
clusterService.pushMsgToCore(tpi, entityId.getId(), toCoreMsg, null);
|
clusterService.pushMsgToCore(tpi, entityId.getId(), toCoreMsg, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,15 +37,15 @@ public class AlarmSubscriptionUpdate {
|
|||||||
@Getter
|
@Getter
|
||||||
private String errorMsg;
|
private String errorMsg;
|
||||||
@Getter
|
@Getter
|
||||||
private AlarmInfo alarm;
|
private Alarm alarm;
|
||||||
@Getter
|
@Getter
|
||||||
private boolean alarmDeleted;
|
private boolean alarmDeleted;
|
||||||
|
|
||||||
public AlarmSubscriptionUpdate(int subscriptionId, AlarmInfo alarm) {
|
public AlarmSubscriptionUpdate(int subscriptionId, Alarm alarm) {
|
||||||
this(subscriptionId, alarm, false);
|
this(subscriptionId, alarm, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlarmSubscriptionUpdate(int subscriptionId, AlarmInfo alarm, boolean alarmDeleted) {
|
public AlarmSubscriptionUpdate(int subscriptionId, Alarm alarm, boolean alarmDeleted) {
|
||||||
super();
|
super();
|
||||||
this.subscriptionId = subscriptionId;
|
this.subscriptionId = subscriptionId;
|
||||||
this.alarm = alarm;
|
this.alarm = alarm;
|
||||||
|
|||||||
@ -84,8 +84,8 @@ public class AlarmsCleanUpService {
|
|||||||
PageData<AlarmId> toRemove = alarmDao.findAlarmsIdsByEndTsBeforeAndTenantId(expirationTime, tenantId, removalBatchRequest);
|
PageData<AlarmId> toRemove = alarmDao.findAlarmsIdsByEndTsBeforeAndTenantId(expirationTime, tenantId, removalBatchRequest);
|
||||||
toRemove.getData().forEach(alarmId -> {
|
toRemove.getData().forEach(alarmId -> {
|
||||||
relationService.deleteEntityRelations(tenantId, alarmId);
|
relationService.deleteEntityRelations(tenantId, alarmId);
|
||||||
AlarmInfo alarmInfo = alarmService.deleteAlarm(tenantId, alarmId).getAlarmInfo();
|
Alarm alarm = alarmService.deleteAlarm(tenantId, alarmId).getAlarm();
|
||||||
entityActionService.pushEntityActionToRuleEngine(alarmInfo.getOriginator(), alarmInfo, tenantId, null, ActionType.ALARM_DELETE, null);
|
entityActionService.pushEntityActionToRuleEngine(alarm.getOriginator(), alarm, tenantId, null, ActionType.ALARM_DELETE, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
totalRemoved += toRemove.getTotalElements();
|
totalRemoved += toRemove.getTotalElements();
|
||||||
|
|||||||
@ -28,26 +28,22 @@ import java.util.List;
|
|||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class AlarmOperationResult {
|
public class AlarmOperationResult {
|
||||||
private final AlarmInfo alarmInfo;
|
private final Alarm alarm;
|
||||||
private final boolean successful;
|
private final boolean successful;
|
||||||
private final boolean created;
|
private final boolean created;
|
||||||
private final AlarmSeverity oldSeverity;
|
private final AlarmSeverity oldSeverity;
|
||||||
private final List<EntityId> propagatedEntitiesList;
|
private final List<EntityId> propagatedEntitiesList;
|
||||||
|
|
||||||
public AlarmOperationResult(Alarm alarm, boolean successful) {
|
public AlarmOperationResult(Alarm alarm, boolean successful) {
|
||||||
this(new AlarmInfo(alarm, null, null, null, null, null), successful, Collections.emptyList());
|
this(alarm, successful, Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlarmOperationResult(AlarmInfo alarmInfo, boolean successful) {
|
public AlarmOperationResult(Alarm alarm, boolean successful, List<EntityId> propagatedEntitiesList) {
|
||||||
this(alarmInfo, successful, Collections.emptyList());
|
this(alarm, successful, false, null, propagatedEntitiesList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlarmOperationResult(AlarmInfo alarmInfo, boolean successful, List<EntityId> propagatedEntitiesList) {
|
public AlarmOperationResult(Alarm alarm, boolean successful, boolean created, List<EntityId> propagatedEntitiesList) {
|
||||||
this(alarmInfo, successful, false, null, propagatedEntitiesList);
|
this.alarm = alarm;
|
||||||
}
|
|
||||||
|
|
||||||
public AlarmOperationResult(AlarmInfo alarmInfo, boolean successful, boolean created, List<EntityId> propagatedEntitiesList) {
|
|
||||||
this.alarmInfo = alarmInfo;
|
|
||||||
this.successful = successful;
|
this.successful = successful;
|
||||||
this.created = created;
|
this.created = created;
|
||||||
this.propagatedEntitiesList = propagatedEntitiesList;
|
this.propagatedEntitiesList = propagatedEntitiesList;
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.dao.entity;
|
package org.thingsboard.server.dao.entity;
|
||||||
|
|
||||||
import org.springframework.data.util.Pair;
|
import org.thingsboard.server.common.data.id.NameLabelAndCustomerDetails;
|
||||||
import org.thingsboard.server.common.data.id.CustomerId;
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
@ -34,8 +34,9 @@ public interface EntityService {
|
|||||||
|
|
||||||
Optional<CustomerId> fetchEntityCustomerId(TenantId tenantId, EntityId entityId);
|
Optional<CustomerId> fetchEntityCustomerId(TenantId tenantId, EntityId entityId);
|
||||||
|
|
||||||
|
Optional<NameLabelAndCustomerDetails> fetchNameLabelAndCustomerDetails(TenantId tenantId, EntityId entityId);
|
||||||
|
|
||||||
long countEntitiesByQuery(TenantId tenantId, CustomerId customerId, EntityCountQuery query);
|
long countEntitiesByQuery(TenantId tenantId, CustomerId customerId, EntityCountQuery query);
|
||||||
|
|
||||||
PageData<EntityData> findEntityDataByQuery(TenantId tenantId, CustomerId customerId, EntityDataQuery query);
|
PageData<EntityData> findEntityDataByQuery(TenantId tenantId, CustomerId customerId, EntityDataQuery query);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.common.data.alarm;
|
package org.thingsboard.server.common.data.alarm;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
@ -45,6 +46,7 @@ import java.util.List;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class Alarm extends BaseData<AlarmId> implements HasName, HasTenantId, HasCustomerId {
|
public class Alarm extends BaseData<AlarmId> implements HasName, HasTenantId, HasCustomerId {
|
||||||
|
|
||||||
@ApiModelProperty(position = 3, value = "JSON object with Tenant Id", accessMode = ApiModelProperty.AccessMode.READ_ONLY)
|
@ApiModelProperty(position = 3, value = "JSON object with Tenant Id", accessMode = ApiModelProperty.AccessMode.READ_ONLY)
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.thingsboard.server.common.data.id;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class NameLabelAndCustomerDetails {
|
||||||
|
private final String name;
|
||||||
|
private final String label;
|
||||||
|
private final CustomerId customerId;
|
||||||
|
}
|
||||||
@ -35,10 +35,19 @@ public class AlarmData extends AlarmInfo {
|
|||||||
@Getter
|
@Getter
|
||||||
private final Map<EntityKeyType, Map<String, TsValue>> latest;
|
private final Map<EntityKeyType, Map<String, TsValue>> latest;
|
||||||
|
|
||||||
public AlarmData(AlarmInfo alarmInfo, EntityId entityId) {
|
public AlarmData update(Alarm alarm) {
|
||||||
super(alarmInfo);
|
this.setEndTs(alarm.getEndTs());
|
||||||
this.entityId = entityId;
|
this.setSeverity(alarm.getSeverity());
|
||||||
this.latest = new HashMap<>();
|
this.setStatus(alarm.getStatus());
|
||||||
|
this.setDetails(alarm.getDetails());
|
||||||
|
this.setPropagate(alarm.isPropagate());
|
||||||
|
this.setPropagateToOwner(alarm.isPropagateToOwner());
|
||||||
|
this.setPropagateToTenant(alarm.isPropagateToTenant());
|
||||||
|
this.setPropagateRelationTypes(alarm.getPropagateRelationTypes());
|
||||||
|
// This should be changed via separate message?
|
||||||
|
this.setAckTs(alarm.getAckTs());
|
||||||
|
this.setClearTs(alarm.getClearTs());
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlarmData(Alarm alarm, EntityId entityId) {
|
public AlarmData(Alarm alarm, EntityId entityId) {
|
||||||
|
|||||||
@ -38,6 +38,7 @@ import org.thingsboard.server.common.data.alarm.AlarmStatus;
|
|||||||
import org.thingsboard.server.common.data.alarm.EntityAlarm;
|
import org.thingsboard.server.common.data.alarm.EntityAlarm;
|
||||||
import org.thingsboard.server.common.data.exception.ApiUsageLimitsExceededException;
|
import org.thingsboard.server.common.data.exception.ApiUsageLimitsExceededException;
|
||||||
import org.thingsboard.server.common.data.id.AlarmId;
|
import org.thingsboard.server.common.data.id.AlarmId;
|
||||||
|
import org.thingsboard.server.common.data.id.NameLabelAndCustomerDetails;
|
||||||
import org.thingsboard.server.common.data.id.CustomerId;
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
import org.thingsboard.server.common.data.id.HasId;
|
import org.thingsboard.server.common.data.id.HasId;
|
||||||
@ -161,8 +162,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
|||||||
if (alarm == null) {
|
if (alarm == null) {
|
||||||
return new AlarmOperationResult(alarm, false);
|
return new AlarmOperationResult(alarm, false);
|
||||||
}
|
}
|
||||||
AlarmInfo alarmInfo = getAlarmInfo(tenantId, alarm);
|
AlarmOperationResult result = new AlarmOperationResult(alarm, true, new ArrayList<>(getPropagationEntityIds(alarm)));
|
||||||
AlarmOperationResult result = new AlarmOperationResult(alarmInfo, true, new ArrayList<>(getPropagationEntityIds(alarm)));
|
|
||||||
deleteEntityRelations(tenantId, alarm.getId());
|
deleteEntityRelations(tenantId, alarm.getId());
|
||||||
alarmDao.removeById(tenantId, alarm.getUuidId());
|
alarmDao.removeById(tenantId, alarm.getUuidId());
|
||||||
return result;
|
return result;
|
||||||
@ -172,8 +172,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
|||||||
log.debug("New Alarm : {}", alarm);
|
log.debug("New Alarm : {}", alarm);
|
||||||
Alarm saved = alarmDao.save(alarm.getTenantId(), alarm);
|
Alarm saved = alarmDao.save(alarm.getTenantId(), alarm);
|
||||||
List<EntityId> propagatedEntitiesList = createEntityAlarmRecords(saved);
|
List<EntityId> propagatedEntitiesList = createEntityAlarmRecords(saved);
|
||||||
AlarmInfo alarmInfo = getAlarmInfo(alarm.getTenantId(), saved);
|
return new AlarmOperationResult(saved, true, true, propagatedEntitiesList);
|
||||||
return new AlarmOperationResult(alarmInfo, true, true, propagatedEntitiesList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<EntityId> createEntityAlarmRecords(Alarm alarm) throws InterruptedException, ExecutionException {
|
private List<EntityId> createEntityAlarmRecords(Alarm alarm) throws InterruptedException, ExecutionException {
|
||||||
@ -229,8 +228,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
|||||||
} else {
|
} else {
|
||||||
propagatedEntitiesList = new ArrayList<>(getPropagationEntityIds(result));
|
propagatedEntitiesList = new ArrayList<>(getPropagationEntityIds(result));
|
||||||
}
|
}
|
||||||
AlarmInfo alarmInfo = getAlarmInfo(newAlarm.getTenantId(), newAlarm);
|
return new AlarmOperationResult(result, true, false, oldAlarmSeverity, propagatedEntitiesList);
|
||||||
return new AlarmOperationResult(alarmInfo, true, false, oldAlarmSeverity, propagatedEntitiesList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -247,8 +245,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
|||||||
alarm.setStatus(newStatus);
|
alarm.setStatus(newStatus);
|
||||||
alarm.setAckTs(ackTime);
|
alarm.setAckTs(ackTime);
|
||||||
alarm = alarmDao.save(alarm.getTenantId(), alarm);
|
alarm = alarmDao.save(alarm.getTenantId(), alarm);
|
||||||
AlarmInfo alarmInfo = getAlarmInfo(tenantId, alarm);
|
return new AlarmOperationResult(alarm, true, new ArrayList<>(getPropagationEntityIds(alarm)));
|
||||||
return new AlarmOperationResult(alarmInfo, true, new ArrayList<>(getPropagationEntityIds(alarm)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -271,8 +268,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
|||||||
alarm.setDetails(details);
|
alarm.setDetails(details);
|
||||||
}
|
}
|
||||||
alarm = alarmDao.save(alarm.getTenantId(), alarm);
|
alarm = alarmDao.save(alarm.getTenantId(), alarm);
|
||||||
AlarmInfo alarmInfo = getAlarmInfo(tenantId, alarm);
|
return new AlarmOperationResult(alarm, true, new ArrayList<>(getPropagationEntityIds(alarm)));
|
||||||
return new AlarmOperationResult(alarmInfo, true, new ArrayList<>(getPropagationEntityIds(alarm)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -290,8 +286,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
|||||||
alarm.setAssigneeId(assigneeId);
|
alarm.setAssigneeId(assigneeId);
|
||||||
alarm.setAssignTs(assignTime);
|
alarm.setAssignTs(assignTime);
|
||||||
alarm = alarmDao.save(alarm.getTenantId(), alarm);
|
alarm = alarmDao.save(alarm.getTenantId(), alarm);
|
||||||
AlarmInfo alarmInfo = getAlarmInfo(tenantId, alarm);
|
return new AlarmOperationResult(alarm, true, new ArrayList<>(getPropagationEntityIds(alarm)));
|
||||||
return new AlarmOperationResult(alarmInfo, true, new ArrayList<>(getPropagationEntityIds(alarm)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -309,8 +304,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
|||||||
alarm.setAssigneeId(null);
|
alarm.setAssigneeId(null);
|
||||||
alarm.setAssignTs(assignTime);
|
alarm.setAssignTs(assignTime);
|
||||||
alarm = alarmDao.save(alarm.getTenantId(), alarm);
|
alarm = alarmDao.save(alarm.getTenantId(), alarm);
|
||||||
AlarmInfo alarmInfo = getAlarmInfo(tenantId, alarm);
|
return new AlarmOperationResult(alarm, true, new ArrayList<>(getPropagationEntityIds(alarm)));
|
||||||
return new AlarmOperationResult(alarmInfo, true, new ArrayList<>(getPropagationEntityIds(alarm)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -359,10 +353,15 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
|||||||
private ListenableFuture<PageData<AlarmInfo>> fetchAlarmsOriginators(TenantId tenantId, PageData<AlarmInfo> alarms) {
|
private ListenableFuture<PageData<AlarmInfo>> fetchAlarmsOriginators(TenantId tenantId, PageData<AlarmInfo> alarms) {
|
||||||
List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(alarms.getData().size());
|
List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(alarms.getData().size());
|
||||||
for (AlarmInfo alarmInfo : alarms.getData()) {
|
for (AlarmInfo alarmInfo : alarms.getData()) {
|
||||||
alarmInfo.setOriginatorName(
|
Optional<NameLabelAndCustomerDetails> detailsOpt = entityService.fetchNameLabelAndCustomerDetails(tenantId, alarmInfo.getOriginator());
|
||||||
entityService.fetchEntityName(tenantId, alarmInfo.getOriginator()).orElse("Deleted"));
|
if (detailsOpt.isPresent() && detailsOpt.get().getName() != null) {
|
||||||
alarmInfo.setOriginatorLabel(
|
NameLabelAndCustomerDetails details = detailsOpt.get();
|
||||||
entityService.fetchEntityLabel(tenantId, alarmInfo.getOriginator()).orElse(alarmInfo.getOriginatorName()));
|
alarmInfo.setOriginatorName(details.getName());
|
||||||
|
alarmInfo.setOriginatorLabel(details.getLabel());
|
||||||
|
} else {
|
||||||
|
alarmInfo.setOriginatorName("Deleted");
|
||||||
|
alarmInfo.setOriginatorLabel("Deleted");
|
||||||
|
}
|
||||||
alarmFutures.add(Futures.immediateFuture(alarmInfo));
|
alarmFutures.add(Futures.immediateFuture(alarmInfo));
|
||||||
}
|
}
|
||||||
return Futures.transform(Futures.successfulAsList(alarmFutures),
|
return Futures.transform(Futures.successfulAsList(alarmFutures),
|
||||||
@ -465,8 +464,15 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
|||||||
String assigneeLastName = null;
|
String assigneeLastName = null;
|
||||||
String assigneeEmail = null;
|
String assigneeEmail = null;
|
||||||
|
|
||||||
originatorName = entityService.fetchEntityName(tenantId, alarm.getOriginator()).orElse("Deleted");
|
Optional<NameLabelAndCustomerDetails> detailsOpt = entityService.fetchNameLabelAndCustomerDetails(tenantId, alarm.getOriginator());
|
||||||
originatorLabel = entityService.fetchEntityLabel(tenantId, alarm.getOriginator()).orElse(originatorName);
|
if (detailsOpt.isPresent() && detailsOpt.get().getName() != null) {
|
||||||
|
NameLabelAndCustomerDetails details = detailsOpt.get();
|
||||||
|
originatorName = details.getName();
|
||||||
|
originatorLabel = details.getLabel();
|
||||||
|
} else {
|
||||||
|
originatorName = "Deleted";
|
||||||
|
originatorLabel = "Deleted";
|
||||||
|
}
|
||||||
|
|
||||||
if (alarm.getAssigneeId() != null) {
|
if (alarm.getAssigneeId() != null) {
|
||||||
User assignedUser = userService.findUserById(tenantId, alarm.getAssigneeId());
|
User assignedUser = userService.findUserById(tenantId, alarm.getAssigneeId());
|
||||||
|
|||||||
@ -16,9 +16,7 @@
|
|||||||
package org.thingsboard.server.dao.entity;
|
package org.thingsboard.server.dao.entity;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.util.Pair;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.thingsboard.server.common.data.HasCustomerId;
|
import org.thingsboard.server.common.data.HasCustomerId;
|
||||||
@ -26,6 +24,8 @@ import org.thingsboard.server.common.data.HasEmail;
|
|||||||
import org.thingsboard.server.common.data.HasLabel;
|
import org.thingsboard.server.common.data.HasLabel;
|
||||||
import org.thingsboard.server.common.data.HasName;
|
import org.thingsboard.server.common.data.HasName;
|
||||||
import org.thingsboard.server.common.data.HasTitle;
|
import org.thingsboard.server.common.data.HasTitle;
|
||||||
|
import org.thingsboard.server.common.data.StringUtils;
|
||||||
|
import org.thingsboard.server.common.data.id.NameLabelAndCustomerDetails;
|
||||||
import org.thingsboard.server.common.data.id.CustomerId;
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
import org.thingsboard.server.common.data.id.HasId;
|
import org.thingsboard.server.common.data.id.HasId;
|
||||||
@ -98,6 +98,12 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe
|
|||||||
return fetchAndConvert(tenantId, entityId, this::getCustomerId);
|
return fetchAndConvert(tenantId, entityId, this::getCustomerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<NameLabelAndCustomerDetails> fetchNameLabelAndCustomerDetails(TenantId tenantId, EntityId entityId) {
|
||||||
|
log.trace("Executing fetchNameLabelAndCustomerDetails [{}]", entityId);
|
||||||
|
return fetchAndConvert(tenantId, entityId, this::getNameLabelAndCustomerDetails);
|
||||||
|
}
|
||||||
|
|
||||||
private <T> Optional<T> fetchAndConvert(TenantId tenantId, EntityId entityId, Function<HasId<?>, T> converter) {
|
private <T> Optional<T> fetchAndConvert(TenantId tenantId, EntityId entityId, Function<HasId<?>, T> converter) {
|
||||||
EntityDaoService entityDaoService = entityServiceRegistry.getServiceByEntityType(entityId.getEntityType());
|
EntityDaoService entityDaoService = entityServiceRegistry.getServiceByEntityType(entityId.getEntityType());
|
||||||
Optional<HasId<?>> entityOpt = entityDaoService.findEntity(tenantId, entityId);
|
Optional<HasId<?>> entityOpt = entityDaoService.findEntity(tenantId, entityId);
|
||||||
@ -109,25 +115,24 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getLabel(HasId<?> entity) {
|
private String getLabel(HasId<?> entity) {
|
||||||
String entityLabel = null;
|
if (entity instanceof HasTitle && StringUtils.isNotEmpty(((HasTitle) entity).getTitle())) {
|
||||||
if (entity instanceof HasTitle) {
|
return ((HasTitle) entity).getTitle();
|
||||||
entityLabel = ((HasTitle) entity).getTitle();
|
|
||||||
}
|
}
|
||||||
if (entity instanceof HasLabel && entityLabel == null) {
|
if (entity instanceof HasLabel && StringUtils.isNotEmpty(((HasLabel) entity).getLabel())) {
|
||||||
entityLabel = ((HasLabel) entity).getLabel();
|
return ((HasLabel) entity).getLabel();
|
||||||
}
|
}
|
||||||
if (entity instanceof HasEmail && entityLabel == null) {
|
if (entity instanceof HasEmail && StringUtils.isNotEmpty(((HasEmail) entity).getEmail())) {
|
||||||
entityLabel = ((HasEmail) entity).getEmail();
|
return ((HasEmail) entity).getEmail();
|
||||||
}
|
}
|
||||||
if (entity instanceof HasName && entityLabel == null) {
|
if (entity instanceof HasName && StringUtils.isNotEmpty(((HasName) entity).getName())) {
|
||||||
entityLabel = ((HasName) entity).getName();
|
return ((HasName) entity).getName();
|
||||||
}
|
}
|
||||||
return entityLabel;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CustomerId getCustomerId(HasId<?> hasId) {
|
private CustomerId getCustomerId(HasId<?> entity) {
|
||||||
if (hasId instanceof HasCustomerId) {
|
if (entity instanceof HasCustomerId) {
|
||||||
HasCustomerId hasCustomerId = (HasCustomerId) hasId;
|
HasCustomerId hasCustomerId = (HasCustomerId) entity;
|
||||||
CustomerId customerId = hasCustomerId.getCustomerId();
|
CustomerId customerId = hasCustomerId.getCustomerId();
|
||||||
if (customerId == null) {
|
if (customerId == null) {
|
||||||
customerId = NULL_CUSTOMER_ID;
|
customerId = NULL_CUSTOMER_ID;
|
||||||
@ -137,6 +142,10 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe
|
|||||||
return NULL_CUSTOMER_ID;
|
return NULL_CUSTOMER_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NameLabelAndCustomerDetails getNameLabelAndCustomerDetails(HasId<?> entity) {
|
||||||
|
return new NameLabelAndCustomerDetails(getName(entity), getLabel(entity), getCustomerId(entity));
|
||||||
|
}
|
||||||
|
|
||||||
private static void validateEntityCountQuery(EntityCountQuery query) {
|
private static void validateEntityCountQuery(EntityCountQuery query) {
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
throw new IncorrectParameterException("Query must be specified.");
|
throw new IncorrectParameterException("Query must be specified.");
|
||||||
|
|||||||
@ -60,7 +60,7 @@ public abstract class BaseAlarmCommentServiceTest extends AbstractServiceTest {
|
|||||||
.type(TEST_ALARM)
|
.type(TEST_ALARM)
|
||||||
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
||||||
.startTs(System.currentTimeMillis()).build();
|
.startTs(System.currentTimeMillis()).build();
|
||||||
alarm = new Alarm(alarmService.createOrUpdateAlarm(alarm).getAlarmInfo());
|
alarm = alarmService.createOrUpdateAlarm(alarm).getAlarm();
|
||||||
|
|
||||||
user = new User();
|
user = new User();
|
||||||
user.setAuthority(Authority.TENANT_ADMIN);
|
user.setAuthority(Authority.TENANT_ADMIN);
|
||||||
|
|||||||
@ -96,7 +96,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.startTs(ts).build();
|
.startTs(ts).build();
|
||||||
|
|
||||||
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm);
|
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm);
|
||||||
Alarm created = new Alarm(result.getAlarmInfo());
|
Alarm created = result.getAlarm();
|
||||||
|
|
||||||
Assert.assertNotNull(created);
|
Assert.assertNotNull(created);
|
||||||
Assert.assertNotNull(created.getId());
|
Assert.assertNotNull(created.getId());
|
||||||
@ -135,7 +135,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.startTs(ts).build();
|
.startTs(ts).build();
|
||||||
|
|
||||||
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm);
|
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm);
|
||||||
Alarm created = new Alarm(result.getAlarmInfo());
|
Alarm created = result.getAlarm();
|
||||||
|
|
||||||
// Check child relation
|
// Check child relation
|
||||||
PageData<AlarmInfo> alarms = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
PageData<AlarmInfo> alarms = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
||||||
@ -160,7 +160,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
|
|
||||||
created.setPropagate(true);
|
created.setPropagate(true);
|
||||||
result = alarmService.createOrUpdateAlarm(created);
|
result = alarmService.createOrUpdateAlarm(created);
|
||||||
created = new Alarm(result.getAlarmInfo());
|
created = result.getAlarm();
|
||||||
|
|
||||||
// Check child relation
|
// Check child relation
|
||||||
alarms = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
alarms = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
||||||
@ -239,7 +239,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.startTs(ts).build();
|
.startTs(ts).build();
|
||||||
|
|
||||||
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm);
|
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm);
|
||||||
AlarmInfo created = result.getAlarmInfo();
|
Alarm created = result.getAlarm();
|
||||||
|
|
||||||
User tenantUser = new User();
|
User tenantUser = new User();
|
||||||
tenantUser.setTenantId(tenantId);
|
tenantUser.setTenantId(tenantId);
|
||||||
@ -252,7 +252,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
Assert.assertNotNull(tenantUser);
|
Assert.assertNotNull(tenantUser);
|
||||||
|
|
||||||
AlarmOperationResult assignmentResult = alarmService.assignAlarm(tenantId, created.getId(), tenantUser.getId(), ts);
|
AlarmOperationResult assignmentResult = alarmService.assignAlarm(tenantId, created.getId(), tenantUser.getId(), ts);
|
||||||
created = assignmentResult.getAlarmInfo();
|
created = assignmentResult.getAlarm();
|
||||||
|
|
||||||
PageData<AlarmInfo> alarms = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
PageData<AlarmInfo> alarms = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
||||||
.assigneeId(tenantUser.getId())
|
.assigneeId(tenantUser.getId())
|
||||||
@ -262,7 +262,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
).build()).get();
|
).build()).get();
|
||||||
Assert.assertNotNull(alarms.getData());
|
Assert.assertNotNull(alarms.getData());
|
||||||
Assert.assertEquals(1, alarms.getData().size());
|
Assert.assertEquals(1, alarms.getData().size());
|
||||||
Assert.assertEquals(created, alarms.getData().get(0));
|
Assert.assertEquals(created, new Alarm(alarms.getData().get(0)));
|
||||||
|
|
||||||
AlarmDataPageLink pageLink = new AlarmDataPageLink();
|
AlarmDataPageLink pageLink = new AlarmDataPageLink();
|
||||||
pageLink.setPage(0);
|
pageLink.setPage(0);
|
||||||
@ -272,7 +272,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
PageData<AlarmData> assignedAlarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(created.getOriginator()));
|
PageData<AlarmData> assignedAlarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(created.getOriginator()));
|
||||||
Assert.assertNotNull(assignedAlarms.getData());
|
Assert.assertNotNull(assignedAlarms.getData());
|
||||||
Assert.assertEquals(1, assignedAlarms.getData().size());
|
Assert.assertEquals(1, assignedAlarms.getData().size());
|
||||||
Assert.assertEquals(created, new AlarmInfo(assignedAlarms.getData().get(0)));
|
Assert.assertEquals(created, new Alarm(assignedAlarms.getData().get(0)));
|
||||||
|
|
||||||
User tenantUser2 = new User();
|
User tenantUser2 = new User();
|
||||||
tenantUser2.setTenantId(tenantId);
|
tenantUser2.setTenantId(tenantId);
|
||||||
@ -319,7 +319,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
||||||
.startTs(ts).build();
|
.startTs(ts).build();
|
||||||
AlarmOperationResult result = alarmService.createOrUpdateAlarm(tenantAlarm);
|
AlarmOperationResult result = alarmService.createOrUpdateAlarm(tenantAlarm);
|
||||||
tenantAlarm = new Alarm(result.getAlarmInfo());
|
tenantAlarm = result.getAlarm();
|
||||||
|
|
||||||
Alarm deviceAlarm = Alarm.builder().tenantId(tenantId)
|
Alarm deviceAlarm = Alarm.builder().tenantId(tenantId)
|
||||||
.originator(customerDevice.getId())
|
.originator(customerDevice.getId())
|
||||||
@ -328,7 +328,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
||||||
.startTs(ts).build();
|
.startTs(ts).build();
|
||||||
result = alarmService.createOrUpdateAlarm(deviceAlarm);
|
result = alarmService.createOrUpdateAlarm(deviceAlarm);
|
||||||
deviceAlarm = result.getAlarmInfo();
|
deviceAlarm = result.getAlarm();
|
||||||
|
|
||||||
AlarmDataPageLink pageLink = new AlarmDataPageLink();
|
AlarmDataPageLink pageLink = new AlarmDataPageLink();
|
||||||
pageLink.setPage(0);
|
pageLink.setPage(0);
|
||||||
@ -346,7 +346,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
|
|
||||||
PageData<AlarmData> customerAlarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(customerDevice.getId()));
|
PageData<AlarmData> customerAlarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(customerDevice.getId()));
|
||||||
Assert.assertEquals(1, customerAlarms.getData().size());
|
Assert.assertEquals(1, customerAlarms.getData().size());
|
||||||
Assert.assertEquals(deviceAlarm, new AlarmInfo(customerAlarms.getData().get(0)));
|
Assert.assertEquals(deviceAlarm, new Alarm(customerAlarms.getData().get(0)));
|
||||||
|
|
||||||
PageData<AlarmInfo> alarms = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
PageData<AlarmInfo> alarms = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
||||||
.affectedEntityId(tenantDevice.getId())
|
.affectedEntityId(tenantDevice.getId())
|
||||||
@ -395,7 +395,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
||||||
.startTs(ts).build();
|
.startTs(ts).build();
|
||||||
AlarmOperationResult result = alarmService.createOrUpdateAlarm(tenantAlarm);
|
AlarmOperationResult result = alarmService.createOrUpdateAlarm(tenantAlarm);
|
||||||
tenantAlarm = new Alarm(result.getAlarmInfo());
|
tenantAlarm = result.getAlarm();
|
||||||
|
|
||||||
Alarm customerAlarm = Alarm.builder().tenantId(tenantId)
|
Alarm customerAlarm = Alarm.builder().tenantId(tenantId)
|
||||||
.originator(tenantDevice.getId())
|
.originator(tenantDevice.getId())
|
||||||
@ -404,7 +404,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
||||||
.startTs(ts).build();
|
.startTs(ts).build();
|
||||||
result = alarmService.createOrUpdateAlarm(customerAlarm);
|
result = alarmService.createOrUpdateAlarm(customerAlarm);
|
||||||
customerAlarm = new Alarm(result.getAlarmInfo());
|
customerAlarm = result.getAlarm();
|
||||||
|
|
||||||
AlarmDataPageLink pageLink = new AlarmDataPageLink();
|
AlarmDataPageLink pageLink = new AlarmDataPageLink();
|
||||||
pageLink.setPage(0);
|
pageLink.setPage(0);
|
||||||
@ -445,7 +445,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
||||||
.startTs(ts).build();
|
.startTs(ts).build();
|
||||||
AlarmOperationResult result = alarmService.createOrUpdateAlarm(tenantAlarm);
|
AlarmOperationResult result = alarmService.createOrUpdateAlarm(tenantAlarm);
|
||||||
tenantAlarm = new Alarm(result.getAlarmInfo());
|
tenantAlarm = result.getAlarm();
|
||||||
|
|
||||||
Alarm customerAlarm = Alarm.builder().tenantId(tenantId)
|
Alarm customerAlarm = Alarm.builder().tenantId(tenantId)
|
||||||
.originator(device.getId())
|
.originator(device.getId())
|
||||||
@ -455,7 +455,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK)
|
||||||
.startTs(ts).build();
|
.startTs(ts).build();
|
||||||
result = alarmService.createOrUpdateAlarm(customerAlarm);
|
result = alarmService.createOrUpdateAlarm(customerAlarm);
|
||||||
customerAlarm = new Alarm(result.getAlarmInfo());
|
customerAlarm = result.getAlarm();
|
||||||
|
|
||||||
AlarmDataPageLink pageLink = new AlarmDataPageLink();
|
AlarmDataPageLink pageLink = new AlarmDataPageLink();
|
||||||
pageLink.setPage(0);
|
pageLink.setPage(0);
|
||||||
@ -512,7 +512,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.status(AlarmStatus.ACTIVE_UNACK)
|
.status(AlarmStatus.ACTIVE_UNACK)
|
||||||
.startTs(System.currentTimeMillis())
|
.startTs(System.currentTimeMillis())
|
||||||
.build();
|
.build();
|
||||||
alarm1 = alarmService.createOrUpdateAlarm(alarm1).getAlarmInfo();
|
alarm1 = alarmService.createOrUpdateAlarm(alarm1).getAlarm();
|
||||||
alarmService.clearAlarm(tenantId, alarm1.getId(), null, System.currentTimeMillis()).get();
|
alarmService.clearAlarm(tenantId, alarm1.getId(), null, System.currentTimeMillis()).get();
|
||||||
|
|
||||||
Alarm alarm2 = Alarm.builder()
|
Alarm alarm2 = Alarm.builder()
|
||||||
@ -523,7 +523,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.status(AlarmStatus.ACTIVE_ACK)
|
.status(AlarmStatus.ACTIVE_ACK)
|
||||||
.startTs(System.currentTimeMillis())
|
.startTs(System.currentTimeMillis())
|
||||||
.build();
|
.build();
|
||||||
alarm2 = alarmService.createOrUpdateAlarm(alarm2).getAlarmInfo();
|
alarm2 = alarmService.createOrUpdateAlarm(alarm2).getAlarm();
|
||||||
alarmService.clearAlarm(tenantId, alarm2.getId(), null, System.currentTimeMillis()).get();
|
alarmService.clearAlarm(tenantId, alarm2.getId(), null, System.currentTimeMillis()).get();
|
||||||
|
|
||||||
Alarm alarm3 = Alarm.builder()
|
Alarm alarm3 = Alarm.builder()
|
||||||
@ -534,7 +534,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.status(AlarmStatus.ACTIVE_ACK)
|
.status(AlarmStatus.ACTIVE_ACK)
|
||||||
.startTs(System.currentTimeMillis())
|
.startTs(System.currentTimeMillis())
|
||||||
.build();
|
.build();
|
||||||
alarm3 = alarmService.createOrUpdateAlarm(alarm3).getAlarmInfo();
|
alarm3 = alarmService.createOrUpdateAlarm(alarm3).getAlarm();
|
||||||
|
|
||||||
Assert.assertEquals(AlarmSeverity.MAJOR, alarmService.findHighestAlarmSeverity(tenantId, customerDevice.getId(), AlarmSearchStatus.UNACK, null, null));
|
Assert.assertEquals(AlarmSeverity.MAJOR, alarmService.findHighestAlarmSeverity(tenantId, customerDevice.getId(), AlarmSearchStatus.UNACK, null, null));
|
||||||
Assert.assertEquals(AlarmSeverity.CRITICAL, alarmService.findHighestAlarmSeverity(tenantId, customerDevice.getId(), null, null, null));
|
Assert.assertEquals(AlarmSeverity.CRITICAL, alarmService.findHighestAlarmSeverity(tenantId, customerDevice.getId(), null, null, null));
|
||||||
@ -564,7 +564,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.startTs(ts).build();
|
.startTs(ts).build();
|
||||||
|
|
||||||
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm);
|
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm);
|
||||||
AlarmInfo created = result.getAlarmInfo();
|
Alarm created = result.getAlarm();
|
||||||
|
|
||||||
AlarmDataPageLink pageLink = new AlarmDataPageLink();
|
AlarmDataPageLink pageLink = new AlarmDataPageLink();
|
||||||
pageLink.setPage(0);
|
pageLink.setPage(0);
|
||||||
@ -581,7 +581,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
|
|
||||||
Assert.assertNotNull(alarms.getData());
|
Assert.assertNotNull(alarms.getData());
|
||||||
Assert.assertEquals(1, alarms.getData().size());
|
Assert.assertEquals(1, alarms.getData().size());
|
||||||
Assert.assertEquals(created, new AlarmInfo(alarms.getData().get(0)));
|
Assert.assertEquals(created, new Alarm(alarms.getData().get(0)));
|
||||||
|
|
||||||
pageLink.setPage(0);
|
pageLink.setPage(0);
|
||||||
pageLink.setPageSize(10);
|
pageLink.setPageSize(10);
|
||||||
@ -596,18 +596,18 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(childId));
|
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(childId));
|
||||||
Assert.assertNotNull(alarms.getData());
|
Assert.assertNotNull(alarms.getData());
|
||||||
Assert.assertEquals(1, alarms.getData().size());
|
Assert.assertEquals(1, alarms.getData().size());
|
||||||
Assert.assertEquals(created, new AlarmInfo(alarms.getData().get(0)));
|
Assert.assertEquals(created, new Alarm(alarms.getData().get(0)));
|
||||||
|
|
||||||
pageLink.setSearchPropagatedAlarms(true);
|
pageLink.setSearchPropagatedAlarms(true);
|
||||||
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(childId));
|
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(childId));
|
||||||
Assert.assertNotNull(alarms.getData());
|
Assert.assertNotNull(alarms.getData());
|
||||||
Assert.assertEquals(1, alarms.getData().size());
|
Assert.assertEquals(1, alarms.getData().size());
|
||||||
Assert.assertEquals(created, new AlarmInfo(alarms.getData().get(0)));
|
Assert.assertEquals(created, new Alarm(alarms.getData().get(0)));
|
||||||
|
|
||||||
// Check child relation
|
// Check child relation
|
||||||
created.setPropagate(true);
|
created.setPropagate(true);
|
||||||
result = alarmService.createOrUpdateAlarm(created);
|
result = alarmService.createOrUpdateAlarm(created);
|
||||||
created = result.getAlarmInfo();
|
created = result.getAlarm();
|
||||||
|
|
||||||
// Check child relation
|
// Check child relation
|
||||||
pageLink.setPage(0);
|
pageLink.setPage(0);
|
||||||
@ -623,7 +623,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(childId));
|
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(childId));
|
||||||
Assert.assertNotNull(alarms.getData());
|
Assert.assertNotNull(alarms.getData());
|
||||||
Assert.assertEquals(1, alarms.getData().size());
|
Assert.assertEquals(1, alarms.getData().size());
|
||||||
Assert.assertEquals(created, new AlarmInfo(alarms.getData().get(0)));
|
Assert.assertEquals(created, new Alarm(alarms.getData().get(0)));
|
||||||
|
|
||||||
// Check parent relation
|
// Check parent relation
|
||||||
pageLink.setPage(0);
|
pageLink.setPage(0);
|
||||||
@ -639,7 +639,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(parentId));
|
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(parentId));
|
||||||
Assert.assertNotNull(alarms.getData());
|
Assert.assertNotNull(alarms.getData());
|
||||||
Assert.assertEquals(1, alarms.getData().size());
|
Assert.assertEquals(1, alarms.getData().size());
|
||||||
Assert.assertEquals(created, new AlarmInfo(alarms.getData().get(0)));
|
Assert.assertEquals(created, new Alarm(alarms.getData().get(0)));
|
||||||
|
|
||||||
PageData<AlarmInfo> alarmsInfoData = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
PageData<AlarmInfo> alarmsInfoData = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
||||||
.affectedEntityId(childId)
|
.affectedEntityId(childId)
|
||||||
@ -650,7 +650,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
).build()).get();
|
).build()).get();
|
||||||
Assert.assertNotNull(alarmsInfoData.getData());
|
Assert.assertNotNull(alarmsInfoData.getData());
|
||||||
Assert.assertEquals(1, alarmsInfoData.getData().size());
|
Assert.assertEquals(1, alarmsInfoData.getData().size());
|
||||||
Assert.assertEquals(created, alarmsInfoData.getData().get(0));
|
Assert.assertEquals(created, new Alarm(alarmsInfoData.getData().get(0)));
|
||||||
|
|
||||||
alarmsInfoData = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
alarmsInfoData = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
||||||
.affectedEntityId(parentId)
|
.affectedEntityId(parentId)
|
||||||
@ -661,7 +661,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
).build()).get();
|
).build()).get();
|
||||||
Assert.assertNotNull(alarmsInfoData.getData());
|
Assert.assertNotNull(alarmsInfoData.getData());
|
||||||
Assert.assertEquals(1, alarmsInfoData.getData().size());
|
Assert.assertEquals(1, alarmsInfoData.getData().size());
|
||||||
Assert.assertEquals(created, alarmsInfoData.getData().get(0));
|
Assert.assertEquals(created, new Alarm(alarmsInfoData.getData().get(0)));
|
||||||
|
|
||||||
alarmsInfoData = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
alarmsInfoData = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
||||||
.affectedEntityId(parentId2)
|
.affectedEntityId(parentId2)
|
||||||
@ -672,7 +672,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
).build()).get();
|
).build()).get();
|
||||||
Assert.assertNotNull(alarmsInfoData.getData());
|
Assert.assertNotNull(alarmsInfoData.getData());
|
||||||
Assert.assertEquals(1, alarmsInfoData.getData().size());
|
Assert.assertEquals(1, alarmsInfoData.getData().size());
|
||||||
Assert.assertEquals(created, alarmsInfoData.getData().get(0));
|
Assert.assertEquals(created, new Alarm(alarmsInfoData.getData().get(0)));
|
||||||
|
|
||||||
pageLink.setPage(0);
|
pageLink.setPage(0);
|
||||||
pageLink.setPageSize(10);
|
pageLink.setPageSize(10);
|
||||||
@ -687,9 +687,9 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(parentId));
|
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(parentId));
|
||||||
Assert.assertNotNull(alarms.getData());
|
Assert.assertNotNull(alarms.getData());
|
||||||
Assert.assertEquals(1, alarms.getData().size());
|
Assert.assertEquals(1, alarms.getData().size());
|
||||||
Assert.assertEquals(created, new AlarmInfo(alarms.getData().get(0)));
|
Assert.assertEquals(created, new Alarm(alarms.getData().get(0)));
|
||||||
|
|
||||||
created = alarmService.ackAlarm(tenantId, created.getId(), System.currentTimeMillis()).get().getAlarmInfo();
|
created = alarmService.ackAlarm(tenantId, created.getId(), System.currentTimeMillis()).get().getAlarm();
|
||||||
|
|
||||||
pageLink.setPage(0);
|
pageLink.setPage(0);
|
||||||
pageLink.setPageSize(10);
|
pageLink.setPageSize(10);
|
||||||
@ -704,7 +704,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(childId));
|
alarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(childId));
|
||||||
Assert.assertNotNull(alarms.getData());
|
Assert.assertNotNull(alarms.getData());
|
||||||
Assert.assertEquals(1, alarms.getData().size());
|
Assert.assertEquals(1, alarms.getData().size());
|
||||||
Assert.assertEquals(created, new AlarmInfo(alarms.getData().get(0)));
|
Assert.assertEquals(created, new Alarm(alarms.getData().get(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -724,7 +724,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
|
|||||||
.startTs(ts).build();
|
.startTs(ts).build();
|
||||||
|
|
||||||
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm);
|
AlarmOperationResult result = alarmService.createOrUpdateAlarm(alarm);
|
||||||
Alarm created = new Alarm(result.getAlarmInfo());
|
Alarm created = result.getAlarm();
|
||||||
|
|
||||||
PageData<AlarmInfo> alarms = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
PageData<AlarmInfo> alarms = alarmService.findAlarms(tenantId, AlarmQuery.builder()
|
||||||
.affectedEntityId(childId)
|
.affectedEntityId(childId)
|
||||||
|
|||||||
@ -40,7 +40,7 @@ import java.util.Collection;
|
|||||||
*/
|
*/
|
||||||
public interface RuleEngineAlarmService {
|
public interface RuleEngineAlarmService {
|
||||||
|
|
||||||
AlarmInfo createOrUpdateAlarm(Alarm alarm);
|
Alarm createOrUpdateAlarm(Alarm alarm);
|
||||||
|
|
||||||
Boolean deleteAlarm(TenantId tenantId, AlarmId alarmId);
|
Boolean deleteAlarm(TenantId tenantId, AlarmId alarmId);
|
||||||
|
|
||||||
@ -50,9 +50,9 @@ public interface RuleEngineAlarmService {
|
|||||||
|
|
||||||
ListenableFuture<AlarmOperationResult> clearAlarmForResult(TenantId tenantId, AlarmId alarmId, JsonNode details, long clearTs);
|
ListenableFuture<AlarmOperationResult> clearAlarmForResult(TenantId tenantId, AlarmId alarmId, JsonNode details, long clearTs);
|
||||||
|
|
||||||
AlarmInfo assignAlarm(TenantId tenantId, AlarmId alarmId, UserId assigneeId, long assignTs);
|
AlarmOperationResult assignAlarm(TenantId tenantId, AlarmId alarmId, UserId assigneeId, long assignTs);
|
||||||
|
|
||||||
AlarmInfo unassignAlarm(TenantId tenantId, AlarmId alarmId, long assignTs);
|
AlarmOperationResult unassignAlarm(TenantId tenantId, AlarmId alarmId, long assignTs);
|
||||||
|
|
||||||
ListenableFuture<Alarm> findAlarmByIdAsync(TenantId tenantId, AlarmId alarmId);
|
ListenableFuture<Alarm> findAlarmByIdAsync(TenantId tenantId, AlarmId alarmId);
|
||||||
|
|
||||||
|
|||||||
@ -132,7 +132,7 @@ class AlarmState {
|
|||||||
);
|
);
|
||||||
DonAsynchron.withCallback(alarmClearOperationResult,
|
DonAsynchron.withCallback(alarmClearOperationResult,
|
||||||
result -> {
|
result -> {
|
||||||
pushMsg(ctx, msg, new TbAlarmResult(false, false, true, result.getAlarmInfo()), clearState);
|
pushMsg(ctx, msg, new TbAlarmResult(false, false, true, result.getAlarm()), clearState);
|
||||||
},
|
},
|
||||||
throwable -> {
|
throwable -> {
|
||||||
throw new RuntimeException(throwable);
|
throw new RuntimeException(throwable);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user