Skip to content

Commit

Permalink
Added appname for resource manager handling (#353)
Browse files Browse the repository at this point in the history
Summary: Added appname for resource manager handling
Type: Feature
Test Plan: UT, Fullstack
Jira:
  • Loading branch information
aczs authored Jan 10, 2025
1 parent a32d95f commit df0fa7d
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 25 deletions.
2 changes: 1 addition & 1 deletion media/server/ipc/source/ServerManagerModuleService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void ServerManagerModuleService::setConfiguration(::google::protobuf::RpcControl
m_sessionServerManager.setConfiguration(request->sessionmanagementsocketname(),
convertSessionServerState(request->initialsessionserverstate()),
maxResource, kClientDisplayName, request->socketpermissions(),
request->socketowner(), request->socketgroup());
request->socketowner(), request->socketgroup(), request->appname());
m_sessionServerManager.setLogLevels(static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().defaultloglevels()),
static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().clientloglevels()),
static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().sessionserverloglevels()),
Expand Down
1 change: 1 addition & 0 deletions media/server/service/include/IPlaybackService.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class IPlaybackService
virtual void setMaxPlaybacks(int maxPlaybacks) = 0;
virtual void setMaxWebAudioPlayers(int maxWebAudio) = 0;
virtual void setClientDisplayName(const std::string &clientDisplayName) const = 0;
virtual void setResourceManagerAppName(const std::string &appName) const = 0;

virtual bool isActive() const = 0;
virtual bool getSharedMemory(int32_t &fd, uint32_t &size) const = 0;
Expand Down
3 changes: 2 additions & 1 deletion media/server/service/include/ISessionServerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ISessionServerManager
virtual bool setConfiguration(const std::string &socketName, const common::SessionServerState &state,
const common::MaxResourceCapabilitites &maxResource,
const std::string &clientDisplayName, unsigned int socketPermissions,
const std::string &socketOwner, const std::string &socketGroup) = 0;
const std::string &socketOwner, const std::string &socketGroup,
const std::string &appName) = 0;
virtual bool setState(const common::SessionServerState &state) = 0;
virtual void setLogLevels(RIALTO_DEBUG_LEVEL defaultLogLevels, RIALTO_DEBUG_LEVEL clientLogLevels,
RIALTO_DEBUG_LEVEL sessionServerLogLevels, RIALTO_DEBUG_LEVEL ipcLogLevels,
Expand Down
9 changes: 9 additions & 0 deletions media/server/service/source/PlaybackService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ void PlaybackService::setClientDisplayName(const std::string &clientDisplayName)
}
}

void PlaybackService::setResourceManagerAppName(const std::string &appName) const
{
// Method called during initialization only (before setting any state), no need to execute it on a task thread.
if (!appName.empty())
{
setenv("ESSRMGR_APPID", appName.c_str(), 1);
}
}

