Skip to content

feat: add meta proto service for service discovery #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 73 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
4c3eb9f
Add meta proto service for service discovery
oguzcanoguz Jan 25, 2024
cdc8fb3
Update protobuf/meta_services/ServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
adb0092
Update protobuf/meta_services/ServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
f15b249
Update protobuf/meta_services/ServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
d5d9dc2
Update protobuf/meta_services/test/TestServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
cf77db0
Update protobuf/meta_services/test/TestServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
9622fe2
Update protobuf/meta_services/ServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
b6cc192
Update protobuf/meta_services/ServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
bbc7075
Update protobuf/meta_services/test/TestServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
b9239e9
Apply suggestions from code review
oguzcanoguz Jan 25, 2024
2850b82
Add service changed notification to ServviceDiscovery
oguzcanoguz Jan 29, 2024
151e119
Merge remote-tracking branch 'origin/main' into feature/proto_service…
oguzcanoguz Apr 23, 2024
e8ca6d6
ServiceDiscoveryEcho refactor header
oguzcanoguz Apr 23, 2024
2dadfb7
Implement StartMethod and NotifyServiceChanges in ServiceDiscoveryEcho
oguzcanoguz Apr 25, 2024
2e575b3
Refactor ServiceDiscoveryTest
oguzcanoguz Apr 26, 2024
0db7aa5
Fix function static storage in ServiceDiscoveryEcho
oguzcanoguz Apr 26, 2024
ca8bdaa
Solve functio storage problem in ServiceDiscoveryTest
oguzcanoguz Apr 26, 2024
914754e
Make EchoConsole accept recursive directories for protobuf files
oguzcanoguz Apr 30, 2024
a2dd642
Start with PeerServiceDiscoverer
oguzcanoguz May 1, 2024
f0fc274
PeerServiceDiscovererTest: Add iterative service discovery
oguzcanoguz May 3, 2024
a8a24b8
PeerServiceDiscovererTest contd
oguzcanoguz May 6, 2024
df27790
Merge commit 'e9afc63890f512f66b28fe2b409de5b9fe471934'
oguzcanoguz Jun 7, 2024
0068cc6
Start with providing id range in NotifyServicesChanged
oguzcanoguz Aug 19, 2024
3685020
Add notifying service changes with a range
oguzcanoguz Sep 6, 2024
5db6745
Make service changes amnesiac
oguzcanoguz Sep 6, 2024
d5519bd
remove ServiceDiscoveryStarted from PeerServiceDiscovery
oguzcanoguz Oct 4, 2024
067ec70
Refactor PeerServiceDiscovererObserver
oguzcanoguz Oct 4, 2024
9118a61
PeerServiceDiscoverer: Start service discovery on construction
oguzcanoguz Oct 4, 2024
abfa695
PeerServiceDiscoverer: Handle service updated notification
oguzcanoguz Oct 4, 2024
e2c95a7
PeerServiceDiscovererTest: WIP Streamlining services changed tests
oguzcanoguz Oct 11, 2024
5a0a2be
Refactor PeerServiceDiscovery tests
oguzcanoguz Oct 28, 2024
a89a492
PeerServiceDiscovery: Discovery can end with a service or no service
oguzcanoguz Nov 1, 2024
6543e14
Start with a test echo server that can be run in devcontainer
oguzcanoguz Nov 4, 2024
a30b880
fix cmakelists
oguzcanoguz Nov 5, 2024
a471b1d
Try to instantiate PeerServiceDiscovery in echo console
oguzcanoguz Nov 11, 2024
62a871f
Fix: Use echo only when the connection observer is attached to a conn…
oguzcanoguz Nov 13, 2024
50d9170
ServiceDiscoveryEcho: Optimize FirstServiceSupported
oguzcanoguz Nov 13, 2024
138fc45
Merge branch 'temp' into feature/proto_service_discovery
oguzcanoguz Nov 13, 2024
161fcb6
trace discovered services
oguzcanoguz Nov 14, 2024
f65605a
Start working on attaching EchoConsole to Echo as a Service
oguzcanoguz Nov 15, 2024
6ad3bb7
TestConsoleService preparation
oguzcanoguz Dec 9, 2024
ba3f652
Merge commit '6c84af5324c79219059d1066cc5ce3aad8f2b927' into feature/…
oguzcanoguz Dec 16, 2024
d3a528f
Fix build error
oguzcanoguz Dec 16, 2024
52afcbd
Remove incorrect include (breaks embedded build)
oguzcanoguz Dec 16, 2024
922f501
Make echo_console only list available services
oguzcanoguz Dec 16, 2024
5410260
Fix lots of stuff to make EchoConsole to discover services of RefProd
oguzcanoguz Dec 17, 2024
8052a28
Remove temporary tracing
oguzcanoguz Dec 19, 2024
9f9594a
Merge branch 'main' into feature/proto_service_discovery
oguzcanoguz Jan 9, 2025
1194ba5
Make ServiceForwarderAll use a reserved svc id and assert this stays …
oguzcanoguz Jan 10, 2025
fd44ae0
Fix the existing ServiceDiscovery tests, more tests need to be added
oguzcanoguz Jan 10, 2025
d6d4b06
ServiceDiscoveryEcho clean
oguzcanoguz Jan 10, 2025
8324508
TestServiceDiscoveryEcho: Add test for clashing responses
oguzcanoguz Jan 10, 2025
10f3094
Clean up echo_console a bit
oguzcanoguz Jan 10, 2025
8a4b938
Make ConsoleService a library to unit test
oguzcanoguz Jan 31, 2025
48c20df
Small refactor on TestConsoleService
oguzcanoguz Feb 4, 2025
20576e8
fix echo_console_test build
oguzcanoguz Apr 8, 2025
9e65474
add first unit test for console_service
oguzcanoguz Apr 9, 2025
8742853
modify consoleservice test, does not work yet
oguzcanoguz Apr 9, 2025
ca225a9
TestConsoleService first test passing
oguzcanoguz Apr 10, 2025
798e39d
Fix echo console build (not tested if it still works)
oguzcanoguz Apr 10, 2025
7fe829e
minor refactor TestConsoleService
oguzcanoguz Apr 10, 2025
12e26ea
ConsoleServiceProxy tests are passing
oguzcanoguz Apr 14, 2025
b529fc4
Implement EchoConsoleService
oguzcanoguz Apr 14, 2025
c942ad1
Merge branch 'main' into feature/proto_service_discovery
oguzcanoguz Apr 14, 2025
ce76d1e
Merge remote-tracking branch 'origin/main' into feature/proto_service…
oguzcanoguz Apr 14, 2025
342aecf
Fix not calling service done in EchoConsoleService
oguzcanoguz Apr 15, 2025
0dcb1d4
Remove commented out code
oguzcanoguz Apr 15, 2025
2195a41
Remove Echo test server, can now use refprod
oguzcanoguz Apr 16, 2025
c8fa558
Update protobuf/meta_services/PeerServiceDiscoverer.hpp
oguzcanoguz Apr 16, 2025
2430613
Update protobuf/meta_services/PeerServiceDiscoverer.cpp
oguzcanoguz Apr 16, 2025
b2a1636
Apply suggestions from code review
oguzcanoguz Apr 17, 2025
9b72b3b
Merge branch 'main' into feature/proto_service_discovery
oguzcanoguz Apr 17, 2025
1f3f33b
Clean up includes
oguzcanoguz Apr 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ add_subdirectory(echo)
add_subdirectory(protoc_echo_plugin)
add_subdirectory(protoc_echo_plugin_csharp)
add_subdirectory(protoc_echo_plugin_java)
add_subdirectory(meta_services)
7 changes: 5 additions & 2 deletions protobuf/echo/test_doubles/ServiceStub.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "protobuf/echo/test_doubles/ServiceStub.hpp"
#include <cstdint>

