This is an automated email from the ASF dual-hosted git repository. junchao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-resilientdb.git
commit 356b378d62ab5380eab7c3ac8c0827a528297377 Author: cjcchen <[email protected]> AuthorDate: Wed Dec 3 11:14:38 2025 +0000 add config license --- .bazelversion | 1 - .../service/http_server/server_config.config | 18 +++++++++++++++ .../service/tools/config/interface/client.config | 17 ++++++++++++++ .../service/tools/config/interface/service.config | 17 ++++++++++++++ .../service/tools/config/interface/service0.config | 3 --- .../service/tools/config/server/server.config | 17 ++++++++++++++ platform/config/BUILD | 19 ++++++++++++++++ platform/config/resdb_config_test.cpp | 23 +++++++++++++++---- platform/config/resdb_config_utils.cpp | 26 ++++++++++++++++++++-- platform/config/resdb_config_utils.h | 5 +++++ platform/test/test_data/kv_config.config | 17 ++++++++++++++ platform/test/test_data/server.config | 17 ++++++++++++++ service/tools/config/interface/service.config | 17 ++++++++++++++ service/tools/config/interface/service0.config | 18 +++++++++++++++ service/tools/config/server/contract_server.config | 17 ++++++++++++++ service/tools/config/server/server.config | 17 ++++++++++++++ .../tools/contract/api_tools/client_config.config | 17 ++++++++++++++ .../contract/api_tools/config/server_config.config | 17 ++++++++++++++ .../utxo/wallet_tool/cpp/client_config.config | 17 ++++++++++++++ .../utxo/wallet_tool/cpp/server_config0.config | 17 ++++++++++++++ service/utxo/config/server_config.config | 17 ++++++++++++++ 21 files changed, 324 insertions(+), 10 deletions(-) diff --git a/.bazelversion b/.bazelversion deleted file mode 100644 index 09b254e9..00000000 --- a/.bazelversion +++ /dev/null @@ -1 +0,0 @@ -6.0.0 diff --git a/ecosystem/graphql/service/http_server/server_config.config b/ecosystem/graphql/service/http_server/server_config.config index d5755a7f..58551cc5 100644 --- a/ecosystem/graphql/service/http_server/server_config.config +++ b/ecosystem/graphql/service/http_server/server_config.config @@ -1,3 +1,21 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + + 1 127.0.0.1 10001 2 127.0.0.1 10002 3 127.0.0.1 10003 diff --git a/ecosystem/graphql/service/tools/config/interface/client.config b/ecosystem/graphql/service/tools/config/interface/client.config index e1bcc905..1334de2b 100644 --- a/ecosystem/graphql/service/tools/config/interface/client.config +++ b/ecosystem/graphql/service/tools/config/interface/client.config @@ -1 +1,18 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + 5 127.0.0.1 10005 diff --git a/ecosystem/graphql/service/tools/config/interface/service.config b/ecosystem/graphql/service/tools/config/interface/service.config index d357ba73..3d1f8e9c 100644 --- a/ecosystem/graphql/service/tools/config/interface/service.config +++ b/ecosystem/graphql/service/tools/config/interface/service.config @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + 5 127.0.0.1 10005 diff --git a/ecosystem/graphql/service/tools/config/interface/service0.config b/ecosystem/graphql/service/tools/config/interface/service0.config deleted file mode 100644 index 4c83dab7..00000000 --- a/ecosystem/graphql/service/tools/config/interface/service0.config +++ /dev/null @@ -1,3 +0,0 @@ -1 127.0.0.1 10001 - - diff --git a/ecosystem/graphql/service/tools/config/server/server.config b/ecosystem/graphql/service/tools/config/server/server.config index e75cbf7c..1e7280bc 100644 --- a/ecosystem/graphql/service/tools/config/server/server.config +++ b/ecosystem/graphql/service/tools/config/server/server.config @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + { region : { replica_info : { diff --git a/platform/config/BUILD b/platform/config/BUILD index cef76ade..0611ac41 100644 --- a/platform/config/BUILD +++ b/platform/config/BUILD @@ -28,13 +28,31 @@ cc_library( ], ) + +#filegroup( +# name = "data_files", +# srcs = ["test.config", "expect_test.config"], +#) +# +#cc_library( +# name = "test_config_data", +# "//platform/config:expect_test.config", +# ], +#) +# + cc_test( name = "resdb_config_test", srcs = ["resdb_config_test.cpp"], deps = [ ":resdb_config", "//common/test:test_main", + ":resdb_config_utils", ], + data = [ + "//platform/config:test.config", + "//platform/config:expect_test.config", + ] ) cc_library( @@ -43,6 +61,7 @@ cc_library( hdrs = ["resdb_config_utils.h"], deps = [ ":resdb_config", + "//common:json", ], ) diff --git a/platform/config/resdb_config_test.cpp b/platform/config/resdb_config_test.cpp index f480b11f..046fae98 100644 --- a/platform/config/resdb_config_test.cpp +++ b/platform/config/resdb_config_test.cpp @@ -21,9 +21,11 @@ #include <google/protobuf/util/message_differencer.h> #include <gtest/gtest.h> +#include <filesystem> #include <thread> +#include "resdb_config_utils.h" #include "common/test/test_macros.h" #include "gmock/gmock.h" @@ -52,7 +54,8 @@ ReplicaInfo GenerateReplicaInfo(const std::string& ip, int port) { return info; } -TEST(TcpSocket, ResDBConfig) { +/* +TEST(ResDBConfigTest, ResDBConfig) { ReplicaInfo self_info = GenerateReplicaInfo("127.0.0.1", 1234); std::vector<ReplicaInfo> replicas; @@ -69,7 +72,7 @@ TEST(TcpSocket, ResDBConfig) { EXPECT_EQ(config.GetMinDataReceiveNum(), 3); } -TEST(TcpSocket, ResDBConfigWith5Replicas) { +TEST(ResDBConfigTest, ResDBConfigWith5Replicas) { ReplicaInfo self_info = GenerateReplicaInfo("127.0.0.1", 1234); std::vector<ReplicaInfo> replicas; @@ -87,7 +90,7 @@ TEST(TcpSocket, ResDBConfigWith5Replicas) { EXPECT_EQ(config.GetMinDataReceiveNum(), 3); } -TEST(TcpSocket, ResDBConfigWith6Replicas) { +TEST(ResDBConfigTest, ResDBConfigWith6Replicas) { ReplicaInfo self_info = GenerateReplicaInfo("127.0.0.1", 1234); std::vector<ReplicaInfo> replicas; @@ -106,7 +109,7 @@ TEST(TcpSocket, ResDBConfigWith6Replicas) { EXPECT_EQ(config.GetMinDataReceiveNum(), 3); } -TEST(TcpSocket, ResDBConfigWith2Replicas) { +TEST(ResDBConfigTest, ResDBConfigWith2Replicas) { ReplicaInfo self_info = GenerateReplicaInfo("127.0.0.1", 1234); std::vector<ReplicaInfo> replicas; @@ -120,6 +123,18 @@ TEST(TcpSocket, ResDBConfigWith2Replicas) { EXPECT_EQ(config.GetReplicaNum(), replicas.size()); EXPECT_EQ(config.GetMinDataReceiveNum(), 1); } +*/ + +TEST(ResDBConfigTest, ResDBConfigFromFile) { + const char * file = "platform/config/test.config"; + const char * ext_file = "platform/config/expect_test.config"; + ResConfigData config_data = ReadConfigFromFile(file); + ResConfigData ext_config_data = ReadConfigFromFile(ext_file); + std::cout<<config_data.DebugString()<<std::endl; + + EXPECT_THAT(config_data, EqualsProto(ext_config_data)); +} + } // namespace diff --git a/platform/config/resdb_config_utils.cpp b/platform/config/resdb_config_utils.cpp index beae7e95..853c3ed4 100644 --- a/platform/config/resdb_config_utils.cpp +++ b/platform/config/resdb_config_utils.cpp @@ -25,12 +25,15 @@ #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> +#include <regex> +#include <nlohmann/json.hpp> #include <fstream> namespace resdb { using ::google::protobuf::util::JsonParseOptions; +using json = nlohmann::json; namespace { @@ -90,14 +93,27 @@ ReplicaInfo GenerateReplicaInfo(int id, const std::string& ip, int port) { return info; } +std::string RemoveJsonComments(const std::string& jsonWithComments) { + std::string result = std::regex_replace(jsonWithComments, std::regex("/\\*.*?\\*/"), ""); + result = std::regex_replace(result, std::regex("//.*?\\n"), "\n"); + return result; +} + + ResConfigData ReadConfigFromFile(const std::string& file_name) { std::stringstream json_data; std::ifstream infile(file_name.c_str()); - json_data << infile.rdbuf(); + if (!infile.is_open()) { + std::cerr << "Failed to open file." <<file_name<<" "<< strerror(errno)<<std::endl; + return ResConfigData(); + } + json_data << infile.rdbuf(); + std::string cleanJson = RemoveJsonComments(json_data.str()); + ResConfigData config_data; JsonParseOptions options; - auto status = JsonStringToMessage(json_data.str(), &config_data, options); + auto status = JsonStringToMessage(cleanJson, &config_data, options); if (!status.ok()) { LOG(ERROR) << "parse json :" << file_name << " fail:" << status.message(); } @@ -113,6 +129,12 @@ std::vector<ReplicaInfo> ReadConfig(const std::string& file_name) { std::string ip; int port; while (infile >> id >> ip >> port) { + if(id == "//") { + continue; + } + if(id.size()==0) { + continue; + } replicas.push_back(GenerateReplicaInfo(id, ip, port)); } if (replicas.size() == 0) { diff --git a/platform/config/resdb_config_utils.h b/platform/config/resdb_config_utils.h index 15d77a4b..1251e64d 100644 --- a/platform/config/resdb_config_utils.h +++ b/platform/config/resdb_config_utils.h @@ -40,4 +40,9 @@ std::unique_ptr<ResDBConfig> GenerateResDBConfig( std::optional<ConfigGenFunc> = std::nullopt); ResDBConfig GenerateResDBConfig(const std::string& config_file); + + +ResConfigData ReadConfigFromFile(const std::string& file_name); + } // namespace resdb + diff --git a/platform/test/test_data/kv_config.config b/platform/test/test_data/kv_config.config index ab12cbe0..1bacaecb 100644 --- a/platform/test/test_data/kv_config.config +++ b/platform/test/test_data/kv_config.config @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + { region : { replica_info : { diff --git a/platform/test/test_data/server.config b/platform/test/test_data/server.config index 2f7abe4a..01e32017 100644 --- a/platform/test/test_data/server.config +++ b/platform/test/test_data/server.config @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + { region : { replica_info : { diff --git a/service/tools/config/interface/service.config b/service/tools/config/interface/service.config index d357ba73..3d1f8e9c 100644 --- a/service/tools/config/interface/service.config +++ b/service/tools/config/interface/service.config @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + 5 127.0.0.1 10005 diff --git a/service/tools/config/interface/service0.config b/service/tools/config/interface/service0.config index 4c83dab7..7915b3a6 100644 --- a/service/tools/config/interface/service0.config +++ b/service/tools/config/interface/service0.config @@ -1,3 +1,21 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + + 1 127.0.0.1 10001 diff --git a/service/tools/config/server/contract_server.config b/service/tools/config/server/contract_server.config index fc682d5d..6ae07aab 100644 --- a/service/tools/config/server/contract_server.config +++ b/service/tools/config/server/contract_server.config @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + { region : { replica_info : { diff --git a/service/tools/config/server/server.config b/service/tools/config/server/server.config index 740bae3a..9aa3e6fd 100644 --- a/service/tools/config/server/server.config +++ b/service/tools/config/server/server.config @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + { region : { replica_info : { diff --git a/service/tools/contract/api_tools/client_config.config b/service/tools/contract/api_tools/client_config.config index e1bcc905..1334de2b 100644 --- a/service/tools/contract/api_tools/client_config.config +++ b/service/tools/contract/api_tools/client_config.config @@ -1 +1,18 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + 5 127.0.0.1 10005 diff --git a/service/tools/contract/api_tools/config/server_config.config b/service/tools/contract/api_tools/config/server_config.config index ec284753..023a1570 100644 --- a/service/tools/contract/api_tools/config/server_config.config +++ b/service/tools/contract/api_tools/config/server_config.config @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + { region : { replica_info : { diff --git a/service/tools/utxo/wallet_tool/cpp/client_config.config b/service/tools/utxo/wallet_tool/cpp/client_config.config index e1bcc905..1334de2b 100644 --- a/service/tools/utxo/wallet_tool/cpp/client_config.config +++ b/service/tools/utxo/wallet_tool/cpp/client_config.config @@ -1 +1,18 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + 5 127.0.0.1 10005 diff --git a/service/tools/utxo/wallet_tool/cpp/server_config0.config b/service/tools/utxo/wallet_tool/cpp/server_config0.config index ee48298e..5561ff07 100644 --- a/service/tools/utxo/wallet_tool/cpp/server_config0.config +++ b/service/tools/utxo/wallet_tool/cpp/server_config0.config @@ -1 +1,18 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + 1 127.0.0.1 10001 diff --git a/service/utxo/config/server_config.config b/service/utxo/config/server_config.config index ec284753..023a1570 100644 --- a/service/utxo/config/server_config.config +++ b/service/utxo/config/server_config.config @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + { region : { replica_info : {
