Commit 43178107c3b2753b9850361720e2b9d4620cca01

Authored by Igor Kulikov
2 parents de0b96ad 2bd28cb0

Merge with master

Showing 100 changed files with 1058 additions and 260 deletions

Too many changes to show.

To preserve performance only 100 of 131 files are displayed.

@@ -279,7 +279,7 @@ @@ -279,7 +279,7 @@
279 </dependency> 279 </dependency>
280 <dependency> 280 <dependency>
281 <groupId>org.mockito</groupId> 281 <groupId>org.mockito</groupId>
282 - <artifactId>mockito-all</artifactId> 282 + <artifactId>mockito-core</artifactId>
283 <scope>test</scope> 283 <scope>test</scope>
284 </dependency> 284 </dependency>
285 <dependency> 285 <dependency>
@@ -15,11 +15,10 @@ @@ -15,11 +15,10 @@
15 # 15 #
16 16
17 export JAVA_OPTS="$JAVA_OPTS -Dplatform=@pkg.platform@ -Dinstall.data_dir=@pkg.installFolder@/data" 17 export JAVA_OPTS="$JAVA_OPTS -Dplatform=@pkg.platform@ -Dinstall.data_dir=@pkg.installFolder@/data"
18 -export JAVA_OPTS="$JAVA_OPTS -Xloggc:@pkg.logFolder@/gc.log -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails -XX:+PrintGCDateStamps"  
19 -export JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10"  
20 -export JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=10M -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"  
21 -export JAVA_OPTS="$JAVA_OPTS -XX:CMSWaitDuration=10000 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+CMSParallelInitialMarkEnabled"  
22 -export JAVA_OPTS="$JAVA_OPTS -XX:+CMSEdenChunksRecordAlways -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly" 18 +export JAVA_OPTS="$JAVA_OPTS -Xlog:gc*,heap*,age*,safepoint=debug:file=@pkg.logFolder@/gc.log:time,uptime,level,tags:filecount=10,filesize=10M"
  19 +export JAVA_OPTS="$JAVA_OPTS -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError"
  20 +export JAVA_OPTS="$JAVA_OPTS -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"
  21 +export JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC -XX:MaxGCPauseMillis=500 -XX:+UseStringDeduplication -XX:+ParallelRefProcEnabled -XX:MaxTenuringThreshold=10"
