From 91111e55550d7d46a007db2f483b02a2dcd0a1a0 Mon Sep 17 00:00:00 2001 From: Calvin Date: Fri, 19 Jul 2024 16:28:40 +0800 Subject: [PATCH] [refactor] remove chinese and change code style in Warehouse (#2312) --- .../WareHouseApplicationReadyListener.java | 2 +- .../warehouse/store/DataStorageDispatch.java | 5 ++--- .../store/history/iotdb/IotDbDataStorage.java | 14 +++++++------- .../history/tdengine/TdEngineDataStorage.java | 6 +++--- .../store/realtime/redis/RedisDataStorage.java | 9 ++++----- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/listener/WareHouseApplicationReadyListener.java b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/listener/WareHouseApplicationReadyListener.java index ba7501071c7..4ce7887f88c 100644 --- a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/listener/WareHouseApplicationReadyListener.java +++ b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/listener/WareHouseApplicationReadyListener.java @@ -31,7 +31,7 @@ @Component public class WareHouseApplicationReadyListener { - private Optional historyDataStorage; + private final Optional historyDataStorage; public WareHouseApplicationReadyListener(Optional historyDataStorage) { this.historyDataStorage = historyDataStorage; diff --git a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/DataStorageDispatch.java b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/DataStorageDispatch.java index 6b4ed8b7083..f9f6b69213e 100644 --- a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/DataStorageDispatch.java +++ b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/DataStorageDispatch.java @@ -78,9 +78,8 @@ protected void startPersistentDataStorage() { if (metricsData == null) { continue; } - if (historyDataWriter.isPresent()) { - historyDataWriter.get().saveData(metricsData); - } + + historyDataWriter.ifPresent(dataWriter -> dataWriter.saveData(metricsData)); } catch (Exception e) { log.error(e.getMessage(), e); } diff --git a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/iotdb/IotDbDataStorage.java b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/iotdb/IotDbDataStorage.java index 777a0a7d30c..9626ba16fd9 100644 --- a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/iotdb/IotDbDataStorage.java +++ b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/iotdb/IotDbDataStorage.java @@ -55,7 +55,7 @@ public class IotDbDataStorage extends AbstractHistoryDataStorage { private static final String NEVER_EXPIRE = "-1"; /** - * storage group (存储组) + * storage group */ private static final String STORAGE_GROUP = "root.hertzbeat"; @@ -379,9 +379,9 @@ private void handleHistoryIntervalSelect(String selectSql, String instance, } /** - * 获取deviceId下的所有设备 + * Query all devices by deviceId * - * @param deviceId 设备/实体 + * @param deviceId deviceId */ private List queryAllDevices(String deviceId) { String showDevicesSql = String.format(SHOW_DEVICES, deviceId + ".*"); @@ -406,10 +406,10 @@ private List queryAllDevices(String deviceId) { } /** - * gets the device ID - * 有instanceId的使用 ${group}.${app}.${metrics}.${monitor}.${labels} 的方式 - * 否则使用 ${group}.${app}.${metrics}.${monitor} 的方式 - * 查询时可以通过 ${group}.${app}.${metrics}.${monitor}.* 的方式获取所有instance数据 + * use ${group}.${app}.${metrics}.${monitor}.${labels} to get device id if there is a way to get instanceId + * otherwise use ${group}.${app}.${metrics}.${monitor} + * + * Use ${group}.${app}.${metrics}.${monitor}.* to get all instance data when you tend to query */ private String getDeviceId(String app, String metrics, Long monitorId, String labels, boolean useQuote) { String deviceId = STORAGE_GROUP + "." diff --git a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/tdengine/TdEngineDataStorage.java b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/tdengine/TdEngineDataStorage.java index 7f9c896a2bd..ead5737f019 100644 --- a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/tdengine/TdEngineDataStorage.java +++ b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/tdengine/TdEngineDataStorage.java @@ -100,9 +100,9 @@ public TdEngineDataStorage(TdEngineProperties tdEngineProperties) { } /** - * {@code TdEngine} 初始化数据库 + * {@code TdEngine} init TdEngineDatabase * - * @param tdEngineProperties {@link TdEngineProperties} 对象实例 + * @param tdEngineProperties {@link TdEngineProperties} */ private void initTdEngineDatabase(final TdEngineProperties tdEngineProperties) throws SQLException { final Properties parseResultProperties = com.taosdata.jdbc.utils.StringUtils.parseUrl(tdEngineProperties.url(), null); @@ -376,7 +376,7 @@ public Map> getHistoryIntervalMetricData(Long monitorId, Str instances.add(label); } if (instances.isEmpty()) { - // 若未指定instance,需查询当前指标数据前1周有多少个instance + // need to confirm that how many instances of current metrics one week ago String queryInstanceSql = String.format(QUERY_INSTANCE_SQL, table); Connection connection = null; try { diff --git a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/realtime/redis/RedisDataStorage.java b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/realtime/redis/RedisDataStorage.java index b9a08953dd7..12ce78738b9 100644 --- a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/realtime/redis/RedisDataStorage.java +++ b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/realtime/redis/RedisDataStorage.java @@ -99,13 +99,12 @@ private boolean initRedisClient(RedisProperties redisProperties) { log.error("init error, please config Warehouse redis props in application.yml"); return false; } - RedisProperties redisProp = redisProperties; RedisURI.Builder uriBuilder = RedisURI.builder() - .withHost(redisProp.host()) - .withPort(redisProp.port()) + .withHost(redisProperties.host()) + .withPort(redisProperties.port()) .withTimeout(Duration.of(10, ChronoUnit.SECONDS)); - if (redisProp.password() != null && !"".equals(redisProp.password())) { - uriBuilder.withPassword(redisProp.password().toCharArray()); + if (redisProperties.password() != null && !"".equals(redisProperties.password())) { + uriBuilder.withPassword(redisProperties.password().toCharArray()); } try { redisClient = RedisClient.create(uriBuilder.build());