Commit ce6eb3778d8c5bd3e8ac54895c7c8ac1863494b9
1 parent
84a5fcce
Bug fixes with logging and gateway API
Showing
5 changed files
with
26 additions
and
20 deletions
@@ -22,6 +22,7 @@ import io.jsonwebtoken.Claims; | @@ -22,6 +22,7 @@ import io.jsonwebtoken.Claims; | ||
22 | import io.jsonwebtoken.Header; | 22 | import io.jsonwebtoken.Header; |
23 | import io.jsonwebtoken.Jwt; | 23 | import io.jsonwebtoken.Jwt; |
24 | import io.jsonwebtoken.Jwts; | 24 | import io.jsonwebtoken.Jwts; |
25 | +import lombok.extern.slf4j.Slf4j; | ||
25 | import org.apache.commons.lang3.StringUtils; | 26 | import org.apache.commons.lang3.StringUtils; |
26 | import org.hamcrest.Matcher; | 27 | import org.hamcrest.Matcher; |
27 | import org.junit.After; | 28 | import org.junit.After; |
@@ -85,6 +86,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC | @@ -85,6 +86,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC | ||
85 | @ComponentScan({"org.thingsboard.server"}) | 86 | @ComponentScan({"org.thingsboard.server"}) |
86 | @WebAppConfiguration | 87 | @WebAppConfiguration |
87 | @SpringBootTest | 88 | @SpringBootTest |
89 | +@Slf4j | ||
88 | public abstract class AbstractControllerTest { | 90 | public abstract class AbstractControllerTest { |
89 | 91 | ||
90 | protected static final String TEST_TENANT_NAME = "TEST TENANT"; | 92 | protected static final String TEST_TENANT_NAME = "TEST TENANT"; |
@@ -130,6 +132,7 @@ public abstract class AbstractControllerTest { | @@ -130,6 +132,7 @@ public abstract class AbstractControllerTest { | ||
130 | 132 | ||
131 | @Before | 133 | @Before |
132 | public void setup() throws Exception { | 134 | public void setup() throws Exception { |
135 | + log.info("Executing setup"); | ||
133 | if (this.mockMvc == null) { | 136 | if (this.mockMvc == null) { |
134 | this.mockMvc = webAppContextSetup(webApplicationContext) | 137 | this.mockMvc = webAppContextSetup(webApplicationContext) |
135 | .apply(springSecurity()).build(); | 138 | .apply(springSecurity()).build(); |
@@ -163,13 +166,16 @@ public abstract class AbstractControllerTest { | @@ -163,13 +166,16 @@ public abstract class AbstractControllerTest { | ||
163 | createUserAndLogin(customerUser, CUSTOMER_USER_PASSWORD); | 166 | createUserAndLogin(customerUser, CUSTOMER_USER_PASSWORD); |
164 | 167 | ||
165 | logout(); | 168 | logout(); |
169 | + log.info("Executed setup"); | ||
166 | } | 170 | } |
167 | 171 | ||
168 | @After | 172 | @After |
169 | public void teardown() throws Exception { | 173 | public void teardown() throws Exception { |
174 | + log.info("Executing teardown"); | ||
170 | loginSysAdmin(); | 175 | loginSysAdmin(); |
171 | doDelete("/api/tenant/"+tenantId.getId().toString()) | 176 | doDelete("/api/tenant/"+tenantId.getId().toString()) |
172 | .andExpect(status().isOk()); | 177 | .andExpect(status().isOk()); |
178 | + log.info("Executed teardown"); | ||
173 | } | 179 | } |
174 | 180 | ||
175 | protected void loginSysAdmin() throws Exception { | 181 | protected void loginSysAdmin() throws Exception { |
@@ -15,19 +15,14 @@ | @@ -15,19 +15,14 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.controller; | 16 | package org.thingsboard.server.controller; |
17 | 17 | ||
18 | -import static org.hamcrest.Matchers.containsString; | ||
19 | -import static org.hamcrest.Matchers.is; | ||
20 | -import static org.hamcrest.Matchers.notNullValue; | ||
21 | -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
22 | -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
23 | -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
24 | - | ||
25 | -import org.thingsboard.server.common.data.AdminSettings; | ||
26 | -import org.junit.Test; | ||
27 | - | ||
28 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
29 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
30 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
20 | +import org.junit.Test; | ||
21 | +import org.thingsboard.server.common.data.AdminSettings; | ||
22 | + | ||
23 | +import static org.hamcrest.Matchers.*; | ||
24 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
25 | + | ||
31 | 26 | ||
32 | public abstract class BaseAdminControllerTest extends AbstractControllerTest { | 27 | public abstract class BaseAdminControllerTest extends AbstractControllerTest { |
33 | 28 |
@@ -7,8 +7,9 @@ | @@ -7,8 +7,9 @@ | ||
7 | </encoder> | 7 | </encoder> |
8 | </appender> | 8 | </appender> |
9 | 9 | ||
10 | - <logger name="org.thingsboard.server" level="WARN"/> | 10 | + <logger name="org.thingsboard.server" level="INFO"/> |
11 | <logger name="org.springframework" level="WARN"/> | 11 | <logger name="org.springframework" level="WARN"/> |
12 | + <logger name="org.springframework.boot.test" level="DEBUG"/> | ||
12 | <logger name="org.apache.cassandra" level="WARN"/> | 13 | <logger name="org.apache.cassandra" level="WARN"/> |
13 | <logger name="org.cassandraunit" level="INFO"/> | 14 | <logger name="org.cassandraunit" level="INFO"/> |
14 | 15 |
@@ -37,7 +37,7 @@ | @@ -37,7 +37,7 @@ | ||
37 | <json-path.version>2.2.0</json-path.version> | 37 | <json-path.version>2.2.0</json-path.version> |
38 | <junit.version>4.12</junit.version> | 38 | <junit.version>4.12</junit.version> |
39 | <slf4j.version>1.7.7</slf4j.version> | 39 | <slf4j.version>1.7.7</slf4j.version> |
40 | - <logback.version>1.1.7</logback.version> | 40 | + <logback.version>1.2.3</logback.version> |
41 | <mockito.version>1.9.5</mockito.version> | 41 | <mockito.version>1.9.5</mockito.version> |
42 | <rat.version>0.10</rat.version> | 42 | <rat.version>0.10</rat.version> |
43 | <cassandra.version>3.0.0</cassandra.version> | 43 | <cassandra.version>3.0.0</cassandra.version> |
@@ -55,6 +55,7 @@ import static org.thingsboard.server.transport.mqtt.adaptors.JsonMqttAdaptor.val | @@ -55,6 +55,7 @@ import static org.thingsboard.server.transport.mqtt.adaptors.JsonMqttAdaptor.val | ||
55 | @Slf4j | 55 | @Slf4j |
56 | public class GatewaySessionCtx { | 56 | public class GatewaySessionCtx { |
57 | 57 | ||
58 | + private static final String DEFAULT_DEVICE_TYPE = "default"; | ||
58 | private final Device gateway; | 59 | private final Device gateway; |
59 | private final SessionId gatewaySessionId; | 60 | private final SessionId gatewaySessionId; |
60 | private final SessionMsgProcessor processor; | 61 | private final SessionMsgProcessor processor; |
@@ -78,6 +79,11 @@ public class GatewaySessionCtx { | @@ -78,6 +79,11 @@ public class GatewaySessionCtx { | ||
78 | JsonElement json = getJson(msg); | 79 | JsonElement json = getJson(msg); |
79 | String deviceName = checkDeviceName(getDeviceName(json)); | 80 | String deviceName = checkDeviceName(getDeviceName(json)); |
80 | String deviceType = getDeviceType(json); | 81 | String deviceType = getDeviceType(json); |
82 | + onDeviceConnect(deviceName, deviceType); | ||
83 | + ack(msg); | ||
84 | + } | ||
85 | + | ||
86 | + private void onDeviceConnect(String deviceName, String deviceType) { | ||
81 | if (!devices.containsKey(deviceName)) { | 87 | if (!devices.containsKey(deviceName)) { |
82 | Optional<Device> deviceOpt = deviceService.findDeviceByTenantIdAndName(gateway.getTenantId(), deviceName); | 88 | Optional<Device> deviceOpt = deviceService.findDeviceByTenantIdAndName(gateway.getTenantId(), deviceName); |
83 | Device device = deviceOpt.orElseGet(() -> { | 89 | Device device = deviceOpt.orElseGet(() -> { |
@@ -95,7 +101,6 @@ public class GatewaySessionCtx { | @@ -95,7 +101,6 @@ public class GatewaySessionCtx { | ||
95 | processor.process(new BasicToDeviceActorSessionMsg(device, new BasicAdaptorToSessionActorMsg(ctx, new AttributesSubscribeMsg()))); | 101 | processor.process(new BasicToDeviceActorSessionMsg(device, new BasicAdaptorToSessionActorMsg(ctx, new AttributesSubscribeMsg()))); |
96 | processor.process(new BasicToDeviceActorSessionMsg(device, new BasicAdaptorToSessionActorMsg(ctx, new RpcSubscribeMsg()))); | 102 | processor.process(new BasicToDeviceActorSessionMsg(device, new BasicAdaptorToSessionActorMsg(ctx, new RpcSubscribeMsg()))); |
97 | } | 103 | } |
98 | - ack(msg); | ||
99 | } | 104 | } |
100 | 105 | ||
101 | public void onDeviceDisconnect(MqttPublishMessage msg) throws AdaptorException { | 106 | public void onDeviceDisconnect(MqttPublishMessage msg) throws AdaptorException { |
@@ -205,10 +210,9 @@ public class GatewaySessionCtx { | @@ -205,10 +210,9 @@ public class GatewaySessionCtx { | ||
205 | private String checkDeviceConnected(String deviceName) { | 210 | private String checkDeviceConnected(String deviceName) { |
206 | if (!devices.containsKey(deviceName)) { | 211 | if (!devices.containsKey(deviceName)) { |
207 | log.debug("[{}] Missing device [{}] for the gateway session", gatewaySessionId, deviceName); | 212 | log.debug("[{}] Missing device [{}] for the gateway session", gatewaySessionId, deviceName); |
208 | - throw new RuntimeException("Device " + deviceName + " is not connected!"); | ||
209 | - } else { | ||
210 | - return deviceName; | 213 | + onDeviceConnect(deviceName, DEFAULT_DEVICE_TYPE); |
211 | } | 214 | } |
215 | + return deviceName; | ||
212 | } | 216 | } |
213 | 217 | ||
214 | private String checkDeviceName(String deviceName) { | 218 | private String checkDeviceName(String deviceName) { |
@@ -225,7 +229,7 @@ public class GatewaySessionCtx { | @@ -225,7 +229,7 @@ public class GatewaySessionCtx { | ||
225 | 229 | ||
226 | private String getDeviceType(JsonElement json) throws AdaptorException { | 230 | private String getDeviceType(JsonElement json) throws AdaptorException { |
227 | JsonElement type = json.getAsJsonObject().get("type"); | 231 | JsonElement type = json.getAsJsonObject().get("type"); |
228 | - return type == null ? "default" : type.getAsString(); | 232 | + return type == null ? DEFAULT_DEVICE_TYPE : type.getAsString(); |
229 | } | 233 | } |
230 | 234 | ||
231 | private JsonElement getJson(MqttPublishMessage mqttMsg) throws AdaptorException { | 235 | private JsonElement getJson(MqttPublishMessage mqttMsg) throws AdaptorException { |
@@ -236,7 +240,7 @@ public class GatewaySessionCtx { | @@ -236,7 +240,7 @@ public class GatewaySessionCtx { | ||
236 | return processor; | 240 | return processor; |
237 | } | 241 | } |
238 | 242 | ||
239 | - protected DeviceAuthService getAuthService() { | 243 | + DeviceAuthService getAuthService() { |
240 | return authService; | 244 | return authService; |
241 | } | 245 | } |
242 | 246 | ||
@@ -250,7 +254,7 @@ public class GatewaySessionCtx { | @@ -250,7 +254,7 @@ public class GatewaySessionCtx { | ||
250 | } | 254 | } |
251 | } | 255 | } |
252 | 256 | ||
253 | - protected void writeAndFlush(MqttMessage mqttMessage) { | 257 | + void writeAndFlush(MqttMessage mqttMessage) { |
254 | channel.writeAndFlush(mqttMessage); | 258 | channel.writeAndFlush(mqttMessage); |
255 | } | 259 | } |
256 | 260 |