Skip to content

Commit 96b3263

Browse files
committed
Merge remote-tracking branch 'upstream/master' into task/improve-condition-query-semantics
# Conflicts: # hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtilOptimizeTest.java
2 parents 952d38e + 89b648a commit 96b3263

93 files changed

Lines changed: 7739 additions & 1167 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/conf/hugegraph.properties.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ store=hugegraph
4545
pd.peers=$PD_PEERS_LIST$
4646

4747
# task config
48-
task.scheduler_type=local
4948
task.schedule_period=10
5049
task.retry=0
5150
task.wait_timeout=10

hugegraph-commons/hugegraph-common/src/main/resources/version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515

1616
# When updating the version, Version can be read from the pom file.
17-
# When hugegraph-common is updated, hugegraph-commons.version in the pom file needs to be updated,
17+
# hugegraph-common follows the project version defined by ${revision} in the root pom.xml,
1818
# and VersionInBash needs to be updated in this file.
1919
Version=${revision}
2020
ApiVersion=0.71

hugegraph-pd/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# Dockerfile for HugeGraph PD
2020
# 1st stage: build source code
21-
FROM maven:3.9.0-eclipse-temurin-11 AS build
21+
FROM --platform=$BUILDPLATFORM maven:3.9.0-eclipse-temurin-11 AS build
2222

2323
WORKDIR /pkg
2424

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hugegraph.pd.util;
19+
20+
import java.net.URI;
21+
import java.util.Optional;
22+
23+
import org.apache.hugegraph.pd.grpc.Metapb;
24+
25+
public final class StoreRestAddressUtil {
26+
27+
private static final String REST_PORT_LABEL = "rest.port";
28+
29+
private StoreRestAddressUtil() {
30+
}
31+
32+
public static String getRestAddress(Metapb.Store store) {
33+
if (store == null || store.getAddress().isEmpty()) {
34+
return null;
35+
}
36+
37+
Optional<String> label = store.getLabelsList().stream()
38+
.filter(item -> REST_PORT_LABEL.equals(
39+
item.getKey()))
40+
.map(Metapb.StoreLabel::getValue)
41+
.findFirst();
42+
if (!label.isPresent()) {
43+
return null;
44+
}
45+
46+
int port;
47+
try {
48+
port = Integer.parseInt(label.get().trim());
49+
} catch (NumberFormatException ignored) {
50+
return null;
51+
}
52+
if (port < 1 || port > 65535) {
53+
return null;
54+
}
55+
56+
try {
57+
String address = store.getAddress().trim();
58+
URI uri = address.contains("://") ? URI.create(address) :
59+
URI.create("http://" + address);
60+
String host = uri.getHost();
61+
if (host == null || host.isEmpty()) {
62+
return null;
63+
}
64+
String hostPart = host.contains(":") && !host.startsWith("[") ?
65+
"[" + host + "]" : host;
66+
return hostPart + ":" + port;
67+
} catch (IllegalArgumentException ignored) {
68+
return null;
69+
}
70+
}
71+
}

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/config/PDConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.stereotype.Component;
3232

3333
import lombok.Data;
34+
import lombok.ToString;
3435

