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 "ServerManagerServiceFactory.h"
21 : #include "ConfigHelper.h"
22 : #include "RialtoServerManagerLogging.h"
23 : #include "ServerManagerService.h"
24 : #include "ServiceContext.h"
25 : #include <memory>
26 :
27 : #ifdef RIALTO_ENABLE_CONFIG_FILE
28 : #include "ConfigReaderFactory.h"
29 : #endif
30 :
31 : namespace
32 : {
33 0 : unsigned int convertSocketPermissions(firebolt::rialto::common::SocketPermissions permissions) // copy param intentionally
34 : {
35 0 : constexpr unsigned int kDefaultPermissions{0666};
36 0 : if (permissions.ownerPermissions > 7 || permissions.groupPermissions > 7 || permissions.otherPermissions > 7)
37 : {
38 0 : RIALTO_SERVER_MANAGER_LOG_WARN("One of permissions values is out of bounds. Default permissions will be used");
39 0 : return kDefaultPermissions;
40 : }
41 0 : permissions.ownerPermissions <<= 6;
42 0 : permissions.groupPermissions <<= 3;
43 0 : return (permissions.ownerPermissions | permissions.groupPermissions | permissions.otherPermissions);
44 : }
45 : } // namespace
46 :
47 : namespace rialto::servermanager::service
48 : {
49 0 : std::unique_ptr<IServerManagerService> create(const std::shared_ptr<IStateObserver> &stateObserver)
50 : {
51 0 : firebolt::rialto::common::ServerManagerConfig config;
52 0 : return create(stateObserver, config);
53 : }
54 :
55 0 : std::unique_ptr<IServerManagerService> create(const std::shared_ptr<IStateObserver> &stateObserver,
56 : const firebolt::rialto::common::ServerManagerConfig &config)
57 : {
58 0 : std::unique_ptr<IConfigReaderFactory> configReaderFactory{};
59 : #ifdef RIALTO_ENABLE_CONFIG_FILE
60 0 : configReaderFactory = std::make_unique<ConfigReaderFactory>();
61 : #endif
62 0 : ConfigHelper configHelper{std::move(configReaderFactory), config};
63 :
64 : std::unique_ptr<IServerManagerService> service = std::make_unique<
65 0 : ServerManagerService>(std::make_unique<ServiceContext>(stateObserver, configHelper.getSessionServerEnvVars(),
66 0 : configHelper.getSessionServerPath(),
67 0 : configHelper.getSessionServerStartupTimeout(),
68 0 : configHelper.getHealthcheckInterval(),
69 0 : configHelper.getNumOfFailedPingsBeforeRecovery(),
70 0 : convertSocketPermissions(
71 0 : configHelper.getSocketPermissions()),
72 0 : configHelper.getSocketPermissions().owner,
73 0 : configHelper.getSocketPermissions().group),
74 0 : configHelper.getNumOfPreloadedServers());
75 : #ifdef RIALTO_ENABLE_CONFIG_FILE
76 0 : service->setLogLevels(configHelper.getLoggingLevels());
77 : #endif
78 0 : return service;
79 : }
80 : } // namespace rialto::servermanager::service
|