23 export LOG_FILENAME=${pkg.name}.out 22 export LOG_FILENAME=${pkg.name}.out
24 export LOADER_PATH=${pkg.installFolder}/conf,${pkg.installFolder}/extensions 23 export LOADER_PATH=${pkg.installFolder}/conf,${pkg.installFolder}/extensions
25 export SQL_DATA_FOLDER=${pkg.installFolder}/data/sql 24 export SQL_DATA_FOLDER=${pkg.installFolder}/data/sql
@@ -476,11 +476,6 @@ class DefaultTbContext implements TbContext { @@ -476,11 +476,6 @@ class DefaultTbContext implements TbContext {
476 } 476 }
477 477
478 @Override 478 @Override
479 - public RedisTemplate<String, Object> getRedisTemplate() {  
480 - return mainCtx.getRedisTemplate();  
481 - }  
482 -  
483 - @Override  
484 public PageData<RuleNodeState> findRuleNodeStates(PageLink pageLink) { 479 public PageData<RuleNodeState> findRuleNodeStates(PageLink pageLink) {
485 if (log.isDebugEnabled()) { 480 if (log.isDebugEnabled()) {
486 log.debug("[{}][{}] Fetch Rule Node States.", getTenantId(), getSelfId()); 481 log.debug("[{}][{}] Fetch Rule Node States.", getTenantId(), getSelfId());
@@ -147,7 +147,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod @@ -147,7 +147,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod
147 TbNode tbNode = null; 147 TbNode tbNode = null;
148 if (ruleNode != null) { 148 if (ruleNode != null) {
149 Class<?> componentClazz = Class.forName(ruleNode.getType()); 149 Class<?> componentClazz = Class.forName(ruleNode.getType());
150 - tbNode = (TbNode) (componentClazz.newInstance()); 150 + tbNode = (TbNode) (componentClazz.getDeclaredConstructor().newInstance());
151 tbNode.init(defaultCtx, new TbNodeConfiguration(ruleNode.getConfiguration())); 151 tbNode.init(defaultCtx, new TbNodeConfiguration(ruleNode.getConfiguration()));
152 } 152 }
153 return tbNode; 153 return tbNode;
@@ -91,6 +91,7 @@ public class CustomOAuth2AuthorizationRequestResolver implements OAuth2Authoriza @@ -91,6 +91,7 @@ public class CustomOAuth2AuthorizationRequestResolver implements OAuth2Authoriza
91 return action; 91 return action;
92 } 92 }
93 93
  94 + @SuppressWarnings("deprecation")
94 private OAuth2AuthorizationRequest resolve(HttpServletRequest request, String registrationId, String redirectUriAction) { 95 private OAuth2AuthorizationRequest resolve(HttpServletRequest request, String registrationId, String redirectUriAction) {
95 if (registrationId == null) { 96 if (registrationId == null) {
96 return null; 97 return null;
@@ -127,7 +127,7 @@ public class ThingsboardSecurityConfiguration extends WebSecurityConfigurerAdapt @@ -127,7 +127,7 @@ public class ThingsboardSecurityConfiguration extends WebSecurityConfigurerAdapt
127 } 127 }
128 128
129 protected JwtTokenAuthenticationProcessingFilter buildJwtTokenAuthenticationProcessingFilter() throws Exception { 129 protected JwtTokenAuthenticationProcessingFilter buildJwtTokenAuthenticationProcessingFilter() throws Exception {
130 - List<String> pathsToSkip = new ArrayList(Arrays.asList(NON_TOKEN_BASED_AUTH_ENTRY_POINTS)); 130 + List<String> pathsToSkip = new ArrayList<>(Arrays.asList(NON_TOKEN_BASED_AUTH_ENTRY_POINTS));
131 pathsToSkip.addAll(Arrays.asList(WS_TOKEN_BASED_AUTH_ENTRY_POINT, TOKEN_REFRESH_ENTRY_POINT, FORM_BASED_LOGIN_ENTRY_POINT, 131 pathsToSkip.addAll(Arrays.asList(WS_TOKEN_BASED_AUTH_ENTRY_POINT, TOKEN_REFRESH_ENTRY_POINT, FORM_BASED_LOGIN_ENTRY_POINT,
132 PUBLIC_LOGIN_ENTRY_POINT, DEVICE_API_ENTRY_POINT, WEBJARS_ENTRY_POINT)); 132 PUBLIC_LOGIN_ENTRY_POINT, DEVICE_API_ENTRY_POINT, WEBJARS_ENTRY_POINT));
133 SkipPathRequestMatcher matcher = new SkipPathRequestMatcher(pathsToSkip, TOKEN_BASED_AUTH_ENTRY_POINT); 133 SkipPathRequestMatcher matcher = new SkipPathRequestMatcher(pathsToSkip, TOKEN_BASED_AUTH_ENTRY_POINT);
@@ -649,6 +649,7 @@ public abstract class BaseController { @@ -649,6 +649,7 @@ public abstract class BaseController {
649 return ruleNode; 649 return ruleNode;
650 } 650 }
651 651
  652 + @SuppressWarnings("unchecked")
652 protected <I extends EntityId> I emptyId(EntityType entityType) { 653 protected <I extends EntityId> I emptyId(EntityType entityType) {
653 return (I) EntityIdFactory.getByTypeAndUuid(entityType, ModelConstants.NULL_UUID); 654 return (I) EntityIdFactory.getByTypeAndUuid(entityType, ModelConstants.NULL_UUID);
654 } 655 }
@@ -763,6 +764,7 @@ public abstract class BaseController { @@ -763,6 +764,7 @@ public abstract class BaseController {
763 entityNode = json.createObjectNode(); 764 entityNode = json.createObjectNode();
764 if (actionType == ActionType.ATTRIBUTES_UPDATED) { 765 if (actionType == ActionType.ATTRIBUTES_UPDATED) {
765 String scope = extractParameter(String.class, 0, additionalInfo); 766 String scope = extractParameter(String.class, 0, additionalInfo);
  767 + @SuppressWarnings("unchecked")
766 List<AttributeKvEntry> attributes = extractParameter(List.class, 1, additionalInfo); 768 List<AttributeKvEntry> attributes = extractParameter(List.class, 1, additionalInfo);
767 metaData.putValue("scope", scope); 769 metaData.putValue("scope", scope);
768 if (attributes != null) { 770 if (attributes != null) {
@@ -772,6 +774,7 @@ public abstract class BaseController { @@ -772,6 +774,7 @@ public abstract class BaseController {
772 } 774 }
773 } else if (actionType == ActionType.ATTRIBUTES_DELETED) { 775 } else if (actionType == ActionType.ATTRIBUTES_DELETED) {
774 String scope = extractParameter(String.class, 0, additionalInfo); 776 String scope = extractParameter(String.class, 0, additionalInfo);
  777 + @SuppressWarnings("unchecked")
775 List<String> keys = extractParameter(List.class, 1, additionalInfo); 778 List<String> keys = extractParameter(List.class, 1, additionalInfo);
776 metaData.putValue("scope", scope); 779 metaData.putValue("scope", scope);
777 ArrayNode attrsArrayNode = entityNode.putArray("attributes"); 780 ArrayNode attrsArrayNode = entityNode.putArray("attributes");
@@ -779,9 +782,11 @@ public abstract class BaseController { @@ -779,9 +782,11 @@ public abstract class BaseController {
779 keys.forEach(attrsArrayNode::add); 782 keys.forEach(attrsArrayNode::add);
780 } 783 }
781 } else if (actionType == ActionType.TIMESERIES_UPDATED) { 784 } else if (actionType == ActionType.TIMESERIES_UPDATED) {
  785 + @SuppressWarnings("unchecked")
782 List<TsKvEntry> timeseries = extractParameter(List.class, 0, additionalInfo); 786 List<TsKvEntry> timeseries = extractParameter(List.class, 0, additionalInfo);
783 addTimeseries(entityNode, timeseries); 787 addTimeseries(entityNode, timeseries);
784 } else if (actionType == ActionType.TIMESERIES_DELETED) { 788 } else if (actionType == ActionType.TIMESERIES_DELETED) {
  789 + @SuppressWarnings("unchecked")
785 List<String> keys = extractParameter(List.class, 0, additionalInfo); 790 List<String> keys = extractParameter(List.class, 0, additionalInfo);
786 if (keys != null) { 791 if (keys != null) {
787 ArrayNode timeseriesArrayNode = entityNode.putArray("timeseries"); 792 ArrayNode timeseriesArrayNode = entityNode.putArray("timeseries");
@@ -63,7 +63,7 @@ import java.util.List; @@ -63,7 +63,7 @@ import java.util.List;
63 import java.util.concurrent.ExecutionException; 63 import java.util.concurrent.ExecutionException;
64 import java.util.stream.Collectors; 64 import java.util.stream.Collectors;
65 65
66 -import static org.apache.commons.lang.StringUtils.isBlank; 66 +import static org.apache.commons.lang3.StringUtils.isBlank;
67 import static org.thingsboard.server.controller.CustomerController.CUSTOMER_ID; 67 import static org.thingsboard.server.controller.CustomerController.CUSTOMER_ID;
68 68
69 /** 69 /**
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Value; @@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Value;
24 import org.springframework.beans.factory.config.BeanDefinition; 24 import org.springframework.beans.factory.config.BeanDefinition;
25 import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; 25 import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
26 import org.springframework.core.env.Environment; 26 import org.springframework.core.env.Environment;
  27 +import org.springframework.core.env.Profiles;
27 import org.springframework.core.type.filter.AnnotationTypeFilter; 28 import org.springframework.core.type.filter.AnnotationTypeFilter;
28 import org.springframework.stereotype.Service; 29 import org.springframework.stereotype.Service;
29 import org.thingsboard.rule.engine.api.NodeConfiguration; 30 import org.thingsboard.rule.engine.api.NodeConfiguration;
@@ -69,7 +70,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe @@ -69,7 +70,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe
69 private ObjectMapper mapper = new ObjectMapper(); 70 private ObjectMapper mapper = new ObjectMapper();
70 71
71 private boolean isInstall() { 72 private boolean isInstall() {
72 - return environment.acceptsProfiles("install"); 73 + return environment.acceptsProfiles(Profiles.of("install"));
73 } 74 }
74 75
75 @PostConstruct 76 @PostConstruct
@@ -185,7 +186,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe @@ -185,7 +186,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe
185 nodeDefinition.setRelationTypes(getRelationTypesWithFailureRelation(nodeAnnotation)); 186 nodeDefinition.setRelationTypes(getRelationTypesWithFailureRelation(nodeAnnotation));
186 nodeDefinition.setCustomRelations(nodeAnnotation.customRelations()); 187 nodeDefinition.setCustomRelations(nodeAnnotation.customRelations());
187 Class<? extends NodeConfiguration> configClazz = nodeAnnotation.configClazz(); 188 Class<? extends NodeConfiguration> configClazz = nodeAnnotation.configClazz();
188 - NodeConfiguration config = configClazz.newInstance(); 189 + NodeConfiguration config = configClazz.getDeclaredConstructor().newInstance();
189 NodeConfiguration defaultConfiguration = config.defaultConfiguration(); 190 NodeConfiguration defaultConfiguration = config.defaultConfiguration();
190 nodeDefinition.setDefaultConfiguration(mapper.valueToTree(defaultConfiguration)); 191 nodeDefinition.setDefaultConfiguration(mapper.valueToTree(defaultConfiguration));
191 nodeDefinition.setUiResources(nodeAnnotation.uiResources()); 192 nodeDefinition.setUiResources(nodeAnnotation.uiResources());
@@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.JsonNode; @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.JsonNode;
20 import com.fasterxml.jackson.databind.node.ObjectNode; 20 import com.fasterxml.jackson.databind.node.ObjectNode;
21 import com.google.common.util.concurrent.ListenableFuture; 21 import com.google.common.util.concurrent.ListenableFuture;
22 import lombok.extern.slf4j.Slf4j; 22 import lombok.extern.slf4j.Slf4j;
23 -import org.apache.commons.lang.RandomStringUtils; 23 +import org.apache.commons.lang3.RandomStringUtils;
24 import org.springframework.beans.factory.annotation.Autowired; 24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Service; 25 import org.springframework.stereotype.Service;
26 import org.springframework.util.StringUtils; 26 import org.springframework.util.StringUtils;
@@ -146,17 +146,17 @@ public class CassandraDbHelper { @@ -146,17 +146,17 @@ public class CassandraDbHelper {
146 if (row.isNull(index)) { 146 if (row.isNull(index)) {
147 return null; 147 return null;
148 } else if (type.getProtocolCode() == ProtocolConstants.DataType.DOUBLE) { 148 } else if (type.getProtocolCode() == ProtocolConstants.DataType.DOUBLE) {
149 - str = new Double(row.getDouble(index)).toString(); 149 + str = Double.valueOf(row.getDouble(index)).toString();
150 } else if (type.getProtocolCode() == ProtocolConstants.DataType.INT) { 150 } else if (type.getProtocolCode() == ProtocolConstants.DataType.INT) {
151 - str = new Integer(row.getInt(index)).toString(); 151 + str = Integer.valueOf(row.getInt(index)).toString();
152 } else if (type.getProtocolCode() == ProtocolConstants.DataType.BIGINT) { 152 } else if (type.getProtocolCode() == ProtocolConstants.DataType.BIGINT) {
153 - str = new Long(row.getLong(index)).toString(); 153 + str = Long.valueOf(row.getLong(index)).toString();
154 } else if (type.getProtocolCode() == ProtocolConstants.DataType.UUID) { 154 } else if (type.getProtocolCode() == ProtocolConstants.DataType.UUID) {
155 str = row.getUuid(index).toString(); 155 str = row.getUuid(index).toString();
156 } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMEUUID) { 156 } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMEUUID) {
157 str = row.getUuid(index).toString(); 157 str = row.getUuid(index).toString();
158 } else if (type.getProtocolCode() == ProtocolConstants.DataType.FLOAT) { 158 } else if (type.getProtocolCode() == ProtocolConstants.DataType.FLOAT) {
159 - str = new Float(row.getFloat(index)).toString(); 159 + str = Float.valueOf(row.getFloat(index)).toString();
160 } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMESTAMP) { 160 } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMESTAMP) {
161 str = ""+row.getInstant(index).toEpochMilli(); 161 str = ""+row.getInstant(index).toEpochMilli();
162 } else { 162 } else {
@@ -153,7 +153,8 @@ public class CassandraToSqlColumn { @@ -153,7 +153,8 @@ public class CassandraToSqlColumn {
153 sqlInsertStatement.setBoolean(this.sqlIndex, Boolean.parseBoolean(value)); 153 sqlInsertStatement.setBoolean(this.sqlIndex, Boolean.parseBoolean(value));
154 break; 154 break;
155 case ENUM_TO_INT: 155 case ENUM_TO_INT:
156 - Enum enumVal = Enum.valueOf(this.enumClass, value); 156 + @SuppressWarnings("unchecked")
  157 + Enum<?> enumVal = Enum.valueOf(this.enumClass, value);
157 int intValue = enumVal.ordinal(); 158 int intValue = enumVal.ordinal();
158 sqlInsertStatement.setInt(this.sqlIndex, intValue); 159 sqlInsertStatement.setInt(this.sqlIndex, intValue);
159 break; 160 break;
@@ -57,7 +57,7 @@ import java.util.List; @@ -57,7 +57,7 @@ import java.util.List;
57 import java.util.concurrent.ExecutionException; 57 import java.util.concurrent.ExecutionException;
58 import java.util.stream.Collectors; 58 import java.util.stream.Collectors;
59 59
60 -import static org.apache.commons.lang.StringUtils.isBlank; 60 +import static org.apache.commons.lang3.StringUtils.isBlank;
61 import static org.thingsboard.server.service.install.DatabaseHelper.objectMapper; 61 import static org.thingsboard.server.service.install.DatabaseHelper.objectMapper;
62 62
63 @Service 63 @Service
@@ -206,7 +206,7 @@ public class DefaultEntityQueryService implements EntityQueryService { @@ -206,7 +206,7 @@ public class DefaultEntityQueryService implements EntityQueryService {
206 addItemsToArrayNode(json.putArray("entityTypes"), types); 206 addItemsToArrayNode(json.putArray("entityTypes"), types);
207 addItemsToArrayNode(json.putArray("timeseries"), timeseriesKeys); 207 addItemsToArrayNode(json.putArray("timeseries"), timeseriesKeys);
208 addItemsToArrayNode(json.putArray("attribute"), attributesKeys); 208 addItemsToArrayNode(json.putArray("attribute"), attributesKeys);
209 - response.setResult(new ResponseEntity(json, HttpStatus.OK)); 209 + response.setResult(new ResponseEntity<>(json, HttpStatus.OK));
210 } 210 }
211 211
212 private void replyWithEmptyResponse(DeferredResult<ResponseEntity> response) { 212 private void replyWithEmptyResponse(DeferredResult<ResponseEntity> response) {
@@ -21,7 +21,6 @@ import com.google.common.util.concurrent.ListenableFuture; @@ -21,7 +21,6 @@ import com.google.common.util.concurrent.ListenableFuture;
21 import com.google.common.util.concurrent.MoreExecutors; 21 import com.google.common.util.concurrent.MoreExecutors;
22 import delight.nashornsandbox.NashornSandbox; 22 import delight.nashornsandbox.NashornSandbox;
23 import delight.nashornsandbox.NashornSandboxes; 23 import delight.nashornsandbox.NashornSandboxes;
24 -import jdk.nashorn.api.scripting.NashornScriptEngineFactory;  
25 import lombok.Getter; 24 import lombok.Getter;
26 import lombok.extern.slf4j.Slf4j; 25 import lombok.extern.slf4j.Slf4j;
27 import org.springframework.beans.factory.annotation.Value; 26 import org.springframework.beans.factory.annotation.Value;
@@ -33,6 +32,7 @@ import javax.annotation.PostConstruct; @@ -33,6 +32,7 @@ import javax.annotation.PostConstruct;
33 import javax.annotation.PreDestroy; 32 import javax.annotation.PreDestroy;
34 import javax.script.Invocable; 33 import javax.script.Invocable;
35 import javax.script.ScriptEngine; 34 import javax.script.ScriptEngine;
  35 +import javax.script.ScriptEngineManager;
36 import javax.script.ScriptException; 36 import javax.script.ScriptException;
37 import java.util.UUID; 37 import java.util.UUID;
38 import java.util.concurrent.ExecutionException; 38 import java.util.concurrent.ExecutionException;
@@ -97,8 +97,8 @@ public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeSer @@ -97,8 +97,8 @@ public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeSer
97 sandbox.allowLoadFunctions(true); 97 sandbox.allowLoadFunctions(true);
98 sandbox.setMaxPreparedStatements(30); 98 sandbox.setMaxPreparedStatements(30);
99 } else { 99 } else {
100 - NashornScriptEngineFactory factory = new NashornScriptEngineFactory();  
101 - engine = factory.getScriptEngine(new String[]{"--no-java"}); 100 + ScriptEngineManager factory = new ScriptEngineManager();
  101 + engine = factory.getEngineByName("nashorn");
102 } 102 }
103 } 103 }
104 104
@@ -29,7 +29,7 @@ public class SkipPathRequestMatcher implements RequestMatcher { @@ -29,7 +29,7 @@ public class SkipPathRequestMatcher implements RequestMatcher {
29 private RequestMatcher processingMatcher; 29 private RequestMatcher processingMatcher;
30 30
31 public SkipPathRequestMatcher(List<String> pathsToSkip, String processingPath) { 31 public SkipPathRequestMatcher(List<String> pathsToSkip, String processingPath) {
32 - Assert.notNull(pathsToSkip); 32 + Assert.notNull(pathsToSkip, "List of paths to skip is required.");
33 List<RequestMatcher> m = pathsToSkip.stream().map(path -> new AntPathRequestMatcher(path)).collect(Collectors.toList()); 33 List<RequestMatcher> m = pathsToSkip.stream().map(path -> new AntPathRequestMatcher(path)).collect(Collectors.toList());
34 matchers = new OrRequestMatcher(m); 34 matchers = new OrRequestMatcher(m);
35 processingMatcher = new AntPathRequestMatcher(processingPath); 35 processingMatcher = new AntPathRequestMatcher(processingPath);
@@ -100,6 +100,7 @@ public class JwtTokenFactory { @@ -100,6 +100,7 @@ public class JwtTokenFactory {
100 Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey()); 100 Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey());
101 Claims claims = jwsClaims.getBody(); 101 Claims claims = jwsClaims.getBody();
102 String subject = claims.getSubject(); 102 String subject = claims.getSubject();
  103 + @SuppressWarnings("unchecked")
103 List<String> scopes = claims.get(SCOPES, List.class); 104 List<String> scopes = claims.get(SCOPES, List.class);
104 if (scopes == null || scopes.isEmpty()) { 105 if (scopes == null || scopes.isEmpty()) {
105 throw new IllegalArgumentException("JWT Token doesn't have any scopes"); 106 throw new IllegalArgumentException("JWT Token doesn't have any scopes");
@@ -155,6 +156,7 @@ public class JwtTokenFactory { @@ -155,6 +156,7 @@ public class JwtTokenFactory {
155 Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey()); 156 Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey());
156 Claims claims = jwsClaims.getBody(); 157 Claims claims = jwsClaims.getBody();
157 String subject = claims.getSubject(); 158 String subject = claims.getSubject();
  159 + @SuppressWarnings("unchecked")
158 List<String> scopes = claims.get(SCOPES, List.class); 160 List<String> scopes = claims.get(SCOPES, List.class);
159 if (scopes == null || scopes.isEmpty()) { 161 if (scopes == null || scopes.isEmpty()) {
160 throw new IllegalArgumentException("Refresh Token doesn't have any scopes"); 162 throw new IllegalArgumentException("Refresh Token doesn't have any scopes");
@@ -47,6 +47,7 @@ public class CustomerUserPermissions extends AbstractPermissions { @@ -47,6 +47,7 @@ public class CustomerUserPermissions extends AbstractPermissions {
47 Operation.READ_ATTRIBUTES, Operation.READ_TELEMETRY, Operation.RPC_CALL, Operation.CLAIM_DEVICES) { 47 Operation.READ_ATTRIBUTES, Operation.READ_TELEMETRY, Operation.RPC_CALL, Operation.CLAIM_DEVICES) {
48 48
49 @Override 49 @Override
  50 + @SuppressWarnings("unchecked")
50 public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) { 51 public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) {
51 52
52 if (!super.hasPermission(user, operation, entityId, entity)) { 53 if (!super.hasPermission(user, operation, entityId, entity)) {
@@ -69,6 +70,7 @@ public class CustomerUserPermissions extends AbstractPermissions { @@ -69,6 +70,7 @@ public class CustomerUserPermissions extends AbstractPermissions {
69 new PermissionChecker.GenericPermissionChecker(Operation.READ, Operation.READ_ATTRIBUTES, Operation.READ_TELEMETRY) { 70 new PermissionChecker.GenericPermissionChecker(Operation.READ, Operation.READ_ATTRIBUTES, Operation.READ_TELEMETRY) {
70 71
71 @Override 72 @Override
  73 + @SuppressWarnings("unchecked")
72 public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) { 74 public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) {
73 if (!super.hasPermission(user, operation, entityId, entity)) { 75 if (!super.hasPermission(user, operation, entityId, entity)) {
74 return false; 76 return false;
@@ -119,6 +121,7 @@ public class CustomerUserPermissions extends AbstractPermissions { @@ -119,6 +121,7 @@ public class CustomerUserPermissions extends AbstractPermissions {
119 private static final PermissionChecker widgetsPermissionChecker = new PermissionChecker.GenericPermissionChecker(Operation.READ) { 121 private static final PermissionChecker widgetsPermissionChecker = new PermissionChecker.GenericPermissionChecker(Operation.READ) {
120 122
121 @Override 123 @Override
  124 + @SuppressWarnings("unchecked")
122 public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) { 125 public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) {
123 if (!super.hasPermission(user, operation, entityId, entity)) { 126 if (!super.hasPermission(user, operation, entityId, entity)) {
124 return false; 127 return false;
@@ -56,6 +56,7 @@ public class DefaultAccessControlService implements AccessControlService { @@ -56,6 +56,7 @@ public class DefaultAccessControlService implements AccessControlService {
56 } 56 }
57 57
58 @Override 58 @Override
  59 + @SuppressWarnings("unchecked")
59 public <I extends EntityId, T extends HasTenantId> void checkPermission(SecurityUser user, Resource resource, 60 public <I extends EntityId, T extends HasTenantId> void checkPermission(SecurityUser user, Resource resource,
60 Operation operation, I entityId, T entity) throws ThingsboardException { 61 Operation operation, I entityId, T entity) throws ThingsboardException {
61 PermissionChecker permissionChecker = getPermissionChecker(user.getAuthority(), resource); 62 PermissionChecker permissionChecker = getPermissionChecker(user.getAuthority(), resource);
@@ -59,6 +59,7 @@ public class TenantAdminPermissions extends AbstractPermissions { @@ -59,6 +59,7 @@ public class TenantAdminPermissions extends AbstractPermissions {
59 new PermissionChecker.GenericPermissionChecker(Operation.READ, Operation.READ_ATTRIBUTES, Operation.READ_TELEMETRY) { 59 new PermissionChecker.GenericPermissionChecker(Operation.READ, Operation.READ_ATTRIBUTES, Operation.READ_TELEMETRY) {
60 60
61 @Override 61 @Override
  62 + @SuppressWarnings("unchecked")
62 public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) { 63 public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) {
63 if (!super.hasPermission(user, operation, entityId, entity)) { 64 if (!super.hasPermission(user, operation, entityId, entity)) {
64 return false; 65 return false;
@@ -15,8 +15,8 @@ @@ -15,8 +15,8 @@
15 */ 15 */
16 package org.thingsboard.server.service.security.system; 16 package org.thingsboard.server.service.security.system;
17 17
  18 +import com.fasterxml.jackson.core.type.TypeReference;
18 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
19 -import com.fasterxml.jackson.databind.ObjectMapper;  
20 import com.fasterxml.jackson.databind.node.ObjectNode; 20 import com.fasterxml.jackson.databind.node.ObjectNode;
21 import lombok.extern.slf4j.Slf4j; 21 import lombok.extern.slf4j.Slf4j;
22 import org.apache.commons.lang3.StringUtils; 22 import org.apache.commons.lang3.StringUtils;
@@ -49,6 +49,7 @@ import org.thingsboard.server.dao.exception.DataValidationException; @@ -49,6 +49,7 @@ import org.thingsboard.server.dao.exception.DataValidationException;
49 import org.thingsboard.server.dao.settings.AdminSettingsService; 49 import org.thingsboard.server.dao.settings.AdminSettingsService;
50 import org.thingsboard.server.dao.user.UserService; 50 import org.thingsboard.server.dao.user.UserService;
51 import org.thingsboard.server.dao.user.UserServiceImpl; 51 import org.thingsboard.server.dao.user.UserServiceImpl;
  52 +import org.thingsboard.server.dao.util.mapping.JacksonUtil;
52 import org.thingsboard.server.service.security.exception.UserPasswordExpiredException; 53 import org.thingsboard.server.service.security.exception.UserPasswordExpiredException;
53 import org.thingsboard.server.utils.MiscUtils; 54 import org.thingsboard.server.utils.MiscUtils;
54 55
@@ -65,8 +66,6 @@ import static org.thingsboard.server.common.data.CacheConstants.SECURITY_SETTING @@ -65,8 +66,6 @@ import static org.thingsboard.server.common.data.CacheConstants.SECURITY_SETTING
65 @Slf4j 66 @Slf4j
66 public class DefaultSystemSecurityService implements SystemSecurityService { 67 public class DefaultSystemSecurityService implements SystemSecurityService {
67 68
68 - private static final ObjectMapper objectMapper = new ObjectMapper();  
69 -  
70 @Autowired 69 @Autowired
71 private AdminSettingsService adminSettingsService; 70 private AdminSettingsService adminSettingsService;
72 71
@@ -89,7 +88,7 @@ public class DefaultSystemSecurityService implements SystemSecurityService { @@ -89,7 +88,7 @@ public class DefaultSystemSecurityService implements SystemSecurityService {
89 AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(tenantId, "securitySettings"); 88 AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(tenantId, "securitySettings");
90 if (adminSettings != null) { 89 if (adminSettings != null) {
91 try { 90 try {
92 - securitySettings = objectMapper.treeToValue(adminSettings.getJsonValue(), SecuritySettings.class); 91 + securitySettings = JacksonUtil.convertValue(adminSettings.getJsonValue(), SecuritySettings.class);
93 } catch (Exception e) { 92 } catch (Exception e) {
94 throw new RuntimeException("Failed to load security settings!", e); 93 throw new RuntimeException("Failed to load security settings!", e);
95 } 94 }
@@ -109,10 +108,10 @@ public class DefaultSystemSecurityService implements SystemSecurityService { @@ -109,10 +108,10 @@ public class DefaultSystemSecurityService implements SystemSecurityService {
109 adminSettings = new AdminSettings(); 108 adminSettings = new AdminSettings();
110 adminSettings.setKey("securitySettings"); 109 adminSettings.setKey("securitySettings");
111 } 110 }
112 - adminSettings.setJsonValue(objectMapper.valueToTree(securitySettings)); 111 + adminSettings.setJsonValue(JacksonUtil.valueToTree(securitySettings));
113 AdminSettings savedAdminSettings = adminSettingsService.saveAdminSettings(tenantId, adminSettings); 112 AdminSettings savedAdminSettings = adminSettingsService.saveAdminSettings(tenantId, adminSettings);
114 try { 113 try {
115 - return objectMapper.treeToValue(savedAdminSettings.getJsonValue(), SecuritySettings.class); 114 + return JacksonUtil.convertValue(savedAdminSettings.getJsonValue(), SecuritySettings.class);
116 } catch (Exception e) { 115 } catch (Exception e) {
117 throw new RuntimeException("Failed to load security settings!", e); 116 throw new RuntimeException("Failed to load security settings!", e);
118 } 117 }
@@ -189,7 +188,7 @@ public class DefaultSystemSecurityService implements SystemSecurityService { @@ -189,7 +188,7 @@ public class DefaultSystemSecurityService implements SystemSecurityService {
189 JsonNode additionalInfo = user.getAdditionalInfo(); 188 JsonNode additionalInfo = user.getAdditionalInfo();
190 if (additionalInfo instanceof ObjectNode && additionalInfo.has(UserServiceImpl.USER_PASSWORD_HISTORY)) { 189 if (additionalInfo instanceof ObjectNode && additionalInfo.has(UserServiceImpl.USER_PASSWORD_HISTORY)) {
191 JsonNode userPasswordHistoryJson = additionalInfo.get(UserServiceImpl.USER_PASSWORD_HISTORY); 190 JsonNode userPasswordHistoryJson = additionalInfo.get(UserServiceImpl.USER_PASSWORD_HISTORY);
192 - Map<String, String> userPasswordHistoryMap = objectMapper.convertValue(userPasswordHistoryJson, Map.class); 191 + Map<String, String> userPasswordHistoryMap = JacksonUtil.convertValue(userPasswordHistoryJson, new TypeReference<>() {});
193 for (Map.Entry<String, String> entry : userPasswordHistoryMap.entrySet()) { 192 for (Map.Entry<String, String> entry : userPasswordHistoryMap.entrySet()) {
194 if (encoder.matches(password, entry.getValue()) && Long.parseLong(entry.getKey()) > passwordReuseFrequencyTs) { 193 if (encoder.matches(password, entry.getValue()) && Long.parseLong(entry.getKey()) > passwordReuseFrequencyTs) {
195 throw new DataValidationException("Password was already used for the last " + passwordPolicy.getPasswordReuseFrequencyDays() + " days"); 194 throw new DataValidationException("Password was already used for the last " + passwordPolicy.getPasswordReuseFrequencyDays() + " days");
@@ -318,6 +318,7 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc @@ -318,6 +318,7 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc
318 return ctx; 318 return ctx;
319 } 319 }
320 320
  321 + @SuppressWarnings("unchecked")
321 private <T extends TbAbstractDataSubCtx> T getSubCtx(String sessionId, int cmdId) { 322 private <T extends TbAbstractDataSubCtx> T getSubCtx(String sessionId, int cmdId) {
322 Map<Integer, TbAbstractDataSubCtx> sessionSubs = subscriptionsBySessionId.get(sessionId); 323 Map<Integer, TbAbstractDataSubCtx> sessionSubs = subscriptionsBySessionId.get(sessionId);
323 if (sessionSubs != null) { 324 if (sessionSubs != null) {
@@ -123,6 +123,7 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer @@ -123,6 +123,7 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer
123 } 123 }
124 124
125 @Override 125 @Override
  126 + @SuppressWarnings("unchecked")
126 public void onSubscriptionUpdate(String sessionId, TelemetrySubscriptionUpdate update, TbCallback callback) { 127 public void onSubscriptionUpdate(String sessionId, TelemetrySubscriptionUpdate update, TbCallback callback) {
127 TbSubscription subscription = subscriptionsBySessionId 128 TbSubscription subscription = subscriptionsBySessionId
128 .getOrDefault(sessionId, Collections.emptyMap()).get(update.getSubscriptionId()); 129 .getOrDefault(sessionId, Collections.emptyMap()).get(update.getSubscriptionId());
@@ -143,6 +144,7 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer @@ -143,6 +144,7 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer
143 } 144 }
144 145
145 @Override 146 @Override
  147 + @SuppressWarnings("unchecked")
146 public void onSubscriptionUpdate(String sessionId, AlarmSubscriptionUpdate update, TbCallback callback) { 148 public void onSubscriptionUpdate(String sessionId, AlarmSubscriptionUpdate update, TbCallback callback) {
147 TbSubscription subscription = subscriptionsBySessionId 149 TbSubscription subscription = subscriptionsBySessionId
148 .getOrDefault(sessionId, Collections.emptyMap()).get(update.getSubscriptionId()); 150 .getOrDefault(sessionId, Collections.emptyMap()).get(update.getSubscriptionId());
@@ -264,6 +264,7 @@ public abstract class TbAbstractDataSubCtx<T extends AbstractDataQuery<? extends @@ -264,6 +264,7 @@ public abstract class TbAbstractDataSubCtx<T extends AbstractDataQuery<? extends
264 }, MoreExecutors.directExecutor()); 264 }, MoreExecutors.directExecutor());
265 } 265 }
266 266
  267 + @SuppressWarnings("unchecked")
267 private void updateDynamicValuesByKey(DynamicValueKeySub sub, TsValue tsValue) { 268 private void updateDynamicValuesByKey(DynamicValueKeySub sub, TsValue tsValue) {
268 DynamicValueKey dvk = sub.getKey(); 269 DynamicValueKey dvk = sub.getKey();
269 switch (dvk.getPredicateType()) { 270 switch (dvk.getPredicateType()) {
@@ -285,6 +286,7 @@ public abstract class TbAbstractDataSubCtx<T extends AbstractDataQuery<? extends @@ -285,6 +286,7 @@ public abstract class TbAbstractDataSubCtx<T extends AbstractDataQuery<? extends
285 } 286 }
286 } 287 }
287 288
  289 + @SuppressWarnings("unchecked")
288 private void registerDynamicValues(KeyFilterPredicate predicate) { 290 private void registerDynamicValues(KeyFilterPredicate predicate) {
289 switch (predicate.getType()) { 291 switch (predicate.getType()) {
290 case STRING: 292 case STRING:
@@ -33,6 +33,7 @@ public class MiscUtils { @@ -33,6 +33,7 @@ public class MiscUtils {
33 return "The " + propertyName + " property need to be set!"; 33 return "The " + propertyName + " property need to be set!";
34 } 34 }
35 35
  36 + @SuppressWarnings("deprecation")
36 public static HashFunction forName(String name) { 37 public static HashFunction forName(String name) {
37 switch (name) { 38 switch (name) {
38 case "murmur3_32": 39 case "murmur3_32":
@@ -375,6 +375,10 @@ public abstract class AbstractWebTest { @@ -375,6 +375,10 @@ public abstract class AbstractWebTest {
375 return readResponse(doGetAsync(urlTemplate, urlVariables).andExpect(status().isOk()), responseClass); 375 return readResponse(doGetAsync(urlTemplate, urlVariables).andExpect(status().isOk()), responseClass);
376 } 376 }
377 377
  378 + protected <T> T doGetAsyncTyped(String urlTemplate, TypeReference<T> responseType, Object... urlVariables) throws Exception {
  379 + return readResponse(doGetAsync(urlTemplate, urlVariables).andExpect(status().isOk()), responseType);
  380 + }
  381 +
378 protected ResultActions doGetAsync(String urlTemplate, Object... urlVariables) throws Exception { 382 protected ResultActions doGetAsync(String urlTemplate, Object... urlVariables) throws Exception {
379 MockHttpServletRequestBuilder getRequest; 383 MockHttpServletRequestBuilder getRequest;
380 getRequest = get(urlTemplate, urlVariables); 384 getRequest = get(urlTemplate, urlVariables);
@@ -347,8 +347,8 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes @@ -347,8 +347,8 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
347 347
348 Thread.sleep(1000); 348 Thread.sleep(1000);
349 349
350 - List<Map<String, Object>> values = doGetAsync("/api/plugins/telemetry/ENTITY_VIEW/" + savedView.getId().getId().toString() +  
351 - "/values/attributes?keys=" + String.join(",", actualAttributesSet), List.class); 350 + List<Map<String, Object>> values = doGetAsyncTyped("/api/plugins/telemetry/ENTITY_VIEW/" + savedView.getId().getId().toString() +
  351 + "/values/attributes?keys=" + String.join(",", actualAttributesSet), new TypeReference<>() {});
352 352
353 assertEquals("value1", getValue(values, "caKey1")); 353 assertEquals("value1", getValue(values, "caKey1"));
354 assertEquals(true, getValue(values, "caKey2")); 354 assertEquals(true, getValue(values, "caKey2"));
@@ -364,8 +364,8 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes @@ -364,8 +364,8 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
364 Set<String> expectedActualAttributesSet = new HashSet<>(Arrays.asList("caKey1", "caKey2", "caKey3", "caKey4")); 364 Set<String> expectedActualAttributesSet = new HashSet<>(Arrays.asList("caKey1", "caKey2", "caKey3", "caKey4"));
365 assertTrue(actualAttributesSet.containsAll(expectedActualAttributesSet)); 365 assertTrue(actualAttributesSet.containsAll(expectedActualAttributesSet));
366 366
367 - List<Map<String, Object>> valueTelemetryOfDevices = doGetAsync("/api/plugins/telemetry/DEVICE/" + testDevice.getId().getId().toString() +  
368 - "/values/attributes?keys=" + String.join(",", actualAttributesSet), List.class); 367 + List<Map<String, Object>> valueTelemetryOfDevices = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + testDevice.getId().getId().toString() +
  368 + "/values/attributes?keys=" + String.join(",", actualAttributesSet), new TypeReference<>() {});
369 369
370 EntityView view = new EntityView(); 370 EntityView view = new EntityView();
371 view.setEntityId(testDevice.getId()); 371 view.setEntityId(testDevice.getId());
@@ -379,8 +379,8 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes @@ -379,8 +379,8 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
379 379
380 Thread.sleep(1000); 380 Thread.sleep(1000);
381 381
382 - List<Map<String, Object>> values = doGetAsync("/api/plugins/telemetry/ENTITY_VIEW/" + savedView.getId().getId().toString() +  
383 - "/values/attributes?keys=" + String.join(",", actualAttributesSet), List.class); 382 + List<Map<String, Object>> values = doGetAsyncTyped("/api/plugins/telemetry/ENTITY_VIEW/" + savedView.getId().getId().toString() +
  383 + "/values/attributes?keys=" + String.join(",", actualAttributesSet), new TypeReference<>() {});
384 assertEquals(0, values.size()); 384 assertEquals(0, values.size());
385 } 385 }
386 386
@@ -449,12 +449,12 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes @@ -449,12 +449,12 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
449 } 449 }
450 450
451 private Set<String> getTelemetryKeys(String type, String id) throws Exception { 451 private Set<String> getTelemetryKeys(String type, String id) throws Exception {
452 - return new HashSet<>(doGetAsync("/api/plugins/telemetry/" + type + "/" + id + "/keys/timeseries", List.class)); 452 + return new HashSet<>(doGetAsyncTyped("/api/plugins/telemetry/" + type + "/" + id + "/keys/timeseries", new TypeReference<>() {}));
453 } 453 }
454 454
455 private Map<String, List<Map<String, String>>> getTelemetryValues(String type, String id, Set<String> keys, Long startTs, Long endTs) throws Exception { 455 private Map<String, List<Map<String, String>>> getTelemetryValues(String type, String id, Set<String> keys, Long startTs, Long endTs) throws Exception {
456 - return doGetAsync("/api/plugins/telemetry/" + type + "/" + id +  
457 - "/values/timeseries?keys=" + String.join(",", keys) + "&startTs=" + startTs + "&endTs=" + endTs, Map.class); 456 + return doGetAsyncTyped("/api/plugins/telemetry/" + type + "/" + id +
  457 + "/values/timeseries?keys=" + String.join(",", keys) + "&startTs=" + startTs + "&endTs=" + endTs, new TypeReference<>() {});
458 } 458 }
459 459
460 private Set<String> getAttributesByKeys(String stringKV) throws Exception { 460 private Set<String> getAttributesByKeys(String stringKV) throws Exception {
@@ -479,7 +479,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes @@ -479,7 +479,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
479 client.publish("v1/devices/me/attributes", message); 479 client.publish("v1/devices/me/attributes", message);
480 Thread.sleep(1000); 480 Thread.sleep(1000);
481 client.disconnect(); 481 client.disconnect();
482 - return new HashSet<>(doGetAsync("/api/plugins/telemetry/DEVICE/" + viewDeviceId + "/keys/attributes", List.class)); 482 + return new HashSet<>(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + viewDeviceId + "/keys/attributes", new TypeReference<>() {}));
483 } 483 }
484 484
485 private Object getValue(List<Map<String, Object>> values, String stringValue) { 485 private Object getValue(List<Map<String, Object>> values, String stringValue) {
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 package org.thingsboard.server.mqtt.telemetry.attributes; 16 package org.thingsboard.server.mqtt.telemetry.attributes;
17 17
18 import com.fasterxml.jackson.core.JsonProcessingException; 18 import com.fasterxml.jackson.core.JsonProcessingException;
  19 +import com.fasterxml.jackson.core.type.TypeReference;
19 import lombok.extern.slf4j.Slf4j; 20 import lombok.extern.slf4j.Slf4j;
20 import org.eclipse.paho.client.mqttv3.MqttAsyncClient; 21 import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
21 import org.junit.After; 22 import org.junit.After;
@@ -80,7 +81,7 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt @@ -80,7 +81,7 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt
80 81
81 List<String> actualKeys = null; 82 List<String> actualKeys = null;
82 while (start <= end) { 83 while (start <= end) {
83 - actualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/attributes/CLIENT_SCOPE", List.class); 84 + actualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/attributes/CLIENT_SCOPE", new TypeReference<>() {});
84 if (actualKeys.size() == expectedKeys.size()) { 85 if (actualKeys.size() == expectedKeys.size()) {
85 break; 86 break;
86 } 87 }
@@ -96,7 +97,7 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt @@ -96,7 +97,7 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt
96 assertEquals(expectedKeySet, actualKeySet); 97 assertEquals(expectedKeySet, actualKeySet);
97 98
98 String getAttributesValuesUrl = getAttributesValuesUrl(deviceId, actualKeySet); 99 String getAttributesValuesUrl = getAttributesValuesUrl(deviceId, actualKeySet);
99 - List<Map<String, Object>> values = doGetAsync(getAttributesValuesUrl, List.class); 100 + List<Map<String, Object>> values = doGetAsyncTyped(getAttributesValuesUrl, new TypeReference<>() {});
100 assertAttributesValues(values, expectedKeySet); 101 assertAttributesValues(values, expectedKeySet);
101 String deleteAttributesUrl = "/api/plugins/telemetry/DEVICE/" + deviceId + "/CLIENT_SCOPE?keys=" + String.join(",", actualKeySet); 102 String deleteAttributesUrl = "/api/plugins/telemetry/DEVICE/" + deviceId + "/CLIENT_SCOPE?keys=" + String.join(",", actualKeySet);
102 doDelete(deleteAttributesUrl); 103 doDelete(deleteAttributesUrl);
@@ -121,10 +122,10 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt @@ -121,10 +122,10 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt
121 122
122 Thread.sleep(2000); 123 Thread.sleep(2000);
123 124
124 - List<String> firstDeviceActualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + firstDevice.getId() + "/keys/attributes/CLIENT_SCOPE", List.class); 125 + List<String> firstDeviceActualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + firstDevice.getId() + "/keys/attributes/CLIENT_SCOPE", new TypeReference<>() {});
125 Set<String> firstDeviceActualKeySet = new HashSet<>(firstDeviceActualKeys); 126 Set<String> firstDeviceActualKeySet = new HashSet<>(firstDeviceActualKeys);
126 127
127 - List<String> secondDeviceActualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + secondDevice.getId() + "/keys/attributes/CLIENT_SCOPE", List.class); 128 + List<String> secondDeviceActualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + secondDevice.getId() + "/keys/attributes/CLIENT_SCOPE", new TypeReference<>() {});
128 Set<String> secondDeviceActualKeySet = new HashSet<>(secondDeviceActualKeys); 129 Set<String> secondDeviceActualKeySet = new HashSet<>(secondDeviceActualKeys);
129 130
130 Set<String> expectedKeySet = new HashSet<>(expectedKeys); 131 Set<String> expectedKeySet = new HashSet<>(expectedKeys);
@@ -135,14 +136,15 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt @@ -135,14 +136,15 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt
135 String getAttributesValuesUrlFirstDevice = getAttributesValuesUrl(firstDevice.getId(), firstDeviceActualKeySet); 136 String getAttributesValuesUrlFirstDevice = getAttributesValuesUrl(firstDevice.getId(), firstDeviceActualKeySet);
136 String getAttributesValuesUrlSecondDevice = getAttributesValuesUrl(firstDevice.getId(), secondDeviceActualKeySet); 137 String getAttributesValuesUrlSecondDevice = getAttributesValuesUrl(firstDevice.getId(), secondDeviceActualKeySet);
137 138
138 - List<Map<String, Object>> firstDeviceValues = doGetAsync(getAttributesValuesUrlFirstDevice, List.class);  
139 - List<Map<String, Object>> secondDeviceValues = doGetAsync(getAttributesValuesUrlSecondDevice, List.class); 139 + List<Map<String, Object>> firstDeviceValues = doGetAsyncTyped(getAttributesValuesUrlFirstDevice, new TypeReference<>() {});
  140 + List<Map<String, Object>> secondDeviceValues = doGetAsyncTyped(getAttributesValuesUrlSecondDevice, new TypeReference<>() {});
140 141
141 assertAttributesValues(firstDeviceValues, expectedKeySet); 142 assertAttributesValues(firstDeviceValues, expectedKeySet);
142 assertAttributesValues(secondDeviceValues, expectedKeySet); 143 assertAttributesValues(secondDeviceValues, expectedKeySet);
143 144
144 } 145 }
145 146
  147 + @SuppressWarnings("unchecked")
146 protected void assertAttributesValues(List<Map<String, Object>> deviceValues, Set<String> expectedKeySet) throws JsonProcessingException { 148 protected void assertAttributesValues(List<Map<String, Object>> deviceValues, Set<String> expectedKeySet) throws JsonProcessingException {
147 for (Map<String, Object> map : deviceValues) { 149 for (Map<String, Object> map : deviceValues) {
148 String key = (String) map.get("key"); 150 String key = (String) map.get("key");
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.mqtt.telemetry.timeseries; 16 package org.thingsboard.server.mqtt.telemetry.timeseries;
17 17
  18 +import com.fasterxml.jackson.core.type.TypeReference;
18 import io.netty.handler.codec.mqtt.MqttQoS; 19 import io.netty.handler.codec.mqtt.MqttQoS;
19 import lombok.extern.slf4j.Slf4j; 20 import lombok.extern.slf4j.Slf4j;
20 import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; 21 import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
@@ -25,6 +26,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; @@ -25,6 +26,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
25 import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; 26 import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
26 import org.junit.After; 27 import org.junit.After;
27 import org.junit.Before; 28 import org.junit.Before;
  29 +import org.junit.Ignore;
28 import org.junit.Test; 30 import org.junit.Test;
29 import org.thingsboard.server.common.data.Device; 31 import org.thingsboard.server.common.data.Device;
30 import org.thingsboard.server.common.data.device.profile.MqttTopics; 32 import org.thingsboard.server.common.data.device.profile.MqttTopics;
@@ -107,7 +109,7 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt @@ -107,7 +109,7 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt
107 109
108 List<String> actualKeys = null; 110 List<String> actualKeys = null;
109 while (start <= end) { 111 while (start <= end) {
110 - actualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/timeseries", List.class); 112 + actualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/timeseries", new TypeReference<>() {});
111 if (actualKeys.size() == expectedKeys.size()) { 113 if (actualKeys.size() == expectedKeys.size()) {
112 break; 114 break;
113 } 115 }
@@ -129,13 +131,13 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt @@ -129,13 +131,13 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt
129 } 131 }
130 start = System.currentTimeMillis(); 132 start = System.currentTimeMillis();
131 end = System.currentTimeMillis() + 5000; 133 end = System.currentTimeMillis() + 5000;
132 - Map<String, List<Map<String, String>>> values = null; 134 + Map<String, List<Map<String, Object>>> values = null;
133 while (start <= end) { 135 while (start <= end) {
134 - values = doGetAsync(getTelemetryValuesUrl, Map.class); 136 + values = doGetAsyncTyped(getTelemetryValuesUrl, new TypeReference<>() {});
135 boolean valid = values.size() == expectedKeys.size(); 137 boolean valid = values.size() == expectedKeys.size();
136 if (valid) { 138 if (valid) {
137 for (String key : expectedKeys) { 139 for (String key : expectedKeys) {
138 - List<Map<String, String>> tsValues = values.get(key); 140 + List<Map<String, Object>> tsValues = values.get(key);
139 if (tsValues != null && tsValues.size() > 0) { 141 if (tsValues != null && tsValues.size() > 0) {
140 Object ts = tsValues.get(0).get("ts"); 142 Object ts = tsValues.get(0).get("ts");
141 if (ts == null) { 143 if (ts == null) {
@@ -181,10 +183,10 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt @@ -181,10 +183,10 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt
181 183
182 Thread.sleep(2000); 184 Thread.sleep(2000);
183 185
184 - List<String> firstDeviceActualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + firstDevice.getId() + "/keys/timeseries", List.class); 186 + List<String> firstDeviceActualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + firstDevice.getId() + "/keys/timeseries", new TypeReference<>() {});
185 Set<String> firstDeviceActualKeySet = new HashSet<>(firstDeviceActualKeys); 187 Set<String> firstDeviceActualKeySet = new HashSet<>(firstDeviceActualKeys);
186 188
187 - List<String> secondDeviceActualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + secondDevice.getId() + "/keys/timeseries", List.class); 189 + List<String> secondDeviceActualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + secondDevice.getId() + "/keys/timeseries", new TypeReference<>() {});
188 Set<String> secondDeviceActualKeySet = new HashSet<>(secondDeviceActualKeys); 190 Set<String> secondDeviceActualKeySet = new HashSet<>(secondDeviceActualKeys);
189 191
190 Set<String> expectedKeySet = new HashSet<>(expectedKeys); 192 Set<String> expectedKeySet = new HashSet<>(expectedKeys);
@@ -195,8 +197,8 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt @@ -195,8 +197,8 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt
195 String getTelemetryValuesUrlFirstDevice = getTelemetryValuesUrl(firstDevice.getId(), firstDeviceActualKeySet); 197 String getTelemetryValuesUrlFirstDevice = getTelemetryValuesUrl(firstDevice.getId(), firstDeviceActualKeySet);
196 String getTelemetryValuesUrlSecondDevice = getTelemetryValuesUrl(firstDevice.getId(), secondDeviceActualKeySet); 198 String getTelemetryValuesUrlSecondDevice = getTelemetryValuesUrl(firstDevice.getId(), secondDeviceActualKeySet);
197 199
198 - Map<String, List<Map<String, String>>> firstDeviceValues = doGetAsync(getTelemetryValuesUrlFirstDevice, Map.class);  
199 - Map<String, List<Map<String, String>>> secondDeviceValues = doGetAsync(getTelemetryValuesUrlSecondDevice, Map.class); 200 + Map<String, List<Map<String, Object>>> firstDeviceValues = doGetAsyncTyped(getTelemetryValuesUrlFirstDevice, new TypeReference<>() {});
  201 + Map<String, List<Map<String, Object>>> secondDeviceValues = doGetAsyncTyped(getTelemetryValuesUrlSecondDevice, new TypeReference<>() {});
200 202
201 assertGatewayDeviceData(firstDeviceValues, expectedKeys); 203 assertGatewayDeviceData(firstDeviceValues, expectedKeys);
202 assertGatewayDeviceData(secondDeviceValues, expectedKeys); 204 assertGatewayDeviceData(secondDeviceValues, expectedKeys);
@@ -212,7 +214,7 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt @@ -212,7 +214,7 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt
212 return "/api/plugins/telemetry/DEVICE/" + deviceId + "/values/timeseries?startTs=0&endTs=25000&keys=" + String.join(",", actualKeySet); 214 return "/api/plugins/telemetry/DEVICE/" + deviceId + "/values/timeseries?startTs=0&endTs=25000&keys=" + String.join(",", actualKeySet);
213 } 215 }
214 216
215 - private void assertGatewayDeviceData(Map<String, List<Map<String, String>>> deviceValues, List<String> expectedKeys) { 217 + private void assertGatewayDeviceData(Map<String, List<Map<String, Object>>> deviceValues, List<String> expectedKeys) {
216 218
217 assertEquals(2, deviceValues.get(expectedKeys.get(0)).size()); 219 assertEquals(2, deviceValues.get(expectedKeys.get(0)).size());
218 assertEquals(2, deviceValues.get(expectedKeys.get(1)).size()); 220 assertEquals(2, deviceValues.get(expectedKeys.get(1)).size());
@@ -228,11 +230,11 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt @@ -228,11 +230,11 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt
228 230
229 } 231 }
230 232
231 - private void assertValues(Map<String, List<Map<String, String>>> deviceValues, int arrayIndex) {  
232 - for (Map.Entry<String, List<Map<String, String>>> entry : deviceValues.entrySet()) { 233 + private void assertValues(Map<String, List<Map<String, Object>>> deviceValues, int arrayIndex) {
  234 + for (Map.Entry<String, List<Map<String, Object>>> entry : deviceValues.entrySet()) {
233 String key = entry.getKey(); 235 String key = entry.getKey();
234 - List<Map<String, String>> tsKv = entry.getValue();  
235 - String value = tsKv.get(arrayIndex).get("value"); 236 + List<Map<String, Object>> tsKv = entry.getValue();
  237 + String value = (String) tsKv.get(arrayIndex).get("value");
236 switch (key) { 238 switch (key) {
237 case "key1": 239 case "key1":
238 assertEquals("value1", value); 240 assertEquals("value1", value);
@@ -253,7 +255,7 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt @@ -253,7 +255,7 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt
253 } 255 }
254 } 256 }
255 257
256 - private void assertTs(Map<String, List<Map<String, String>>> deviceValues, List<String> expectedKeys, int ts, int arrayIndex) { 258 + private void assertTs(Map<String, List<Map<String, Object>>> deviceValues, List<String> expectedKeys, int ts, int arrayIndex) {
257 assertEquals(ts, deviceValues.get(expectedKeys.get(0)).get(arrayIndex).get("ts")); 259 assertEquals(ts, deviceValues.get(expectedKeys.get(0)).get(arrayIndex).get("ts"));
258 assertEquals(ts, deviceValues.get(expectedKeys.get(1)).get(arrayIndex).get("ts")); 260 assertEquals(ts, deviceValues.get(expectedKeys.get(1)).get(arrayIndex).get("ts"));
259 assertEquals(ts, deviceValues.get(expectedKeys.get(2)).get(arrayIndex).get("ts")); 261 assertEquals(ts, deviceValues.get(expectedKeys.get(2)).get(arrayIndex).get("ts"));
@@ -21,12 +21,11 @@ import org.junit.Assert; @@ -21,12 +21,11 @@ import org.junit.Assert;
21 import org.junit.Before; 21 import org.junit.Before;
22 import org.junit.Test; 22 import org.junit.Test;
23 import org.junit.runner.RunWith; 23 import org.junit.runner.RunWith;
24 -import org.mockito.runners.MockitoJUnitRunner; 24 +import org.mockito.junit.MockitoJUnitRunner;
25 import org.springframework.context.ApplicationEventPublisher; 25 import org.springframework.context.ApplicationEventPublisher;
26 import org.springframework.test.util.ReflectionTestUtils; 26 import org.springframework.test.util.ReflectionTestUtils;
27 import org.thingsboard.server.common.data.id.DeviceId; 27 import org.thingsboard.server.common.data.id.DeviceId;
28 import org.thingsboard.server.common.data.id.TenantId; 28 import org.thingsboard.server.common.data.id.TenantId;
29 -import org.thingsboard.server.common.msg.queue.ServiceQueue;  
30 import org.thingsboard.server.queue.discovery.HashPartitionService; 29 import org.thingsboard.server.queue.discovery.HashPartitionService;
31 import org.thingsboard.server.common.msg.queue.ServiceType; 30 import org.thingsboard.server.common.msg.queue.ServiceType;
32 import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; 31 import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
@@ -20,7 +20,7 @@ import org.junit.Assert; @@ -20,7 +20,7 @@ import org.junit.Assert;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.junit.runner.RunWith; 21 import org.junit.runner.RunWith;
22 import org.mockito.Mockito; 22 import org.mockito.Mockito;
23 -import org.mockito.runners.MockitoJUnitRunner; 23 +import org.mockito.junit.MockitoJUnitRunner;
24 import org.thingsboard.server.gen.transport.TransportProtos; 24 import org.thingsboard.server.gen.transport.TransportProtos;
25 import org.thingsboard.server.queue.common.TbProtoQueueMsg; 25 import org.thingsboard.server.queue.common.TbProtoQueueMsg;
26 import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrategy; 26 import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrategy;
@@ -20,7 +20,7 @@ import lombok.extern.slf4j.Slf4j; @@ -20,7 +20,7 @@ import lombok.extern.slf4j.Slf4j;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.junit.runner.RunWith; 21 import org.junit.runner.RunWith;
22 import org.mockito.Mockito; 22 import org.mockito.Mockito;
23 -import org.mockito.runners.MockitoJUnitRunner; 23 +import org.mockito.junit.MockitoJUnitRunner;
24 import org.thingsboard.server.utils.EventDeduplicationExecutor; 24 import org.thingsboard.server.utils.EventDeduplicationExecutor;
25 25
26 import java.util.concurrent.ExecutorService; 26 import java.util.concurrent.ExecutorService;
@@ -67,7 +67,7 @@ @@ -67,7 +67,7 @@
67 </dependency> 67 </dependency>
68 <dependency> 68 <dependency>
69 <groupId>org.mockito</groupId> 69 <groupId>org.mockito</groupId>
70 - <artifactId>mockito-all</artifactId> 70 + <artifactId>mockito-core</artifactId>
71 <scope>test</scope> 71 <scope>test</scope>
72 </dependency> 72 </dependency>
73 </dependencies> 73 </dependencies>
@@ -21,7 +21,7 @@ import org.junit.Assert; @@ -21,7 +21,7 @@ import org.junit.Assert;
21 import org.junit.Before; 21 import org.junit.Before;
22 import org.junit.Test; 22 import org.junit.Test;
23 import org.junit.runner.RunWith; 23 import org.junit.runner.RunWith;
24 -import org.mockito.runners.MockitoJUnitRunner; 24 +import org.mockito.junit.MockitoJUnitRunner;
25 import org.thingsboard.server.common.data.id.DeviceId; 25 import org.thingsboard.server.common.data.id.DeviceId;
26 26
27 import java.util.ArrayList; 27 import java.util.ArrayList;
@@ -49,6 +49,10 @@ @@ -49,6 +49,10 @@
49 <artifactId>guava</artifactId> 49 <artifactId>guava</artifactId>
50 </dependency> 50 </dependency>
51 <dependency> 51 <dependency>
  52 + <groupId>javax.annotation</groupId>
  53 + <artifactId>javax.annotation-api</artifactId>
  54 + </dependency>
  55 + <dependency>
52 <groupId>com.github.fge</groupId> 56 <groupId>com.github.fge</groupId>
53 <artifactId>json-schema-validator</artifactId> 57 <artifactId>json-schema-validator</artifactId>
54 </dependency> 58 </dependency>
@@ -99,7 +103,7 @@ @@ -99,7 +103,7 @@
99 </dependency> 103 </dependency>
100 <dependency> 104 <dependency>
101 <groupId>org.mockito</groupId> 105 <groupId>org.mockito</groupId>
102 - <artifactId>mockito-all</artifactId> 106 + <artifactId>mockito-core</artifactId>
103 <scope>test</scope> 107 <scope>test</scope>
104 </dependency> 108 </dependency>
105 </dependencies> 109 </dependencies>
@@ -23,6 +23,7 @@ import lombok.extern.slf4j.Slf4j; @@ -23,6 +23,7 @@ import lombok.extern.slf4j.Slf4j;
23 import org.springframework.beans.factory.annotation.Autowired; 23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.beans.factory.annotation.Value; 24 import org.springframework.beans.factory.annotation.Value;
25 import org.springframework.core.env.Environment; 25 import org.springframework.core.env.Environment;
  26 +import org.springframework.core.env.Profiles;
26 import org.thingsboard.server.dao.cassandra.guava.GuavaSession; 27 import org.thingsboard.server.dao.cassandra.guava.GuavaSession;
27 import org.thingsboard.server.dao.cassandra.guava.GuavaSessionBuilder; 28 import org.thingsboard.server.dao.cassandra.guava.GuavaSessionBuilder;
28 import org.thingsboard.server.dao.cassandra.guava.GuavaSessionUtils; 29 import org.thingsboard.server.dao.cassandra.guava.GuavaSessionUtils;
@@ -77,7 +78,7 @@ public abstract class AbstractCassandraCluster { @@ -77,7 +78,7 @@ public abstract class AbstractCassandraCluster {
77 } 78 }
78 79
79 private boolean isInstall() { 80 private boolean isInstall() {
80 - return environment.acceptsProfiles("install"); 81 + return environment.acceptsProfiles(Profiles.of("install"));
81 } 82 }
82 83
83 private void initSession() { 84 private void initSession() {
@@ -18,38 +18,25 @@ package org.thingsboard.server.dao.cassandra.guava; @@ -18,38 +18,25 @@ package org.thingsboard.server.dao.cassandra.guava;
18 import com.datastax.oss.driver.api.core.CqlSession; 18 import com.datastax.oss.driver.api.core.CqlSession;
19 import com.datastax.oss.driver.api.core.config.DriverConfigLoader; 19 import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
20 import com.datastax.oss.driver.api.core.context.DriverContext; 20 import com.datastax.oss.driver.api.core.context.DriverContext;
21 -import com.datastax.oss.driver.api.core.metadata.Node;  
22 -import com.datastax.oss.driver.api.core.metadata.NodeStateListener;  
23 -import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener; 21 +import com.datastax.oss.driver.api.core.session.ProgrammaticArguments;
24 import com.datastax.oss.driver.api.core.session.SessionBuilder; 22 import com.datastax.oss.driver.api.core.session.SessionBuilder;
25 -import com.datastax.oss.driver.api.core.tracker.RequestTracker;  
26 -import com.datastax.oss.driver.api.core.type.codec.TypeCodec;  
27 import edu.umd.cs.findbugs.annotations.NonNull; 23 import edu.umd.cs.findbugs.annotations.NonNull;
28 -import java.util.List;  
29 -import java.util.Map;  
30 -import java.util.function.Predicate;  
31 24
32 public class GuavaSessionBuilder extends SessionBuilder<GuavaSessionBuilder, GuavaSession> { 25 public class GuavaSessionBuilder extends SessionBuilder<GuavaSessionBuilder, GuavaSession> {
33 26
34 @Override 27 @Override
35 protected DriverContext buildContext( 28 protected DriverContext buildContext(
36 DriverConfigLoader configLoader, 29 DriverConfigLoader configLoader,
37 - List<TypeCodec<?>> typeCodecs,  
38 - NodeStateListener nodeStateListener,  
39 - SchemaChangeListener schemaChangeListener,  
40 - RequestTracker requestTracker,  
41 - Map<String, String> localDatacenters,  
42 - Map<String, Predicate<Node>> nodeFilters,  
43 - ClassLoader classLoader) { 30 + ProgrammaticArguments programmaticArguments) {
44 return new GuavaDriverContext( 31 return new GuavaDriverContext(
45 configLoader, 32 configLoader,
46 - typeCodecs,  
47 - nodeStateListener,  
48 - schemaChangeListener,  
49 - requestTracker,  
50 - localDatacenters,  
51 - nodeFilters,  
52 - classLoader); 33 + programmaticArguments.getTypeCodecs(),
  34 + programmaticArguments.getNodeStateListener(),
  35 + programmaticArguments.getSchemaChangeListener(),
  36 + programmaticArguments.getRequestTracker(),
  37 + programmaticArguments.getLocalDatacenters(),
  38 + programmaticArguments.getNodeFilters(),
  39 + programmaticArguments.getClassLoader());
53 } 40 }
54 41
55 @Override 42 @Override
@@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
63 </dependency> 63 </dependency>
64 <dependency> 64 <dependency>
65 <groupId>org.mockito</groupId> 65 <groupId>org.mockito</groupId>
66 - <artifactId>mockito-all</artifactId> 66 + <artifactId>mockito-core</artifactId>
67 <scope>test</scope> 67 <scope>test</scope>
68 </dependency> 68 </dependency>
69 <dependency> 69 <dependency>
@@ -19,7 +19,7 @@ import com.datastax.oss.driver.api.core.uuid.Uuids; @@ -19,7 +19,7 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import org.junit.Assert; 19 import org.junit.Assert;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.junit.runner.RunWith; 21 import org.junit.runner.RunWith;
22 -import org.mockito.runners.MockitoJUnitRunner; 22 +import org.mockito.junit.MockitoJUnitRunner;
23 23
24 import java.util.ArrayList; 24 import java.util.ArrayList;
25 import java.util.Arrays; 25 import java.util.Arrays;
@@ -76,7 +76,7 @@ @@ -76,7 +76,7 @@
76 </dependency> 76 </dependency>
77 <dependency> 77 <dependency>
78 <groupId>org.mockito</groupId> 78 <groupId>org.mockito</groupId>
79 - <artifactId>mockito-all</artifactId> 79 + <artifactId>mockito-core</artifactId>
80 <scope>test</scope> 80 <scope>test</scope>
81 </dependency> 81 </dependency>
82 </dependencies> 82 </dependencies>
@@ -124,7 +124,7 @@ @@ -124,7 +124,7 @@
124 </dependency> 124 </dependency>
125 <dependency> 125 <dependency>
126 <groupId>org.mockito</groupId> 126 <groupId>org.mockito</groupId>
127 - <artifactId>mockito-all</artifactId> 127 + <artifactId>mockito-core</artifactId>
128 <scope>test</scope> 128 <scope>test</scope>
129 </dependency> 129 </dependency>
130 </dependencies> 130 </dependencies>
@@ -154,6 +154,7 @@ public class TbServiceBusConsumerTemplate<T extends TbQueueMsg> extends Abstract @@ -154,6 +154,7 @@ public class TbServiceBusConsumerTemplate<T extends TbQueueMsg> extends Abstract
154 } 154 }
155 155
156 private <V> CompletableFuture<List<V>> fromList(List<CompletableFuture<V>> futures) { 156 private <V> CompletableFuture<List<V>> fromList(List<CompletableFuture<V>> futures) {
  157 + @SuppressWarnings("unchecked")
157 CompletableFuture<Collection<V>>[] arrayFuture = new CompletableFuture[futures.size()]; 158 CompletableFuture<Collection<V>>[] arrayFuture = new CompletableFuture[futures.size()];
158 futures.toArray(arrayFuture); 159 futures.toArray(arrayFuture);
159 160
@@ -60,6 +60,7 @@ public final class InMemoryStorage { @@ -60,6 +60,7 @@ public final class InMemoryStorage {
60 public <T extends TbQueueMsg> List<T> get(String topic) throws InterruptedException { 60 public <T extends TbQueueMsg> List<T> get(String topic) throws InterruptedException {
61 if (storage.containsKey(topic)) { 61 if (storage.containsKey(topic)) {
62 List<T> entities; 62 List<T> entities;
  63 + @SuppressWarnings("unchecked")
63 T first = (T) storage.get(topic).poll(); 64 T first = (T) storage.get(topic).poll();
64 if (first != null) { 65 if (first != null) {
65 entities = new ArrayList<>(); 66 entities = new ArrayList<>();
@@ -67,7 +68,9 @@ public final class InMemoryStorage { @@ -67,7 +68,9 @@ public final class InMemoryStorage {
67 List<TbQueueMsg> otherList = new ArrayList<>(); 68 List<TbQueueMsg> otherList = new ArrayList<>();
68 storage.get(topic).drainTo(otherList, 999); 69 storage.get(topic).drainTo(otherList, 999);
69 for (TbQueueMsg other : otherList) { 70 for (TbQueueMsg other : otherList) {
70 - entities.add((T) other); 71 + @SuppressWarnings("unchecked")
  72 + T entity = (T) other;
  73 + entities.add(entity);
71 } 74 }
72 } else { 75 } else {
73 entities = Collections.emptyList(); 76 entities = Collections.emptyList();
@@ -64,6 +64,7 @@ public class InMemoryTbQueueConsumer<T extends TbQueueMsg> implements TbQueueCon @@ -64,6 +64,7 @@ public class InMemoryTbQueueConsumer<T extends TbQueueMsg> implements TbQueueCon
64 @Override 64 @Override
65 public List<T> poll(long durationInMillis) { 65 public List<T> poll(long durationInMillis) {
66 if (subscribed) { 66 if (subscribed) {
  67 + @SuppressWarnings("unchecked")
67 List<T> messages = partitions 68 List<T> messages = partitions
68 .stream() 69 .stream()
69 .map(tpi -> { 70 .map(tpi -> {
@@ -47,6 +47,7 @@ public class DefaultTbApiUsageClient implements TbApiUsageClient { @@ -47,6 +47,7 @@ public class DefaultTbApiUsageClient implements TbApiUsageClient {
47 @Value("${usage.stats.report.interval:10}") 47 @Value("${usage.stats.report.interval:10}")
48 private int interval; 48 private int interval;
49 49
  50 + @SuppressWarnings("unchecked")
50 private final ConcurrentMap<TenantId, AtomicLong>[] values = new ConcurrentMap[ApiUsageRecordKey.values().length]; 51 private final ConcurrentMap<TenantId, AtomicLong>[] values = new ConcurrentMap[ApiUsageRecordKey.values().length];
51 private final PartitionService partitionService; 52 private final PartitionService partitionService;
52 private final SchedulerComponent scheduler; 53 private final SchedulerComponent scheduler;
@@ -79,7 +79,7 @@ @@ -79,7 +79,7 @@
79 </dependency> 79 </dependency>
80 <dependency> 80 <dependency>
81 <groupId>org.mockito</groupId> 81 <groupId>org.mockito</groupId>
82 - <artifactId>mockito-all</artifactId> 82 + <artifactId>mockito-core</artifactId>
83 <scope>test</scope> 83 <scope>test</scope>
84 </dependency> 84 </dependency>
85 </dependencies> 85 </dependencies>
@@ -89,4 +89,4 @@ @@ -89,4 +89,4 @@
89 </plugins> 89 </plugins>
90 </build> 90 </build>
91 91
92 -</project>  
  92 +</project>
@@ -80,7 +80,7 @@ @@ -80,7 +80,7 @@
80 </dependency> 80 </dependency>
81 <dependency> 81 <dependency>
82 <groupId>org.mockito</groupId> 82 <groupId>org.mockito</groupId>
83 - <artifactId>mockito-all</artifactId> 83 + <artifactId>mockito-core</artifactId>
84 <scope>test</scope> 84 <scope>test</scope>
85 </dependency> 85 </dependency>
86 </dependencies> 86 </dependencies>
@@ -73,7 +73,7 @@ @@ -73,7 +73,7 @@
73 </dependency> 73 </dependency>
74 <dependency> 74 <dependency>
75 <groupId>org.mockito</groupId> 75 <groupId>org.mockito</groupId>
76 - <artifactId>mockito-all</artifactId> 76 + <artifactId>mockito-core</artifactId>
77 <scope>test</scope> 77 <scope>test</scope>
78 </dependency> 78 </dependency>
79 </dependencies> 79 </dependencies>
@@ -90,7 +90,7 @@ @@ -90,7 +90,7 @@
90 </dependency> 90 </dependency>
91 <dependency> 91 <dependency>
92 <groupId>org.mockito</groupId> 92 <groupId>org.mockito</groupId>
93 - <artifactId>mockito-all</artifactId> 93 + <artifactId>mockito-core</artifactId>
94 <scope>test</scope> 94 <scope>test</scope>
95 </dependency> 95 </dependency>
96 </dependencies> 96 </dependencies>
@@ -45,6 +45,7 @@ import java.io.IOException; @@ -45,6 +45,7 @@ import java.io.IOException;
45 import java.io.InputStream; 45 import java.io.InputStream;
46 import java.net.URL; 46 import java.net.URL;
47 import java.security.KeyStore; 47 import java.security.KeyStore;
  48 +import java.security.cert.CertificateEncodingException;
48 import java.security.cert.CertificateException; 49 import java.security.cert.CertificateException;
49 import java.security.cert.X509Certificate; 50 import java.security.cert.X509Certificate;
50 import java.util.concurrent.CountDownLatch; 51 import java.util.concurrent.CountDownLatch;
@@ -154,7 +155,7 @@ public class MqttSslHandlerProvider { @@ -154,7 +155,7 @@ public class MqttSslHandlerProvider {
154 String credentialsBody = null; 155 String credentialsBody = null;
155 for (X509Certificate cert : chain) { 156 for (X509Certificate cert : chain) {
156 try { 157 try {
157 - String strCert = SslUtil.getX509CertificateString(cert); 158 + String strCert = SslUtil.getCertificateString(cert);
158 String sha3Hash = EncryptionUtil.getSha3Hash(strCert); 159 String sha3Hash = EncryptionUtil.getSha3Hash(strCert);
159 final String[] credentialsBodyHolder = new String[1]; 160 final String[] credentialsBodyHolder = new String[1];
160 CountDownLatch latch = new CountDownLatch(1); 161 CountDownLatch latch = new CountDownLatch(1);
@@ -179,7 +180,7 @@ public class MqttSslHandlerProvider { @@ -179,7 +180,7 @@ public class MqttSslHandlerProvider {
179 credentialsBody = credentialsBodyHolder[0]; 180 credentialsBody = credentialsBodyHolder[0];
180 break; 181 break;
181 } 182 }
182 - } catch (InterruptedException | IOException e) { 183 + } catch (InterruptedException | CertificateEncodingException e) {
183 log.error(e.getMessage(), e); 184 log.error(e.getMessage(), e);
184 } 185 }
185 } 186 }
@@ -35,6 +35,7 @@ import io.netty.handler.codec.mqtt.MqttSubscribeMessage; @@ -35,6 +35,7 @@ import io.netty.handler.codec.mqtt.MqttSubscribeMessage;
35 import io.netty.handler.codec.mqtt.MqttTopicSubscription; 35 import io.netty.handler.codec.mqtt.MqttTopicSubscription;
36 import io.netty.handler.codec.mqtt.MqttUnsubscribeMessage; 36 import io.netty.handler.codec.mqtt.MqttUnsubscribeMessage;
37 import io.netty.handler.ssl.SslHandler; 37 import io.netty.handler.ssl.SslHandler;
  38 +import io.netty.util.CharsetUtil;
38 import io.netty.util.ReferenceCountUtil; 39 import io.netty.util.ReferenceCountUtil;
39 import io.netty.util.concurrent.Future; 40 import io.netty.util.concurrent.Future;
40 import io.netty.util.concurrent.GenericFutureListener; 41 import io.netty.util.concurrent.GenericFutureListener;
@@ -68,7 +69,8 @@ import org.thingsboard.server.transport.mqtt.session.MqttTopicMatcher; @@ -68,7 +69,8 @@ import org.thingsboard.server.transport.mqtt.session.MqttTopicMatcher;
68 import org.thingsboard.server.transport.mqtt.util.SslUtil; 69 import org.thingsboard.server.transport.mqtt.util.SslUtil;
69 70
70 import javax.net.ssl.SSLPeerUnverifiedException; 71 import javax.net.ssl.SSLPeerUnverifiedException;
71 -import javax.security.cert.X509Certificate; 72 +import java.security.cert.Certificate;
  73 +import java.security.cert.X509Certificate;
72 import java.io.IOException; 74 import java.io.IOException;
73 import java.net.InetSocketAddress; 75 import java.net.InetSocketAddress;
74 import java.util.ArrayList; 76 import java.util.ArrayList;
@@ -315,7 +317,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @@ -315,7 +317,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
315 } 317 }
316 318
317 private <T> TransportServiceCallback<Void> getPubAckCallback(final ChannelHandlerContext ctx, final int msgId, final T msg) { 319 private <T> TransportServiceCallback<Void> getPubAckCallback(final ChannelHandlerContext ctx, final int msgId, final T msg) {
318 - return new TransportServiceCallback<Void>() { 320 + return new TransportServiceCallback<>() {
319 @Override 321 @Override
320 public void onSuccess(Void dummy) { 322 public void onSuccess(Void dummy) {
321 log.trace("[{}] Published msg: {}", sessionId, msg); 323 log.trace("[{}] Published msg: {}", sessionId, msg);
@@ -482,12 +484,13 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @@ -482,12 +484,13 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
482 if (userName != null) { 484 if (userName != null) {
483 request.setUserName(userName); 485 request.setUserName(userName);
484 } 486 }
485 - String password = connectMessage.payload().password();  
486 - if (password != null) { 487 + byte[] passwordBytes = connectMessage.payload().passwordInBytes();
  488 + if (passwordBytes != null) {
  489 + String password = new String(passwordBytes, CharsetUtil.UTF_8);
487 request.setPassword(password); 490 request.setPassword(password);
488 } 491 }
489 transportService.process(DeviceTransportType.MQTT, request.build(), 492 transportService.process(DeviceTransportType.MQTT, request.build(),
490 - new TransportServiceCallback<ValidateDeviceCredentialsResponse>() { 493 + new TransportServiceCallback<>() {
491 @Override 494 @Override
492 public void onSuccess(ValidateDeviceCredentialsResponse msg) { 495 public void onSuccess(ValidateDeviceCredentialsResponse msg) {
493 onValidateDeviceResponse(msg, ctx, connectMessage); 496 onValidateDeviceResponse(msg, ctx, connectMessage);
@@ -507,10 +510,10 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @@ -507,10 +510,10 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
507 if (!context.isSkipValidityCheckForClientCert()) { 510 if (!context.isSkipValidityCheckForClientCert()) {
508 cert.checkValidity(); 511 cert.checkValidity();
509 } 512 }
510 - String strCert = SslUtil.getX509CertificateString(cert); 513 + String strCert = SslUtil.getCertificateString(cert);
511 String sha3Hash = EncryptionUtil.getSha3Hash(strCert); 514 String sha3Hash = EncryptionUtil.getSha3Hash(strCert);
512 transportService.process(DeviceTransportType.MQTT, ValidateDeviceX509CertRequestMsg.newBuilder().setHash(sha3Hash).build(), 515 transportService.process(DeviceTransportType.MQTT, ValidateDeviceX509CertRequestMsg.newBuilder().setHash(sha3Hash).build(),
513 - new TransportServiceCallback<ValidateDeviceCredentialsResponse>() { 516 + new TransportServiceCallback<>() {
514 @Override 517 @Override
515 public void onSuccess(ValidateDeviceCredentialsResponse msg) { 518 public void onSuccess(ValidateDeviceCredentialsResponse msg) {
516 onValidateDeviceResponse(msg, ctx, connectMessage); 519 onValidateDeviceResponse(msg, ctx, connectMessage);
@@ -531,9 +534,9 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @@ -531,9 +534,9 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
531 534
532 private X509Certificate getX509Certificate() { 535 private X509Certificate getX509Certificate() {
533 try { 536 try {
534 - X509Certificate[] certChain = sslHandler.engine().getSession().getPeerCertificateChain(); 537 + Certificate[] certChain = sslHandler.engine().getSession().getPeerCertificates();
535 if (certChain.length > 0) { 538 if (certChain.length > 0) {
536 - return certChain[0]; 539 + return (X509Certificate) certChain[0];
537 } 540 }
538 } catch (SSLPeerUnverifiedException e) { 541 } catch (SSLPeerUnverifiedException e) {
539 log.warn(e.getMessage()); 542 log.warn(e.getMessage());
@@ -20,8 +20,8 @@ import org.springframework.util.Base64Utils; @@ -20,8 +20,8 @@ import org.springframework.util.Base64Utils;
20 import org.thingsboard.server.common.msg.EncryptionUtil; 20 import org.thingsboard.server.common.msg.EncryptionUtil;
21 21
22 import java.io.IOException; 22 import java.io.IOException;
  23 +import java.security.cert.Certificate;
23 import java.security.cert.CertificateEncodingException; 24 import java.security.cert.CertificateEncodingException;
24 -import java.security.cert.X509Certificate;  
25 25
26 /** 26 /**
27 * @author Valerii Sosliuk 27 * @author Valerii Sosliuk
@@ -32,15 +32,8 @@ public class SslUtil { @@ -32,15 +32,8 @@ public class SslUtil {
32 private SslUtil() { 32 private SslUtil() {
33 } 33 }
34 34
35 - public static String getX509CertificateString(X509Certificate cert)  
36 - throws CertificateEncodingException, IOException {  
37 - Base64Utils.encodeToString(cert.getEncoded());  
38 - return EncryptionUtil.trimNewLines(Base64Utils.encodeToString(cert.getEncoded()));  
39 - }  
40 -  
41 - public static String getX509CertificateString(javax.security.cert.X509Certificate cert)  
42 - throws javax.security.cert.CertificateEncodingException, IOException {  
43 - Base64Utils.encodeToString(cert.getEncoded()); 35 + public static String getCertificateString(Certificate cert)
  36 + throws CertificateEncodingException {
44 return EncryptionUtil.trimNewLines(Base64Utils.encodeToString(cert.getEncoded())); 37 return EncryptionUtil.trimNewLines(Base64Utils.encodeToString(cert.getEncoded()));
45 } 38 }
46 } 39 }
@@ -17,7 +17,7 @@ package org.thingsboard.server.transport.mqtt.util; @@ -17,7 +17,7 @@ package org.thingsboard.server.transport.mqtt.util;
17 17
18 import org.junit.Test; 18 import org.junit.Test;
19 import org.junit.runner.RunWith; 19 import org.junit.runner.RunWith;
20 -import org.mockito.runners.MockitoJUnitRunner; 20 +import org.mockito.junit.MockitoJUnitRunner;
21 21
22 import javax.script.ScriptException; 22 import javax.script.ScriptException;
23 23
@@ -87,7 +87,7 @@ @@ -87,7 +87,7 @@
87 </dependency> 87 </dependency>
88 <dependency> 88 <dependency>
89 <groupId>org.mockito</groupId> 89 <groupId>org.mockito</groupId>
90 - <artifactId>mockito-all</artifactId> 90 + <artifactId>mockito-core</artifactId>
91 <scope>test</scope> 91 <scope>test</scope>
92 </dependency> 92 </dependency>
93 <dependency> 93 <dependency>
@@ -32,6 +32,7 @@ public class ProtoWithFSTService implements DataDecodingEncodingService { @@ -32,6 +32,7 @@ public class ProtoWithFSTService implements DataDecodingEncodingService {
32 @Override 32 @Override
33 public <T> Optional<T> decode(byte[] byteArray) { 33 public <T> Optional<T> decode(byte[] byteArray) {
34 try { 34 try {
  35 + @SuppressWarnings("unchecked")
35 T msg = (T) config.asObject(byteArray); 36 T msg = (T) config.asObject(byteArray);
36 return Optional.of(msg); 37 return Optional.of(msg);
37 } catch (IllegalArgumentException e) { 38 } catch (IllegalArgumentException e) {
@@ -42,6 +42,10 @@ @@ -42,6 +42,10 @@
42 <scope>provided</scope> 42 <scope>provided</scope>
43 </dependency> 43 </dependency>
44 <dependency> 44 <dependency>
  45 + <groupId>javax.annotation</groupId>
  46 + <artifactId>javax.annotation-api</artifactId>
  47 + </dependency>
  48 + <dependency>
45 <groupId>org.slf4j</groupId> 49 <groupId>org.slf4j</groupId>
46 <artifactId>slf4j-api</artifactId> 50 <artifactId>slf4j-api</artifactId>
47 </dependency> 51 </dependency>
@@ -64,7 +68,7 @@ @@ -64,7 +68,7 @@
64 </dependency> 68 </dependency>
65 <dependency> 69 <dependency>
66 <groupId>org.mockito</groupId> 70 <groupId>org.mockito</groupId>
67 - <artifactId>mockito-all</artifactId> 71 + <artifactId>mockito-core</artifactId>
68 <scope>test</scope> 72 <scope>test</scope>
69 </dependency> 73 </dependency>
70 </dependencies> 74 </dependencies>
@@ -92,7 +92,7 @@ @@ -92,7 +92,7 @@
92 </dependency> 92 </dependency>
93 <dependency> 93 <dependency>
94 <groupId>org.mockito</groupId> 94 <groupId>org.mockito</groupId>
95 - <artifactId>mockito-all</artifactId> 95 + <artifactId>mockito-core</artifactId>
96 <scope>test</scope> 96 <scope>test</scope>
97 </dependency> 97 </dependency>
98 <dependency> 98 <dependency>
@@ -40,11 +40,11 @@ public abstract class DaoUtil { @@ -40,11 +40,11 @@ public abstract class DaoUtil {
40 40
41 public static <T> PageData<T> toPageData(Page<? extends ToData<T>> page) { 41 public static <T> PageData<T> toPageData(Page<? extends ToData<T>> page) {
42 List<T> data = convertDataList(page.getContent()); 42 List<T> data = convertDataList(page.getContent());
43 - return new PageData(data, page.getTotalPages(), page.getTotalElements(), page.hasNext()); 43 + return new PageData<>(data, page.getTotalPages(), page.getTotalElements(), page.hasNext());
44 } 44 }
45 45
46 public static <T> PageData<T> pageToPageData(Page<T> page) { 46 public static <T> PageData<T> pageToPageData(Page<T> page) {
47 - return new PageData(page.getContent(), page.getTotalPages(), page.getTotalElements(), page.hasNext()); 47 + return new PageData<>(page.getContent(), page.getTotalPages(), page.getTotalElements(), page.hasNext());
48 } 48 }
49 49
50 public static Pageable toPageable(PageLink pageLink) { 50 public static Pageable toPageable(PageLink pageLink) {
@@ -306,7 +306,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ @@ -306,7 +306,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
306 )); 306 ));
307 } 307 }
308 return Futures.transform(Futures.successfulAsList(alarmFutures), 308 return Futures.transform(Futures.successfulAsList(alarmFutures),
309 - alarmInfos -> new PageData(alarmInfos, alarms.getTotalPages(), alarms.getTotalElements(), 309 + alarmInfos -> new PageData<>(alarmInfos, alarms.getTotalPages(), alarms.getTotalElements(),
310 alarms.hasNext()), MoreExecutors.directExecutor()); 310 alarms.hasNext()), MoreExecutors.directExecutor());
311 } 311 }
312 return Futures.immediateFuture(alarms); 312 return Futures.immediateFuture(alarms);
@@ -190,6 +190,7 @@ public class AuditLogServiceImpl implements AuditLogService { @@ -190,6 +190,7 @@ public class AuditLogServiceImpl implements AuditLogService {
190 case ATTRIBUTES_UPDATED: 190 case ATTRIBUTES_UPDATED:
191 actionData.put("entityId", entityId.toString()); 191 actionData.put("entityId", entityId.toString());
192 String scope = extractParameter(String.class, 0, additionalInfo); 192 String scope = extractParameter(String.class, 0, additionalInfo);
  193 + @SuppressWarnings("unchecked")
193 List<AttributeKvEntry> attributes = extractParameter(List.class, 1, additionalInfo); 194 List<AttributeKvEntry> attributes = extractParameter(List.class, 1, additionalInfo);
194 actionData.put("scope", scope); 195 actionData.put("scope", scope);
195 ObjectNode attrsNode = JacksonUtil.newObjectNode(); 196 ObjectNode attrsNode = JacksonUtil.newObjectNode();
@@ -205,6 +206,7 @@ public class AuditLogServiceImpl implements AuditLogService { @@ -205,6 +206,7 @@ public class AuditLogServiceImpl implements AuditLogService {
205 actionData.put("entityId", entityId.toString()); 206 actionData.put("entityId", entityId.toString());
206 scope = extractParameter(String.class, 0, additionalInfo); 207 scope = extractParameter(String.class, 0, additionalInfo);
207 actionData.put("scope", scope); 208 actionData.put("scope", scope);
  209 + @SuppressWarnings("unchecked")
208 List<String> keys = extractParameter(List.class, 1, additionalInfo); 210 List<String> keys = extractParameter(List.class, 1, additionalInfo);
209 ArrayNode attrsArrayNode = actionData.putArray("attributes"); 211 ArrayNode attrsArrayNode = actionData.putArray("attributes");
210 if (keys != null) { 212 if (keys != null) {
@@ -267,6 +269,7 @@ public class AuditLogServiceImpl implements AuditLogService { @@ -267,6 +269,7 @@ public class AuditLogServiceImpl implements AuditLogService {
267 break; 269 break;
268 case TIMESERIES_UPDATED: 270 case TIMESERIES_UPDATED:
269 actionData.put("entityId", entityId.toString()); 271 actionData.put("entityId", entityId.toString());
  272 + @SuppressWarnings("unchecked")
270 List<TsKvEntry> updatedTimeseries = extractParameter(List.class, 0, additionalInfo); 273 List<TsKvEntry> updatedTimeseries = extractParameter(List.class, 0, additionalInfo);
271 if (updatedTimeseries != null) { 274 if (updatedTimeseries != null) {
272 ArrayNode result = actionData.putArray("timeseries"); 275 ArrayNode result = actionData.putArray("timeseries");
@@ -283,6 +286,7 @@ public class AuditLogServiceImpl implements AuditLogService { @@ -283,6 +286,7 @@ public class AuditLogServiceImpl implements AuditLogService {
283 break; 286 break;
284 case TIMESERIES_DELETED: 287 case TIMESERIES_DELETED:
285 actionData.put("entityId", entityId.toString()); 288 actionData.put("entityId", entityId.toString());
  289 + @SuppressWarnings("unchecked")
286 List<String> timeseriesKeys = extractParameter(List.class, 0, additionalInfo); 290 List<String> timeseriesKeys = extractParameter(List.class, 0, additionalInfo);
287 if (timeseriesKeys != null) { 291 if (timeseriesKeys != null) {
288 ArrayNode timeseriesArrayNode = actionData.putArray("timeseries"); 292 ArrayNode timeseriesArrayNode = actionData.putArray("timeseries");
@@ -36,22 +36,22 @@ public class DummyAuditLogServiceImpl implements AuditLogService { @@ -36,22 +36,22 @@ public class DummyAuditLogServiceImpl implements AuditLogService {
36 36
37 @Override 37 @Override
38 public PageData<AuditLog> findAuditLogsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, List<ActionType> actionTypes, TimePageLink pageLink) { 38 public PageData<AuditLog> findAuditLogsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, List<ActionType> actionTypes, TimePageLink pageLink) {
39 - return new PageData(); 39 + return new PageData<>();
40 } 40 }
41 41
42 @Override 42 @Override
43 public PageData<AuditLog> findAuditLogsByTenantIdAndUserId(TenantId tenantId, UserId userId, List<ActionType> actionTypes, TimePageLink pageLink) { 43 public PageData<AuditLog> findAuditLogsByTenantIdAndUserId(TenantId tenantId, UserId userId, List<ActionType> actionTypes, TimePageLink pageLink) {
44 - return new PageData(); 44 + return new PageData<>();
45 } 45 }
46 46
47 @Override 47 @Override
48 public PageData<AuditLog> findAuditLogsByTenantIdAndEntityId(TenantId tenantId, EntityId entityId, List<ActionType> actionTypes, TimePageLink pageLink) { 48 public PageData<AuditLog> findAuditLogsByTenantIdAndEntityId(TenantId tenantId, EntityId entityId, List<ActionType> actionTypes, TimePageLink pageLink) {
49 - return new PageData(); 49 + return new PageData<>();
50 } 50 }
51 51
52 @Override 52 @Override
53 public PageData<AuditLog> findAuditLogsByTenantId(TenantId tenantId, List<ActionType> actionTypes, TimePageLink pageLink) { 53 public PageData<AuditLog> findAuditLogsByTenantId(TenantId tenantId, List<ActionType> actionTypes, TimePageLink pageLink) {
54 - return new PageData(); 54 + return new PageData<>();
55 } 55 }
56 56
57 @Override 57 @Override
@@ -232,6 +232,8 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -232,6 +232,8 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
232 } catch (Exception t) { 232 } catch (Exception t) {
233 ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); 233 ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
234 if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_name_unq_key")) { 234 if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_name_unq_key")) {
  235 + // remove device from cache in case null value cached in the distributed redis.
  236 + removeDeviceFromCache(device.getTenantId(), device.getName());
235 throw new DataValidationException("Device with such name already exists!"); 237 throw new DataValidationException("Device with such name already exists!");
236 } else { 238 } else {
237 throw t; 239 throw t;
@@ -302,13 +304,17 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -302,13 +304,17 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
302 } 304 }
303 deleteEntityRelations(tenantId, deviceId); 305 deleteEntityRelations(tenantId, deviceId);
304 306
  307 + removeDeviceFromCache(tenantId, device.getName());
  308 +
  309 + deviceDao.removeById(tenantId, deviceId.getId());
  310 + }
  311 +
  312 + private void removeDeviceFromCache(TenantId tenantId, String name) {
305 List<Object> list = new ArrayList<>(); 313 List<Object> list = new ArrayList<>();
306 - list.add(device.getTenantId());  
307 - list.add(device.getName()); 314 + list.add(tenantId);
  315 + list.add(name);
308 Cache cache = cacheManager.getCache(DEVICE_CACHE); 316 Cache cache = cacheManager.getCache(DEVICE_CACHE);
309 cache.evict(list); 317 cache.evict(list);
310 -  
311 - deviceDao.removeById(tenantId, deviceId.getId());  
312 } 318 }
313 319
314 @Override 320 @Override
@@ -275,6 +275,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti @@ -275,6 +275,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
275 tenantIdAndEntityId.add(entityId); 275 tenantIdAndEntityId.add(entityId);
276 276
277 Cache cache = cacheManager.getCache(ENTITY_VIEW_CACHE); 277 Cache cache = cacheManager.getCache(ENTITY_VIEW_CACHE);
  278 + @SuppressWarnings("unchecked")
278 List<EntityView> fromCache = cache.get(tenantIdAndEntityId, List.class); 279 List<EntityView> fromCache = cache.get(tenantIdAndEntityId, List.class);
279 if (fromCache != null) { 280 if (fromCache != null) {
280 return Futures.immediateFuture(fromCache); 281 return Futures.immediateFuture(fromCache);
@@ -53,7 +53,7 @@ public class HybridClientRegistrationRepository implements ClientRegistrationRep @@ -53,7 +53,7 @@ public class HybridClientRegistrationRepository implements ClientRegistrationRep
53 .userNameAttributeName(localClientRegistration.getUserNameAttributeName()) 53 .userNameAttributeName(localClientRegistration.getUserNameAttributeName())
54 .jwkSetUri(localClientRegistration.getJwkSetUri()) 54 .jwkSetUri(localClientRegistration.getJwkSetUri())
55 .clientAuthenticationMethod(new ClientAuthenticationMethod(localClientRegistration.getClientAuthenticationMethod())) 55 .clientAuthenticationMethod(new ClientAuthenticationMethod(localClientRegistration.getClientAuthenticationMethod()))
56 - .redirectUriTemplate(defaultRedirectUriTemplate) 56 + .redirectUri(defaultRedirectUriTemplate)
57 .build(); 57 .build();
58 } 58 }
59 } 59 }
@@ -301,6 +301,7 @@ public class BaseRelationService implements RelationService { @@ -301,6 +301,7 @@ public class BaseRelationService implements RelationService {
301 fromAndTypeGroup.add(EntitySearchDirection.FROM.name()); 301 fromAndTypeGroup.add(EntitySearchDirection.FROM.name());
302 302
303 Cache cache = cacheManager.getCache(RELATIONS_CACHE); 303 Cache cache = cacheManager.getCache(RELATIONS_CACHE);
  304 + @SuppressWarnings("unchecked")
304 List<EntityRelation> fromCache = cache.get(fromAndTypeGroup, List.class); 305 List<EntityRelation> fromCache = cache.get(fromAndTypeGroup, List.class);
305 if (fromCache != null) { 306 if (fromCache != null) {
306 return Futures.immediateFuture(fromCache); 307 return Futures.immediateFuture(fromCache);
@@ -382,6 +383,7 @@ public class BaseRelationService implements RelationService { @@ -382,6 +383,7 @@ public class BaseRelationService implements RelationService {
382 toAndTypeGroup.add(EntitySearchDirection.TO.name()); 383 toAndTypeGroup.add(EntitySearchDirection.TO.name());
383 384
384 Cache cache = cacheManager.getCache(RELATIONS_CACHE); 385 Cache cache = cacheManager.getCache(RELATIONS_CACHE);
  386 + @SuppressWarnings("unchecked")
385 List<EntityRelation> fromCache = cache.get(toAndTypeGroup, List.class); 387 List<EntityRelation> fromCache = cache.get(toAndTypeGroup, List.class);
386 if (fromCache != null) { 388 if (fromCache != null) {
387 return Futures.immediateFuture(fromCache); 389 return Futures.immediateFuture(fromCache);
@@ -45,12 +45,12 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE @@ -45,12 +45,12 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE
45 private DashboardInfoRepository dashboardInfoRepository; 45 private DashboardInfoRepository dashboardInfoRepository;
46 46
47 @Override 47 @Override
48 - protected Class getEntityClass() { 48 + protected Class<DashboardInfoEntity> getEntityClass() {
49 return DashboardInfoEntity.class; 49 return DashboardInfoEntity.class;
50 } 50 }
51 51
52 @Override 52 @Override
53 - protected CrudRepository getCrudRepository() { 53 + protected CrudRepository<DashboardInfoEntity, UUID> getCrudRepository() {
54 return dashboardInfoRepository; 54 return dashboardInfoRepository;
55 } 55 }
56 56
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.device; 16 package org.thingsboard.server.dao.sql.device;
17 17
18 -import org.apache.commons.lang.StringUtils; 18 +import org.apache.commons.lang3.StringUtils;
19 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.data.repository.CrudRepository; 20 import org.springframework.data.repository.CrudRepository;
21 import org.springframework.stereotype.Component; 21 import org.springframework.stereotype.Component;
@@ -49,7 +49,7 @@ public interface RelationRepository @@ -49,7 +49,7 @@ public interface RelationRepository
49 String fromType); 49 String fromType);
50 50
51 @Transactional 51 @Transactional
52 - RelationEntity save(RelationEntity entity); 52 + <S extends RelationEntity> S save(S entity);
53 53
54 @Transactional 54 @Transactional
55 void deleteById(RelationCompositeKey id); 55 void deleteById(RelationCompositeKey id);
@@ -39,12 +39,12 @@ public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, R @@ -39,12 +39,12 @@ public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, R
39 private RuleChainRepository ruleChainRepository; 39 private RuleChainRepository ruleChainRepository;
40 40
41 @Override 41 @Override
42 - protected Class getEntityClass() { 42 + protected Class<RuleChainEntity> getEntityClass() {
43 return RuleChainEntity.class; 43 return RuleChainEntity.class;
44 } 44 }
45 45
46 @Override 46 @Override
47 - protected CrudRepository getCrudRepository() { 47 + protected CrudRepository<RuleChainEntity, UUID> getCrudRepository() {
48 return ruleChainRepository; 48 return ruleChainRepository;
49 } 49 }
50 50
@@ -24,6 +24,8 @@ import org.thingsboard.server.dao.model.sql.RuleNodeEntity; @@ -24,6 +24,8 @@ import org.thingsboard.server.dao.model.sql.RuleNodeEntity;
24 import org.thingsboard.server.dao.rule.RuleNodeDao; 24 import org.thingsboard.server.dao.rule.RuleNodeDao;
25 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; 25 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
26 26
  27 +import java.util.UUID;
  28 +
27 @Slf4j 29 @Slf4j
28 @Component 30 @Component
29 public class JpaRuleNodeDao extends JpaAbstractSearchTextDao<RuleNodeEntity, RuleNode> implements RuleNodeDao { 31 public class JpaRuleNodeDao extends JpaAbstractSearchTextDao<RuleNodeEntity, RuleNode> implements RuleNodeDao {
@@ -32,12 +34,12 @@ public class JpaRuleNodeDao extends JpaAbstractSearchTextDao<RuleNodeEntity, Rul @@ -32,12 +34,12 @@ public class JpaRuleNodeDao extends JpaAbstractSearchTextDao<RuleNodeEntity, Rul
32 private RuleNodeRepository ruleNodeRepository; 34 private RuleNodeRepository ruleNodeRepository;
33 35
34 @Override 36 @Override
35 - protected Class getEntityClass() { 37 + protected Class<RuleNodeEntity> getEntityClass() {
36 return RuleNodeEntity.class; 38 return RuleNodeEntity.class;
37 } 39 }
38 40
39 @Override 41 @Override
40 - protected CrudRepository getCrudRepository() { 42 + protected CrudRepository<RuleNodeEntity, UUID> getCrudRepository() {
41 return ruleNodeRepository; 43 return ruleNodeRepository;
42 } 44 }
43 45
@@ -39,12 +39,12 @@ public class JpaRuleNodeStateDao extends JpaAbstractDao<RuleNodeStateEntity, Rul @@ -39,12 +39,12 @@ public class JpaRuleNodeStateDao extends JpaAbstractDao<RuleNodeStateEntity, Rul
39 private RuleNodeStateRepository ruleNodeStateRepository; 39 private RuleNodeStateRepository ruleNodeStateRepository;
40 40
41 @Override 41 @Override
42 - protected Class getEntityClass() { 42 + protected Class<RuleNodeStateEntity> getEntityClass() {
43 return RuleNodeStateEntity.class; 43 return RuleNodeStateEntity.class;
44 } 44 }
45 45
46 @Override 46 @Override
47 - protected CrudRepository getCrudRepository() { 47 + protected CrudRepository<RuleNodeStateEntity, UUID> getCrudRepository() {
48 return ruleNodeStateRepository; 48 return ruleNodeStateRepository;
49 } 49 }
50 50
@@ -18,6 +18,8 @@ package org.thingsboard.server.dao.sql.rule; @@ -18,6 +18,8 @@ package org.thingsboard.server.dao.sql.rule;
18 import org.springframework.data.repository.CrudRepository; 18 import org.springframework.data.repository.CrudRepository;
19 import org.thingsboard.server.dao.model.sql.RuleNodeEntity; 19 import org.thingsboard.server.dao.model.sql.RuleNodeEntity;
20 20
21 -public interface RuleNodeRepository extends CrudRepository<RuleNodeEntity, String> { 21 +import java.util.UUID;
  22 +
  23 +public interface RuleNodeRepository extends CrudRepository<RuleNodeEntity, UUID> {
22 24
23 } 25 }
@@ -32,6 +32,7 @@ import lombok.extern.slf4j.Slf4j; @@ -32,6 +32,7 @@ import lombok.extern.slf4j.Slf4j;
32 import org.springframework.beans.factory.annotation.Autowired; 32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.beans.factory.annotation.Value; 33 import org.springframework.beans.factory.annotation.Value;
34 import org.springframework.core.env.Environment; 34 import org.springframework.core.env.Environment;
  35 +import org.springframework.core.env.Profiles;
35 import org.springframework.stereotype.Component; 36 import org.springframework.stereotype.Component;
36 import org.thingsboard.server.common.data.id.EntityId; 37 import org.thingsboard.server.common.data.id.EntityId;
37 import org.thingsboard.server.common.data.id.TenantId; 38 import org.thingsboard.server.common.data.id.TenantId;
@@ -108,7 +109,7 @@ public class CassandraBaseTimeseriesDao extends AbstractCassandraBaseTimeseriesD @@ -108,7 +109,7 @@ public class CassandraBaseTimeseriesDao extends AbstractCassandraBaseTimeseriesD
108 private PreparedStatement deletePartitionStmt; 109 private PreparedStatement deletePartitionStmt;
109 110
110 private boolean isInstall() { 111 private boolean isInstall() {
111 - return environment.acceptsProfiles("install"); 112 + return environment.acceptsProfiles(Profiles.of("install"));
112 } 113 }
113 114
114 @PostConstruct 115 @PostConstruct
@@ -15,8 +15,8 @@ @@ -15,8 +15,8 @@
15 */ 15 */
16 package org.thingsboard.server.dao.user; 16 package org.thingsboard.server.dao.user;
17 17
  18 +import com.fasterxml.jackson.core.type.TypeReference;
18 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
19 -import com.fasterxml.jackson.databind.ObjectMapper;  
20 import com.fasterxml.jackson.databind.node.ObjectNode; 20 import com.fasterxml.jackson.databind.node.ObjectNode;
21 import com.google.common.util.concurrent.ListenableFuture; 21 import com.google.common.util.concurrent.ListenableFuture;
22 import lombok.extern.slf4j.Slf4j; 22 import lombok.extern.slf4j.Slf4j;
@@ -48,6 +48,7 @@ import org.thingsboard.server.dao.service.DataValidator; @@ -48,6 +48,7 @@ import org.thingsboard.server.dao.service.DataValidator;
48 import org.thingsboard.server.dao.service.PaginatedRemover; 48 import org.thingsboard.server.dao.service.PaginatedRemover;
49 import org.thingsboard.server.dao.tenant.TbTenantProfileCache; 49 import org.thingsboard.server.dao.tenant.TbTenantProfileCache;
50 import org.thingsboard.server.dao.tenant.TenantDao; 50 import org.thingsboard.server.dao.tenant.TenantDao;
  51 +import org.thingsboard.server.dao.util.mapping.JacksonUtil;
51 52
52 import java.util.HashMap; 53 import java.util.HashMap;
53 import java.util.Map; 54 import java.util.Map;
@@ -71,8 +72,6 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic @@ -71,8 +72,6 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
71 72
72 private static final String USER_CREDENTIALS_ENABLED = "userCredentialsEnabled"; 73 private static final String USER_CREDENTIALS_ENABLED = "userCredentialsEnabled";
73 74
74 - private static final ObjectMapper objectMapper = new ObjectMapper();  
75 -  
76 @Value("${security.user_login_case_sensitive:true}") 75 @Value("${security.user_login_case_sensitive:true}")
77 private boolean userLoginCaseSensitive; 76 private boolean userLoginCaseSensitive;
78 77
@@ -279,7 +278,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic @@ -279,7 +278,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
279 User user = findUserById(tenantId, userId); 278 User user = findUserById(tenantId, userId);
280 JsonNode additionalInfo = user.getAdditionalInfo(); 279 JsonNode additionalInfo = user.getAdditionalInfo();
281 if (!(additionalInfo instanceof ObjectNode)) { 280 if (!(additionalInfo instanceof ObjectNode)) {
282 - additionalInfo = objectMapper.createObjectNode(); 281 + additionalInfo = JacksonUtil.newObjectNode();
283 } 282 }
284 ((ObjectNode) additionalInfo).put(USER_CREDENTIALS_ENABLED, enabled); 283 ((ObjectNode) additionalInfo).put(USER_CREDENTIALS_ENABLED, enabled);
285 user.setAdditionalInfo(additionalInfo); 284 user.setAdditionalInfo(additionalInfo);
@@ -302,7 +301,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic @@ -302,7 +301,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
302 private void setLastLoginTs(User user) { 301 private void setLastLoginTs(User user) {
303 JsonNode additionalInfo = user.getAdditionalInfo(); 302 JsonNode additionalInfo = user.getAdditionalInfo();
304 if (!(additionalInfo instanceof ObjectNode)) { 303 if (!(additionalInfo instanceof ObjectNode)) {
305 - additionalInfo = objectMapper.createObjectNode(); 304 + additionalInfo = JacksonUtil.newObjectNode();
306 } 305 }
307 ((ObjectNode) additionalInfo).put(LAST_LOGIN_TS, System.currentTimeMillis()); 306 ((ObjectNode) additionalInfo).put(LAST_LOGIN_TS, System.currentTimeMillis());
308 user.setAdditionalInfo(additionalInfo); 307 user.setAdditionalInfo(additionalInfo);
@@ -311,7 +310,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic @@ -311,7 +310,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
311 private void resetFailedLoginAttempts(User user) { 310 private void resetFailedLoginAttempts(User user) {
312 JsonNode additionalInfo = user.getAdditionalInfo(); 311 JsonNode additionalInfo = user.getAdditionalInfo();
313 if (!(additionalInfo instanceof ObjectNode)) { 312 if (!(additionalInfo instanceof ObjectNode)) {
314 - additionalInfo = objectMapper.createObjectNode(); 313 + additionalInfo = JacksonUtil.newObjectNode();
315 } 314 }
316 ((ObjectNode) additionalInfo).put(FAILED_LOGIN_ATTEMPTS, 0); 315 ((ObjectNode) additionalInfo).put(FAILED_LOGIN_ATTEMPTS, 0);
317 user.setAdditionalInfo(additionalInfo); 316 user.setAdditionalInfo(additionalInfo);
@@ -329,7 +328,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic @@ -329,7 +328,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
329 private int increaseFailedLoginAttempts(User user) { 328 private int increaseFailedLoginAttempts(User user) {
330 JsonNode additionalInfo = user.getAdditionalInfo(); 329 JsonNode additionalInfo = user.getAdditionalInfo();
331 if (!(additionalInfo instanceof ObjectNode)) { 330 if (!(additionalInfo instanceof ObjectNode)) {
332 - additionalInfo = objectMapper.createObjectNode(); 331 + additionalInfo = JacksonUtil.newObjectNode();
333 } 332 }
334 int failedLoginAttempts = 0; 333 int failedLoginAttempts = 0;
335 if (additionalInfo.has(FAILED_LOGIN_ATTEMPTS)) { 334 if (additionalInfo.has(FAILED_LOGIN_ATTEMPTS)) {
@@ -353,26 +352,30 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic @@ -353,26 +352,30 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
353 private void updatePasswordHistory(User user, UserCredentials userCredentials) { 352 private void updatePasswordHistory(User user, UserCredentials userCredentials) {
354 JsonNode additionalInfo = user.getAdditionalInfo(); 353 JsonNode additionalInfo = user.getAdditionalInfo();
355 if (!(additionalInfo instanceof ObjectNode)) { 354 if (!(additionalInfo instanceof ObjectNode)) {
356 - additionalInfo = objectMapper.createObjectNode(); 355 + additionalInfo = JacksonUtil.newObjectNode();
357 } 356 }
  357 + Map<String, String> userPasswordHistoryMap = null;
  358 + JsonNode userPasswordHistoryJson;
358 if (additionalInfo.has(USER_PASSWORD_HISTORY)) { 359 if (additionalInfo.has(USER_PASSWORD_HISTORY)) {
359 - JsonNode userPasswordHistoryJson = additionalInfo.get(USER_PASSWORD_HISTORY);  
360 - Map<String, String> userPasswordHistoryMap = objectMapper.convertValue(userPasswordHistoryJson, Map.class); 360 + userPasswordHistoryJson = additionalInfo.get(USER_PASSWORD_HISTORY);
  361 + userPasswordHistoryMap = JacksonUtil.convertValue(userPasswordHistoryJson, new TypeReference<>(){});
  362 + }
  363 + if (userPasswordHistoryMap != null) {
361 userPasswordHistoryMap.put(Long.toString(System.currentTimeMillis()), userCredentials.getPassword()); 364 userPasswordHistoryMap.put(Long.toString(System.currentTimeMillis()), userCredentials.getPassword());
362 - userPasswordHistoryJson = objectMapper.valueToTree(userPasswordHistoryMap); 365 + userPasswordHistoryJson = JacksonUtil.valueToTree(userPasswordHistoryMap);
363 ((ObjectNode) additionalInfo).replace(USER_PASSWORD_HISTORY, userPasswordHistoryJson); 366 ((ObjectNode) additionalInfo).replace(USER_PASSWORD_HISTORY, userPasswordHistoryJson);
364 } else { 367 } else {
365 - Map<String, String> userPasswordHistoryMap = new HashMap<>(); 368 + userPasswordHistoryMap = new HashMap<>();
366 userPasswordHistoryMap.put(Long.toString(System.currentTimeMillis()), userCredentials.getPassword()); 369 userPasswordHistoryMap.put(Long.toString(System.currentTimeMillis()), userCredentials.getPassword());
367 - JsonNode userPasswordHistoryJson = objectMapper.valueToTree(userPasswordHistoryMap); 370 + userPasswordHistoryJson = JacksonUtil.valueToTree(userPasswordHistoryMap);
368 ((ObjectNode) additionalInfo).set(USER_PASSWORD_HISTORY, userPasswordHistoryJson); 371 ((ObjectNode) additionalInfo).set(USER_PASSWORD_HISTORY, userPasswordHistoryJson);
369 } 372 }
370 user.setAdditionalInfo(additionalInfo); 373 user.setAdditionalInfo(additionalInfo);
371 saveUser(user); 374 saveUser(user);
372 } 375 }
373 376
374 - private DataValidator<User> userValidator =  
375 - new DataValidator<User>() { 377 + private final DataValidator<User> userValidator =
  378 + new DataValidator<>() {
376 @Override 379 @Override
377 protected void validateCreate(TenantId tenantId, User user) { 380 protected void validateCreate(TenantId tenantId, User user) {
378 if (!user.getTenantId().getId().equals(ModelConstants.NULL_UUID)) { 381 if (!user.getTenantId().getId().equals(ModelConstants.NULL_UUID)) {
@@ -452,8 +455,8 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic @@ -452,8 +455,8 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
452 } 455 }
453 }; 456 };
454 457
455 - private DataValidator<UserCredentials> userCredentialsValidator =  
456 - new DataValidator<UserCredentials>() { 458 + private final DataValidator<UserCredentials> userCredentialsValidator =
  459 + new DataValidator<>() {
457 460
458 @Override 461 @Override
459 protected void validateCreate(TenantId tenantId, UserCredentials userCredentials) { 462 protected void validateCreate(TenantId tenantId, UserCredentials userCredentials) {
@@ -484,7 +487,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic @@ -484,7 +487,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
484 } 487 }
485 }; 488 };
486 489
487 - private PaginatedRemover<TenantId, User> tenantAdminsRemover = new PaginatedRemover<TenantId, User>() { 490 + private final PaginatedRemover<TenantId, User> tenantAdminsRemover = new PaginatedRemover<>() {
488 @Override 491 @Override
489 protected PageData<User> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) { 492 protected PageData<User> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) {
490 return userDao.findTenantAdmins(id.getId(), pageLink); 493 return userDao.findTenantAdmins(id.getId(), pageLink);
@@ -496,7 +499,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic @@ -496,7 +499,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
496 } 499 }
497 }; 500 };
498 501
499 - private PaginatedRemover<CustomerId, User> customerUsersRemover = new PaginatedRemover<CustomerId, User>() { 502 + private final PaginatedRemover<CustomerId, User> customerUsersRemover = new PaginatedRemover<>() {
500 @Override 503 @Override
501 protected PageData<User> findEntities(TenantId tenantId, CustomerId id, PageLink pageLink) { 504 protected PageData<User> findEntities(TenantId tenantId, CustomerId id, PageLink pageLink) {
502 return userDao.findCustomerUsers(tenantId.getId(), id.getId(), pageLink); 505 return userDao.findCustomerUsers(tenantId.getId(), id.getId(), pageLink);
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 package org.thingsboard.server.dao.util.mapping; 16 package org.thingsboard.server.dao.util.mapping;
17 17
18 import com.fasterxml.jackson.core.JsonProcessingException; 18 import com.fasterxml.jackson.core.JsonProcessingException;
  19 +import com.fasterxml.jackson.core.type.TypeReference;
19 import com.fasterxml.jackson.databind.JsonNode; 20 import com.fasterxml.jackson.databind.JsonNode;
20 import com.fasterxml.jackson.databind.ObjectMapper; 21 import com.fasterxml.jackson.databind.ObjectMapper;
21 import com.fasterxml.jackson.databind.node.ObjectNode; 22 import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -38,6 +39,15 @@ public class JacksonUtil { @@ -38,6 +39,15 @@ public class JacksonUtil {
38 } 39 }
39 } 40 }
40 41
  42 + public static <T> T convertValue(Object fromValue, TypeReference<T> toValueTypeRef) {
  43 + try {
  44 + return fromValue != null ? OBJECT_MAPPER.convertValue(fromValue, toValueTypeRef) : null;
  45 + } catch (IllegalArgumentException e) {
  46 + throw new IllegalArgumentException("The given object value: "
  47 + + fromValue + " cannot be converted to " + toValueTypeRef, e);
  48 + }
  49 + }
  50 +
41 public static <T> T fromString(String string, Class<T> clazz) { 51 public static <T> T fromString(String string, Class<T> clazz) {
42 try { 52 try {
43 return string != null ? OBJECT_MAPPER.readValue(string, clazz) : null; 53 return string != null ? OBJECT_MAPPER.readValue(string, clazz) : null;
@@ -72,7 +82,9 @@ public class JacksonUtil { @@ -72,7 +82,9 @@ public class JacksonUtil {
72 } 82 }
73 83
74 public static <T> T clone(T value) { 84 public static <T> T clone(T value) {
75 - return fromString(toString(value), (Class<T>) value.getClass()); 85 + @SuppressWarnings("unchecked")
  86 + Class<T> valueClass = (Class<T>) value.getClass();
  87 + return fromString(toString(value), valueClass);
76 } 88 }
77 89
78 public static <T> JsonNode valueToTree(T value) { 90 public static <T> JsonNode valueToTree(T value) {
@@ -244,6 +244,7 @@ public class Descriptor @@ -244,6 +244,7 @@ public class Descriptor
244 * 244 *
245 * @return A Descriptor for the SSTable, and the Component remainder. 245 * @return A Descriptor for the SSTable, and the Component remainder.
246 */ 246 */
  247 + @SuppressWarnings("deprecation")
247 public static Pair<Descriptor, String> fromFilename(File directory, String name, boolean skipComponent) 248 public static Pair<Descriptor, String> fromFilename(File directory, String name, boolean skipComponent)
248 { 249 {
249 File parentDirectory = directory != null ? directory : new File("."); 250 File parentDirectory = directory != null ? directory : new File(".");
@@ -319,6 +320,7 @@ public class Descriptor @@ -319,6 +320,7 @@ public class Descriptor
319 component); 320 component);
320 } 321 }
321 322
  323 + @SuppressWarnings("deprecation")
322 public IMetadataSerializer getMetadataSerializer() 324 public IMetadataSerializer getMetadataSerializer()
323 { 325 {
324 if (version.hasNewStatsFile()) 326 if (version.hasNewStatsFile())
@@ -56,6 +56,7 @@ public interface SSTableFormat @@ -56,6 +56,7 @@ public interface SSTableFormat
56 return BIG; 56 return BIG;
57 } 57 }
58 58
  59 + @SuppressWarnings("deprecation")
59 private Type(String name, SSTableFormat info) 60 private Type(String name, SSTableFormat info)
60 { 61 {
61 //Since format comes right after generation 62 //Since format comes right after generation
  1 +/*
  2 + * Licensed to the Apache Software Foundation (ASF) under one
  3 + * or more contributor license agreements. See the NOTICE file
  4 + * distributed with this work for additional information
  5 + * regarding copyright ownership. The ASF licenses this file
  6 + * to you under the Apache License, Version 2.0 (the
  7 + * "License"); you may not use this file except in compliance
  8 + * with the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + */
  18 +package org.apache.cassandra.io.util;
  19 +
  20 +import java.io.*;
  21 +import java.nio.ByteBuffer;
  22 +import java.nio.channels.FileChannel;
  23 +import java.nio.charset.Charset;
  24 +import java.nio.charset.StandardCharsets;
  25 +import java.nio.file.*;
  26 +import java.nio.file.attribute.BasicFileAttributes;
  27 +import java.nio.file.attribute.FileAttributeView;
  28 +import java.nio.file.attribute.FileStoreAttributeView;
  29 +import java.text.DecimalFormat;
  30 +import java.util.Arrays;
  31 +import java.util.Collections;
  32 +import java.util.List;
  33 +import java.util.Optional;
  34 +import java.util.concurrent.atomic.AtomicReference;
  35 +import java.util.function.Consumer;
  36 +import java.util.function.Predicate;
  37 +import java.util.stream.StreamSupport;
  38 +
  39 +import org.slf4j.Logger;
  40 +import org.slf4j.LoggerFactory;
  41 +
  42 +import org.apache.cassandra.concurrent.ScheduledExecutors;
  43 +import org.apache.cassandra.io.FSError;
  44 +import org.apache.cassandra.io.FSErrorHandler;
  45 +import org.apache.cassandra.io.FSReadError;
  46 +import org.apache.cassandra.io.FSWriteError;
  47 +import org.apache.cassandra.io.sstable.CorruptSSTableException;
  48 +import org.apache.cassandra.utils.JVMStabilityInspector;
  49 +
  50 +import static com.google.common.base.Throwables.throwIfUnchecked;
  51 +import static org.apache.cassandra.utils.Throwables.maybeFail;
  52 +import static org.apache.cassandra.utils.Throwables.merge;
  53 +
  54 +public final class FileUtils
  55 +{
  56 + public static final Charset CHARSET = StandardCharsets.UTF_8;
  57 +
  58 + private static final Logger logger = LoggerFactory.getLogger(FileUtils.class);
  59 + public static final long ONE_KB = 1024;
  60 + public static final long ONE_MB = 1024 * ONE_KB;
  61 + public static final long ONE_GB = 1024 * ONE_MB;
  62 + public static final long ONE_TB = 1024 * ONE_GB;
  63 +
  64 + private static final DecimalFormat df = new DecimalFormat("#.##");
  65 + public static final boolean isCleanerAvailable = false;
  66 + private static final AtomicReference<Optional<FSErrorHandler>> fsErrorHandler = new AtomicReference<>(Optional.empty());
  67 +
  68 + public static void createHardLink(String from, String to)
  69 + {
  70 + createHardLink(new File(from), new File(to));
  71 + }
  72 +
  73 + public static void createHardLink(File from, File to)
  74 + {
  75 + if (to.exists())
  76 + throw new RuntimeException("Tried to create duplicate hard link to " + to);
  77 + if (!from.exists())
  78 + throw new RuntimeException("Tried to hard link to file that does not exist " + from);
  79 +
  80 + try
  81 + {
  82 + Files.createLink(to.toPath(), from.toPath());
  83 + }
  84 + catch (IOException e)
  85 + {
  86 + throw new FSWriteError(e, to);
  87 + }
  88 + }
  89 +
  90 + public static File createTempFile(String prefix, String suffix, File directory)
  91 + {
  92 + try
  93 + {
  94 + return File.createTempFile(prefix, suffix, directory);
  95 + }
  96 + catch (IOException e)
  97 + {
  98 + throw new FSWriteError(e, directory);
  99 + }
  100 + }
  101 +
  102 + public static File createTempFile(String prefix, String suffix)
  103 + {
  104 + return createTempFile(prefix, suffix, new File(System.getProperty("java.io.tmpdir")));
  105 + }
  106 +
  107 + public static Throwable deleteWithConfirm(String filePath, boolean expect, Throwable accumulate)
  108 + {
  109 + return deleteWithConfirm(new File(filePath), expect, accumulate);
  110 + }
  111 +
  112 + public static Throwable deleteWithConfirm(File file, boolean expect, Throwable accumulate)
  113 + {
  114 + boolean exists = file.exists();
  115 + assert exists || !expect : "attempted to delete non-existing file " + file.getName();
  116 + try
  117 + {
  118 + if (exists)
  119 + Files.delete(file.toPath());
  120 + }
  121 + catch (Throwable t)
  122 + {
  123 + try
  124 + {
  125 + throw new FSWriteError(t, file);
  126 + }
  127 + catch (Throwable t2)
  128 + {
  129 + accumulate = merge(accumulate, t2);
  130 + }
  131 + }
  132 + return accumulate;
  133 + }
  134 +
  135 + public static void deleteWithConfirm(String file)
  136 + {
  137 + deleteWithConfirm(new File(file));
  138 + }
  139 +
  140 + public static void deleteWithConfirm(File file)
  141 + {
  142 + maybeFail(deleteWithConfirm(file, true, null));
  143 + }
  144 +
  145 + public static void renameWithOutConfirm(String from, String to)
  146 + {
  147 + try
  148 + {
  149 + atomicMoveWithFallback(new File(from).toPath(), new File(to).toPath());
  150 + }
  151 + catch (IOException e)
  152 + {
  153 + if (logger.isTraceEnabled())
  154 + logger.trace("Could not move file "+from+" to "+to, e);
  155 + }
  156 + }
  157 +
  158 + public static void renameWithConfirm(String from, String to)
  159 + {
  160 + renameWithConfirm(new File(from), new File(to));
  161 + }
  162 +
  163 + public static void renameWithConfirm(File from, File to)
  164 + {
  165 + assert from.exists();
  166 + if (logger.isTraceEnabled())
  167 + logger.trace("Renaming {} to {}", from.getPath(), to.getPath());
  168 + // this is not FSWE because usually when we see it it's because we didn't close the file before renaming it,
  169 + // and Windows is picky about that.
  170 + try
  171 + {
  172 + atomicMoveWithFallback(from.toPath(), to.toPath());
  173 + }
  174 + catch (IOException e)
  175 + {
  176 + throw new RuntimeException(String.format("Failed to rename %s to %s", from.getPath(), to.getPath()), e);
  177 + }
  178 + }
  179 +
  180 + /**
  181 + * Move a file atomically, if it fails, it falls back to a non-atomic operation
  182 + * @param from
  183 + * @param to
  184 + * @throws IOException
  185 + */
  186 + private static void atomicMoveWithFallback(Path from, Path to) throws IOException
  187 + {
  188 + try
  189 + {
  190 + Files.move(from, to, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
  191 + }
  192 + catch (AtomicMoveNotSupportedException e)
  193 + {
  194 + logger.trace("Could not do an atomic move", e);
  195 + Files.move(from, to, StandardCopyOption.REPLACE_EXISTING);
  196 + }
  197 +
  198 + }
  199 + public static void truncate(String path, long size)
  200 + {
  201 + try(FileChannel channel = FileChannel.open(Paths.get(path), StandardOpenOption.READ, StandardOpenOption.WRITE))
  202 + {
  203 + channel.truncate(size);
  204 + }
  205 + catch (IOException e)
  206 + {
  207 + throw new RuntimeException(e);
  208 + }
  209 + }
  210 +
  211 + public static void closeQuietly(Closeable c)
  212 + {
  213 + try
  214 + {
  215 + if (c != null)
  216 + c.close();
  217 + }
  218 + catch (Exception e)
  219 + {
  220 + logger.warn("Failed closing {}", c, e);
  221 + }
  222 + }
  223 +
  224 + public static void closeQuietly(AutoCloseable c)
  225 + {
  226 + try
  227 + {
  228 + if (c != null)
  229 + c.close();
  230 + }
  231 + catch (Exception e)
  232 + {
  233 + logger.warn("Failed closing {}", c, e);
  234 + }
  235 + }
  236 +
  237 + public static void close(Closeable... cs) throws IOException
  238 + {
  239 + close(Arrays.asList(cs));
  240 + }
  241 +
  242 + public static void close(Iterable<? extends Closeable> cs) throws IOException
  243 + {
  244 + Throwable e = null;
  245 + for (Closeable c : cs)
  246 + {
  247 + try
  248 + {
  249 + if (c != null)
  250 + c.close();
  251 + }
  252 + catch (Throwable ex)
  253 + {
  254 + if (e == null) e = ex;
  255 + else e.addSuppressed(ex);
  256 + logger.warn("Failed closing stream {}", c, ex);
  257 + }
  258 + }
  259 + maybeFail(e, IOException.class);
  260 + }
  261 +
  262 + public static void closeQuietly(Iterable<? extends AutoCloseable> cs)
  263 + {
  264 + for (AutoCloseable c : cs)
  265 + {
  266 + try
  267 + {
  268 + if (c != null)
  269 + c.close();
  270 + }
  271 + catch (Exception ex)
  272 + {
  273 + logger.warn("Failed closing {}", c, ex);
  274 + }
  275 + }
  276 + }
  277 +
  278 + public static String getCanonicalPath(String filename)
  279 + {
  280 + try
  281 + {
  282 + return new File(filename).getCanonicalPath();
  283 + }
  284 + catch (IOException e)
  285 + {
  286 + throw new FSReadError(e, filename);
  287 + }
  288 + }
  289 +
  290 + public static String getCanonicalPath(File file)
  291 + {
  292 + try
  293 + {
  294 + return file.getCanonicalPath();
  295 + }
  296 + catch (IOException e)
  297 + {
  298 + throw new FSReadError(e, file);
  299 + }
  300 + }
  301 +
  302 + /** Return true if file is contained in folder */
  303 + public static boolean isContained(File folder, File file)
  304 + {
  305 + Path folderPath = Paths.get(getCanonicalPath(folder));
  306 + Path filePath = Paths.get(getCanonicalPath(file));
  307 +
  308 + return filePath.startsWith(folderPath);
  309 + }
  310 +
  311 + /** Convert absolute path into a path relative to the base path */
  312 + public static String getRelativePath(String basePath, String path)
  313 + {
  314 + try
  315 + {
  316 + return Paths.get(basePath).relativize(Paths.get(path)).toString();
  317 + }
  318 + catch(Exception ex)
  319 + {
  320 + String absDataPath = FileUtils.getCanonicalPath(basePath);
  321 + return Paths.get(absDataPath).relativize(Paths.get(path)).toString();
  322 + }
  323 + }
  324 +
  325 + public static void clean(ByteBuffer buffer)
  326 + {
  327 + if (buffer == null)
  328 + return;
  329 + }
  330 +
  331 + public static void createDirectory(String directory)
  332 + {
  333 + createDirectory(new File(directory));
  334 + }
  335 +
  336 + public static void createDirectory(File directory)
  337 + {
  338 + if (!directory.exists())
  339 + {
  340 + if (!directory.mkdirs())
  341 + throw new FSWriteError(new IOException("Failed to mkdirs " + directory), directory);
  342 + }
  343 + }
  344 +
  345 + public static boolean delete(String file)
  346 + {
  347 + File f = new File(file);
  348 + return f.delete();
  349 + }
  350 +
  351 + public static void delete(File... files)
  352 + {
  353 + if (files == null)
  354 + {
  355 + // CASSANDRA-13389: some callers use Files.listFiles() which, on error, silently returns null
  356 + logger.debug("Received null list of files to delete");
  357 + return;
  358 + }
  359 +
  360 + for ( File file : files )
  361 + {
  362 + file.delete();
  363 + }
  364 + }
  365 +
  366 + public static void deleteAsync(final String file)
  367 + {
  368 + Runnable runnable = new Runnable()
  369 + {
  370 + public void run()
  371 + {
  372 + deleteWithConfirm(new File(file));
  373 + }
  374 + };
  375 + ScheduledExecutors.nonPeriodicTasks.execute(runnable);
  376 + }
  377 +
  378 + public static void visitDirectory(Path dir, Predicate<? super File> filter, Consumer<? super File> consumer)
  379 + {
  380 + try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir))
  381 + {
  382 + StreamSupport.stream(stream.spliterator(), false)
  383 + .map(Path::toFile)
  384 + // stream directories are weakly consistent so we always check if the file still exists
  385 + .filter(f -> f.exists() && (filter == null || filter.test(f)))
  386 + .forEach(consumer);
  387 + }
  388 + catch (IOException|DirectoryIteratorException ex)
  389 + {
  390 + logger.error("Failed to list files in {} with exception: {}", dir, ex.getMessage(), ex);
  391 + }
  392 + }
  393 +
  394 + public static String stringifyFileSize(double value)
  395 + {
  396 + double d;
  397 + if ( value >= ONE_TB )
  398 + {
  399 + d = value / ONE_TB;
  400 + String val = df.format(d);
  401 + return val + " TiB";
  402 + }
  403 + else if ( value >= ONE_GB )
  404 + {
  405 + d = value / ONE_GB;
  406 + String val = df.format(d);
  407 + return val + " GiB";
  408 + }
  409 + else if ( value >= ONE_MB )
  410 + {
  411 + d = value / ONE_MB;
  412 + String val = df.format(d);
  413 + return val + " MiB";
  414 + }
  415 + else if ( value >= ONE_KB )
  416 + {
  417 + d = value / ONE_KB;
  418 + String val = df.format(d);
  419 + return val + " KiB";
  420 + }
  421 + else
  422 + {
  423 + String val = df.format(value);
  424 + return val + " bytes";
  425 + }
  426 + }
  427 +
  428 + /**
  429 + * Deletes all files and subdirectories under "dir".
  430 + * @param dir Directory to be deleted
  431 + * @throws FSWriteError if any part of the tree cannot be deleted
  432 + */
  433 + public static void deleteRecursive(File dir)
  434 + {
  435 + if (dir.isDirectory())
  436 + {
  437 + String[] children = dir.list();
  438 + for (String child : children)
  439 + deleteRecursive(new File(dir, child));
  440 + }
  441 +
  442 + // The directory is now empty so now it can be smoked
  443 + deleteWithConfirm(dir);
  444 + }
  445 +
  446 + /**
  447 + * Schedules deletion of all file and subdirectories under "dir" on JVM shutdown.
  448 + * @param dir Directory to be deleted
  449 + */
  450 + public static void deleteRecursiveOnExit(File dir)
  451 + {
  452 + if (dir.isDirectory())
  453 + {
  454 + String[] children = dir.list();
  455 + for (String child : children)
  456 + deleteRecursiveOnExit(new File(dir, child));
  457 + }
  458 +
  459 + logger.trace("Scheduling deferred deletion of file: {}", dir);
  460 + dir.deleteOnExit();
  461 + }
  462 +
  463 + public static void handleCorruptSSTable(CorruptSSTableException e)
  464 + {
  465 + fsErrorHandler.get().ifPresent(handler -> handler.handleCorruptSSTable(e));
  466 + }
  467 +
  468 + public static void handleFSError(FSError e)
  469 + {
  470 + fsErrorHandler.get().ifPresent(handler -> handler.handleFSError(e));
  471 + }
  472 +
  473 + /**
  474 + * handleFSErrorAndPropagate will invoke the disk failure policy error handler,
  475 + * which may or may not stop the daemon or transports. However, if we don't exit,
  476 + * we still want to propagate the exception to the caller in case they have custom
  477 + * exception handling
  478 + *
  479 + * @param e A filesystem error
  480 + */
  481 + public static void handleFSErrorAndPropagate(FSError e)
  482 + {
  483 + JVMStabilityInspector.inspectThrowable(e);
  484 + throwIfUnchecked(e);
  485 + throw new RuntimeException(e);
  486 + }
  487 +
  488 + /**
  489 + * Get the size of a directory in bytes
  490 + * @param folder The directory for which we need size.
  491 + * @return The size of the directory
  492 + */
  493 + public static long folderSize(File folder)
  494 + {
  495 + final long [] sizeArr = {0L};
  496 + try
  497 + {
  498 + Files.walkFileTree(folder.toPath(), new SimpleFileVisitor<Path>()
  499 + {
  500 + @Override
  501 + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
  502 + {
  503 + sizeArr[0] += attrs.size();
  504 + return FileVisitResult.CONTINUE;
  505 + }
  506 + });
  507 + }
  508 + catch (IOException e)
  509 + {
  510 + logger.error("Error while getting {} folder size. {}", folder, e);
  511 + }
  512 + return sizeArr[0];
  513 + }
  514 +
  515 + public static void copyTo(DataInput in, OutputStream out, int length) throws IOException
  516 + {
  517 + byte[] buffer = new byte[64 * 1024];
  518 + int copiedBytes = 0;
  519 +
  520 + while (copiedBytes + buffer.length < length)
  521 + {
  522 + in.readFully(buffer);
  523 + out.write(buffer);
  524 + copiedBytes += buffer.length;
  525 + }
  526 +
  527 + if (copiedBytes < length)
  528 + {
  529 + int left = length - copiedBytes;
  530 + in.readFully(buffer, 0, left);
  531 + out.write(buffer, 0, left);
  532 + }
  533 + }
  534 +
  535 + public static boolean isSubDirectory(File parent, File child) throws IOException
  536 + {
  537 + parent = parent.getCanonicalFile();
  538 + child = child.getCanonicalFile();
  539 +
  540 + File toCheck = child;
  541 + while (toCheck != null)
  542 + {
  543 + if (parent.equals(toCheck))
  544 + return true;
  545 + toCheck = toCheck.getParentFile();
  546 + }
  547 + return false;
  548 + }
  549 +
  550 + public static void append(File file, String ... lines)
  551 + {
  552 + if (file.exists())
  553 + write(file, Arrays.asList(lines), StandardOpenOption.APPEND);
  554 + else
  555 + write(file, Arrays.asList(lines), StandardOpenOption.CREATE);
  556 + }
  557 +
  558 + public static void appendAndSync(File file, String ... lines)
  559 + {
  560 + if (file.exists())
  561 + write(file, Arrays.asList(lines), StandardOpenOption.APPEND, StandardOpenOption.SYNC);
  562 + else
  563 + write(file, Arrays.asList(lines), StandardOpenOption.CREATE, StandardOpenOption.SYNC);
  564 + }
  565 +
  566 + public static void replace(File file, String ... lines)
  567 + {
  568 + write(file, Arrays.asList(lines), StandardOpenOption.TRUNCATE_EXISTING);
  569 + }
  570 +
  571 + public static void write(File file, List<String> lines, StandardOpenOption ... options)
  572 + {
  573 + try
  574 + {
  575 + Files.write(file.toPath(),
  576 + lines,
  577 + CHARSET,
  578 + options);
  579 + }
  580 + catch (IOException ex)
  581 + {
  582 + throw new RuntimeException(ex);
  583 + }
  584 + }
  585 +
  586 + public static List<String> readLines(File file)
  587 + {
  588 + try
  589 + {
  590 + return Files.readAllLines(file.toPath(), CHARSET);
  591 + }
  592 + catch (IOException ex)
  593 + {
  594 + if (ex instanceof NoSuchFileException)
  595 + return Collections.emptyList();
  596 +
  597 + throw new RuntimeException(ex);
  598 + }
  599 + }
  600 +
  601 + public static void setFSErrorHandler(FSErrorHandler handler)
  602 + {
  603 + fsErrorHandler.getAndSet(Optional.ofNullable(handler));
  604 + }
  605 +
  606 + /**
  607 + * Returns the size of the specified partition.
  608 + * <p>This method handles large file system by returning {@code Long.MAX_VALUE} if the size overflow.
  609 + * See <a href='https://bugs.openjdk.java.net/browse/JDK-8179320'>JDK-8179320</a> for more information.</p>
  610 + *
  611 + * @param file the partition
  612 + * @return the size, in bytes, of the partition or {@code 0L} if the abstract pathname does not name a partition
  613 + */
  614 + public static long getTotalSpace(File file)
  615 + {
  616 + return handleLargeFileSystem(file.getTotalSpace());
  617 + }
  618 +
  619 + /**
  620 + * Returns the number of unallocated bytes on the specified partition.
  621 + * <p>This method handles large file system by returning {@code Long.MAX_VALUE} if the number of unallocated bytes
  622 + * overflow. See <a href='https://bugs.openjdk.java.net/browse/JDK-8179320'>JDK-8179320</a> for more information</p>
  623 + *
  624 + * @param file the partition
  625 + * @return the number of unallocated bytes on the partition or {@code 0L}
  626 + * if the abstract pathname does not name a partition.
  627 + */
  628 + public static long getFreeSpace(File file)
  629 + {
  630 + return handleLargeFileSystem(file.getFreeSpace());
  631 + }
  632 +
  633 + /**
  634 + * Returns the number of available bytes on the specified partition.
  635 + * <p>This method handles large file system by returning {@code Long.MAX_VALUE} if the number of available bytes
  636 + * overflow. See <a href='https://bugs.openjdk.java.net/browse/JDK-8179320'>JDK-8179320</a> for more information</p>
  637 + *
  638 + * @param file the partition
  639 + * @return the number of available bytes on the partition or {@code 0L}
  640 + * if the abstract pathname does not name a partition.
  641 + */
  642 + public static long getUsableSpace(File file)
  643 + {
  644 + return handleLargeFileSystem(file.getUsableSpace());
  645 + }
  646 +
  647 + /**
  648 + * Returns the {@link FileStore} representing the file store where a file
  649 + * is located. This {@link FileStore} handles large file system by returning {@code Long.MAX_VALUE}
  650 + * from {@code FileStore#getTotalSpace()}, {@code FileStore#getUnallocatedSpace()} and {@code FileStore#getUsableSpace()}
  651 + * it the value is bigger than {@code Long.MAX_VALUE}. See <a href='https://bugs.openjdk.java.net/browse/JDK-8162520'>JDK-8162520</a>
  652 + * for more information.
  653 + *
  654 + * @param path the path to the file
  655 + * @return the file store where the file is stored
  656 + */
  657 + public static FileStore getFileStore(Path path) throws IOException
  658 + {
  659 + return new SafeFileStore(Files.getFileStore(path));
  660 + }
  661 +
  662 + /**
  663 + * Handle large file system by returning {@code Long.MAX_VALUE} when the size overflows.
  664 + * @param size returned by the Java's FileStore methods
  665 + * @return the size or {@code Long.MAX_VALUE} if the size was bigger than {@code Long.MAX_VALUE}
  666 + */
  667 + private static long handleLargeFileSystem(long size)
  668 + {
  669 + return size < 0 ? Long.MAX_VALUE : size;
  670 + }
  671 +
  672 + /**
  673 + * Private constructor as the class contains only static methods.
  674 + */
  675 + private FileUtils()
  676 + {
  677 + }
  678 +
  679 + /**
  680 + * FileStore decorator used to safely handle large file system.
  681 + *
  682 + * <p>Java's FileStore methods (getTotalSpace/getUnallocatedSpace/getUsableSpace) are limited to reporting bytes as
  683 + * signed long (2^63-1), if the filesystem is any bigger, then the size overflows. {@code SafeFileStore} will
  684 + * return {@code Long.MAX_VALUE} if the size overflow.</p>
  685 + *
  686 + * @see https://bugs.openjdk.java.net/browse/JDK-8162520.
  687 + */
  688 + private static final class SafeFileStore extends FileStore
  689 + {
  690 + /**
  691 + * The decorated {@code FileStore}
  692 + */
  693 + private final FileStore fileStore;
  694 +
  695 + public SafeFileStore(FileStore fileStore)
  696 + {
  697 + this.fileStore = fileStore;
  698 + }
  699 +
  700 + @Override
  701 + public String name()
  702 + {
  703 + return fileStore.name();
  704 + }
  705 +
  706 + @Override
  707 + public String type()
  708 + {
  709 + return fileStore.type();
  710 + }
  711 +
  712 + @Override
  713 + public boolean isReadOnly()
  714 + {
  715 + return fileStore.isReadOnly();
  716 + }
  717 +
  718 + @Override
  719 + public long getTotalSpace() throws IOException
  720 + {
  721 + return handleLargeFileSystem(fileStore.getTotalSpace());
  722 + }
  723 +
  724 + @Override
  725 + public long getUsableSpace() throws IOException
  726 + {
  727 + return handleLargeFileSystem(fileStore.getUsableSpace());
  728 + }
  729 +
  730 + @Override
  731 + public long getUnallocatedSpace() throws IOException
  732 + {
  733 + return handleLargeFileSystem(fileStore.getUnallocatedSpace());
  734 + }
  735 +
  736 + @Override
  737 + public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type)
  738 + {
  739 + return fileStore.supportsFileAttributeView(type);
  740 + }
  741 +
  742 + @Override
  743 + public boolean supportsFileAttributeView(String name)
  744 + {
  745 + return fileStore.supportsFileAttributeView(name);
  746 + }
  747 +
  748 + @Override
  749 + public <V extends FileStoreAttributeView> V getFileStoreAttributeView(Class<V> type)
  750 + {
  751 + return fileStore.getFileStoreAttributeView(type);
  752 + }
  753 +
  754 + @Override
  755 + public Object getAttribute(String attribute) throws IOException
  756 + {
  757 + return fileStore.getAttribute(attribute);
  758 + }
  759 + }
  760 +}
@@ -25,7 +25,7 @@ import org.junit.Test; @@ -25,7 +25,7 @@ import org.junit.Test;
25 import org.junit.runner.RunWith; 25 import org.junit.runner.RunWith;
26 import org.mockito.Mock; 26 import org.mockito.Mock;
27 import org.mockito.Spy; 27 import org.mockito.Spy;
28 -import org.mockito.runners.MockitoJUnitRunner; 28 +import org.mockito.junit.MockitoJUnitRunner;
29 import org.springframework.core.env.Environment; 29 import org.springframework.core.env.Environment;
30 import org.springframework.test.util.ReflectionTestUtils; 30 import org.springframework.test.util.ReflectionTestUtils;
31 import org.thingsboard.server.common.data.id.TenantId; 31 import org.thingsboard.server.common.data.id.TenantId;
@@ -35,9 +35,9 @@ import org.thingsboard.server.dao.timeseries.CassandraBaseTimeseriesDao; @@ -35,9 +35,9 @@ import org.thingsboard.server.dao.timeseries.CassandraBaseTimeseriesDao;
35 35
36 import java.util.UUID; 36 import java.util.UUID;
37 37
38 -import static org.mockito.Matchers.any;  
39 -import static org.mockito.Matchers.anyInt;  
40 -import static org.mockito.Matchers.anyString; 38 +import static org.mockito.ArgumentMatchers.any;
  39 +import static org.mockito.ArgumentMatchers.anyInt;
  40 +import static org.mockito.ArgumentMatchers.anyString;
41 import static org.mockito.Mockito.doReturn; 41 import static org.mockito.Mockito.doReturn;
42 import static org.mockito.Mockito.times; 42 import static org.mockito.Mockito.times;
43 import static org.mockito.Mockito.verify; 43 import static org.mockito.Mockito.verify;
@@ -347,7 +347,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest { @@ -347,7 +347,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
347 } 347 }
348 348
349 private AlarmDataQuery toQuery(AlarmDataPageLink pageLink){ 349 private AlarmDataQuery toQuery(AlarmDataPageLink pageLink){
350 - return toQuery(pageLink, Collections.EMPTY_LIST); 350 + return toQuery(pageLink, Collections.emptyList());
351 } 351 }
352 352
353 private AlarmDataQuery toQuery(AlarmDataPageLink pageLink, List<EntityKey> alarmFields){ 353 private AlarmDataQuery toQuery(AlarmDataPageLink pageLink, List<EntityKey> alarmFields){
@@ -1193,7 +1193,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest { @@ -1193,7 +1193,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
1193 1193
1194 EntityDataPageLink pageLink = new EntityDataPageLink(100, 0, null, sortOrder); 1194 EntityDataPageLink pageLink = new EntityDataPageLink(100, 0, null, sortOrder);
1195 EntityDataQuery query = new EntityDataQuery(filter, pageLink, entityFields, null, deviceTypeFilters); 1195 EntityDataQuery query = new EntityDataQuery(filter, pageLink, entityFields, null, deviceTypeFilters);
1196 - PageData data = entityService.findEntityDataByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), query); 1196 + PageData<EntityData> data = entityService.findEntityDataByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), query);
1197 List<EntityData> loadedEntities = getLoadedEntities(data, query); 1197 List<EntityData> loadedEntities = getLoadedEntities(data, query);
1198 Assert.assertEquals(devices.size(), loadedEntities.size()); 1198 Assert.assertEquals(devices.size(), loadedEntities.size());
1199 1199
@@ -1220,7 +1220,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest { @@ -1220,7 +1220,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
1220 return A.containsAll(B) && B.containsAll(A); 1220 return A.containsAll(B) && B.containsAll(A);
1221 } 1221 }
1222 1222
1223 - private List<EntityData> getLoadedEntities(PageData data, EntityDataQuery query) { 1223 + private List<EntityData> getLoadedEntities(PageData<EntityData> data, EntityDataQuery query) {
1224 List<EntityData> loadedEntities = new ArrayList<>(data.getData()); 1224 List<EntityData> loadedEntities = new ArrayList<>(data.getData());
1225 1225
1226 while (data.hasNext()) { 1226 while (data.hasNext()) {
@@ -15,10 +15,10 @@ @@ -15,10 +15,10 @@
15 # 15 #
16 16
17 export JAVA_OPTS="$JAVA_OPTS -Dplatform=deb -Dinstall.data_dir=/usr/share/thingsboard/data" 17 export JAVA_OPTS="$JAVA_OPTS -Dplatform=deb -Dinstall.data_dir=/usr/share/thingsboard/data"
18 -export JAVA_OPTS="$JAVA_OPTS -Xloggc:/var/log/thingsboard/${TB_SERVICE_ID}/gc.log -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/thingsboard/${TB_SERVICE_ID}/heapdump.bin -XX:+PrintGCDetails -XX:+PrintGCDateStamps"  
19 -export JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10"  
20 -export JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=10M -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"  
21 -export JAVA_OPTS="$JAVA_OPTS -XX:CMSWaitDuration=10000 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+CMSParallelInitialMarkEnabled"  
22 -export JAVA_OPTS="$JAVA_OPTS -XX:+CMSEdenChunksRecordAlways -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+ExitOnOutOfMemoryError" 18 +export JAVA_OPTS="$JAVA_OPTS -Xlog:gc*,heap*,age*,safepoint=debug:file=/var/log/thingsboard/${TB_SERVICE_ID}-gc.log:time,uptime,level,tags:filecount=10,filesize=10M"
  19 +export JAVA_OPTS="$JAVA_OPTS -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/thingsboard/${TB_SERVICE_ID}-heapdump.bin"
  20 +export JAVA_OPTS="$JAVA_OPTS -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"
  21 +export JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC -XX:MaxGCPauseMillis=500 -XX:+UseStringDeduplication -XX:+ParallelRefProcEnabled -XX:MaxTenuringThreshold=10"
  22 +export JAVA_OPTS="$JAVA_OPTS -XX:+ExitOnOutOfMemoryError"
23 export LOG_FILENAME=thingsboard.out 23 export LOG_FILENAME=thingsboard.out
24 export LOADER_PATH=/usr/share/thingsboard/conf,/usr/share/thingsboard/extensions 24 export LOADER_PATH=/usr/share/thingsboard/conf,/usr/share/thingsboard/extensions
@@ -14,10 +14,10 @@ @@ -14,10 +14,10 @@
14 # limitations under the License. 14 # limitations under the License.
15 # 15 #
16 16
17 -export JAVA_OPTS="$JAVA_OPTS -Xloggc:/var/log/tb-coap-transport/${TB_SERVICE_ID}/gc.log -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/tb-coap-transport/${TB_SERVICE_ID}/heapdump.bin -XX:+PrintGCDetails -XX:+PrintGCDateStamps"  
18 -export JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10"  
19 -export JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=10M -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"  
20 -export JAVA_OPTS="$JAVA_OPTS -XX:CMSWaitDuration=10000 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+CMSParallelInitialMarkEnabled"  
21 -export JAVA_OPTS="$JAVA_OPTS -XX:+CMSEdenChunksRecordAlways -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+ExitOnOutOfMemoryError" 17 +export JAVA_OPTS="$JAVA_OPTS -Xlog:gc*,heap*,age*,safepoint=debug:file=/var/log/tb-coap-transport/${TB_SERVICE_ID}-gc.log:time,uptime,level,tags:filecount=10,filesize=10M"
  18 +export JAVA_OPTS="$JAVA_OPTS -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/tb-coap-transport/${TB_SERVICE_ID}-heapdump.bin"
  19 +export JAVA_OPTS="$JAVA_OPTS -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"
  20 +export JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC -XX:MaxGCPauseMillis=500 -XX:+UseStringDeduplication -XX:+ParallelRefProcEnabled -XX:MaxTenuringThreshold=10"
  21 +export JAVA_OPTS="$JAVA_OPTS -XX:+ExitOnOutOfMemoryError"
22 export LOG_FILENAME=tb-coap-transport.out 22 export LOG_FILENAME=tb-coap-transport.out
23 export LOADER_PATH=/usr/share/tb-coap-transport/conf 23 export LOADER_PATH=/usr/share/tb-coap-transport/conf
@@ -14,10 +14,10 @@ @@ -14,10 +14,10 @@
14 # limitations under the License. 14 # limitations under the License.
15 # 15 #
16 16
17 -export JAVA_OPTS="$JAVA_OPTS -Xloggc:/var/log/tb-http-transport/${TB_SERVICE_ID}/gc.log -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/tb-http-transport/${TB_SERVICE_ID}/heapdump.bin -XX:+PrintGCDetails -XX:+PrintGCDateStamps"  
18 -export JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10"  
19 -export JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=10M -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"  
20 -export JAVA_OPTS="$JAVA_OPTS -XX:CMSWaitDuration=10000 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+CMSParallelInitialMarkEnabled"  
21 -export JAVA_OPTS="$JAVA_OPTS -XX:+CMSEdenChunksRecordAlways -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+ExitOnOutOfMemoryError" 17 +export JAVA_OPTS="$JAVA_OPTS -Xlog:gc*,heap*,age*,safepoint=debug:file=/var/log/tb-http-transport/${TB_SERVICE_ID}-gc.log:time,uptime,level,tags:filecount=10,filesize=10M"
  18 +export JAVA_OPTS="$JAVA_OPTS -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/tb-http-transport/${TB_SERVICE_ID}-heapdump.bin"
  19 +export JAVA_OPTS="$JAVA_OPTS -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"
  20 +export JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC -XX:MaxGCPauseMillis=500 -XX:+UseStringDeduplication -XX:+ParallelRefProcEnabled -XX:MaxTenuringThreshold=10"
  21 +export JAVA_OPTS="$JAVA_OPTS -XX:+ExitOnOutOfMemoryError"
22 export LOG_FILENAME=tb-http-transport.out 22 export LOG_FILENAME=tb-http-transport.out
23 export LOADER_PATH=/usr/share/tb-http-transport/conf 23 export LOADER_PATH=/usr/share/tb-http-transport/conf
@@ -14,10 +14,10 @@ @@ -14,10 +14,10 @@
14 # limitations under the License. 14 # limitations under the License.
15 # 15 #
16 16
17 -export JAVA_OPTS="$JAVA_OPTS -Xloggc:/var/log/tb-mqtt-transport/${TB_SERVICE_ID}/gc.log -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/tb-mqtt-transport/${TB_SERVICE_ID}/heapdump.bin -XX:+PrintGCDetails -XX:+PrintGCDateStamps"  
18 -export JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10"  
19 -export JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=10M -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"  
20 -export JAVA_OPTS="$JAVA_OPTS -XX:CMSWaitDuration=10000 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+CMSParallelInitialMarkEnabled"  
21 -export JAVA_OPTS="$JAVA_OPTS -XX:+CMSEdenChunksRecordAlways -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+ExitOnOutOfMemoryError" 17 +export JAVA_OPTS="$JAVA_OPTS -Xlog:gc*,heap*,age*,safepoint=debug:file=/var/log/tb-mqtt-transport/${TB_SERVICE_ID}-gc.log:time,uptime,level,tags:filecount=10,filesize=10M"
  18 +export JAVA_OPTS="$JAVA_OPTS -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/tb-mqtt-transport/${TB_SERVICE_ID}-heapdump.bin"
  19 +export JAVA_OPTS="$JAVA_OPTS -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"
  20 +export JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC -XX:MaxGCPauseMillis=500 -XX:+UseStringDeduplication -XX:+ParallelRefProcEnabled -XX:MaxTenuringThreshold=10"
  21 +export JAVA_OPTS="$JAVA_OPTS -XX:+ExitOnOutOfMemoryError"
22 export LOG_FILENAME=tb-mqtt-transport.out 22 export LOG_FILENAME=tb-mqtt-transport.out
23 export LOADER_PATH=/usr/share/tb-mqtt-transport/conf 23 export LOADER_PATH=/usr/share/tb-mqtt-transport/conf
  1 +config.stopbubbling = true
  2 +lombok.anyconstructor.addconstructorproperties = true
@@ -51,6 +51,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; @@ -51,6 +51,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentials;
51 import org.thingsboard.server.msa.mapper.WsTelemetryResponse; 51 import org.thingsboard.server.msa.mapper.WsTelemetryResponse;
52 52
53 53
  54 +import javax.net.ssl.HostnameVerifier;
54 import javax.net.ssl.SSLContext; 55 import javax.net.ssl.SSLContext;
55 import javax.net.ssl.SSLSession; 56 import javax.net.ssl.SSLSession;
56 import javax.net.ssl.SSLSocket; 57 import javax.net.ssl.SSLSocket;
@@ -114,14 +115,17 @@ public abstract class AbstractContainerTest { @@ -114,14 +115,17 @@ public abstract class AbstractContainerTest {
114 } 115 }
115 116
116 protected Device createDevice(String name) { 117 protected Device createDevice(String name) {
117 - return restClient.createDevice(name + RandomStringUtils.randomAlphanumeric(7), "DEFAULT"); 118 + Device device = new Device();
  119 + device.setName(name + RandomStringUtils.randomAlphanumeric(7));
  120 + device.setType("DEFAULT");
  121 + return restClient.saveDevice(device);
118 } 122 }
119 123
120 protected WsClient subscribeToWebSocket(DeviceId deviceId, String scope, CmdsType property) throws Exception { 124 protected WsClient subscribeToWebSocket(DeviceId deviceId, String scope, CmdsType property) throws Exception {
121 WsClient wsClient = new WsClient(new URI(WSS_URL + "/api/ws/plugins/telemetry?token=" + restClient.getToken())); 125 WsClient wsClient = new WsClient(new URI(WSS_URL + "/api/ws/plugins/telemetry?token=" + restClient.getToken()));
122 SSLContextBuilder builder = SSLContexts.custom(); 126 SSLContextBuilder builder = SSLContexts.custom();
123 builder.loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true); 127 builder.loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true);
124 - wsClient.setSocket(builder.build().getSocketFactory().createSocket()); 128 + wsClient.setSocketFactory(builder.build().getSocketFactory());
125 wsClient.connectBlocking(); 129 wsClient.connectBlocking();
126 130
127 JsonObject cmdsObject = new JsonObject(); 131 JsonObject cmdsObject = new JsonObject();
@@ -218,24 +222,7 @@ public abstract class AbstractContainerTest { @@ -218,24 +222,7 @@ public abstract class AbstractContainerTest {
218 SSLContextBuilder builder = SSLContexts.custom(); 222 SSLContextBuilder builder = SSLContexts.custom();
219 builder.loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true); 223 builder.loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true);
220 SSLContext sslContext = builder.build(); 224 SSLContext sslContext = builder.build();
221 - SSLConnectionSocketFactory sslSelfSigned = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() {  
222 - @Override  
223 - public void verify(String host, SSLSocket ssl) {  
224 - }  
225 -  
226 - @Override  
227 - public void verify(String host, X509Certificate cert) {  
228 - }  
229 -  
230 - @Override  
231 - public void verify(String host, String[] cns, String[] subjectAlts) {  
232 - }  
233 -  
234 - @Override  
235 - public boolean verify(String s, SSLSession sslSession) {  
236 - return true;  
237 - }  
238 - }); 225 + SSLConnectionSocketFactory sslSelfSigned = new SSLConnectionSocketFactory(sslContext, (s, sslSession) -> true);
239 226
240 Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder 227 Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
241 .<ConnectionSocketFactory>create() 228 .<ConnectionSocketFactory>create()
@@ -34,7 +34,7 @@ import java.util.Map; @@ -34,7 +34,7 @@ import java.util.Map;
34 @ClasspathSuite.ClassnameFilters({"org.thingsboard.server.msa.*Test"}) 34 @ClasspathSuite.ClassnameFilters({"org.thingsboard.server.msa.*Test"})
35 public class ContainerTestSuite { 35 public class ContainerTestSuite {
36 36
37 - private static DockerComposeContainer testContainer; 37 + private static DockerComposeContainer<?> testContainer;
38 38
39 @ClassRule 39 @ClassRule
40 public static ThingsBoardDbInstaller installTb = new ThingsBoardDbInstaller(); 40 public static ThingsBoardDbInstaller installTb = new ThingsBoardDbInstaller();
@@ -43,7 +43,7 @@ public class ContainerTestSuite { @@ -43,7 +43,7 @@ public class ContainerTestSuite {
43 public static DockerComposeContainer getTestContainer() { 43 public static DockerComposeContainer getTestContainer() {
44 if (testContainer == null) { 44 if (testContainer == null) {
45 boolean skipTailChildContainers = Boolean.valueOf(System.getProperty("blackBoxTests.skipTailChildContainers")); 45 boolean skipTailChildContainers = Boolean.valueOf(System.getProperty("blackBoxTests.skipTailChildContainers"));
46 - testContainer = new DockerComposeContainer( 46 + testContainer = new DockerComposeContainer<>(
47 new File("./../../docker/docker-compose.yml"), 47 new File("./../../docker/docker-compose.yml"),
48 new File("./../../docker/docker-compose.postgres.yml"), 48 new File("./../../docker/docker-compose.postgres.yml"),
49 new File("./../../docker/docker-compose.postgres.volumes.yml"), 49 new File("./../../docker/docker-compose.postgres.volumes.yml"),
@@ -44,7 +44,7 @@ public class HttpClientTest extends AbstractContainerTest { @@ -44,7 +44,7 @@ public class HttpClientTest extends AbstractContainerTest {
44 restClient.login("tenant@thingsboard.org", "tenant"); 44 restClient.login("tenant@thingsboard.org", "tenant");
45 45
46 Device device = createDevice("http_"); 46 Device device = createDevice("http_");
47 - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); 47 + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get();
48 48
49 WsClient wsClient = subscribeToWebSocket(device.getId(), "LATEST_TELEMETRY", CmdsType.TS_SUB_CMDS); 49 WsClient wsClient = subscribeToWebSocket(device.getId(), "LATEST_TELEMETRY", CmdsType.TS_SUB_CMDS);
50 ResponseEntity deviceTelemetryResponse = restClient.getRestTemplate() 50 ResponseEntity deviceTelemetryResponse = restClient.getRestTemplate()
@@ -73,7 +73,7 @@ public class HttpClientTest extends AbstractContainerTest { @@ -73,7 +73,7 @@ public class HttpClientTest extends AbstractContainerTest {
73 TB_TOKEN = restClient.getToken(); 73 TB_TOKEN = restClient.getToken();
74 74
75 Device device = createDevice("test"); 75 Device device = createDevice("test");
76 - String accessToken = restClient.getCredentials(device.getId()).getCredentialsId(); 76 + String accessToken = restClient.getDeviceCredentialsByDeviceId(device.getId()).get().getCredentialsId();
77 assertNotNull(accessToken); 77 assertNotNull(accessToken);
78 78
79 ResponseEntity deviceSharedAttributes = restClient.getRestTemplate() 79 ResponseEntity deviceSharedAttributes = restClient.getRestTemplate()
@@ -92,6 +92,7 @@ public class HttpClientTest extends AbstractContainerTest { @@ -92,6 +92,7 @@ public class HttpClientTest extends AbstractContainerTest {
92 92
93 TimeUnit.SECONDS.sleep(3); 93 TimeUnit.SECONDS.sleep(3);
94 94
  95 + @SuppressWarnings("deprecation")
95 Optional<JsonNode> allOptional = restClient.getAttributes(accessToken, null, null); 96 Optional<JsonNode> allOptional = restClient.getAttributes(accessToken, null, null);
96 assertTrue(allOptional.isPresent()); 97 assertTrue(allOptional.isPresent());
97 98
@@ -101,6 +102,7 @@ public class HttpClientTest extends AbstractContainerTest { @@ -101,6 +102,7 @@ public class HttpClientTest extends AbstractContainerTest {
101 assertEquals(mapper.readTree(createPayload().toString()), all.get("shared")); 102 assertEquals(mapper.readTree(createPayload().toString()), all.get("shared"));
102 assertEquals(mapper.readTree(createPayload().toString()), all.get("client")); 103 assertEquals(mapper.readTree(createPayload().toString()), all.get("client"));
103 104
  105 + @SuppressWarnings("deprecation")
104 Optional<JsonNode> sharedOptional = restClient.getAttributes(accessToken, null, "stringKey"); 106 Optional<JsonNode> sharedOptional = restClient.getAttributes(accessToken, null, "stringKey");
105 assertTrue(sharedOptional.isPresent()); 107 assertTrue(sharedOptional.isPresent());
106 108
@@ -108,6 +110,7 @@ public class HttpClientTest extends AbstractContainerTest { @@ -108,6 +110,7 @@ public class HttpClientTest extends AbstractContainerTest {
108 assertEquals(shared.get("shared").get("stringKey"), mapper.readTree(createPayload().get("stringKey").toString())); 110 assertEquals(shared.get("shared").get("stringKey"), mapper.readTree(createPayload().get("stringKey").toString()));
109 assertFalse(shared.has("client")); 111 assertFalse(shared.has("client"));
110 112
  113 + @SuppressWarnings("deprecation")
111 Optional<JsonNode> clientOptional = restClient.getAttributes(accessToken, "longKey,stringKey", null); 114 Optional<JsonNode> clientOptional = restClient.getAttributes(accessToken, "longKey,stringKey", null);
112 assertTrue(clientOptional.isPresent()); 115 assertTrue(clientOptional.isPresent());
113 116
@@ -62,7 +62,7 @@ public class MqttClientTest extends AbstractContainerTest { @@ -62,7 +62,7 @@ public class MqttClientTest extends AbstractContainerTest {
62 public void telemetryUpload() throws Exception { 62 public void telemetryUpload() throws Exception {
63 restClient.login("tenant@thingsboard.org", "tenant"); 63 restClient.login("tenant@thingsboard.org", "tenant");
64 Device device = createDevice("mqtt_"); 64 Device device = createDevice("mqtt_");
65 - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); 65 + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get();
66 66
67 WsClient wsClient = subscribeToWebSocket(device.getId(), "LATEST_TELEMETRY", CmdsType.TS_SUB_CMDS); 67 WsClient wsClient = subscribeToWebSocket(device.getId(), "LATEST_TELEMETRY", CmdsType.TS_SUB_CMDS);
68 MqttClient mqttClient = getMqttClient(deviceCredentials, null); 68 MqttClient mqttClient = getMqttClient(deviceCredentials, null);
@@ -89,7 +89,7 @@ public class MqttClientTest extends AbstractContainerTest { @@ -89,7 +89,7 @@ public class MqttClientTest extends AbstractContainerTest {
89 89
90 restClient.login("tenant@thingsboard.org", "tenant"); 90 restClient.login("tenant@thingsboard.org", "tenant");
91 Device device = createDevice("mqtt_"); 91 Device device = createDevice("mqtt_");
92 - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); 92 + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get();
93 93
94 WsClient wsClient = subscribeToWebSocket(device.getId(), "LATEST_TELEMETRY", CmdsType.TS_SUB_CMDS); 94 WsClient wsClient = subscribeToWebSocket(device.getId(), "LATEST_TELEMETRY", CmdsType.TS_SUB_CMDS);
95 MqttClient mqttClient = getMqttClient(deviceCredentials, null); 95 MqttClient mqttClient = getMqttClient(deviceCredentials, null);
@@ -113,7 +113,7 @@ public class MqttClientTest extends AbstractContainerTest { @@ -113,7 +113,7 @@ public class MqttClientTest extends AbstractContainerTest {
113 public void publishAttributeUpdateToServer() throws Exception { 113 public void publishAttributeUpdateToServer() throws Exception {
114 restClient.login("tenant@thingsboard.org", "tenant"); 114 restClient.login("tenant@thingsboard.org", "tenant");
115 Device device = createDevice("mqtt_"); 115 Device device = createDevice("mqtt_");
116 - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); 116 + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get();
117 117
118 WsClient wsClient = subscribeToWebSocket(device.getId(), "CLIENT_SCOPE", CmdsType.ATTR_SUB_CMDS); 118 WsClient wsClient = subscribeToWebSocket(device.getId(), "CLIENT_SCOPE", CmdsType.ATTR_SUB_CMDS);
119 MqttMessageListener listener = new MqttMessageListener(); 119 MqttMessageListener listener = new MqttMessageListener();
@@ -144,7 +144,7 @@ public class MqttClientTest extends AbstractContainerTest { @@ -144,7 +144,7 @@ public class MqttClientTest extends AbstractContainerTest {
144 public void requestAttributeValuesFromServer() throws Exception { 144 public void requestAttributeValuesFromServer() throws Exception {
145 restClient.login("tenant@thingsboard.org", "tenant"); 145 restClient.login("tenant@thingsboard.org", "tenant");
146 Device device = createDevice("mqtt_"); 146 Device device = createDevice("mqtt_");
147 - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); 147 + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get();
148 148
149 WsClient wsClient = subscribeToWebSocket(device.getId(), "CLIENT_SCOPE", CmdsType.ATTR_SUB_CMDS); 149 WsClient wsClient = subscribeToWebSocket(device.getId(), "CLIENT_SCOPE", CmdsType.ATTR_SUB_CMDS);
150 MqttMessageListener listener = new MqttMessageListener(); 150 MqttMessageListener listener = new MqttMessageListener();
@@ -204,7 +204,7 @@ public class MqttClientTest extends AbstractContainerTest { @@ -204,7 +204,7 @@ public class MqttClientTest extends AbstractContainerTest {
204 public void subscribeToAttributeUpdatesFromServer() throws Exception { 204 public void subscribeToAttributeUpdatesFromServer() throws Exception {
205 restClient.login("tenant@thingsboard.org", "tenant"); 205 restClient.login("tenant@thingsboard.org", "tenant");
206 Device device = createDevice("mqtt_"); 206 Device device = createDevice("mqtt_");
207 - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); 207 + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get();
208 208
209 MqttMessageListener listener = new MqttMessageListener(); 209 MqttMessageListener listener = new MqttMessageListener();
210 MqttClient mqttClient = getMqttClient(deviceCredentials, listener); 210 MqttClient mqttClient = getMqttClient(deviceCredentials, listener);
@@ -250,7 +250,7 @@ public class MqttClientTest extends AbstractContainerTest { @@ -250,7 +250,7 @@ public class MqttClientTest extends AbstractContainerTest {
250 public void serverSideRpc() throws Exception { 250 public void serverSideRpc() throws Exception {
251 restClient.login("tenant@thingsboard.org", "tenant"); 251 restClient.login("tenant@thingsboard.org", "tenant");
252 Device device = createDevice("mqtt_"); 252 Device device = createDevice("mqtt_");
253 - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); 253 + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get();
254 254
255 MqttMessageListener listener = new MqttMessageListener(); 255 MqttMessageListener listener = new MqttMessageListener();
256 MqttClient mqttClient = getMqttClient(deviceCredentials, listener); 256 MqttClient mqttClient = getMqttClient(deviceCredentials, listener);
@@ -297,7 +297,7 @@ public class MqttClientTest extends AbstractContainerTest { @@ -297,7 +297,7 @@ public class MqttClientTest extends AbstractContainerTest {
297 public void clientSideRpc() throws Exception { 297 public void clientSideRpc() throws Exception {
298 restClient.login("tenant@thingsboard.org", "tenant"); 298 restClient.login("tenant@thingsboard.org", "tenant");
299 Device device = createDevice("mqtt_"); 299 Device device = createDevice("mqtt_");
300 - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); 300 + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get();
301 301
302 MqttMessageListener listener = new MqttMessageListener(); 302 MqttMessageListener listener = new MqttMessageListener();
303 MqttClient mqttClient = getMqttClient(deviceCredentials, listener); 303 MqttClient mqttClient = getMqttClient(deviceCredentials, listener);
@@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
50 <plugin> 50 <plugin>
51 <groupId>com.spotify</groupId> 51 <groupId>com.spotify</groupId>
52 <artifactId>dockerfile-maven-plugin</artifactId> 52 <artifactId>dockerfile-maven-plugin</artifactId>
53 - <version>1.4.5</version> 53 + <version>1.4.13</version>
54 </plugin> 54 </plugin>
55 </plugins> 55 </plugins>
56 </pluginManagement> 56 </pluginManagement>
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 # limitations under the License. 14 # limitations under the License.
15 # 15 #
16 16
17 -FROM thingsboard/openjdk8 17 +FROM thingsboard/openjdk11
18 18
19 COPY start-tb-node.sh ${pkg.name}.deb /tmp/ 19 COPY start-tb-node.sh ${pkg.name}.deb /tmp/
20 20
@@ -14,14 +14,15 @@ @@ -14,14 +14,15 @@
14 # limitations under the License. 14 # limitations under the License.
15 # 15 #
16 16
17 -FROM thingsboard/openjdk8 17 +FROM thingsboard/openjdk11
18 18
19 RUN apt-get update 19 RUN apt-get update
20 RUN apt-get install -y curl nmap procps 20 RUN apt-get install -y curl nmap procps
  21 +RUN echo 'deb http://ftp.us.debian.org/debian sid main' | tee --append /etc/apt/sources.list.d/debian.list > /dev/null
21 RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ sid-pgdg main' | tee --append /etc/apt/sources.list.d/pgdg.list > /dev/null 22 RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ sid-pgdg main' | tee --append /etc/apt/sources.list.d/pgdg.list > /dev/null
22 RUN curl -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - 23 RUN curl -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
23 -RUN echo 'deb http://www.apache.org/dist/cassandra/debian 311x main' | tee --append /etc/apt/sources.list.d/cassandra.list > /dev/null  
24 -RUN curl -L https://www.apache.org/dist/cassandra/KEYS | apt-key add - 24 +RUN echo 'deb http://downloads.apache.org/cassandra/debian 40x main' | tee --append /etc/apt/sources.list.d/cassandra.list > /dev/null
  25 +RUN curl -L https://downloads.apache.org/cassandra/KEYS | apt-key add -
25 ENV PG_MAJOR=11 26 ENV PG_MAJOR=11
26 RUN apt-get update 27 RUN apt-get update
27 RUN apt-get install -y cassandra cassandra-tools postgresql-11 28 RUN apt-get install -y cassandra cassandra-tools postgresql-11
@@ -14,10 +14,11 @@ @@ -14,10 +14,11 @@
14 # limitations under the License. 14 # limitations under the License.
15 # 15 #
16 16
17 -FROM thingsboard/openjdk8 17 +FROM thingsboard/openjdk11
18 18
19 RUN apt-get update 19 RUN apt-get update
20 RUN apt-get install -y curl 20 RUN apt-get install -y curl
  21 +RUN echo 'deb http://ftp.us.debian.org/debian sid main' | tee --append /etc/apt/sources.list.d/debian.list > /dev/null
21 RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ sid-pgdg main' | tee --append /etc/apt/sources.list.d/pgdg.list > /dev/null 22 RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ sid-pgdg main' | tee --append /etc/apt/sources.list.d/pgdg.list > /dev/null
22 RUN curl -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - 23 RUN curl -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
23 ENV PG_MAJOR 11 24 ENV PG_MAJOR 11
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 # limitations under the License. 14 # limitations under the License.
15 # 15 #
16 16
17 -FROM thingsboard/openjdk8 17 +FROM thingsboard/openjdk11
18 18
19 COPY logback.xml ${pkg.name}.conf start-db.sh stop-db.sh start-tb.sh upgrade-tb.sh install-tb.sh ${pkg.name}.deb /tmp/ 19 COPY logback.xml ${pkg.name}.conf start-db.sh stop-db.sh start-tb.sh upgrade-tb.sh install-tb.sh ${pkg.name}.deb /tmp/
20 20
@@ -15,10 +15,10 @@ @@ -15,10 +15,10 @@
15 # 15 #
16 16
17 export JAVA_OPTS="$JAVA_OPTS -Dplatform=deb -Dinstall.data_dir=/usr/share/thingsboard/data" 17 export JAVA_OPTS="$JAVA_OPTS -Dplatform=deb -Dinstall.data_dir=/usr/share/thingsboard/data"
18 -export JAVA_OPTS="$JAVA_OPTS -Xloggc:/var/log/thingsboard/gc.log -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails -XX:+PrintGCDateStamps"  
19 -export JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10"  
20 -export JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=10M -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"  
21 -export JAVA_OPTS="$JAVA_OPTS -XX:CMSWaitDuration=10000 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+CMSParallelInitialMarkEnabled"  
22 -export JAVA_OPTS="$JAVA_OPTS -XX:+CMSEdenChunksRecordAlways -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+ExitOnOutOfMemoryError" 18 +export JAVA_OPTS="$JAVA_OPTS -Xlog:gc*,heap*,age*,safepoint=debug:file=/var/log/thingsboard/gc.log:time,uptime,level,tags:filecount=10,filesize=10M"
  19 +export JAVA_OPTS="$JAVA_OPTS -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError"
  20 +export JAVA_OPTS="$JAVA_OPTS -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark"
  21 +export JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC -XX:MaxGCPauseMillis=500 -XX:+UseStringDeduplication -XX:+ParallelRefProcEnabled -XX:MaxTenuringThreshold=10"
  22 +export JAVA_OPTS="$JAVA_OPTS -XX:+ExitOnOutOfMemoryError"
23 export LOG_FILENAME=thingsboard.out 23 export LOG_FILENAME=thingsboard.out
24 export LOADER_PATH=/usr/share/thingsboard/conf,/usr/share/thingsboard/extensions 24 export LOADER_PATH=/usr/share/thingsboard/conf,/usr/share/thingsboard/extensions
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 # limitations under the License. 14 # limitations under the License.
15 # 15 #
16 16
17 -FROM thingsboard/openjdk8 17 +FROM thingsboard/openjdk11
18 18
19 COPY start-tb-coap-transport.sh ${pkg.name}.deb /tmp/ 19 COPY start-tb-coap-transport.sh ${pkg.name}.deb /tmp/
20 20
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 # limitations under the License. 14 # limitations under the License.
15 # 15 #
16 16
17 -FROM thingsboard/openjdk8 17 +FROM thingsboard/openjdk11
18 18
19 COPY start-tb-http-transport.sh ${pkg.name}.deb /tmp/ 19 COPY start-tb-http-transport.sh ${pkg.name}.deb /tmp/
20 20
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 # limitations under the License. 14 # limitations under the License.
15 # 15 #
16 16
17 -FROM thingsboard/openjdk8 17 +FROM thingsboard/openjdk11
18 18
19 COPY start-tb-mqtt-transport.sh ${pkg.name}.deb /tmp/ 19 COPY start-tb-mqtt-transport.sh ${pkg.name}.deb /tmp/
20 20
@@ -40,17 +40,4 @@ @@ -40,17 +40,4 @@
40 <module>coap</module> 40 <module>coap</module>
41 <module>lwm2m</module> 41 <module>lwm2m</module>
42 </modules> 42 </modules>
43 -  
44 - <build>  
45 - <pluginManagement>  
46 - <plugins>  
47 - <plugin>  
48 - <groupId>com.spotify</groupId>  
49 - <artifactId>dockerfile-maven-plugin</artifactId>  
50 - <version>1.4.5</version>  
51 - </plugin>  
52 - </plugins>  
53 - </pluginManagement>  
54 - </build>  
55 -  
56 </project> 43 </project>