namespace services
{
Expand Down Expand Up @@ -26,8 +27,9 @@ namespace services
return value;
}

ServiceStub::ServiceStub(Echo& echo)
ServiceStub::ServiceStub(Echo& echo, uint32_t serviceId)
: Service(echo)
, serviceId(serviceId)
{}

bool ServiceStub::AcceptsService(uint32_t id) const
Expand Down Expand Up @@ -55,8 +57,9 @@ namespace services
}
}

ServiceStubProxy::ServiceStubProxy(services::Echo& echo)
ServiceStubProxy::ServiceStubProxy(services::Echo& echo, uint32_t serviceId)
: services::ServiceProxy(echo, maxMessageSize)
, serviceId(serviceId)
{}

void ServiceStubProxy::Method(uint32_t value)
Expand Down
15 changes: 11 additions & 4 deletions protobuf/echo/test_doubles/ServiceStub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "protobuf/echo/Echo.hpp"
#include "gmock/gmock.h"
#include <cstdint>

namespace services
{
Expand Down Expand Up @@ -37,7 +38,7 @@ namespace services
: public services::Service
{
public:
ServiceStub(Echo& echo);
ServiceStub(Echo& echo, uint32_t serviceId = defaultServiceId);

bool AcceptsService(uint32_t id) const override;

Expand All @@ -48,33 +49,39 @@ namespace services
infra::SharedPtr<MethodDeserializer> StartMethod(uint32_t serviceId, uint32_t methodId, uint32_t size, const services::EchoErrorPolicy& errorPolicy) override;

public:
static const uint32_t serviceId = 1;
static constexpr uint32_t defaultServiceId = 1;
static const uint32_t idMethod = 1;
static const uint32_t idMethodNoParameter = 3;
static const uint32_t maxMessageSize = 18;

public:
using MethodTypeList = infra::List<Message, EmptyMessage>;

private:
const uint32_t serviceId;
};

class ServiceStubProxy
: public services::ServiceProxy
{
public:
ServiceStubProxy(services::Echo& echo);
ServiceStubProxy(services::Echo& echo, uint32_t serviceId = defaultServiceId);

public:
void Method(uint32_t value);
void MethodNoParameter();

public:
static constexpr uint32_t serviceId = 1;
static constexpr uint32_t defaultServiceId = 1;
static constexpr uint32_t idMethod = 1;
static const uint32_t idMethodNoParameter = 3;
static constexpr uint32_t maxMessageSize = 18;

public:
using MethodTypeList = infra::List<Message, EmptyMessage>;

private:
const uint32_t serviceId;
};
}

