SDK: Implement WaitForIdleAgents and CommanderInfoRequest

This commit is contained in:
Dennis Klein 2019-07-24 10:37:58 +02:00
parent bc98ab1eed
commit a93840b240
No known key found for this signature in database
GPG Key ID: 08E62D23FA0ECBBC
3 changed files with 30 additions and 13 deletions

View File

@ -187,25 +187,36 @@ auto DDSSession::RequestAgentInfo() -> void
blocker.Wait();
}
auto DDSSession::RequestCommanderInfo() -> void
auto DDSSession::RequestCommanderInfo() -> CommanderInfo
{
dds::tools_api::SCommanderInfoRequestData commanderInfoInfo;
tools::Semaphore blocker;
auto commanderInfoRequest =
dds::tools_api::SCommanderInfoRequest::makeRequest(commanderInfoInfo);
CommanderInfo info;
commanderInfoRequest->setResponseCallback(
[&](const dds::tools_api::SCommanderInfoResponseData& _response) {
LOG(debug) << "pid: " << _response.m_pid;
LOG(debug) << "idle agents: " << _response.m_idleAgentsCount;
// LOG(debug) << "active topology: "
// << ((_response.m_hasActiveTopology) ? _response.m_activeTopologyName
// : "<none>");
[&info](const dds::tools_api::SCommanderInfoResponseData& _response) {
info.pid = _response.m_pid;
info.idleAgentsCount = _response.m_idleAgentsCount;
});
commanderInfoRequest->setMessageCallback(
[](const dds::tools_api::SMessageResponseData& _message) { LOG(debug) << _message; });
commanderInfoRequest->setDoneCallback([&]() { blocker.Signal(); });
fImpl->fSession.sendRequest<dds::tools_api::SCommanderInfoRequest>(commanderInfoRequest);
blocker.Wait();
return info;
}
auto DDSSession::WaitForIdleAgents(Quantity minCount) -> void
{
auto info(RequestCommanderInfo());
int interval(8);
while (info.idleAgentsCount < minCount) {
std::this_thread::sleep_for(std::chrono::milliseconds(8));
interval = std::min(256, interval * 2);
info = RequestCommanderInfo();
}
}
auto DDSSession::ActivateTopology(const Path& topologyFile) -> void

View File

@ -65,7 +65,12 @@ class DDSSession
auto IsRunning() const -> bool;
auto SubmitAgents(Quantity agents) -> void;
auto RequestAgentInfo() -> void;
auto RequestCommanderInfo() -> void;
struct CommanderInfo {
int pid;
Quantity idleAgentsCount;
};
auto RequestCommanderInfo() -> CommanderInfo;
auto WaitForIdleAgents(Quantity) -> void;
auto ActivateTopology(const Path& topologyFile) -> void;
auto Stop() -> void;

View File

@ -58,12 +58,13 @@ struct TopologyFixture : ::testing::Test
auto SetUp() -> void override {
LOG(info) << mDDSEnv;
LOG(info) << mDDSSession;
mDDSSession.RequestCommanderInfo();
mDDSSession.SubmitAgents(2);
mDDSSession.RequestCommanderInfo();
std::this_thread::sleep_for(std::chrono::seconds(1)); // TODO implement WaitForIdleAgents
LOG(info) << mDDSTopo;
auto n(mDDSTopo.GetNumRequiredAgents());
mDDSSession.SubmitAgents(n);
mDDSSession.WaitForIdleAgents(n);
mDDSSession.ActivateTopology(mDDSTopoFile);
mDDSSession.RequestCommanderInfo();
std::this_thread::sleep_for(std::chrono::seconds(1)); // TODO implement WaitForActiveAgents
mDDSSession.RequestAgentInfo();
}
auto TearDown() -> void override {