Skip to content
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

feat: add meta proto service for service discovery #543

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
47 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
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)
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; }
}

47 changes: 47 additions & 0 deletions protobuf/meta_services/ServiceDiscoveryEcho.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "protobuf/meta_services/ServiceDiscoveryEcho.hpp"
#include "echo/ServiceDiscovery.pb.hpp"

namespace application
{
void ServiceDiscoveryEcho::FindFirstServiceInRange(uint32_t startServiceId, uint32_t endServiceId)
{
infra::Optional<uint32_t> service;

for (auto id = startServiceId; id <= endServiceId; ++id)
{
if (AcceptsService(id))
{
service = id;
break;
}
}

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

MethodDone();
}

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

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

return serviceFound;
}
}
50 changes: 50 additions & 0 deletions protobuf/meta_services/ServiceDiscoveryEcho.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#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;

void FindFirstServiceInRange(uint32_t startServiceId, uint32_t endServiceId) override;
void NotifyServiceChanges(bool value) override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MegaLinter] reported by reviewdog 🐶

Suggested change
void NotifyServiceChanges(bool value) override
void NotifyServiceChanges(bool value) override

{}

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;

void RequestSend(ServiceProxy& serviceProxy) override
{
service_discovery::ServiceDiscovery::Rpc().RequestSend(serviceProxy);
}

void ServiceDone() override
{
service_discovery::ServiceDiscovery::Rpc().ServiceDone();
}

services::MethodSerializerFactory& SerializerFactory() override
{
return service_discovery::ServiceDiscovery::Rpc().SerializerFactory();
}

protected:
bool IsProxyServiceSupported(uint32_t& serviceId) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MegaLinter] reported by reviewdog 🐶

Suggested change
bool IsProxyServiceSupported(uint32_t& serviceId) const;
bool IsProxyServiceSupported(uint32_t& serviceId) const;

};
}

#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
)
134 changes: 134 additions & 0 deletions protobuf/meta_services/test/TestServiceDiscoveryEcho.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#include "echo/ServiceDiscovery.pb.hpp"
#include "infra/util/Optional.hpp"
#include "protobuf/echo/Echo.hpp"
#include "protobuf/echo/test_doubles/EchoSingleLoopback.hpp"
#include "protobuf/echo/test_doubles/ServiceStub.hpp"
#include "protobuf/meta_services/ServiceDiscoveryEcho.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cstdint>
#include <sys/types.h>

oguzcanoguz marked this conversation as resolved.
Show resolved Hide resolved
namespace
{
class ServiceDiscoveryResponseMock
: public service_discovery::ServiceDiscoveryResponse
{
public:
using service_discovery::ServiceDiscoveryResponse::ServiceDiscoveryResponse;
virtual ~ServiceDiscoveryResponseMock() = default;

void FirstServiceSupported(uint32_t value) override
{
FirstServiceSupportedMock(value);
MethodDone();
}

void NoServiceSupported() override
{
NoServiceSupportedMock();
MethodDone();
}

void ServicesChanged() override
{
ServicesChangedMock();
MethodDone();
}

MOCK_METHOD(void, FirstServiceSupportedMock, (uint32_t));
MOCK_METHOD(void, NoServiceSupportedMock, ());
MOCK_METHOD(void, ServicesChangedMock, ());
};

class ServiceStubWithCustomServiceId
: public services::ServiceStub
{
public:
ServiceStubWithCustomServiceId(services::Echo& echo, uint32_t serviceId)
: services::ServiceStub(echo)
, serviceId(serviceId)
{}

virtual ~ServiceStubWithCustomServiceId() = default;

bool AcceptsService(uint32_t serviceId) const override
{
return this->serviceId == serviceId;
}

private:
const uint32_t serviceId;
};
};

class ServiceDiscoveryTest
: public testing::Test
{
public:
services::MethodSerializerFactory::ForServices<service_discovery::ServiceDiscovery, service_discovery::ServiceDiscoveryResponse>::AndProxies<service_discovery::ServiceDiscoveryProxy> serializerFactory;
application::EchoSingleLoopback echo{ serializerFactory };
service_discovery::ServiceDiscoveryProxy proxy{ echo };
testing::StrictMock<ServiceDiscoveryResponseMock> serviceDiscoveryResponse{ echo };

application::ServiceDiscoveryEcho serviceDiscoveryEcho{ echo };
};

TEST_F(ServiceDiscoveryTest, return_no_service)
{
ServiceStubWithCustomServiceId serviceMock{ serviceDiscoveryEcho, 5 };

EXPECT_CALL(serviceDiscoveryResponse, NoServiceSupportedMock);

proxy.RequestSend([this]
{
proxy.FindFirstServiceInRange(0, 4);
});
}

TEST_F(ServiceDiscoveryTest, return_service)
{
ServiceStubWithCustomServiceId serviceMock{ serviceDiscoveryEcho, 5 };

EXPECT_CALL(serviceDiscoveryResponse, FirstServiceSupportedMock(5));

proxy.RequestSend([this]
{
proxy.FindFirstServiceInRange(0, 15);
});
}

TEST_F(ServiceDiscoveryTest, return_service_with_lowest_id)
{
ServiceStubWithCustomServiceId serviceMock{ serviceDiscoveryEcho, 5 };
ServiceStubWithCustomServiceId serviceMock2{ serviceDiscoveryEcho, 6 };

EXPECT_CALL(serviceDiscoveryResponse, FirstServiceSupportedMock(5));

proxy.RequestSend([this]
{
proxy.FindFirstServiceInRange(0, 15);
});
}

oguzcanoguz marked this conversation as resolved.
Show resolved Hide resolved
TEST_F(ServiceDiscoveryTest, DISABLED_notify_service_change)
{
proxy.RequestSend([this]
{
proxy.NotifyServiceChanges(true);
});

EXPECT_CALL(serviceDiscoveryResponse, ServicesChangedMock());

ServiceStubWithCustomServiceId serviceMock{ serviceDiscoveryEcho, 5 };
}

TEST_F(ServiceDiscoveryTest, find_own_service_id)
{
EXPECT_CALL(serviceDiscoveryResponse, FirstServiceSupportedMock(service_discovery::ServiceDiscovery::serviceId));

proxy.RequestSend([this]
{
proxy.FindFirstServiceInRange(service_discovery::ServiceDiscovery::serviceId, service_discovery::ServiceDiscovery::serviceId);
});
}
Loading