Skip to content

Commit 2dfb5ce

Browse files
authored
add NodeDiscovery to fetch alive node information (#81)
* add NodeDiscovery to fetch alive node information * update generated java and python code * psi node register serviceMeta to gateway * model service register service inforamtion * support update-meta at runtime * fix fetch psi file when use_psi is false
1 parent 2c1aebb commit 2dfb5ce

File tree

64 files changed

+11054
-5592
lines changed

Some content is hidden

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

64 files changed

+11054
-5592
lines changed

.github/workflows/cpp_toolkit_workflow.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ jobs:
3939
with:
4040
toolchain: nightly-2022-07-28
4141
override: true
42-
- name: Prepare python
43-
if: runner.os == 'Windows'
44-
uses: actions/setup-python@v5
45-
with:
46-
python-version: '3.8'
47-
cache: 'pip'
4842
- name: Prepare vcpkg
4943
if: runner.os != 'Windows'
5044
uses: friendlyanon/setup-vcpkg@v1
@@ -70,7 +64,7 @@ jobs:
7064
- name: Build for windows
7165
if: runner.os == 'Windows'
7266
run: |
73-
mkdir -p cpp/build && cd cpp/build && cmake -G "Visual Studio 16 2019" -A x64 -DBUILD_PYTHON=ON -DCMAKE_BUILD_TYPE=Release -DTESTS=OFF -DBUILD_WEDPR_TOOLKIT=ON -DVCPKG_TARGET_TRIPLET=x64-windows-static -DVCPKG_HOST_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake .. && MSBuild /version && MSBuild WeDPR-Component.sln /p:Configuration=Release /p:Platform=x64
67+
mkdir -p cpp/build && cd cpp/build && cmake -G "Visual Studio 16 2019" -A x64 -DBUILD_PYTHON=OFF -DCMAKE_BUILD_TYPE=Release -DTESTS=OFF -DBUILD_WEDPR_TOOLKIT=ON -DVCPKG_TARGET_TRIPLET=x64-windows-static -DVCPKG_HOST_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake .. && MSBuild /version && MSBuild WeDPR-Component.sln /p:Configuration=Release /p:Platform=x64
7468
- name: Build for linux
7569
if: runner.os == 'Linux'
7670
run: |

cpp/ppc-framework/front/FrontConfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,17 @@ class FrontConfig
7777

7878
std::vector<std::string>& mutableComponents() { return m_components; }
7979

80+
std::string const meta() const { return m_meta; }
81+
void setMeta(std::string meta) { m_meta = std::move(meta); }
82+
8083
protected:
8184
ppc::protocol::GrpcConfig::Ptr m_grpcConfig;
8285
ppc::protocol::EndPoint m_selfEndPoint;
8386
int m_threadPoolSize;
8487
std::string m_nodeID;
8588
std::string m_gatewayGrpcTarget;
8689
std::vector<std::string> m_components;
90+
std::string m_meta;
8791
};
8892

8993
class FrontConfigBuilder

cpp/ppc-framework/front/IFront.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
#pragma once
2121
#include "FrontConfig.h"
22+
#include "INodeDiscovery.h"
2223
#include "ppc-framework/protocol/Handler.h"
2324
#include "ppc-framework/protocol/INodeInfo.h"
2425
#include "ppc-framework/protocol/Message.h"
@@ -256,10 +257,14 @@ class IFront : virtual public IFrontClient
256257
virtual void registerComponent(std::string const& component) = 0;
257258
virtual void unRegisterComponent(std::string const& component) = 0;
258259

260+
virtual void updateMetaInfo(std::string const& meta) = 0;
261+
259262
// get the target nodeList according to the routeInfo
260263
virtual std::vector<std::string> selectNodesByRoutePolicy(
261264
int16_t routeType, ppc::protocol::MessageOptionalHeader::Ptr const& routeInfo) = 0;
262265

