Different message on parse error
This commit is contained in:
parent
ce0bebf9e8
commit
c4390e896a
@ -251,7 +251,7 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc
|
|||||||
ctx.cancelTasks();
|
ctx.cancelTasks();
|
||||||
ctx.clearEntitySubscriptions();
|
ctx.clearEntitySubscriptions();
|
||||||
if (entities.isEmpty()) {
|
if (entities.isEmpty()) {
|
||||||
AlarmDataUpdate update = new AlarmDataUpdate(cmd.getCmdId(), new PageData<>(), null, false);
|
AlarmDataUpdate update = new AlarmDataUpdate(cmd.getCmdId(), new PageData<>(), null, 0, 0);
|
||||||
wsService.sendWsMsg(ctx.getSessionId(), update);
|
wsService.sendWsMsg(ctx.getSessionId(), update);
|
||||||
} else {
|
} else {
|
||||||
ctx.fetchAlarms();
|
ctx.fetchAlarms();
|
||||||
|
|||||||
@ -88,7 +88,7 @@ public class TbAlarmDataSubCtx extends TbAbstractDataSubCtx<AlarmDataQuery> {
|
|||||||
|
|
||||||
public void fetchAlarms() {
|
public void fetchAlarms() {
|
||||||
AlarmDataUpdate update;
|
AlarmDataUpdate update;
|
||||||
if(!entitiesMap.isEmpty()) {
|
if (!entitiesMap.isEmpty()) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
PageData<AlarmData> alarms = alarmService.findAlarmDataByQueryForEntities(getTenantId(), getCustomerId(),
|
PageData<AlarmData> alarms = alarmService.findAlarmDataByQueryForEntities(getTenantId(), getCustomerId(),
|
||||||
query, getOrderedEntityIds());
|
query, getOrderedEntityIds());
|
||||||
@ -96,9 +96,9 @@ public class TbAlarmDataSubCtx extends TbAbstractDataSubCtx<AlarmDataQuery> {
|
|||||||
stats.getAlarmQueryInvocationCnt().incrementAndGet();
|
stats.getAlarmQueryInvocationCnt().incrementAndGet();
|
||||||
stats.getAlarmQueryTimeSpent().addAndGet(end - start);
|
stats.getAlarmQueryTimeSpent().addAndGet(end - start);
|
||||||
alarms = setAndMergeAlarmsData(alarms);
|
alarms = setAndMergeAlarmsData(alarms);
|
||||||
update = new AlarmDataUpdate(cmdId, alarms, null, tooManyEntities);
|
update = new AlarmDataUpdate(cmdId, alarms, null, maxEntitiesPerAlarmSubscription, data.getTotalElements());
|
||||||
} else {
|
} else {
|
||||||
update = new AlarmDataUpdate(cmdId, new PageData<>(), null, false);
|
update = new AlarmDataUpdate(cmdId, new PageData<>(), null, maxEntitiesPerAlarmSubscription, data.getTotalElements());
|
||||||
}
|
}
|
||||||
wsService.sendWsMsg(getSessionId(), update);
|
wsService.sendWsMsg(getSessionId(), update);
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ public class TbAlarmDataSubCtx extends TbAbstractDataSubCtx<AlarmDataQuery> {
|
|||||||
alarm.getLatest().computeIfAbsent(keyType, tmp -> new HashMap<>()).putAll(latestUpdate);
|
alarm.getLatest().computeIfAbsent(keyType, tmp -> new HashMap<>()).putAll(latestUpdate);
|
||||||
return alarm;
|
return alarm;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
wsService.sendWsMsg(sessionId, new AlarmDataUpdate(cmdId, null, update, tooManyEntities));
|
wsService.sendWsMsg(sessionId, new AlarmDataUpdate(cmdId, null, update, maxEntitiesPerAlarmSubscription, data.getTotalElements()));
|
||||||
} else {
|
} else {
|
||||||
log.trace("[{}][{}][{}][{}] Received stale subscription update: {}", sessionId, cmdId, subscriptionUpdate.getSubscriptionId(), keyType, subscriptionUpdate);
|
log.trace("[{}][{}][{}][{}] Received stale subscription update: {}", sessionId, cmdId, subscriptionUpdate.getSubscriptionId(), keyType, subscriptionUpdate);
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ public class TbAlarmDataSubCtx extends TbAbstractDataSubCtx<AlarmDataQuery> {
|
|||||||
AlarmData updated = new AlarmData(alarm, current.getOriginatorName(), current.getEntityId());
|
AlarmData updated = new AlarmData(alarm, current.getOriginatorName(), current.getEntityId());
|
||||||
updated.getLatest().putAll(current.getLatest());
|
updated.getLatest().putAll(current.getLatest());
|
||||||
alarmsMap.put(alarmId, updated);
|
alarmsMap.put(alarmId, updated);
|
||||||
wsService.sendWsMsg(sessionId, new AlarmDataUpdate(cmdId, null, Collections.singletonList(updated), tooManyEntities));
|
wsService.sendWsMsg(sessionId, new AlarmDataUpdate(cmdId, null, Collections.singletonList(updated), maxEntitiesPerAlarmSubscription, data.getTotalElements()));
|
||||||
} else {
|
} else {
|
||||||
fetchAlarms();
|
fetchAlarms();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -108,6 +108,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
|
|||||||
private static final String FAILED_TO_FETCH_DATA = "Failed to fetch data!";
|
private static final String FAILED_TO_FETCH_DATA = "Failed to fetch data!";
|
||||||
private static final String FAILED_TO_FETCH_ATTRIBUTES = "Failed to fetch attributes!";
|
private static final String FAILED_TO_FETCH_ATTRIBUTES = "Failed to fetch attributes!";
|
||||||
private static final String SESSION_META_DATA_NOT_FOUND = "Session meta-data not found!";
|
private static final String SESSION_META_DATA_NOT_FOUND = "Session meta-data not found!";
|
||||||
|
private static final String FAILED_TO_PARSE_WS_COMMAND = "Failed to parse websocket command!";
|
||||||
|
|
||||||
private final ConcurrentMap<String, WsSessionMetaData> wsSessionsMap = new ConcurrentHashMap<>();
|
private final ConcurrentMap<String, WsSessionMetaData> wsSessionsMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@ -224,8 +225,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
|
|||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.warn("Failed to decode subscription cmd: {}", e.getMessage(), e);
|
log.warn("Failed to decode subscription cmd: {}", e.getMessage(), e);
|
||||||
TelemetrySubscriptionUpdate update = new TelemetrySubscriptionUpdate(UNKNOWN_SUBSCRIPTION_ID, SubscriptionErrorCode.INTERNAL_ERROR, SESSION_META_DATA_NOT_FOUND);
|
sendWsMsg(sessionRef, new TelemetrySubscriptionUpdate(UNKNOWN_SUBSCRIPTION_ID, SubscriptionErrorCode.BAD_REQUEST, FAILED_TO_PARSE_WS_COMMAND));
|
||||||
sendWsMsg(sessionRef, update);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,7 @@ package org.thingsboard.server.service.telemetry.cmd.v2;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.thingsboard.server.common.data.page.PageData;
|
import org.thingsboard.server.common.data.page.PageData;
|
||||||
import org.thingsboard.server.common.data.query.AlarmData;
|
import org.thingsboard.server.common.data.query.AlarmData;
|
||||||
@ -27,11 +28,15 @@ import java.util.List;
|
|||||||
|
|
||||||
public class AlarmDataUpdate extends DataUpdate<AlarmData> {
|
public class AlarmDataUpdate extends DataUpdate<AlarmData> {
|
||||||
|
|
||||||
private boolean tooManyEntities;
|
@Getter
|
||||||
|
private long allowedEntities;
|
||||||
|
@Getter
|
||||||
|
private long totalEntities;
|
||||||
|
|
||||||
public AlarmDataUpdate(int cmdId, PageData<AlarmData> data, List<AlarmData> update, boolean tooManyEntities) {
|
public AlarmDataUpdate(int cmdId, PageData<AlarmData> data, List<AlarmData> update, long allowedEntities, long totalEntities) {
|
||||||
super(cmdId, data, update, SubscriptionErrorCode.NO_ERROR.getCode(), null);
|
super(cmdId, data, update, SubscriptionErrorCode.NO_ERROR.getCode(), null);
|
||||||
this.tooManyEntities = tooManyEntities;
|
this.allowedEntities = allowedEntities;
|
||||||
|
this.totalEntities = totalEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlarmDataUpdate(int cmdId, int errorCode, String errorMsg) {
|
public AlarmDataUpdate(int cmdId, int errorCode, String errorMsg) {
|
||||||
@ -49,8 +54,10 @@ public class AlarmDataUpdate extends DataUpdate<AlarmData> {
|
|||||||
@JsonProperty("update") List<AlarmData> update,
|
@JsonProperty("update") List<AlarmData> update,
|
||||||
@JsonProperty("errorCode") int errorCode,
|
@JsonProperty("errorCode") int errorCode,
|
||||||
@JsonProperty("errorMsg") String errorMsg,
|
@JsonProperty("errorMsg") String errorMsg,
|
||||||
@JsonProperty("tooManyEntities") boolean tooManyEntities) {
|
@JsonProperty("allowedEntities") long allowedEntities,
|
||||||
|
@JsonProperty("totalEntities") long totalEntities) {
|
||||||
super(cmdId, data, update, errorCode, errorMsg);
|
super(cmdId, data, update, errorCode, errorMsg);
|
||||||
this.tooManyEntities = tooManyEntities;
|
this.allowedEntities = allowedEntities;
|
||||||
|
this.totalEntities = totalEntities;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user