Expand Down
13 changes: 13 additions & 0 deletions protobuf/meta_services/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_library(protobuf.meta_services ${EMIL_EXCLUDE_FROM_ALL} STATIC)

protocol_buffer_csharp(protobuf.meta_services ServiceDiscovery.proto)
protocol_buffer_java(protobuf.meta_services ServiceDiscovery.proto)
protocol_buffer_echo_all(protobuf.meta_services ServiceDiscovery.proto)

target_sources(protobuf.meta_services PRIVATE
ServiceDiscoveryEcho.cpp
ServiceDiscoveryEcho.hpp
)

add_subdirectory(test)

40 changes: 40 additions & 0 deletions protobuf/meta_services/ServiceDiscovery.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "proto3";

import "EchoAttributes.proto";

package service_discovery;
option java_package = "com.philips.emil.protobufEcho";
option java_outer_classname = "ServiceDiscoveryProto";

message Uint32Value {
uint32 value = 1;
}

message BoolValue
{
bool value = 1;
}

message ServiceRange
{
uint32 startServiceId = 1;
uint32 endServiceId = 2;
}

service ServiceDiscovery
{
option (service_id) = 1000;

rpc FindFirstServiceInRange(ServiceRange) returns (Nothing) { option (method_id) = 1; }
rpc NotifyServiceChanges(BoolValue) returns (Nothing) { option (method_id) = 2; }
}

service ServiceDiscoveryResponse
{
option (service_id) = 1001;

rpc FirstServiceSupported(Uint32Value) returns (Nothing) { option (method_id) = 1; }
rpc NoServiceSupported(Nothing) returns (Nothing) { option (method_id) = 2; }
rpc ServicesChanged(Nothing) returns (Nothing) { option (method_id) = 3; }
}

127 changes: 127 additions & 0 deletions protobuf/meta_services/ServiceDiscoveryEcho.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include "protobuf/meta_services/ServiceDiscoveryEcho.hpp"
#include "echo/ServiceDiscovery.pb.hpp"
#include "infra/util/Optional.hpp"
#include "protobuf/echo/Echo.hpp"
#include <cstdint>
#include <tuple>

