Commit 302cc5985e0a718ae463c59372bcb38f40fe8381

Authored by Andrew Shvayka
2 parents eb47eb3c ad8ef894

Merge branch 'master' of github.com:thingsboard/thingsboard

@@ -99,7 +99,7 @@ public class DefaultActorService implements ActorService { @@ -99,7 +99,7 @@ public class DefaultActorService implements ActorService {
99 99
100 @PostConstruct 100 @PostConstruct
101 public void initActorSystem() { 101 public void initActorSystem() {
102 - log.info("Initializing Actor system. {}", actorContext.getRuleChainService()); 102 + log.info("Initializing Actor system.");
103 actorContext.setActorService(this); 103 actorContext.setActorService(this);
104 system = ActorSystem.create(ACTOR_SYSTEM_NAME, actorContext.getConfig()); 104 system = ActorSystem.create(ACTOR_SYSTEM_NAME, actorContext.getConfig());
105 actorContext.setActorSystem(system); 105 actorContext.setActorSystem(system);
@@ -263,7 +263,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr @@ -263,7 +263,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
263 if (regularUserSessions.size() < maxSessionsPerRegularUser) { 263 if (regularUserSessions.size() < maxSessionsPerRegularUser) {
264 regularUserSessions.add(sessionId); 264 regularUserSessions.add(sessionId);
265 } else { 265 } else {
266 - log.info("[{}][{}][{}] Failed to start session. Max user sessions limit reached" 266 + log.info("[{}][{}][{}] Failed to start session. Max regular user sessions limit reached"
267 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), sessionId); 267 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), sessionId);
268 session.close(CloseStatus.POLICY_VIOLATION.withReason("Max regular user sessions limit reached")); 268 session.close(CloseStatus.POLICY_VIOLATION.withReason("Max regular user sessions limit reached"));
269 return false; 269 return false;
@@ -276,7 +276,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr @@ -276,7 +276,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
276 if (publicUserSessions.size() < maxSessionsPerPublicUser) { 276 if (publicUserSessions.size() < maxSessionsPerPublicUser) {
277 publicUserSessions.add(sessionId); 277 publicUserSessions.add(sessionId);
278 } else { 278 } else {
279 - log.info("[{}][{}][{}] Failed to start session. Max user sessions limit reached" 279 + log.info("[{}][{}][{}] Failed to start session. Max public user sessions limit reached"
280 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), sessionId); 280 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), sessionId);
281 session.close(CloseStatus.POLICY_VIOLATION.withReason("Max public user sessions limit reached")); 281 session.close(CloseStatus.POLICY_VIOLATION.withReason("Max public user sessions limit reached"));
282 return false; 282 return false;
@@ -266,7 +266,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi @@ -266,7 +266,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
266 } else if (customerSessions.size() < maxSubscriptionsPerCustomer) { 266 } else if (customerSessions.size() < maxSubscriptionsPerCustomer) {
267 customerSessions.add(subId); 267 customerSessions.add(subId);
268 } else { 268 } else {
269 - log.info("[{}][{}][{}] Failed to start subscription. Max customer sessions limit reached" 269 + log.info("[{}][{}][{}] Failed to start subscription. Max customer subscriptions limit reached"
270 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId); 270 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId);
271 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max customer subscriptions limit reached")); 271 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max customer subscriptions limit reached"));
272 return false; 272 return false;
@@ -279,7 +279,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi @@ -279,7 +279,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
279 if (regularUserSessions.size() < maxSubscriptionsPerRegularUser) { 279 if (regularUserSessions.size() < maxSubscriptionsPerRegularUser) {
280 regularUserSessions.add(subId); 280 regularUserSessions.add(subId);
281 } else { 281 } else {
282 - log.info("[{}][{}][{}] Failed to start subscription. Max user sessions limit reached" 282 + log.info("[{}][{}][{}] Failed to start subscription. Max regular user subscriptions limit reached"
283 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId); 283 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId);
284 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max regular user subscriptions limit reached")); 284 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max regular user subscriptions limit reached"));
285 return false; 285 return false;
@@ -292,7 +292,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi @@ -292,7 +292,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
292 if (publicUserSessions.size() < maxSubscriptionsPerPublicUser) { 292 if (publicUserSessions.size() < maxSubscriptionsPerPublicUser) {
293 publicUserSessions.add(subId); 293 publicUserSessions.add(subId);
294 } else { 294 } else {
295 - log.info("[{}][{}][{}] Failed to start subscription. Max user sessions limit reached" 295 + log.info("[{}][{}][{}] Failed to start subscription. Max public user subscriptions limit reached"
296 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId); 296 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId);
297 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max public user subscriptions limit reached")); 297 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max public user subscriptions limit reached"));
298 return false; 298 return false;
@@ -26,7 +26,7 @@ const WS_IDLE_TIMEOUT = 90000; @@ -26,7 +26,7 @@ const WS_IDLE_TIMEOUT = 90000;
26 const MAX_PUBLISH_COMMANDS = 10; 26 const MAX_PUBLISH_COMMANDS = 10;
27 27
28 /*@ngInject*/ 28 /*@ngInject*/
29 -function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, types, userService) { 29 +function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, $mdUtil, toast, types, userService) {
30 30
31 var isOpening = false, 31 var isOpening = false,
32 isOpened = false, 32 isOpened = false,
@@ -111,7 +111,10 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, ty @@ -111,7 +111,10 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, ty
111 } 111 }
112 } 112 }
113 113
114 - function onError (/*message*/) { 114 + function onError (errorEvent) {
  115 + if (errorEvent) {
  116 + showWsError(0, errorEvent);
  117 + }
115 isOpening = false; 118 isOpening = false;
116 } 119 }
117 120
@@ -137,7 +140,10 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, ty @@ -137,7 +140,10 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, ty
137 } 140 }
138 } 141 }
139 142
140 - function onClose () { 143 + function onClose (closeEvent) {
  144 + if (closeEvent && closeEvent.code > 1000 && closeEvent.code !== 1006) {
  145 + showWsError(closeEvent.code, closeEvent.reason);
  146 + }
141 isOpening = false; 147 isOpening = false;
142 isOpened = false; 148 isOpened = false;
143 if (isActive) { 149 if (isActive) {
@@ -162,7 +168,9 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, ty @@ -162,7 +168,9 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, ty
162 function onMessage (message) { 168 function onMessage (message) {
163 if (message.data) { 169 if (message.data) {
164 var data = angular.fromJson(message.data); 170 var data = angular.fromJson(message.data);
165 - if (data.subscriptionId) { 171 + if (data.errorCode) {
  172 + showWsError(data.errorCode, data.errorMsg);
  173 + } else if (data.subscriptionId) {
166 var subscriber = subscribers[data.subscriptionId]; 174 var subscriber = subscribers[data.subscriptionId];
167 if (subscriber && data) { 175 if (subscriber && data) {
168 var keys = fetchKeys(data.subscriptionId); 176 var keys = fetchKeys(data.subscriptionId);
@@ -182,6 +190,18 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, ty @@ -182,6 +190,18 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, ty
182 checkToClose(); 190 checkToClose();
183 } 191 }
184 192
  193 + function showWsError(errorCode, errorMsg) {
  194 + var message = 'WebSocket Error: ';
  195 + if (errorMsg) {
  196 + message += errorMsg;
  197 + } else {
  198 + message += "error code - " + errorCode + ".";
  199 + }
  200 + $mdUtil.nextTick(function () {
  201 + toast.showError(message);
  202 + });
  203 + }
  204 +
185 function fetchKeys(subscriptionId) { 205 function fetchKeys(subscriptionId) {
186 var command = commands[subscriptionId]; 206 var command = commands[subscriptionId];
187 if (command && command.keys && command.keys.length > 0) { 207 if (command && command.keys && command.keys.length > 0) {
@@ -23,7 +23,9 @@ export default angular.module('thingsboard.types', []) @@ -23,7 +23,9 @@ export default angular.module('thingsboard.types', [])
23 permissionDenied: 20, 23 permissionDenied: 20,
24 invalidArguments: 30, 24 invalidArguments: 30,
25 badRequestParams: 31, 25 badRequestParams: 31,
26 - itemNotFound: 32 26 + itemNotFound: 32,
  27 + tooManyRequests: 33,
  28 + tooManyUpdates: 34
27 }, 29 },
28 entryPoints: { 30 entryPoints: {
29 login: "/api/auth/login", 31 login: "/api/auth/login",
@@ -16,18 +16,21 @@ @@ -16,18 +16,21 @@
16 16
17 md-toast.tb-info-toast .md-toast-content { 17 md-toast.tb-info-toast .md-toast-content {
18 height: 100%; 18 height: 100%;
  19 + max-height: 100%;
19 padding: 18px; 20 padding: 18px;
20 font-size: 18px; 21 font-size: 18px;
21 } 22 }
22 23
23 md-toast.tb-success-toast .md-toast-content { 24 md-toast.tb-success-toast .md-toast-content {
24 height: 100%; 25 height: 100%;
  26 + max-height: 100%;
25 font-size: 18px !important; 27 font-size: 18px !important;
26 background-color: #008000; 28 background-color: #008000;
27 } 29 }
28 30
29 md-toast.tb-error-toast .md-toast-content { 31 md-toast.tb-error-toast .md-toast-content {
30 height: 100%; 32 height: 100%;
  33 + max-height: 100%;
31 font-size: 18px !important; 34 font-size: 18px !important;
32 background-color: #800000; 35 background-color: #800000;
33 } 36 }