bool PlaybackService::getSharedMemory(int32_t &fd, uint32_t &size) const
{
auto shmBuffer = m_shmBuffer;
Expand Down
1 change: 1 addition & 0 deletions media/server/service/source/PlaybackService.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PlaybackService : public IPlaybackService
void setMaxPlaybacks(int maxPlaybacks) override;
void setMaxWebAudioPlayers(int maxWebAudio) override;
void setClientDisplayName(const std::string &clientDisplayName) const override;
void setResourceManagerAppName(const std::string &clientDisplayName) const override;

bool isActive() const override;
bool getSharedMemory(int32_t &fd, uint32_t &size) const override;
Expand Down
4 changes: 3 additions & 1 deletion media/server/service/source/SessionServerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ void SessionServerManager::stopService()
bool SessionServerManager::setConfiguration(const std::string &socketName, const common::SessionServerState &state,
const common::MaxResourceCapabilitites &maxResource,
const std::string &clientDisplayName, unsigned int socketPermissions,
const std::string &socketOwner, const std::string &socketGroup)
const std::string &socketOwner, const std::string &socketGroup,
const std::string &appName)
{
if (!m_sessionManagementServer->initialize(socketName, socketPermissions, socketOwner, socketGroup))
{
Expand All @@ -121,6 +122,7 @@ bool SessionServerManager::setConfiguration(const std::string &socketName, const
m_playbackService.setMaxPlaybacks(maxResource.maxPlaybacks);
m_playbackService.setMaxWebAudioPlayers(maxResource.maxWebAudioPlayers);
m_playbackService.setClientDisplayName(clientDisplayName);
m_playbackService.setResourceManagerAppName(appName);
return setState(state);
}

Expand Down
2 changes: 1 addition & 1 deletion media/server/service/source/SessionServerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SessionServerManager : public ISessionServerManager
bool setConfiguration(const std::string &socketName, const common::SessionServerState &state,
const common::MaxResourceCapabilitites &maxResource, const std::string &clientDisplayName,
unsigned int socketPermissions, const std::string &socketOwner,
const std::string &socketGroup) override;
const std::string &socketGroup, const std::string &appName) override;
bool setState(const common::SessionServerState &state) override;
void setLogLevels(RIALTO_DEBUG_LEVEL defaultLogLevels, RIALTO_DEBUG_LEVEL clientLogLevels,
RIALTO_DEBUG_LEVEL sessionServerLogLevels, RIALTO_DEBUG_LEVEL ipcLogLevels,
Expand Down
1 change: 1 addition & 0 deletions proto/servermanagermodule.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ message SetConfigurationRequest {
optional string clientDisplayName = 6;
optional string socketOwner = 7;
optional string socketGroup = 8;
optional string appName = 9;
}
message SetConfigurationResponse {
}
Expand Down
4 changes: 3 additions & 1 deletion serverManager/common/source/SessionServerAppManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,13 @@ bool SessionServerAppManager::configureSessionServer(const std::unique_ptr<ISess
const auto kSocketPermissions{kSessionServer->getSessionManagementSocketPermissions()};
const auto kSocketOwner{kSessionServer->getSessionManagementSocketOwner()};
const auto kSocketGroup{kSessionServer->getSessionManagementSocketGroup()};
const auto kAppName{kSessionServer->getAppName()};

const firebolt::rialto::common::MaxResourceCapabilitites kMaxResource{kSessionServer->getMaxPlaybackSessions(),
kSessionServer->getMaxWebAudioPlayers()};
if (!m_ipcController->performSetConfiguration(kSessionServer->getServerId(), kInitialState, kSocketName,
kClientDisplayName, kMaxResource, kSocketPermissions, kSocketOwner,
kSocketGroup))
kSocketGroup, kAppName))
{
RIALTO_SERVER_MANAGER_LOG_ERROR("Configuration of server with id %d failed - ipc error.",
kSessionServer->getServerId());
Expand Down
2 changes: 1 addition & 1 deletion serverManager/ipc/include/IController.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class IController
const std::string &socketName, const std::string &clientDisplayName,
const firebolt::rialto::common::MaxResourceCapabilitites &maxResource,
const unsigned int socketPermissions, const std::string &socketOwner,
const std::string &socketGroup) = 0;
const std::string &socketGroup, const std::string &appName) = 0;
virtual bool performPing(int serverId, int pingId) = 0;
virtual bool performSetState(int serverId, const firebolt::rialto::common::SessionServerState &state) = 0;
virtual bool setLogLevels(const service::LoggingLevels &logLevels) const = 0;
Expand Down
3 changes: 2 additions & 1 deletion serverManager/ipc/source/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ bool Client::performSetConfiguration(const firebolt::rialto::common::SessionServ
const std::string &socketName, const std::string &clientDisplayName,
const firebolt::rialto::common::MaxResourceCapabilitites &maxResource,
const unsigned int socketPermissions, const std::string &socketOwner,
const std::string &socketGroup) const
const std::string &socketGroup, const std::string &appName) const
{
if (!m_ipcLoop || !m_serviceStub)
{
Expand All @@ -203,6 +203,7 @@ bool Client::performSetConfiguration(const firebolt::rialto::common::SessionServ
request.set_socketpermissions(socketPermissions);
request.set_socketowner(socketOwner);
request.set_socketgroup(socketGroup);
request.set_appname(appName);
*(request.mutable_loglevels()) = getCurrentLogLevels();
request.set_initialsessionserverstate(convert(initialState));
auto ipcController = m_ipcLoop->createRpcController();
Expand Down
2 changes: 1 addition & 1 deletion serverManager/ipc/source/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Client
const std::string &socketName, const std::string &clientDisplayName,
const firebolt::rialto::common::MaxResourceCapabilitites &maxResource,
const unsigned int socketPermissions, const std::string &socketOwner,
const std::string &socketGroup) const;
const std::string &socketGroup, const std::string &appName) const;
bool performPing(int pingId) const;
bool setLogLevels(const service::LoggingLevels &logLevels) const;
void onDisconnected() const;
Expand Down
4 changes: 2 additions & 2 deletions serverManager/ipc/source/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ bool Controller::performSetConfiguration(int serverId, const firebolt::rialto::c
const std::string &socketName, const std::string &clientDisplayName,
const firebolt::rialto::common::MaxResourceCapabilitites &maxResource,
const unsigned int socketPermissions, const std::string &socketOwner,
const std::string &socketGroup)
const std::string &socketGroup, const std::string &appName)
{
std::unique_lock<std::mutex> lock{m_clientMutex};
auto client = m_clients.find(serverId);
if (client != m_clients.end())
{
return client->second->performSetConfiguration(initialState, socketName, clientDisplayName, maxResource,
socketPermissions, socketOwner, socketGroup);
socketPermissions, socketOwner, socketGroup, appName);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion serverManager/ipc/source/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Controller : public IController
const std::string &socketName, const std::string &clientDisplayName,
const firebolt::rialto::common::MaxResourceCapabilitites &maxResource,
const unsigned int socketPermissions, const std::string &socketOwner,
const std::string &socketGroup) override;
const std::string &socketGroup, const std::string &appName) override;
bool performPing(int serverId, int pingId) override;
bool performSetState(int serverId, const firebolt::rialto::common::SessionServerState &state) override;
bool setLogLevels(const service::LoggingLevels &logLevels) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ constexpr int kPingId{29};
// socket being owned by the user executing the code (and the group would be their primary group)
const std::string kSocketOwner{};
const std::string kSocketGroup{};
const std::string kAppId{"app"};