3536
/**
3637
* PD profile
@@ -69,6 +70,7 @@ public class PDConfig {
6970
private ThreadPoolGrpc threadPoolGrpc;
7071

7172
@Value("${auth.secret-key: 'FXQXbJtbCLxODc6tGci732pkH1cyf8Qg'}")
73+
@ToString.Exclude
7274
private String secretKey;
7375

7476
@Autowired

hugegraph-pd/hg-pd-service/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
<dependency>
143143
<groupId>org.apache.hugegraph</groupId>
144144
<artifactId>hugegraph-common</artifactId>
145-
<version>${hugegraph-commons.version}</version>
145+
<version>${project.version}</version>
146146
<exclusions>
147147
<exclusion>
148148
<groupId>org.apache.logging.log4j</groupId>

hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/StoreAPI.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.hugegraph.pd.model.TimeRangeRequest;
3434
import org.apache.hugegraph.pd.service.PDRestService;
3535
import org.apache.hugegraph.pd.util.DateUtil;
36+
import org.apache.hugegraph.pd.util.StoreRestAddressUtil;
3637
import org.springframework.beans.factory.annotation.Autowired;
3738
import org.springframework.http.MediaType;
3839
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -278,6 +279,7 @@ class StoreStatistics {
278279
// store statistics
279280
String storeId;
280281
String address;
282+
String restAddress;
281283
String raftAddress;
282284
String version;
283285
String state;
@@ -302,6 +304,7 @@ class StoreStatistics {
302304
if (store != null) {
303305
storeId = String.valueOf(store.getId());
304306
address = store.getAddress();
307+
restAddress = StoreRestAddressUtil.getRestAddress(store);
305308
raftAddress = store.getRaftAddress();
306309
state = String.valueOf(store.getState());
307310
version = store.getVersion();

hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/service/SDConfigService.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.LinkedList;
2323
import java.util.List;
2424
import java.util.Map;
25-
import java.util.Optional;
2625
import java.util.Set;
2726
import java.util.function.Supplier;
2827
import java.util.stream.Collectors;
@@ -33,6 +32,7 @@
3332
import org.apache.hugegraph.pd.common.PDException;
3433
import org.apache.hugegraph.pd.config.PDConfig;
3534
import org.apache.hugegraph.pd.grpc.Metapb;
35+
import org.apache.hugegraph.pd.util.StoreRestAddressUtil;
3636
import org.apache.hugegraph.pd.grpc.Pdpb;
3737
import org.apache.hugegraph.pd.grpc.discovery.NodeInfo;
3838
import org.apache.hugegraph.pd.grpc.discovery.NodeInfos;
@@ -206,7 +206,7 @@ private Set<String> getStoreAddresses() {
206206
}
207207
if (stores != null) {
208208
stores.stream().forEach(e -> {
209-
String buf = getRestAddress(e);
209+
String buf = StoreRestAddressUtil.getRestAddress(e);
210210
if (buf != null) {
211211
res.add(buf);
212212
}
@@ -215,37 +215,6 @@ private Set<String> getStoreAddresses() {
215215
return res;
216216
}
217217

218-
// TODO: optimized store registry data, to add host:port of REST server.
219-
private String getRestAddress(Metapb.Store store) {
220-
String address = store.getAddress();
221-
if (address == null || address.isEmpty()) {
222-
return null;
223-
}
224-
try {
225-
Optional<String> port = store.getLabelsList().stream().map(
226-
e -> {
227-
if ("rest.port".equals(e.getKey())) {
228-
return e.getValue();
229-
}
230-
return null;
231-
}).filter(e -> e != null).findFirst();
232-
233-
if (port.isPresent()) {
234-
java.net.URI uri = address.contains("://")
235-
? java.net.URI.create(address)
236-
: java.net.URI.create("http://" + address);
237-
String host = uri.getHost() != null ? uri.getHost() : address;
238-
String hostPart =
239-
host.contains(":") && !host.startsWith("[") ? "[" + host + "]" : host;
240-
address = hostPart + ":" + port.get().trim();
241-
}
242-
} catch (Throwable t) {
243-
log.error("Failed to extract the REST address of store, cause by:", t);
244-
}
245-
return address;
246-
247-
}
248-
249218
public List<SDConfig> getConfigs(String appName, String path) {
250219
HgAssert.isArgumentNotNull(appName, "appName");
251220
SDConfig config;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hugegraph.pd.core;
19+
20+
import org.apache.hugegraph.pd.config.PDConfig;
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
24+
public class PDConfigTest {
25+
26+
@Test
27+
public void testToStringDoesNotExposeSecretKey() {
28+
PDConfig config = new PDConfig();
29+
config.setClusterId(123L);
30+
config.setDataPath("pd-test-data");
31+
config.setInitialStoreList("");
32+
config.setSecretKey("secret-value-that-must-not-appear");
33+
34+
String text = config.toString();
35+
36+
Assert.assertEquals("secret-value-that-must-not-appear",
37+
config.getSecretKey());
38+
Assert.assertFalse(text.contains("secret-value-that-must-not-appear"));
39+
Assert.assertFalse(text.contains("secretKey"));
40+
Assert.assertTrue(text.contains("clusterId=123"));
41+
Assert.assertTrue(text.contains("dataPath=pd-test-data"));
42+
}
43+
}

hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreSuiteTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@Suite.SuiteClasses({
3232
MetadataKeyHelperTest.class,
3333
HgKVStoreImplTest.class,
34+
PDConfigTest.class,
3435
ConfigServiceTest.class,
3536
IdServiceTest.class,
3637
KvServiceTest.class,

0 commit comments

Comments
 (0)