Skip to content

Commit b3892da

Browse files
authored
Add TrimProperties to trim properties auto (#14289)
* Add TrimProperties to trim properties auto * add license
1 parent 01f0a8f commit b3892da

File tree

11 files changed

+224
-79
lines changed

11 files changed

+224
-79
lines changed

iotdb-core/confignode/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@
154154
<artifactId>mockito-core</artifactId>
155155
<scope>test</scope>
156156
</dependency>
157+
<dependency>
158+
<groupId>com.tngtech.archunit</groupId>
159+
<artifactId>archunit</artifactId>
160+
<version>1.3.0</version>
161+
<scope>test</scope>
162+
</dependency>
157163
</dependencies>
158164
<build>
159165
<plugins>

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.iotdb.commons.conf.CommonDescriptor;
2424
import org.apache.iotdb.commons.conf.ConfigurationFileUtils;
2525
import org.apache.iotdb.commons.conf.IoTDBConstant;
26+
import org.apache.iotdb.commons.conf.TrimProperties;
2627
import org.apache.iotdb.commons.exception.BadNodeUrlException;
2728
import org.apache.iotdb.commons.schema.SchemaConstant;
2829
import org.apache.iotdb.commons.utils.NodeUrlUtils;
@@ -46,7 +47,6 @@
4647
import java.nio.charset.StandardCharsets;
4748
import java.util.Collections;
4849
import java.util.Optional;
49-
import java.util.Properties;
5050

5151
public class ConfigNodeDescriptor {
5252
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigNodeDescriptor.class);
@@ -118,13 +118,13 @@ else if (!urlString.endsWith(".properties")) {
118118
}
119119

120120
private void loadProps() {
121-
Properties commonProperties = new Properties();
121+
TrimProperties trimProperties = new TrimProperties();
122122
URL url = getPropsUrl(CommonConfig.SYSTEM_CONFIG_NAME);
123123
if (url != null) {
124124
try (InputStream inputStream = url.openStream()) {
125125
LOGGER.info("start reading ConfigNode conf file: {}", url);
126-
commonProperties.load(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
127-
loadProperties(commonProperties);
126+
trimProperties.load(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
127+
loadProperties(trimProperties);
128128
} catch (IOException | BadNodeUrlException e) {
129129
LOGGER.error("Couldn't load ConfigNode conf file, reject ConfigNode startup.", e);
130130
System.exit(-1);
@@ -133,7 +133,7 @@ private void loadProps() {
133133
commonDescriptor
134134
.getConfig()
135135
.updatePath(System.getProperty(ConfigNodeConstant.CONFIGNODE_HOME, null));
136-
MetricConfigDescriptor.getInstance().loadProps(commonProperties, true);
136+
MetricConfigDescriptor.getInstance().loadProps(trimProperties, true);
137137
MetricConfigDescriptor.getInstance()
138138
.getMetricConfig()
139139
.updateRpcInstance(NodeType.CONFIGNODE, SchemaConstant.SYSTEM_DATABASE);
@@ -145,7 +145,7 @@ private void loadProps() {
145145
}
146146
}
147147

148-
private void loadProperties(Properties properties) throws BadNodeUrlException, IOException {
148+
private void loadProperties(TrimProperties properties) throws BadNodeUrlException, IOException {
149149
conf.setClusterName(
150150
properties.getProperty(IoTDBConstant.CLUSTER_NAME, conf.getClusterName()).trim());
151151

@@ -401,7 +401,7 @@ private void loadProperties(Properties properties) throws BadNodeUrlException, I
401401
loadCQConfig(properties);
402402
}
403403

404-
private void loadRatisConsensusConfig(Properties properties) {
404+
private void loadRatisConsensusConfig(TrimProperties properties) {
405405
conf.setDataRegionRatisConsensusLogAppenderBufferSize(
406406
Long.parseLong(
407407
properties
@@ -813,7 +813,7 @@ private void loadRatisConsensusConfig(Properties properties) {
813813
.trim()));
814814
}
815815

816-
private void loadCQConfig(Properties properties) {
816+
private void loadCQConfig(TrimProperties properties) {
817817
int cqSubmitThread =
818818
Integer.parseInt(
819819
properties
@@ -871,7 +871,7 @@ public boolean isSeedConfigNode() {
871871
}
872872
}
873873

874-
public void loadHotModifiedProps(Properties properties) {
874+
public void loadHotModifiedProps(TrimProperties properties) {
875875
Optional.ofNullable(properties.getProperty(IoTDBConstant.CLUSTER_NAME))
876876
.ifPresent(conf::setClusterName);
877877
}

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.apache.iotdb.commons.conf.CommonDescriptor;
4343
import org.apache.iotdb.commons.conf.ConfigurationFileUtils;
4444
import org.apache.iotdb.commons.conf.IoTDBConstant;
45+
import org.apache.iotdb.commons.conf.TrimProperties;
4546
import org.apache.iotdb.commons.exception.IllegalPathException;
4647
import org.apache.iotdb.commons.exception.MetadataException;
4748
import org.apache.iotdb.commons.path.PartialPath;
@@ -257,7 +258,6 @@
257258
import java.util.HashSet;
258259
import java.util.List;
259260
import java.util.Map;
260-
import java.util.Properties;
261261
import java.util.Set;
262262
import java.util.concurrent.TimeUnit;
263263
import java.util.concurrent.atomic.AtomicBoolean;
@@ -1672,7 +1672,7 @@ public TSStatus setConfiguration(TSetConfigurationReq req) {
16721672
return tsStatus;
16731673
}
16741674
File file = new File(url.getFile());
1675-
Properties properties = new Properties();
1675+
TrimProperties properties = new TrimProperties();
16761676
properties.putAll(req.getConfigs());
16771677
try {
16781678
ConfigurationFileUtils.updateConfigurationFile(file, properties);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.iotdb.confignode.conf;
20+
21+
import com.tngtech.archunit.core.domain.JavaClasses;
22+
import com.tngtech.archunit.core.importer.ClassFileImporter;
23+
import com.tngtech.archunit.core.importer.ImportOption;
24+
import com.tngtech.archunit.lang.ArchRule;
25+
import org.junit.Test;
26+
27+
import java.util.Properties;
28+
29+
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
30+
31+
public class ConfigNodePropertiesTest {
32+
@Test
33+
public void TrimPropertiesOnly() {
34+
JavaClasses allClasses =
35+
new ClassFileImporter()
36+
.withImportOption(new ImportOption.DoNotIncludeTests())
37+
.importPackages("org.apache.iotdb");
38+
39+
ArchRule rule =
40+
noClasses()
41+
.that()
42+
.areAssignableTo("org.apache.iotdb.confignode.conf.ConfigNodeDescriptor")
43+
.should()
44+
.callMethod(Properties.class, "getProperty", String.class)
45+
.orShould()
46+
.callMethod(Properties.class, "getProperty", String.class, String.class);
47+
48+
rule.check(allClasses);
49+
}
50+
}

0 commit comments

Comments
 (0)