rialto::SessionServerState convertSessionServerState(const firebolt::rialto::common::SessionServerState &state)
{
Expand Down Expand Up @@ -79,7 +80,7 @@ void ServerManagerModuleServiceTests::sessionServerManagerWillSetConfiguration(
{
EXPECT_CALL(m_sessionServerManagerMock,
setConfiguration(kSocketName, state, MaxResourceMatcher(kMaxSessions, kMaxWebAudioPlayers),
kClientDisplayName, kSocketPermissions, kSocketOwner, kSocketGroup))
kClientDisplayName, kSocketPermissions, kSocketOwner, kSocketGroup, kAppId))
.WillOnce(Return(true));
}

Expand All @@ -101,7 +102,7 @@ void ServerManagerModuleServiceTests::sessionServerManagerWillFailToSetConfigura
{
EXPECT_CALL(m_sessionServerManagerMock,
setConfiguration(kSocketName, state, MaxResourceMatcher(kMaxSessions, kMaxWebAudioPlayers),
kClientDisplayName, kSocketPermissions, kSocketOwner, kSocketGroup))
kClientDisplayName, kSocketPermissions, kSocketOwner, kSocketGroup, kAppId))
.WillOnce(Return(false));
}

Expand Down Expand Up @@ -142,6 +143,7 @@ void ServerManagerModuleServiceTests::sendSetConfiguration(const firebolt::rialt
request.set_socketpermissions(kSocketPermissions);
request.set_socketowner(kSocketOwner);
request.set_socketgroup(kSocketGroup);
request.set_appname(kAppId);

m_sut->setConfiguration(m_controllerMock.get(), &request, &response, m_closureMock.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PlaybackServiceMock : public IPlaybackService
MOCK_METHOD(void, setMaxPlaybacks, (int maxPlaybacks), (override));
MOCK_METHOD(void, setMaxWebAudioPlayers, (int maxWebAudio), (override));
MOCK_METHOD(void, setClientDisplayName, (const std::string &clientDisplayName), (const, override));
MOCK_METHOD(void, setResourceManagerAppName, (const std::string &appName), (const, override));
MOCK_METHOD(bool, isActive, (), (const, override));
MOCK_METHOD(bool, getSharedMemory, (int32_t & fd, uint32_t &size), (const, override));
MOCK_METHOD(int, getMaxPlaybacks, (), (const, override));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class SessionServerManagerMock : public ISessionServerManager
MOCK_METHOD(bool, setConfiguration,
(const std::string &socketName, const common::SessionServerState &state,
const common::MaxResourceCapabilitites &maxResource, const std::string &clientDisplayName,
unsigned int socketPermissions, const std::string &socketOwner, const std::string &socketGroup),
unsigned int socketPermissions, const std::string &socketOwner, const std::string &socketGroup,
const std::string &appName),
(override));
MOCK_METHOD(bool, setState, (const common::SessionServerState &state), (override));
MOCK_METHOD(void, setLogLevels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ constexpr unsigned int kSessionManagementSocketPermissions{0777};
// socket being owned by the user executing the code (and the group would be their primary group)
const std::string kSocketOwner{};
const std::string kSocketGroup{};
const std::string kAppId{"app"};
const std::string kClientDisplayName{"westeros-rialto"};
} // namespace

Expand Down Expand Up @@ -155,7 +156,7 @@ void SessionServerManagerTests::willFailToSetConfigurationWhenSessionManagementS
EXPECT_TRUE(m_sut);
EXPECT_FALSE(m_sut->setConfiguration(kSessionManagementSocket, SessionServerState::INACTIVE, kMaxResource,
kClientDisplayName, kSessionManagementSocketPermissions, kSocketOwner,
kSocketGroup));
kSocketGroup, kAppId));
}

