Multiple DBAAS Redis Sentinel groups
[ric-plt/sdl.git] / src / databaseconfigurationimpl.cpp
index f1fb2be..211c537 100644 (file)
    limitations under the License.
 */
 
+/*
+ * This source code is part of the near-RT RIC (RAN Intelligent Controller)
+ * platform project (RICP).
+*/
+
 #include "private/databaseconfigurationimpl.hpp"
 #include <arpa/inet.h>
+#include <boost/crc.hpp>
 
 using namespace shareddatalayer;
 
@@ -28,6 +34,7 @@ namespace
     }
 
     const uint16_t DEFAULT_PORT(6379U);
+    const uint16_t DEFAULT_SENTINEL_PORT(26379U);
 }
 
 DatabaseConfigurationImpl::DatabaseConfigurationImpl():
@@ -45,6 +52,10 @@ void DatabaseConfigurationImpl::checkAndApplyDbType(const std::string& type)
         dbType = DatabaseConfiguration::DbType::REDIS_STANDALONE;
     else if (type == "redis-cluster")
         dbType = DatabaseConfiguration::DbType::REDIS_CLUSTER;
+    else if (type == "redis-sentinel")
+        dbType = DatabaseConfiguration::DbType::REDIS_SENTINEL;
+    else if (type == "sdl-cluster")
+        dbType = DatabaseConfiguration::DbType::SDL_CLUSTER;
     else
         throw DatabaseConfiguration::InvalidDbType(type);
 }
@@ -73,3 +84,31 @@ DatabaseConfiguration::Addresses DatabaseConfigurationImpl::getDefaultServerAddr
 {
     return { HostAndPort(getDefaultHost(), htons(DEFAULT_PORT)) };
 }
+
+void DatabaseConfigurationImpl::checkAndApplySentinelAddress(const std::string& address)
+{
+    sentinelAddress = HostAndPort(address, htons(DEFAULT_SENTINEL_PORT));
+}
+
+boost::optional<HostAndPort> DatabaseConfigurationImpl::getSentinelAddress() const
+{
+    return sentinelAddress;
+}
+
+boost::optional<HostAndPort> DatabaseConfigurationImpl::getSentinelAddress(const boost::optional<std::size_t>& addressIndex) const
+{
+    if (addressIndex)
+        return { HostAndPort(serverAddresses.at(*addressIndex).getHost(), sentinelAddress->getPort()) };
+
+    return getSentinelAddress();
+}
+
+void DatabaseConfigurationImpl::checkAndApplySentinelMasterName(const std::string& name)
+{
+    sentinelMasterName = name;
+}
+
+std::string DatabaseConfigurationImpl::getSentinelMasterName() const
+{
+    return sentinelMasterName;
+}