RIC:1060: Change in PTL
[ric-plt/sdl.git] / include / private / asyncstorageimpl.hpp
1 /*
2    Copyright (c) 2018-2019 Nokia.
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 */
16
17 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20 */
21
22 #ifndef SHAREDDATALAYER_REDIS_ASYNCSTORAGEIMPL_HPP_
23 #define SHAREDDATALAYER_REDIS_ASYNCSTORAGEIMPL_HPP_
24
25 #include <functional>
26 #include <sdl/asyncstorage.hpp>
27 #include <sdl/publisherid.hpp>
28 #include "private/configurationreader.hpp"
29 #include "private/databaseconfigurationimpl.hpp"
30 #include "private/logger.hpp"
31 #include "private/namespaceconfigurationsimpl.hpp"
32 #include "private/redis/asyncdatabasediscovery.hpp"
33 #include "private/redis/asyncredisstorage.hpp"
34
35 namespace shareddatalayer
36 {
37     class Engine;
38
39     class AsyncStorageImpl: public AsyncStorage
40     {
41     public:
42         using AsyncDatabaseDiscoveryCreator = std::function<std::shared_ptr<redis::AsyncDatabaseDiscovery>(std::shared_ptr<Engine> engine,
43                                                                                                            const std::string& ns,
44                                                                                                            const DatabaseConfiguration& databaseConfiguration,
45                                                                                                            const boost::optional<std::size_t>& addressIndex,
46                                                                                                            std::shared_ptr<Logger> logger)>;
47
48         AsyncStorageImpl(const AsyncStorageImpl&) = delete;
49
50         AsyncStorageImpl& operator = (const AsyncStorageImpl&) = delete;
51
52         AsyncStorageImpl(AsyncStorageImpl&&) = delete;
53
54         AsyncStorageImpl& operator = (AsyncStorageImpl&&) = delete;
55
56         AsyncStorageImpl(std::shared_ptr<Engine> engine,
57                          const boost::optional<PublisherId>& pId,
58                          std::shared_ptr<Logger> logger);
59
60         // Meant for UT
61         AsyncStorageImpl(std::shared_ptr<Engine> engine,
62                          const boost::optional<PublisherId>& pId,
63                          std::shared_ptr<DatabaseConfiguration> databaseConfiguration,
64                          std::shared_ptr<NamespaceConfigurations> namespaceConfigurations,
65                          std::shared_ptr<Logger> logger,
66                          const AsyncDatabaseDiscoveryCreator& asyncDatabaseDiscoveryCreator);
67
68         int fd() const override;
69
70         void handleEvents() override;
71
72         void waitReadyAsync(const Namespace& ns, const ReadyAck& readyAck) override;
73
74         void setAsync(const Namespace& ns, const DataMap& dataMap, const ModifyAck& modifyAck) override;
75
76         void setIfAsync(const Namespace& ns, const Key& key, const Data& oldData, const Data& newData, const ModifyIfAck& modifyIfAck) override;
77
78         void setIfNotExistsAsync(const Namespace& ns, const Key& key, const Data& data, const ModifyIfAck& modifyIfAck) override;
79
80         void getAsync(const Namespace& ns, const Keys& keys, const GetAck& getAck) override;
81
82         void removeAsync(const Namespace& ns, const Keys& keys, const ModifyAck& modifyAck) override;
83
84         void removeIfAsync(const Namespace& ns, const Key& key, const Data& data, const ModifyIfAck& modifyIfAck) override;
85
86         void findKeysAsync(const Namespace& ns, const std::string& keyPrefix, const FindKeysAck& findKeysAck) override;
87
88         void listKeys(const Namespace& ns, const std::string& pattern, const FindKeysAck& findKeysAck) override;
89
90         void removeAllAsync(const Namespace& ns, const ModifyAck& modifyAck) override;
91
92         //public for UT
93         AsyncStorage& getOperationHandler(const std::string& ns);
94     private:
95         std::shared_ptr<Engine> engine;
96         std::shared_ptr<DatabaseConfiguration> databaseConfiguration;
97         std::shared_ptr<NamespaceConfigurations> namespaceConfigurations;
98         const boost::optional<PublisherId> publisherId;
99         std::shared_ptr<Logger> logger;
100         AsyncDatabaseDiscoveryCreator asyncDatabaseDiscoveryCreator;
101
102         std::vector<std::shared_ptr<AsyncRedisStorage>> asyncStorages;
103
104         AsyncStorage& getRedisHandler(const std::string& ns);
105         AsyncStorage& getDummyHandler();
106
107         void setAsyncRedisStorageHandlers(const std::string& ns);
108         void setAsyncRedisStorageHandlersForCluster(const std::string& ns);
109         AsyncStorage& getAsyncRedisStorageHandler(const std::string& ns);
110     };
111 }
112
113 #endif