Browse Source

Code cleaning. JsonIgnore added to getter of TenantProfile

pull/4650/head
AndrewVolosytnykhThingsboard 5 years ago
parent
commit
7c701906f8
  1. 11
      application/src/main/java/org/thingsboard/server/config/RateLimitProcessingFilter.java
  2. 8
      application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java
  3. 4
      application/src/main/java/org/thingsboard/server/service/telemetry/DefaultTelemetryWebSocketService.java
  4. 6
      common/data/src/main/java/org/thingsboard/server/common/data/TenantProfile.java
  5. 4
      dao/src/main/java/org/thingsboard/server/dao/nosql/CassandraBufferedRateExecutor.java

11
application/src/main/java/org/thingsboard/server/config/RateLimitProcessingFilter.java

@ -42,15 +42,6 @@ import java.util.concurrent.ConcurrentMap;
@Component
public class RateLimitProcessingFilter extends GenericFilterBean {
// @Value("${server.rest.limits.tenant.enabled:false}")
// private boolean perTenantLimitsEnabled;
// @Value("${server.rest.limits.tenant.configuration:}")
// private String perTenantLimitsConfiguration;
// @Value("${server.rest.limits.customer.enabled:false}")
// private boolean perCustomerLimitsEnabled;
// @Value("${server.rest.limits.customer.configuration:}")
// private String perCustomerLimitsConfiguration;
@Autowired
private ThingsboardErrorResponseHandler errorResponseHandler;
@ -65,7 +56,7 @@ public class RateLimitProcessingFilter extends GenericFilterBean {
SecurityUser user = getCurrentUser();
if (user != null && !user.isSystemAdmin()) {
var profile= tenantProfileCache.get(user.getTenantId()).getDefaultTenantConfiguration();
var profile= tenantProfileCache.get(user.getTenantId()).getDefaultTenantProfileConfiguration();
if(profile != null) {
if (StringUtils.isNotEmpty(profile.getRateLimitsTenantConfiguration())) {

8
application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java

@ -118,7 +118,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
if (!checkLimits(session, sessionRef)) {
return;
}
var tenantProfileConfiguration = tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantConfiguration();
var tenantProfileConfiguration = tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantProfileConfiguration();
if(tenantProfileConfiguration.getWsLimitQueuePerWsSession() <= 0) {
tenantProfileConfiguration.setWsLimitQueuePerWsSession(500);
}
@ -283,7 +283,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
log.debug("[{}] Processing {}", externalId, msg);
String internalId = externalSessionMap.get(externalId);
var tenantProfileConfiguration = tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantConfiguration();
var tenantProfileConfiguration = tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantProfileConfiguration();
if (internalId != null) {
SessionMetaData sessionMd = internalSessionMap.get(internalId);
@ -346,7 +346,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
private boolean checkLimits(WebSocketSession session, TelemetryWebSocketSessionRef sessionRef) throws Exception {
var tenantProfileConfiguration =
tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantConfiguration();
tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantProfileConfiguration();
if(tenantProfileConfiguration == null) {
return true;
@ -414,7 +414,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
}
private void cleanupLimits(WebSocketSession session, TelemetryWebSocketSessionRef sessionRef) {
var tenantProfileConfiguration = tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantConfiguration();
var tenantProfileConfiguration = tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantProfileConfiguration();
String sessionId = session.getId();
perSessionUpdateLimits.remove(sessionRef.getSessionId());

4
application/src/main/java/org/thingsboard/server/service/telemetry/DefaultTelemetryWebSocketService.java

@ -298,7 +298,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
}
private void processSessionClose(TelemetryWebSocketSessionRef sessionRef) {
var tenantProfileConfiguration = (DefaultTenantProfileConfiguration) tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantConfiguration();
var tenantProfileConfiguration = (DefaultTenantProfileConfiguration) tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantProfileConfiguration();
if(tenantProfileConfiguration != null) {
String sessionId = "[" + sessionRef.getSessionId() + "]";
@ -332,7 +332,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
}
private boolean processSubscription(TelemetryWebSocketSessionRef sessionRef, SubscriptionCmd cmd) {
var tenantProfileConfiguration = (DefaultTenantProfileConfiguration) tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantConfiguration();
var tenantProfileConfiguration = (DefaultTenantProfileConfiguration) tenantProfileCache.get(sessionRef.getSecurityCtx().getTenantId()).getDefaultTenantProfileConfiguration();
String subId = "[" + sessionRef.getSessionId() + "]:[" + cmd.getCmdId() + "]";
try {

6
common/data/src/main/java/org/thingsboard/server/common/data/TenantProfile.java

@ -107,8 +107,10 @@ public class TenantProfile extends SearchTextBased<TenantProfileId> implements H
}
}
public DefaultTenantProfileConfiguration getDefaultTenantConfiguration() {
if(this.profileData != null && this.profileData.getConfiguration().getType().equals(TenantProfileType.DEFAULT)) {
@JsonIgnore
public DefaultTenantProfileConfiguration getDefaultTenantProfileConfiguration() {
if(getProfileData().getConfiguration() != null &&
getProfileData().getConfiguration().getType().equals(TenantProfileType.DEFAULT)) {
return (DefaultTenantProfileConfiguration) this.profileData.getConfiguration();
}
return null;

4
dao/src/main/java/org/thingsboard/server/dao/nosql/CassandraBufferedRateExecutor.java

@ -102,7 +102,7 @@ public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor<
DefaultCounter counter = entry.getValue();
int rateLimitedRequests = counter.get();
counter.clear();
var profile = tenantProfileCache.get(tenantId).getDefaultTenantConfiguration();
var profile = tenantProfileCache.get(tenantId).getDefaultTenantProfileConfiguration();
if (profile != null && profile.isPrintTenantNames()) {
String name = tenantNamesCache.computeIfAbsent(tenantId, tId -> {
try {
@ -145,7 +145,7 @@ public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor<
@Override
protected boolean checkRateLimits(CassandraStatementTask task, SettableFuture<TbResultSet> future) {
var tenantProfileConfiguration = tenantProfileCache.get(task.getTenantId()).getDefaultTenantConfiguration();
var tenantProfileConfiguration = tenantProfileCache.get(task.getTenantId()).getDefaultTenantProfileConfiguration();
if (StringUtils.isNotEmpty(tenantProfileConfiguration.getCassandraTenantLimitsConfiguration())) {
if (task.getTenantId() == null) {
log.info("Invalid task received: {}", task);

Loading…
Cancel
Save