Browse Source

added ability to configure network configuration for lwm2m

pull/5577/head
YevhenBondarenko 5 years ago
parent
commit
52578645b8
  1. 3
      application/src/main/resources/thingsboard.yml
  2. 4
      common/data/src/main/java/org/thingsboard/server/common/data/TbProperty.java
  3. 5
      common/queue/src/main/java/org/thingsboard/server/queue/kafka/TbKafkaSettings.java
  4. 11
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/config/LwM2MTransportServerConfig.java
  5. 9
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mNetworkConfig.java
  6. 3
      transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml

3
application/src/main/resources/thingsboard.yml

@ -819,6 +819,9 @@ transport:
log_max_length: "${LWM2M_LOG_MAX_LENGTH:1024}" log_max_length: "${LWM2M_LOG_MAX_LENGTH:1024}"
# Use redis for Security and Registration stores # Use redis for Security and Registration stores
redis.enabled: "${LWM2M_REDIS_ENABLED:false}" redis.enabled: "${LWM2M_REDIS_ENABLED:false}"
network_config:
- key: "PROTOCOL_STAGE_THREAD_COUNT"
value: "${LWM2M_PROTOCOL_STAGE_THREAD_COUNT:12}"
snmp: snmp:
enabled: "${SNMP_ENABLED:true}" enabled: "${SNMP_ENABLED:true}"
response_processing: response_processing:

4
common/queue/src/main/java/org/thingsboard/server/queue/kafka/TbKafkaProperty.java → common/data/src/main/java/org/thingsboard/server/common/data/TbProperty.java

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.thingsboard.server.queue.kafka; package org.thingsboard.server.common.data;
import lombok.Data; import lombok.Data;
@ -21,7 +21,7 @@ import lombok.Data;
* Created by ashvayka on 25.09.18. * Created by ashvayka on 25.09.18.
*/ */
@Data @Data
public class TbKafkaProperty { public class TbProperty {
private String key; private String key;
private String value; private String value;

5
common/queue/src/main/java/org/thingsboard/server/queue/kafka/TbKafkaSettings.java

@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.TbProperty;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -104,10 +105,10 @@ public class TbKafkaSettings {
private String securityProtocol; private String securityProtocol;
@Setter @Setter
private List<TbKafkaProperty> other; private List<TbProperty> other;
@Setter @Setter
private Map<String, List<TbKafkaProperty>> consumerPropertiesPerTopic = Collections.emptyMap(); private Map<String, List<TbProperty>> consumerPropertiesPerTopic = Collections.emptyMap();
public Properties toAdminProps() { public Properties toAdminProps() {
Properties props = toProps(); Properties props = toProps();

11
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/config/LwM2MTransportServerConfig.java

@ -25,17 +25,16 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.ResourceUtils; import org.thingsboard.server.common.data.TbProperty;
import org.thingsboard.server.common.transport.config.ssl.SslCredentials; import org.thingsboard.server.common.transport.config.ssl.SslCredentials;
import org.thingsboard.server.common.transport.config.ssl.SslCredentialsConfig; import org.thingsboard.server.common.transport.config.ssl.SslCredentialsConfig;
import javax.annotation.PostConstruct; import java.util.List;
import java.io.InputStream;
import java.security.KeyStore;
@Slf4j @Slf4j
@Component @Component
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") @ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'")
@ConfigurationProperties(prefix = "transport.lwm2m")
public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig { public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig {
@Getter @Getter
@ -102,6 +101,10 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig {
@Value("${transport.lwm2m.paging_transmission_window:10000}") @Value("${transport.lwm2m.paging_transmission_window:10000}")
private long pagingTransmissionWindow; private long pagingTransmissionWindow;
@Getter
@Setter
private List<TbProperty> networkConfig;
@Bean @Bean
@ConfigurationProperties(prefix = "transport.lwm2m.server.security.credentials") @ConfigurationProperties(prefix = "transport.lwm2m.server.security.credentials")
public SslCredentialsConfig lwm2mServerCredentials() { public SslCredentialsConfig lwm2mServerCredentials() {

9
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mNetworkConfig.java

@ -17,6 +17,7 @@ package org.thingsboard.server.transport.lwm2m.server;
import org.eclipse.californium.core.network.config.NetworkConfig; import org.eclipse.californium.core.network.config.NetworkConfig;
import org.eclipse.californium.core.network.config.NetworkConfigDefaults; import org.eclipse.californium.core.network.config.NetworkConfigDefaults;
import org.springframework.util.CollectionUtils;
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
import static org.eclipse.californium.core.network.config.NetworkConfigDefaults.DEFAULT_BLOCKWISE_STATUS_LIFETIME; import static org.eclipse.californium.core.network.config.NetworkConfigDefaults.DEFAULT_BLOCKWISE_STATUS_LIFETIME;
@ -25,8 +26,8 @@ public class LwM2mNetworkConfig {
public static NetworkConfig getCoapConfig(Integer serverPortNoSec, Integer serverSecurePort, LwM2MTransportServerConfig config) { public static NetworkConfig getCoapConfig(Integer serverPortNoSec, Integer serverSecurePort, LwM2MTransportServerConfig config) {
NetworkConfig coapConfig = new NetworkConfig(); NetworkConfig coapConfig = new NetworkConfig();
coapConfig.setInt(NetworkConfig.Keys.COAP_PORT,serverPortNoSec); coapConfig.setInt(NetworkConfig.Keys.COAP_PORT, serverPortNoSec);
coapConfig.setInt(NetworkConfig.Keys.COAP_SECURE_PORT,serverSecurePort); coapConfig.setInt(NetworkConfig.Keys.COAP_SECURE_PORT, serverSecurePort);
/** /**
Example:Property for large packet: Example:Property for large packet:
#NetworkConfig config = new NetworkConfig(); #NetworkConfig config = new NetworkConfig();
@ -105,6 +106,10 @@ public class LwM2mNetworkConfig {
coapConfig.setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 10); coapConfig.setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 10);
if (!CollectionUtils.isEmpty(config.getNetworkConfig())) {
config.getNetworkConfig().forEach(p -> coapConfig.setString(p.getKey(), p.getValue()));
}
return coapConfig; return coapConfig;
} }
} }

3
transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml

@ -204,6 +204,9 @@ transport:
paging_transmission_window: "${LWM2M_PAGING_TRANSMISSION_WINDOW:10000}" paging_transmission_window: "${LWM2M_PAGING_TRANSMISSION_WINDOW:10000}"
# Use redis for Security and Registration stores # Use redis for Security and Registration stores
redis.enabled: "${LWM2M_REDIS_ENABLED:false}" redis.enabled: "${LWM2M_REDIS_ENABLED:false}"
network_config:
- key: "PROTOCOL_STAGE_THREAD_COUNT"
value: "${LWM2M_PROTOCOL_STAGE_THREAD_COUNT:12}"
stats: stats:
enabled: "${TB_TRANSPORT_STATS_ENABLED:true}" enabled: "${TB_TRANSPORT_STATS_ENABLED:true}"
print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}" print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}"

Loading…
Cancel
Save