void SessionServerManagerTests::willFailToSetConfigurationWhenSessionManagementServerFailsToSetInitialState()
Expand All @@ -167,14 +168,15 @@ void SessionServerManagerTests::willFailToSetConfigurationWhenSessionManagementS
EXPECT_CALL(m_playbackServiceMock, setMaxPlaybacks(kMaxPlaybacks));
EXPECT_CALL(m_playbackServiceMock, setMaxWebAudioPlayers(kMaxWebAudioPlayers));
EXPECT_CALL(m_playbackServiceMock, setClientDisplayName(kClientDisplayName));
EXPECT_CALL(m_playbackServiceMock, setResourceManagerAppName(kAppId));
EXPECT_CALL(m_playbackServiceMock, switchToInactive());
EXPECT_CALL(m_cdmServiceMock, switchToInactive());
EXPECT_CALL(m_applicationManagementServerMock, sendStateChangedEvent(SessionServerState::INACTIVE))
.WillOnce(Return(false));
EXPECT_TRUE(m_sut);
EXPECT_FALSE(m_sut->setConfiguration(kSessionManagementSocket, SessionServerState::INACTIVE, kMaxResource,
kClientDisplayName, kSessionManagementSocketPermissions, kSocketOwner,
kSocketGroup));
kSocketGroup, kAppId));
}

void SessionServerManagerTests::willSetConfiguration()
Expand All @@ -186,6 +188,7 @@ void SessionServerManagerTests::willSetConfiguration()
EXPECT_CALL(m_playbackServiceMock, setMaxPlaybacks(kMaxPlaybacks));
EXPECT_CALL(m_playbackServiceMock, setMaxWebAudioPlayers(kMaxWebAudioPlayers));
EXPECT_CALL(m_playbackServiceMock, setClientDisplayName(kClientDisplayName));
EXPECT_CALL(m_playbackServiceMock, setResourceManagerAppName(kAppId));
EXPECT_CALL(m_playbackServiceMock, switchToInactive());
EXPECT_CALL(m_cdmServiceMock, switchToInactive());
EXPECT_CALL(m_controlServiceMock, setApplicationState(ApplicationState::INACTIVE));
Expand All @@ -194,7 +197,7 @@ void SessionServerManagerTests::willSetConfiguration()
EXPECT_TRUE(m_sut);
EXPECT_TRUE(m_sut->setConfiguration(kSessionManagementSocket, SessionServerState::INACTIVE, kMaxResource,
kClientDisplayName, kSessionManagementSocketPermissions, kSocketOwner,
kSocketGroup));
kSocketGroup, kAppId));
}

void SessionServerManagerTests::willFailToSetUnsupportedState()
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/serverManager/mocks/ControllerMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ControllerMock : public IController
MOCK_METHOD(bool, performSetConfiguration,
(int, const firebolt::rialto::common::SessionServerState &, const std::string &, const std::string &,
const firebolt::rialto::common::MaxResourceCapabilitites &, const unsigned int, const std::string &,
const std::string &),
const std::string &, const std::string &),
(override));
MOCK_METHOD(bool, performSetState, (int, const firebolt::rialto::common::SessionServerState &), (override));
MOCK_METHOD(bool, performPing, (int serverId, int pingId), (override));
Expand Down
Loading

0 comments on commit df0fa7d

Please sign in to comment.