Line data Source code
1 : /*
2 : * If not stated otherwise in this file or this component's LICENSE file the
3 : * following copyright and licenses apply:
4 : *
5 : * Copyright 2022 Sky UK
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : #include "SessionServerAppManager.h"
21 : #include "RialtoServerManagerLogging.h"
22 : #include "Utils.h"
23 : #include <algorithm>
24 : #include <future>
25 : #include <utility>
26 :
27 : namespace rialto::servermanager::common
28 : {
29 34 : SessionServerAppManager::SessionServerAppManager(
30 : std::unique_ptr<ipc::IController> &ipcController, const std::shared_ptr<service::IStateObserver> &stateObserver,
31 : std::unique_ptr<ISessionServerAppFactory> &&sessionServerAppFactory,
32 : std::unique_ptr<IHealthcheckServiceFactory> &&healthcheckServiceFactory,
33 : const std::shared_ptr<firebolt::rialto::common::IEventThreadFactory> &eventThreadFactory,
34 34 : const firebolt::rialto::ipc::INamedSocketFactory &namedSocketFactory)
35 34 : : m_ipcController{ipcController},
36 68 : m_eventThread{eventThreadFactory->createEventThread("rialtoservermanager-appmanager")},
37 34 : m_sessionServerAppFactory{std::move(sessionServerAppFactory)}, m_stateObserver{stateObserver},
38 34 : m_healthcheckService{healthcheckServiceFactory->createHealthcheckService(*this)},
39 68 : m_namedSocketFactory{namedSocketFactory}, m_isShuttingDown{false}
40 : {
41 34 : }
42 :
43 68 : SessionServerAppManager::~SessionServerAppManager()
44 : {
45 34 : m_eventThread->add(&SessionServerAppManager::shutdownAllSessionServers, this);
46 34 : m_eventThread->flush();
47 34 : m_eventThread.reset();
48 68 : }
49 :
50 7 : void SessionServerAppManager::preloadSessionServers(unsigned numOfPreloadedServers)
51 : {
52 7 : m_eventThread->add(
53 7 : [this, numOfPreloadedServers]()
54 : {
55 14 : for (unsigned i = 0; i < numOfPreloadedServers; ++i)
56 : {
57 7 : connectSessionServer(preloadSessionServer());
58 : }
59 7 : });
60 : }
61 :
62 29 : bool SessionServerAppManager::initiateApplication(const std::string &appName,
63 : const firebolt::rialto::common::SessionServerState &state,
64 : const firebolt::rialto::common::AppConfig &appConfig)
65 : {
66 29 : std::promise<bool> p;
67 29 : std::future<bool> f{p.get_future()};
68 58 : m_eventThread->add([&]() { return p.set_value(handleInitiateApplication(appName, state, appConfig)); });
69 58 : return f.get();
70 29 : }
71 :
72 29 : bool SessionServerAppManager::handleInitiateApplication(const std::string &appName,
73 : const firebolt::rialto::common::SessionServerState &state,
74 : const firebolt::rialto::common::AppConfig &appConfig)
75 : {
76 29 : RIALTO_SERVER_MANAGER_LOG_INFO("RialtoServerManager requests to launch %s with initial state: %s", appName.c_str(),
77 : toString(state));
78 29 : if (state != firebolt::rialto::common::SessionServerState::NOT_RUNNING && !getServerByAppName(appName))
79 : {
80 27 : auto preloadedServer{getPreloadedServer()};
81 27 : if (preloadedServer)
82 : {
83 4 : return configurePreloadedSessionServer(preloadedServer, appName, state, appConfig);
84 : }
85 23 : return connectSessionServer(launchSessionServer(appName, state, appConfig));
86 27 : }
87 2 : else if (state == firebolt::rialto::common::SessionServerState::NOT_RUNNING)
88 : {
89 1 : RIALTO_SERVER_MANAGER_LOG_ERROR("Initialization of %s failed - wrong state", appName.c_str());
90 : }
91 : else
92 : {
93 1 : RIALTO_SERVER_MANAGER_LOG_ERROR("Initialization of %s failed. App is already launched", appName.c_str());
94 : }
95 2 : return false;
96 : }
97 :
98 4 : bool SessionServerAppManager::setSessionServerState(const std::string &appName,
99 : const firebolt::rialto::common::SessionServerState &newState)
100 : {
101 4 : std::promise<bool> p;
102 4 : std::future<bool> f{p.get_future()};
103 8 : m_eventThread->add([&]() { return p.set_value(changeSessionServerState(appName, newState)); });
104 8 : return f.get();
105 4 : }
106 :
107 15 : void SessionServerAppManager::onSessionServerStateChanged(int serverId,
108 : const firebolt::rialto::common::SessionServerState &newState)
109 : {
110 15 : RIALTO_SERVER_MANAGER_LOG_DEBUG("Queue state change of serverId: %d to %s", serverId, toString(newState));
111 : // Event loop needed here, as function caller may be deleted as a result of this call
112 15 : m_eventThread->add(&SessionServerAppManager::handleSessionServerStateChange, this, serverId, newState);
113 : }
114 :
115 2 : void SessionServerAppManager::sendPingEvents(int pingId)
116 : {
117 2 : RIALTO_SERVER_MANAGER_LOG_DEBUG("Queue ping procedure with id: %d", pingId);
118 2 : m_eventThread->add(
119 2 : [this, pingId]()
120 : {
121 2 : if (m_healthcheckService)
122 : {
123 4 : for (const auto &sessionServer : m_sessionServerApps)
124 : {
125 2 : auto serverId{sessionServer->getServerId()};
126 2 : if (!m_ipcController->performPing(serverId, pingId))
127 : {
128 1 : RIALTO_SERVER_MANAGER_LOG_ERROR("Ping with id: %d failed for server: %d", pingId, serverId);
129 1 : m_healthcheckService->onPingFailed(serverId, pingId);
130 1 : continue;
131 : }
132 1 : m_healthcheckService->onPingSent(serverId, pingId);
133 : }
134 : }
135 2 : });
136 : }
137 :
138 2 : void SessionServerAppManager::onAck(int serverId, int pingId, bool success)
139 : {
140 2 : RIALTO_SERVER_MANAGER_LOG_DEBUG("Queue ack handling for serverId: %d ping id: %d", serverId, pingId);
141 2 : m_eventThread->add(&SessionServerAppManager::handleAck, this, serverId, pingId, success);
142 : }
143 :
144 7 : std::string SessionServerAppManager::getAppConnectionInfo(const std::string &appName) const
145 : {
146 7 : std::promise<std::string> p;
147 7 : std::future<std::string> f{p.get_future()};
148 7 : m_eventThread->add(
149 7 : [&]()
150 : {
151 7 : auto sessionServer{getServerByAppName(appName)};
152 7 : if (sessionServer)
153 : {
154 1 : return p.set_value(sessionServer->getSessionManagementSocketName());
155 : }
156 6 : RIALTO_SERVER_MANAGER_LOG_ERROR("App: %s could not be found", appName.c_str());
157 18 : return p.set_value("");
158 7 : });
159 14 : return f.get();
160 7 : }
161 :
162 2 : bool SessionServerAppManager::setLogLevels(const service::LoggingLevels &logLevels) const
163 : {
164 2 : std::promise<bool> p;
165 2 : std::future<bool> f{p.get_future()};
166 2 : m_eventThread->add(
167 2 : [&]()
168 : {
169 2 : setLocalLogLevels(logLevels);
170 2 : if (!m_ipcController->setLogLevels(logLevels))
171 : {
172 1 : RIALTO_SERVER_MANAGER_LOG_WARN("Change log levels failed.");
173 1 : return p.set_value(false);
174 : }
175 1 : RIALTO_SERVER_MANAGER_LOG_INFO("Change log levels succeeded.");
176 1 : return p.set_value(true);
177 : });
178 4 : return f.get();
179 2 : }
180 :
181 2 : void SessionServerAppManager::restartServer(int serverId)
182 : {
183 2 : RIALTO_SERVER_MANAGER_LOG_DEBUG("Queue restart server handling for serverId: %d", serverId);
184 2 : m_eventThread->add(&SessionServerAppManager::handleRestartServer, this, serverId);
185 : }
186 :
187 2 : void SessionServerAppManager::handleRestartServer(int serverId)
188 : {
189 2 : if (m_isShuttingDown)
190 : {
191 0 : RIALTO_SERVER_MANAGER_LOG_DEBUG("Not restarting serverId: %d as server manager is shutting down", serverId);
192 1 : return;
193 : }
194 2 : auto sessionServer{getServerById(serverId)};
195 2 : if (!sessionServer)
196 : {
197 0 : RIALTO_SERVER_MANAGER_LOG_WARN("Unable to restart server, serverId: %d", serverId);
198 0 : return;
199 : }
200 2 : if (m_healthcheckService)
201 : {
202 2 : m_healthcheckService->onServerRemoved(sessionServer->getServerId());
203 : }
204 : // First, get all needed information from current app
205 2 : const std::string kAppName{sessionServer->getAppName()};
206 2 : const firebolt::rialto::common::SessionServerState kState{sessionServer->getExpectedState()};
207 2 : const firebolt::rialto::common::AppConfig kAppConfig{sessionServer->getSessionManagementSocketName(),
208 2 : sessionServer->getClientDisplayName()};
209 2 : std::unique_ptr<firebolt::rialto::ipc::INamedSocket> namedSocket{std::move(sessionServer->releaseNamedSocket())};
210 2 : if (firebolt::rialto::common::SessionServerState::INACTIVE != kState &&
211 1 : firebolt::rialto::common::SessionServerState::ACTIVE != kState)
212 : {
213 1 : RIALTO_SERVER_MANAGER_LOG_DEBUG("Restart server to %s not needed for serverId: %d", toString(kState), serverId);
214 1 : return;
215 : }
216 1 : RIALTO_SERVER_MANAGER_LOG_DEBUG("Restarting server with id: %d", serverId);
217 : // Then kill the app
218 1 : sessionServer->kill();
219 1 : handleSessionServerStateChange(serverId, firebolt::rialto::common::SessionServerState::NOT_RUNNING);
220 1 : sessionServer.reset();
221 :
222 : // Finally, spawn the new app with old settings and set named socket if present
223 1 : auto app = m_sessionServerAppFactory->create(kAppName, kState, kAppConfig, *this, std::move(namedSocket));
224 1 : if (app->launch())
225 : {
226 1 : auto result = m_sessionServerApps.emplace(std::move(app));
227 1 : if (result.second)
228 : {
229 1 : connectSessionServer(*result.first);
230 : }
231 : }
232 : else
233 : {
234 0 : RIALTO_SERVER_MANAGER_LOG_ERROR("Failed to restart server");
235 : }
236 5 : }
237 :
238 36 : bool SessionServerAppManager::connectSessionServer(const std::shared_ptr<ISessionServerApp> &kSessionServer)
239 : {
240 36 : if (!kSessionServer)
241 : {
242 7 : RIALTO_SERVER_MANAGER_LOG_ERROR("Unable to connect Session Server - pointer is null!");
243 7 : return false;
244 : }
245 29 : if (!m_ipcController->createClient(kSessionServer->getServerId(), kSessionServer->getAppManagementSocketName()))
246 : {
247 2 : RIALTO_SERVER_MANAGER_LOG_ERROR("Failed to establish RialtoServerManager - RialtoSessionServer connection for "
248 : "session server with id: %d",
249 : kSessionServer->getServerId());
250 2 : kSessionServer->kill();
251 2 : if (m_healthcheckService)
252 : {
253 2 : m_healthcheckService->onServerRemoved(kSessionServer->getServerId());
254 : }
255 2 : m_sessionServerApps.erase(kSessionServer);
256 2 : return false;
257 : }
258 27 : RIALTO_SERVER_MANAGER_LOG_INFO("RialtoServerManager with id %d successfully connected",
259 : kSessionServer->getServerId());
260 27 : return true;
261 : }
262 :
263 8 : bool SessionServerAppManager::configureSessionServer(const std::shared_ptr<ISessionServerApp> &kSessionServer)
264 : {
265 8 : if (!kSessionServer)
266 : {
267 0 : RIALTO_SERVER_MANAGER_LOG_ERROR("Unable to configure Session Server - pointer is null!");
268 0 : return false;
269 : }
270 8 : if (kSessionServer->isNamedSocketInitialized())
271 : {
272 2 : return configureSessionServerWithSocketFd(kSessionServer);
273 : }
274 6 : return configureSessionServerWithSocketName(kSessionServer);
275 : }
276 :
277 4 : bool SessionServerAppManager::configurePreloadedSessionServer(const std::shared_ptr<ISessionServerApp> &kSessionServer,
278 : const std::string &appName,
279 : const firebolt::rialto::common::SessionServerState &state,
280 : const firebolt::rialto::common::AppConfig &appConfig)
281 : {
282 4 : RIALTO_SERVER_MANAGER_LOG_INFO("Configuration of preloaded session server with id: %d for %s app",
283 : kSessionServer->getServerId(), appName.c_str());
284 4 : if (kSessionServer->configure(appName, state, appConfig) && configureSessionServer(kSessionServer))
285 : {
286 : // Schedule adding new preloaded session server (as we've just used one) and return immediately
287 4 : m_eventThread->add([this]() { connectSessionServer(preloadSessionServer()); });
288 2 : return true;
289 : }
290 : // Configuration failed, kill server and return error
291 2 : handleSessionServerStateChange(kSessionServer->getServerId(), firebolt::rialto::common::SessionServerState::ERROR);
292 2 : kSessionServer->kill();
293 2 : handleSessionServerStateChange(kSessionServer->getServerId(),
294 : firebolt::rialto::common::SessionServerState::NOT_RUNNING);
295 : // Schedule adding new preloaded session server
296 4 : m_eventThread->add([this]() { connectSessionServer(preloadSessionServer()); });
297 2 : return false;
298 : }
299 :
300 4 : bool SessionServerAppManager::changeSessionServerState(const std::string &appName,
301 : const firebolt::rialto::common::SessionServerState &newState)
302 : {
303 4 : RIALTO_SERVER_MANAGER_LOG_INFO("RialtoServerManager requests to change state of %s to %s", appName.c_str(),
304 : toString(newState));
305 4 : auto sessionServer{getServerByAppName(appName)};
306 4 : if (!sessionServer)
307 : {
308 1 : RIALTO_SERVER_MANAGER_LOG_ERROR("Change state of %s to %s failed - session server not found.", appName.c_str(),
309 : toString(newState));
310 1 : return false;
311 : }
312 3 : sessionServer->setExpectedState(newState);
313 3 : if (m_healthcheckService && firebolt::rialto::common::SessionServerState::NOT_RUNNING == newState)
314 : {
315 1 : m_healthcheckService->onServerRemoved(sessionServer->getServerId());
316 : }
317 3 : if (!m_ipcController->performSetState(sessionServer->getServerId(), newState))
318 : {
319 2 : RIALTO_SERVER_MANAGER_LOG_ERROR("Change state of %s to %s failed.", appName.c_str(), toString(newState));
320 2 : handleStateChangeFailure(sessionServer, newState);
321 2 : return false;
322 : }
323 1 : RIALTO_SERVER_MANAGER_LOG_INFO("Change state of %s to %s succeeded.", appName.c_str(), toString(newState));
324 1 : return true;
325 4 : }
326 :
327 28 : void SessionServerAppManager::handleSessionServerStateChange(int serverId,
328 : firebolt::rialto::common::SessionServerState newState)
329 : {
330 28 : RIALTO_SERVER_MANAGER_LOG_INFO("SessionServer with id: %d changed state to %s", serverId, toString(newState));
331 28 : auto sessionServer{getServerById(serverId)};
332 28 : if (!sessionServer)
333 : {
334 0 : RIALTO_SERVER_MANAGER_LOG_WARN("SessionServer with id: %d not found", serverId);
335 0 : return;
336 : }
337 28 : std::string appName{sessionServer->getAppName()};
338 28 : if (!appName.empty() && m_stateObserver) // empty app name is when SessionServer is preloaded
339 : {
340 19 : m_stateObserver->stateChanged(appName, newState);
341 : }
342 28 : if (firebolt::rialto::common::SessionServerState::UNINITIALIZED == newState)
343 : {
344 10 : sessionServer->cancelStartupTimer();
345 10 : if (!sessionServer->isPreloaded() && !configureSessionServer(sessionServer))
346 : {
347 2 : handleSessionServerStateChange(serverId, firebolt::rialto::common::SessionServerState::ERROR);
348 2 : sessionServer->kill();
349 2 : handleSessionServerStateChange(serverId, firebolt::rialto::common::SessionServerState::NOT_RUNNING);
350 : }
351 : }
352 18 : else if (newState == firebolt::rialto::common::SessionServerState::ERROR && sessionServer->isPreloaded())
353 : {
354 1 : m_ipcController->removeClient(serverId);
355 1 : sessionServer->kill();
356 1 : if (m_healthcheckService)
357 : {
358 1 : m_healthcheckService->onServerRemoved(sessionServer->getServerId());
359 : }
360 1 : m_sessionServerApps.erase(sessionServer);
361 1 : if (!m_isShuttingDown)
362 : {
363 1 : connectSessionServer(preloadSessionServer());
364 : }
365 : }
366 17 : else if (newState == firebolt::rialto::common::SessionServerState::NOT_RUNNING)
367 : {
368 8 : m_ipcController->removeClient(serverId);
369 8 : if (m_healthcheckService)
370 : {
371 8 : m_healthcheckService->onServerRemoved(sessionServer->getServerId());
372 : }
373 8 : m_sessionServerApps.erase(sessionServer);
374 : }
375 28 : }
376 :
377 2 : void SessionServerAppManager::handleAck(int serverId, int pingId, bool success)
378 : {
379 2 : if (success)
380 : {
381 1 : RIALTO_SERVER_MANAGER_LOG_DEBUG("Ping with id: %d succeeded for server: %d", pingId, serverId);
382 : }
383 : else
384 : {
385 1 : RIALTO_SERVER_MANAGER_LOG_ERROR("Ping with id: %d failed for server: %d", pingId, serverId);
386 : }
387 2 : if (m_healthcheckService)
388 : {
389 2 : m_healthcheckService->onAckReceived(serverId, pingId, success);
390 : }
391 : }
392 :
393 34 : void SessionServerAppManager::shutdownAllSessionServers()
394 : {
395 34 : m_isShuttingDown = true;
396 34 : m_healthcheckService.reset();
397 52 : for (const auto &kSessionServer : m_sessionServerApps)
398 : {
399 18 : kSessionServer->kill();
400 : }
401 34 : m_sessionServerApps.clear();
402 : }
403 :
404 : std::shared_ptr<ISessionServerApp>
405 23 : SessionServerAppManager::launchSessionServer(const std::string &appName,
406 : const firebolt::rialto::common::SessionServerState &kInitialState,
407 : const firebolt::rialto::common::AppConfig &appConfig)
408 : {
409 23 : RIALTO_SERVER_MANAGER_LOG_INFO("Launching Rialto Session Server for %s", appName.c_str());
410 23 : auto app = m_sessionServerAppFactory->create(appName, kInitialState, appConfig, *this,
411 23 : m_namedSocketFactory.createNamedSocket());
412 23 : if (app->launch())
413 : {
414 22 : if (m_sessionServerApps.emplace(app).second)
415 : {
416 22 : return app;
417 : }
418 : }
419 1 : return nullptr;
420 23 : }
421 :
422 12 : std::shared_ptr<ISessionServerApp> SessionServerAppManager::preloadSessionServer()
423 : {
424 12 : RIALTO_SERVER_MANAGER_LOG_INFO("Preloading new Rialto Session Server");
425 12 : auto app = m_sessionServerAppFactory->create(*this, m_namedSocketFactory.createNamedSocket());
426 12 : if (app->launch())
427 : {
428 6 : if (m_sessionServerApps.emplace(app).second)
429 : {
430 6 : return app;
431 : }
432 : }
433 6 : return nullptr;
434 12 : }
435 :
436 27 : std::shared_ptr<ISessionServerApp> SessionServerAppManager::getPreloadedServer() const
437 : {
438 27 : auto iter = std::find_if(m_sessionServerApps.begin(), m_sessionServerApps.end(),
439 4 : [](const auto &srv) { return srv->isPreloaded() && srv->isConnected(); });
440 27 : if (m_sessionServerApps.end() != iter)
441 : {
442 4 : return *iter;
443 : }
444 23 : return nullptr;
445 : }
446 :
447 39 : std::shared_ptr<ISessionServerApp> SessionServerAppManager::getServerByAppName(const std::string &appName) const
448 : {
449 39 : auto iter{std::find_if(m_sessionServerApps.begin(), m_sessionServerApps.end(),
450 9 : [&](const auto &srv) { return srv->getAppName() == appName; })};
451 39 : if (m_sessionServerApps.end() != iter)
452 : {
453 5 : return *iter;
454 : }
455 34 : return nullptr;
456 : }
457 :
458 32 : std::shared_ptr<ISessionServerApp> SessionServerAppManager::getServerById(int serverId) const
459 : {
460 32 : auto iter{std::find_if(m_sessionServerApps.begin(), m_sessionServerApps.end(),
461 31 : [&](const auto &srv) { return srv->getServerId() == serverId; })};
462 32 : if (m_sessionServerApps.end() != iter)
463 : {
464 31 : return *iter;
465 : }
466 1 : return nullptr;
467 : }
468 :
469 2 : void SessionServerAppManager::handleStateChangeFailure(const std::shared_ptr<ISessionServerApp> &kSessionServer,
470 : const firebolt::rialto::common::SessionServerState &state)
471 : {
472 2 : if (state == firebolt::rialto::common::SessionServerState::NOT_RUNNING)
473 : {
474 1 : RIALTO_SERVER_MANAGER_LOG_WARN("Force change of %s to NotRunning.", kSessionServer->getAppName().c_str());
475 1 : kSessionServer->kill();
476 1 : handleSessionServerStateChange(kSessionServer->getServerId(), state);
477 : }
478 : else
479 : {
480 1 : handleSessionServerStateChange(kSessionServer->getServerId(),
481 : firebolt::rialto::common::SessionServerState::ERROR);
482 : }
483 2 : }
484 :
485 6 : bool SessionServerAppManager::configureSessionServerWithSocketName(const std::shared_ptr<ISessionServerApp> &kSessionServer)
486 : {
487 6 : RIALTO_SERVER_MANAGER_LOG_DEBUG("Configuring Session Server using socket name");
488 6 : const auto kInitialState{kSessionServer->getInitialState()};
489 6 : const auto kSocketName{kSessionServer->getSessionManagementSocketName()};
490 6 : const auto kClientDisplayName{kSessionServer->getClientDisplayName()};
491 6 : const auto kSocketPermissions{kSessionServer->getSessionManagementSocketPermissions()};
492 6 : const auto kSocketOwner{kSessionServer->getSessionManagementSocketOwner()};
493 6 : const auto kSocketGroup{kSessionServer->getSessionManagementSocketGroup()};
494 6 : const auto kAppName{kSessionServer->getAppName()};
495 :
496 6 : const firebolt::rialto::common::MaxResourceCapabilitites kMaxResource{kSessionServer->getMaxPlaybackSessions(),
497 6 : kSessionServer->getMaxWebAudioPlayers()};
498 6 : if (!m_ipcController->performSetConfiguration(kSessionServer->getServerId(), kInitialState, kSocketName,
499 : kClientDisplayName, kMaxResource, kSocketPermissions, kSocketOwner,
500 : kSocketGroup, kAppName))
501 : {
502 2 : RIALTO_SERVER_MANAGER_LOG_ERROR("Configuration of server with id %d failed - ipc error.",
503 : kSessionServer->getServerId());
504 2 : return false;
505 : }
506 4 : RIALTO_SERVER_MANAGER_LOG_INFO("Configuration of server with id %d succeeded.", kSessionServer->getServerId());
507 4 : return true;
508 6 : }
509 :
510 2 : bool SessionServerAppManager::configureSessionServerWithSocketFd(const std::shared_ptr<ISessionServerApp> &kSessionServer)
511 : {
512 2 : RIALTO_SERVER_MANAGER_LOG_DEBUG("Configuring Session Server using socket fd");
513 2 : const auto kInitialState{kSessionServer->getInitialState()};
514 2 : const auto kSocketFd{kSessionServer->getSessionManagementSocketFd()};
515 2 : const auto kClientDisplayName{kSessionServer->getClientDisplayName()};
516 2 : const auto kAppName{kSessionServer->getAppName()};
517 :
518 2 : const firebolt::rialto::common::MaxResourceCapabilitites kMaxResource{kSessionServer->getMaxPlaybackSessions(),
519 2 : kSessionServer->getMaxWebAudioPlayers()};
520 2 : if (!m_ipcController->performSetConfiguration(kSessionServer->getServerId(), kInitialState, kSocketFd,
521 : kClientDisplayName, kMaxResource, kAppName))
522 : {
523 1 : RIALTO_SERVER_MANAGER_LOG_ERROR("Configuration of server with id %d failed - ipc error.",
524 : kSessionServer->getServerId());
525 1 : return false;
526 : }
527 1 : RIALTO_SERVER_MANAGER_LOG_INFO("Configuration of server with id %d succeeded.", kSessionServer->getServerId());
528 1 : return true;
529 2 : }
530 :
531 2 : void SessionServerAppManager::onServerStartupTimeout(int serverId)
532 : {
533 2 : m_eventThread->add(&SessionServerAppManager::handleServerStartupTimeout, this, serverId);
534 : }
535 :
536 2 : void SessionServerAppManager::handleServerStartupTimeout(int serverId)
537 : {
538 2 : auto sessionServer{getServerById(serverId)};
539 2 : if (!sessionServer)
540 : {
541 1 : RIALTO_SERVER_MANAGER_LOG_WARN("Unable to handle startup timeout for serverId: %d", serverId);
542 1 : return;
543 : }
544 1 : const bool isPreloaded{sessionServer->isPreloaded()};
545 1 : RIALTO_SERVER_MANAGER_LOG_WARN("Killing: %d", serverId);
546 1 : handleSessionServerStateChange(serverId, firebolt::rialto::common::SessionServerState::ERROR);
547 :
548 1 : if (!isPreloaded)
549 : {
550 1 : if (m_healthcheckService)
551 : {
552 1 : m_healthcheckService->onServerRemoved(sessionServer->getServerId());
553 : }
554 1 : sessionServer->kill();
555 1 : handleSessionServerStateChange(serverId, firebolt::rialto::common::SessionServerState::NOT_RUNNING);
556 : }
557 2 : }
558 : } // namespace rialto::servermanager::common
|