namespace application
{
void ServiceDiscoveryEcho::FindFirstServiceInRange(uint32_t startServiceId, uint32_t endServiceId)
{
auto service = FirstSupportedServiceId(startServiceId, endServiceId);

service_discovery::ServiceDiscoveryResponseProxy::RequestSend([this, service]
{
if (service)
FirstServiceSupported(*service);
else
NoServiceSupported();
});

MethodDone();
}

infra::Optional<uint32_t> ServiceDiscoveryEcho::FirstSupportedServiceId(uint32_t startServiceId, uint32_t endServiceId)
{
for (auto id = startServiceId; id <= endServiceId; ++id)
if (AcceptsService(id))
return infra::MakeOptional(id);

return infra::none;
}

void ServiceDiscoveryEcho::NotifyServiceChanges(bool value)
{
notifyServiceChanges = value;

MethodDone();
}

bool ServiceDiscoveryEcho::AcceptsService(uint32_t serviceId) const
{
return service_discovery::ServiceDiscovery::AcceptsService(serviceId)
|| IsProxyServiceSupported(serviceId);
}

infra::SharedPtr<services::MethodDeserializer> ServiceDiscoveryEcho::StartMethod(uint32_t serviceId, uint32_t methodId, uint32_t size, const services::EchoErrorPolicy& errorPolicy)
{
if (service_discovery::ServiceDiscovery::AcceptsService(serviceId))
return service_discovery::ServiceDiscovery::StartMethod(serviceId, methodId, size, errorPolicy);
else
return StartProxyServiceMethod(serviceId, methodId, size, errorPolicy);
}

infra::SharedPtr<services::MethodDeserializer> ServiceDiscoveryEcho::StartProxyServiceMethod(uint32_t serviceId, uint32_t methodId, uint32_t size, const services::EchoErrorPolicy& errorPolicy)
{
infra::SharedPtr<services::MethodDeserializer> methodSerializer;

auto startMethodArgs = std::tie(serviceId, methodId, size, errorPolicy);
NotifyObservers([&methodSerializer, &startMethodArgs](auto& obs)
{
if(obs.AcceptsService(std::get<0>(startMethodArgs)))
{
methodSerializer = obs.StartMethod(std::get<0>(startMethodArgs), std::get<1>(startMethodArgs), std::get<2>(startMethodArgs), std::get<3>(startMethodArgs));
return true;
}

return false;
});

return methodSerializer;
}

bool ServiceDiscoveryEcho::IsProxyServiceSupported(uint32_t serviceId) const
{
return services::Echo::NotifyObservers([serviceId](auto& observer)
{
if (observer.AcceptsService(serviceId))
return true;
else
return false;
});
}

void ServiceDiscoveryEcho::RequestSend(ServiceProxy& serviceProxy)
{
UpstreamRpc().RequestSend(serviceProxy);
}

void ServiceDiscoveryEcho::ServiceDone()
{
UpstreamRpc().ServiceDone();
}

services::MethodSerializerFactory& ServiceDiscoveryEcho::SerializerFactory()
{
return UpstreamRpc().SerializerFactory();
}

services::Echo& ServiceDiscoveryEcho::UpstreamRpc()
{
return service_discovery::ServiceDiscovery::Rpc();
}

void ServiceDiscoveryEcho::RegisterObserver(infra::Observer<Service, Echo>* observer)
{
services::Echo::RegisterObserver(observer);

ServicesChangeNotification();
}

void ServiceDiscoveryEcho::UnregisterObserver(infra::Observer<Service, Echo>* observer)
{
services::Echo::UnregisterObserver(observer);

ServicesChangeNotification();
}

void ServiceDiscoveryEcho::ServicesChangeNotification()
{
if (notifyServiceChanges)
service_discovery::ServiceDiscoveryResponseProxy::RequestSend([this]
{
ServicesChanged();
});
}
}
51 changes: 51 additions & 0 deletions protobuf/meta_services/ServiceDiscoveryEcho.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef PROTOBUF_ECHO_SERVICE_DISCOVERY_HPP
#define PROTOBUF_ECHO_SERVICE_DISCOVERY_HPP

#include "generated/echo/ServiceDiscovery.pb.hpp"
#include "protobuf/echo/Echo.hpp"
#include <cstdint>

namespace application
{
class ServiceDiscoveryEcho
: public service_discovery::ServiceDiscovery
, public service_discovery::ServiceDiscoveryResponseProxy
, public services::Echo
{
public:
explicit ServiceDiscoveryEcho(services::Echo& echo)
: service_discovery::ServiceDiscovery(echo)
, service_discovery::ServiceDiscoveryResponseProxy(echo)
{}

virtual ~ServiceDiscoveryEcho() = default;

//Implementation of services::ServiceDiscovery
void FindFirstServiceInRange(uint32_t startServiceId, uint32_t endServiceId) override;
void NotifyServiceChanges(bool value) override;

//Implementation of services::Service
bool AcceptsService(uint32_t id) const override;
infra::SharedPtr<services::MethodDeserializer> StartMethod(uint32_t serviceId, uint32_t methodId, uint32_t size, const services::EchoErrorPolicy& errorPolicy) override;

//Implementation of services::Echo
void RequestSend(ServiceProxy& serviceProxy) override;
void ServiceDone() override;
services::MethodSerializerFactory& SerializerFactory() override;

private:
void RegisterObserver(infra::Observer<Service, Echo>* observer) override;
void UnregisterObserver(infra::Observer<Service, Echo>* observer) override;

infra::Optional<uint32_t> FirstSupportedServiceId(uint32_t startServiceId, uint32_t endServiceId);
bool IsProxyServiceSupported(uint32_t serviceId) const;
infra::SharedPtr<services::MethodDeserializer> StartProxyServiceMethod(uint32_t serviceId, uint32_t methodId, uint32_t size, const services::EchoErrorPolicy& errorPolicy);
services::Echo& UpstreamRpc();
void ServicesChangeNotification();

private:
bool notifyServiceChanges = false;
};
}

#endif
13 changes: 13 additions & 0 deletions protobuf/meta_services/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_executable(protobuf.meta_services_test)
emil_build_for(protobuf.meta_services_test BOOL EMIL_BUILD_TESTS)
emil_add_test(protobuf.meta_services_test)

target_sources(protobuf.meta_services_test PRIVATE
TestServiceDiscoveryEcho.cpp
)

target_link_libraries(protobuf.meta_services_test PUBLIC
gmock_main
protobuf.test_doubles
protobuf.meta_services
)
Loading
Loading