266+
virtual INodeDiscovery::Ptr const getNodeDiscovery() = 0;
267+
263268
private:
264269
ppc::protocol::ReceiveMsgFunc populateErrorCallback(ErrorCallback::Ptr errorCallback)
265270
{
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright (C) 2023 WeDPR.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* @file INodeDiscovery.h
17+
* @author: yujiechen
18+
* @date 2024-11-06
19+
*/
20+
#pragma once
21+
#include "ppc-framework/protocol/INodeInfo.h"
22+
#include <memory>
23+
24+
namespace ppc::front
25+
{
26+
class INodeDiscovery
27+
{
28+
public:
29+
using Ptr = std::shared_ptr<INodeDiscovery>;
30+
INodeDiscovery() = default;
31+
virtual ~INodeDiscovery() = default;
32+
33+
virtual void start() = 0;
34+
virtual void stop() = 0;
35+
36+
// Note: use std::shared_ptr here for swig wrapper
37+
virtual std::vector<std::shared_ptr<ppc::protocol::INodeInfo>> getAliveNodeList() const = 0;
38+
};
39+
} // namespace ppc::front

cpp/ppc-framework/gateway/IGateway.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class IGateway
7979
// get the target nodeList according to the routeInfo
8080
virtual std::vector<std::string> selectNodesByRoutePolicy(ppc::protocol::RouteType routeType,
8181
ppc::protocol::MessageOptionalHeader::Ptr const& routeInfo) = 0;
82+
83+
virtual std::vector<ppc::protocol::INodeInfo::Ptr> getAliveNodeList() const = 0;
8284
};
8385

8486
} // namespace ppc::gateway

cpp/ppc-framework/protocol/INodeInfo.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ class INodeInfo
6161

6262
virtual bool equal(INodeInfo::Ptr const& info)
6363
{
64-
return (nodeID().toBytes() == info->nodeID().toBytes()) &&
65-
(copiedComponents() == info->copiedComponents());
64+
return (nodeID().toBytes() == info->nodeID().toBytes()) && (endPoint() == info->endPoint());
6665
}
6766

67+
virtual std::string meta() const = 0;
68+
// the node meta information
69+
virtual void setMeta(std::string const& meta) = 0;
6870
virtual void toJson(Json::Value& jsonObject) const = 0;
6971
};
7072
class INodeInfoFactory
@@ -93,7 +95,7 @@ inline std::string printNodeInfo(INodeInfo::Ptr const& nodeInfo)
9395
{
9496
components = components + it + ",";
9597
}
96-
stringstream << LOG_KV("components", components);
98+
stringstream << LOG_KV("components", components) << LOG_KV("meta", nodeInfo->meta());
9799
return stringstream.str();
98100
}
99101
} // namespace ppc::protocol

cpp/ppc-framework/protocol/Protocol.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -481,18 +481,4 @@ struct FileInfo
481481
return oss.str();
482482
}
483483
};
484-
485-
const std::string FRONT_NAME = "Front";
486-
const std::string FRONT_SERVANT_NAME = "FrontServiceObj";
487-
const std::string FRONT_SERVICE_NAME = "FrontService";
488-
489-
const std::string GATEWAY_NAME = "Gateway";
490-
const std::string GATEWAY_SERVANT_NAME = "GatewayServiceObj";
491-
const std::string GATEWAY_SERVICE_NAME = "GatewayService";
492-
493-
inline std::string getPrxDesc(std::string const& _serviceName, std::string const& _objName)
494-
{
495-
return _serviceName + "." + _objName;
496-
}
497-
498484
} // namespace ppc::protocol

cpp/ppc-framework/protocol/RouteType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ inline std::ostream& operator<<(std::ostream& _out, RouteType const& _type)
5454
}
5555
return _out;
5656
}
57-
} // namespace ppc::protocol
57+
} // namespace ppc::protocol
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (C) 2023 WeDPR.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* @file ServiceType.h
17+
* @author: yujiechen
18+
* @date 2024-11-07
19+
*/
20+
21+
#pragma once
22+
#include <sstream>
23+
#include <string>
24+
25+
namespace ppc::protocol
26+
{
27+
const static std::string PSI_SERVICE_TYPE = "PSI";
28+
const static std::string MPC_SERVICE_TYPE = "MPC";
29+
} // namespace ppc::protocol

cpp/wedpr-helper/ppc-tools/src/config/PPCConfig.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ void PPCConfig::loadFrontConfig(bool requireTransport,
156156
// the components
157157
auto components = pt.get<std::string>("transport.components", "");
158158
boost::split(m_frontConfig->mutableComponents(), components, boost::is_any_of(","));
159-
160159
PPCConfig_LOG(INFO) << LOG_DESC("loadFrontConfig") << printFrontDesc(m_frontConfig);
161160
}
162161

0 commit comments

Comments
 (0)