This is an automated email from the ASF dual-hosted git repository.
gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new f1ed92a52 [refactor] change the warehouse properties the type to
record (#1806)
f1ed92a52 is described below
commit f1ed92a525da5ba105d940012e649819e1abb209
Author: xuziyang <[email protected]>
AuthorDate: Mon Apr 22 11:28:04 2024 +0800
[refactor] change the warehouse properties the type to record (#1806)
Co-authored-by: tomsun28 <[email protected]>
---
.../warehouse/config/WarehouseProperties.java | 296 +++++----------------
.../store/HistoryGrepTimeDbDataStorage.java | 2 +-
.../store/HistoryInfluxdbDataStorage.java | 2 +-
.../warehouse/store/HistoryIotDbDataStorage.java | 2 +-
.../store/HistoryJpaDatabaseDataStorage.java | 2 +-
.../store/HistoryTdEngineDataStorage.java | 6 +-
.../store/HistoryVictoriaMetricsDataStorage.java | 4 +-
.../warehouse/store/RealTimeMemoryDataStorage.java | 6 +-
.../warehouse/store/RealTimeRedisDataStorage.java | 6 +-
9 files changed, 88 insertions(+), 238 deletions(-)
diff --git
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/config/WarehouseProperties.java
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/config/WarehouseProperties.java
index f0c7548ae..3dc69dfd8 100644
---
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/config/WarehouseProperties.java
+++
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/config/WarehouseProperties.java
@@ -24,209 +24,62 @@ import
org.springframework.boot.context.properties.bind.DefaultValue;
/**
* Data warehouse configuration properties
+ * @param entrance Data entry configuration properties
+ * @param store Datastore configuration properties
*/
@ConfigurationProperties(prefix = "warehouse")
-public class WarehouseProperties {
-
- /**
- * Data entry configuration properties
- */
- private EntranceProperties entrance;
-
- /**
- * Datastore configuration properties
- */
- private StoreProperties store;
-
- public EntranceProperties getEntrance() {
- return entrance;
- }
-
- public void setEntrance(EntranceProperties entrance) {
- this.entrance = entrance;
- }
-
- public StoreProperties getStore() {
- return store;
- }
-
- public void setStore(StoreProperties store) {
- this.store = store;
- }
+public record WarehouseProperties (
+ EntranceProperties entrance,
+ StoreProperties store
+) {
/**
* Data entry configuration properties
* The entrance can be to obtain data from message middleware such as
kafka rabbitmq rocketmq
*/
- public static class EntranceProperties {
-
- /**
- * kafka configuration information
- */
- private KafkaProperties kafka;
-
- public KafkaProperties getKafka() {
- return kafka;
- }
-
- public void setKafka(KafkaProperties kafka) {
- this.kafka = kafka;
- }
-
+ public record EntranceProperties(
+ KafkaProperties kafka
+ ){
/**
* kafka configuration information
*/
- public static class KafkaProperties {
- /**
- * Whether kafka data entry is started
- */
- private boolean enabled = true;
-
- /**
- * kafka connection server url
- */
- private String servers = "127.0.0.1:9092";
- /**
- * Topic name to receive data
- */
- private String topic;
- /**
- * Consumer group ID
- */
- private String groupId;
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public String getServers() {
- return servers;
- }
-
- public String getTopic() {
- return topic;
- }
-
- public String getGroupId() {
- return groupId;
- }
- }
-
+ public record KafkaProperties(
+ @DefaultValue("true") boolean enabled,
+ @DefaultValue("127.0.0.1:9092") String servers,
+ String topic,
+ String groupId
+ ){}
}
-
/**
* Scheduling data export configuration properties
+ * @param jpa use mysql/h2 jpa store metrics history data
+ * @param memory Memory storage configuration information
+ * @param influxdb influxdb configuration information
+ * @param redis redis configuration information
+ * @param victoriaMetrics VictoriaMetrics Properties
+ * @param tdEngine TdEngine configuration information
+ * @param iotDb IoTDB configuration information
+ * @param greptime GrepTimeDB Config
*/
- public static class StoreProperties {
-
- /**
- * use mysql/h2 jpa store metrics history data
- */
- private JpaProperties jpa;
-
- /**
- * Memory storage configuration information
- */
- private MemoryProperties memory;
-
- /**
- * influxdb configuration information
- */
- private InfluxdbProperties influxdb;
- /**
- * redis configuration information
- */
- private RedisProperties redis;
- /**
- * VictoriaMetrics Properties
- */
- private VictoriaMetricsProperties victoriaMetrics;
- /**
- * TdEngine configuration information
- */
- private TdEngineProperties tdEngine;
- /**
- * IoTDB configuration information
- */
- private IotDbProperties iotDb;
- /**
- * GrepTimeDB Config
- */
- private GreptimeProperties greptime;
-
- public JpaProperties getJpa() {
- return jpa;
- }
-
- public void setJpa(JpaProperties jpa) {
- this.jpa = jpa;
- }
-
- public MemoryProperties getMemory() {
- return memory;
- }
-
- public void setMemory(MemoryProperties memory) {
- this.memory = memory;
- }
-
- public InfluxdbProperties getInfluxdb() {
- return influxdb;
- }
-
- public void setInfluxdb(InfluxdbProperties influxdb) {
- this.influxdb = influxdb;
- }
-
- public RedisProperties getRedis() {
- return redis;
- }
-
- public void setRedis(RedisProperties redis) {
- this.redis = redis;
- }
-
- public VictoriaMetricsProperties getVictoriaMetrics() {
- return victoriaMetrics;
- }
-
- public void setVictoriaMetrics(VictoriaMetricsProperties
victoriaMetrics) {
- this.victoriaMetrics = victoriaMetrics;
- }
-
- public TdEngineProperties getTdEngine() {
- return tdEngine;
- }
-
- public void setTdEngine(TdEngineProperties tdEngine) {
- this.tdEngine = tdEngine;
- }
-
- public IotDbProperties getIotDb() {
- return iotDb;
- }
-
- public void setIotDb(IotDbProperties iotDb) {
- this.iotDb = iotDb;
- }
-
- public GreptimeProperties getGreptime() {
- return greptime;
- }
-
- public void setGreptime(GreptimeProperties greptime) {
- this.greptime = greptime;
- }
-
+ public record StoreProperties(
+ JpaProperties jpa,
+ MemoryProperties memory,
+ InfluxdbProperties influxdb,
+ RedisProperties redis,
+ VictoriaMetricsProperties victoriaMetrics,
+ TdEngineProperties tdEngine,
+ IotDbProperties iotDb,
+ GreptimeProperties greptime
+ ){
/**
* Memory storage configuration information
* @param enabled Whether memory data storage is enabled
* @param initSize Memory storage map initialization size
*/
public record MemoryProperties(
- @DefaultValue("true") boolean enabled,
- @DefaultValue("1024") Integer initSize
+ @DefaultValue("true") boolean enabled,
+ @DefaultValue("1024") Integer initSize
){}
/**
@@ -236,21 +89,21 @@ public class WarehouseProperties {
* @param maxHistoryRecordNum The maximum number of history records
retained
*/
public record JpaProperties(
- @DefaultValue("true") boolean enabled,
- @DefaultValue("1h") String expireTime,
- @DefaultValue("20000") Integer maxHistoryRecordNum
+ @DefaultValue("true") boolean enabled,
+ @DefaultValue("1h") String expireTime,
+ @DefaultValue("20000") Integer maxHistoryRecordNum
) {}
/**
* Influxdb configuration information
*/
public record InfluxdbProperties(
- @DefaultValue("false") boolean enabled,
- String serverUrl,
- String username,
- String password,
- @DefaultValue("30d") String expireTime,
- @DefaultValue("1") int replication) {}
+ @DefaultValue("false") boolean enabled,
+ String serverUrl,
+ String username,
+ String password,
+ @DefaultValue("30d") String expireTime,
+ @DefaultValue("1") int replication) {}
/**
*
@@ -262,32 +115,31 @@ public class WarehouseProperties {
* @param tableStrColumnDefineMaxLength auto create table's string
column define max length : NCHAR(200)
*/
public record TdEngineProperties(
- @DefaultValue("false") boolean enabled,
- @DefaultValue("jdbc:TAOS-RS://localhost:6041/demo") String url,
- @DefaultValue("com.taosdata.jdbc.rs.RestfulDriver") String
driverClassName,
- String username,
- String password,
- @DefaultValue("200") int tableStrColumnDefineMaxLength) {}
+ @DefaultValue("false") boolean enabled,
+ @DefaultValue("jdbc:TAOS-RS://localhost:6041/demo") String url,
+ @DefaultValue("com.taosdata.jdbc.rs.RestfulDriver") String
driverClassName,
+ String username,
+ String password,
+ @DefaultValue("200") int tableStrColumnDefineMaxLength) {}
/**
* Victoriametrics configuration information
*/
public record VictoriaMetricsProperties(
- @DefaultValue("false") boolean enabled,
- @DefaultValue("http://localhost:8428") String url,
- String username,
- String password)
- {}
+ @DefaultValue("false") boolean enabled,
+ @DefaultValue("http://localhost:8428") String url,
+ String username,
+ String password) {}
/**
* Redis configuration information
*/
public record RedisProperties(
- @DefaultValue("false") boolean enabled,
- @DefaultValue("127.0.0.1") String host,
- @DefaultValue("6379") Integer port,
- String password,
- @DefaultValue("0") Integer db) {}
+ @DefaultValue("false") boolean enabled,
+ @DefaultValue("127.0.0.1") String host,
+ @DefaultValue("6379") Integer port,
+ String password,
+ @DefaultValue("0") Integer db) {}
/**
* IotDB configuration information
@@ -296,31 +148,29 @@ public class WarehouseProperties {
* @param expireTime save data expire time(ms),-1 means it never
expires Data storage time (unit: ms,-1 means never expire)
* Note: Why is String used here instead of Long? At
present, the set ttl of IoTDB only supports milliseconds as a unit,
* and other units may be added later, so the String
type is used for compatibility Data storage time (unit: ms, -1 means never
expires)
- *
* Note: Why use String instead of Long here?
Currently, IoTDB's set ttl only supports milliseconds as the unit.
* Other units may be added later. In order to be
compatible with the future, the String type is used.
*/
public record IotDbProperties(
- @DefaultValue("false") boolean enabled,
- @DefaultValue("127.0.0.1") String host,
- @DefaultValue("6667") Integer rpcPort,
- String username,
- String password,
- List<String> nodeUrls,
- ZoneId zoneId,
- IotDbVersion version,
- long queryTimeoutInMs,
- String expireTime) {}
+ @DefaultValue("false") boolean enabled,
+ @DefaultValue("127.0.0.1") String host,
+ @DefaultValue("6667") Integer rpcPort,
+ String username,
+ String password,
+ List<String> nodeUrls,
+ ZoneId zoneId,
+ IotDbVersion version,
+ long queryTimeoutInMs,
+ String expireTime) {}
/**
* GrepTimeDB configuration information
*/
public record GreptimeProperties(
- @DefaultValue("false") boolean enabled,
- @DefaultValue("127.0.0.1:4001") String endpoint,
- String username,
- String password) {}
-
+ @DefaultValue("false") boolean enabled,
+ @DefaultValue("127.0.0.1:4001") String endpoint,
+ String username,
+ String password) {}
}
}
diff --git
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryGrepTimeDbDataStorage.java
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryGrepTimeDbDataStorage.java
index e9cd26067..7e408c97b 100644
---
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryGrepTimeDbDataStorage.java
+++
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryGrepTimeDbDataStorage.java
@@ -84,7 +84,7 @@ public class HistoryGrepTimeDbDataStorage extends
AbstractHistoryDataStorage {
private GreptimeDB greptimeDb;
public HistoryGrepTimeDbDataStorage(WarehouseProperties properties) {
- this.serverAvailable =
this.initDbSession(properties.getStore().getGreptime());
+ this.serverAvailable =
this.initDbSession(properties.store().greptime());
}
private boolean
initDbSession(WarehouseProperties.StoreProperties.GreptimeProperties
properties) {
diff --git
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryInfluxdbDataStorage.java
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryInfluxdbDataStorage.java
index a786e4f85..d86f9beb5 100644
---
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryInfluxdbDataStorage.java
+++
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryInfluxdbDataStorage.java
@@ -93,7 +93,7 @@ public class HistoryInfluxdbDataStorage extends
AbstractHistoryDataStorage {
client.sslSocketFactory(defaultSslSocketFactory(),
defaultTrustManager());
client.hostnameVerifier(noopHostnameVerifier());
- WarehouseProperties.StoreProperties.InfluxdbProperties
influxdbProperties = properties.getStore().getInfluxdb();
+ WarehouseProperties.StoreProperties.InfluxdbProperties
influxdbProperties = properties.store().influxdb();
this.influxDb =
InfluxDBFactory.connect(influxdbProperties.serverUrl(),
influxdbProperties.username(), influxdbProperties.password(), client);
// Close it if your application is terminating, or you are not using
it anymore.
Runtime.getRuntime().addShutdownHook(new Thread(influxDb::close));
diff --git
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryIotDbDataStorage.java
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryIotDbDataStorage.java
index b5665104a..bbafe19a9 100644
---
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryIotDbDataStorage.java
+++
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryIotDbDataStorage.java
@@ -88,7 +88,7 @@ public class HistoryIotDbDataStorage extends
AbstractHistoryDataStorage {
private long queryTimeoutInMs;
public HistoryIotDbDataStorage(WarehouseProperties properties) {
- this.serverAvailable =
this.initIotDbSession(properties.getStore().getIotDb());
+ this.serverAvailable =
this.initIotDbSession(properties.store().iotDb());
}
private boolean
initIotDbSession(WarehouseProperties.StoreProperties.IotDbProperties
properties) {
diff --git
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java
index 9324ccc9f..942f203b3 100644
---
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java
+++
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java
@@ -64,7 +64,7 @@ public class HistoryJpaDatabaseDataStorage extends
AbstractHistoryDataStorage {
public HistoryJpaDatabaseDataStorage(WarehouseProperties properties,
HistoryDao historyDao) {
- this.jpaProperties = properties.getStore().getJpa();
+ this.jpaProperties = properties.store().jpa();
this.serverAvailable = true;
this.historyDao = historyDao;
expiredDataCleaner();
diff --git
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryTdEngineDataStorage.java
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryTdEngineDataStorage.java
index 1fff1a401..4b96694b2 100644
---
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryTdEngineDataStorage.java
+++
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryTdEngineDataStorage.java
@@ -73,12 +73,12 @@ public class HistoryTdEngineDataStorage extends
AbstractHistoryDataStorage {
private final int tableStrColumnDefineMaxLength;
public HistoryTdEngineDataStorage(WarehouseProperties properties) {
- if (properties == null || properties.getStore() == null ||
properties.getStore().getTdEngine() == null) {
+ if (properties == null || properties.store() == null ||
properties.store().tdEngine() == null) {
log.error("init error, please config Warehouse TdEngine props in
application.yml");
throw new IllegalArgumentException("please config Warehouse
TdEngine props");
}
- tableStrColumnDefineMaxLength =
properties.getStore().getTdEngine().tableStrColumnDefineMaxLength();
- serverAvailable =
initTdEngineDatasource(properties.getStore().getTdEngine());
+ tableStrColumnDefineMaxLength =
properties.store().tdEngine().tableStrColumnDefineMaxLength();
+ serverAvailable =
initTdEngineDatasource(properties.store().tdEngine());
}
private boolean
initTdEngineDatasource(WarehouseProperties.StoreProperties.TdEngineProperties
tdEngineProperties) {
diff --git
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryVictoriaMetricsDataStorage.java
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryVictoriaMetricsDataStorage.java
index 6033e4397..e2279618b 100644
---
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryVictoriaMetricsDataStorage.java
+++
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryVictoriaMetricsDataStorage.java
@@ -92,12 +92,12 @@ public class HistoryVictoriaMetricsDataStorage extends
AbstractHistoryDataStorag
private final RestTemplate restTemplate;
public HistoryVictoriaMetricsDataStorage(WarehouseProperties properties,
RestTemplate restTemplate) {
- if (properties == null || properties.getStore() == null ||
properties.getStore().getVictoriaMetrics() == null) {
+ if (properties == null || properties.store() == null ||
properties.store().victoriaMetrics() == null) {
log.error("init error, please config Warehouse victoriaMetrics
props in application.yml");
throw new IllegalArgumentException("please config Warehouse
victoriaMetrics props");
}
this.restTemplate = restTemplate;
- victoriaMetricsProp = properties.getStore().getVictoriaMetrics();
+ victoriaMetricsProp = properties.store().victoriaMetrics();
serverAvailable = checkVictoriaMetricsDatasourceAvailable();
}
diff --git
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/RealTimeMemoryDataStorage.java
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/RealTimeMemoryDataStorage.java
index 3f9d1defc..94beb837c 100644
---
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/RealTimeMemoryDataStorage.java
+++
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/RealTimeMemoryDataStorage.java
@@ -46,9 +46,9 @@ public class RealTimeMemoryDataStorage extends
AbstractRealTimeDataStorage {
public RealTimeMemoryDataStorage(WarehouseProperties properties) {
int initSize = DEFAULT_INIT_SIZE;
- if (properties != null && properties.getStore() != null &&
properties.getStore().getMemory() != null
- && properties.getStore().getMemory().initSize() != null) {
- initSize = properties.getStore().getMemory().initSize();
+ if (properties != null && properties.store() != null &&
properties.store().memory() != null
+ && properties.store().memory().initSize() != null) {
+ initSize = properties.store().memory().initSize();
}
monitorMetricsDataMap = new ConcurrentHashMap<>(initSize);
this.serverAvailable = true;
diff --git
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/RealTimeRedisDataStorage.java
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/RealTimeRedisDataStorage.java
index 7dcefb05f..5d8c1459b 100644
---
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/RealTimeRedisDataStorage.java
+++
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/RealTimeRedisDataStorage.java
@@ -55,7 +55,7 @@ public class RealTimeRedisDataStorage extends
AbstractRealTimeDataStorage {
}
private Integer getRedisSelectDb(WarehouseProperties properties){
- return properties.getStore().getRedis().db();
+ return properties.store().redis().db();
}
@Override
@@ -96,11 +96,11 @@ public class RealTimeRedisDataStorage extends
AbstractRealTimeDataStorage {
}
private boolean initRedisClient(WarehouseProperties properties) {
- if (properties == null || properties.getStore() == null ||
properties.getStore().getRedis() == null) {
+ if (properties == null || properties.store() == null ||
properties.store().redis() == null) {
log.error("init error, please config Warehouse redis props in
application.yml");
return false;
}
- WarehouseProperties.StoreProperties.RedisProperties redisProp =
properties.getStore().getRedis();
+ WarehouseProperties.StoreProperties.RedisProperties redisProp =
properties.store().redis();
RedisURI.Builder uriBuilder = RedisURI.builder()
.withHost(redisProp.host())
.withPort(redisProp.port())
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]