src/cli/dumpconfigurationcommand.cpp \
src/cli/testgetsetcommand.cpp \
src/cli/testconnectivitycommand.cpp \
+ src/cli/listkeyscommand.cpp \
+ src/cli/setcommand.cpp \
+ src/cli/getcommand.cpp \
src/exception.cpp \
src/configurationpaths.cpp \
include/private/configurationpaths.hpp \
m4_define([SDL_MAJOR], [1])
m4_define([SDL_MINOR], [5])
-m4_define([SDL_MICRO], [0])
+m4_define([SDL_MICRO], [1])
# SDL ABI version with libtool
#
# Change the numbers just before release.
m4_define([SDL_CURRENT], [5])
-m4_define([SDL_REVISION], [12])
+m4_define([SDL_REVISION], [13])
m4_define([SDL_AGE], [0])
AC_INIT([shareddatalayer], [SDL_MAJOR.SDL_MINOR.SDL_MICRO], [], [], [https://gerrit.o-ran-sc.org/r/admin/repos/ric-plt/sdl])
+sdl (1.5.1-1) UNRELEASED; urgency=low
+
+ * Add set, get and listKeys -sdltool CLI commands
+
+ -- Petri Ovaska <petri.ovaska@nokia.com> Fri, 17 Sep 2021 12:33:24 +0300
+
sdl (1.5.0-1) UNRELEASED; urgency=low
* New listKeys API to support glob-style search pattern
Version history
---------------
+[1.5.1] - 2021-09-17
+
+* Add set, get and listKeys -sdltool CLI commands
+
[1.5.0] - 2021-09-17
* New listKeys API to support glob-style search pattern
--- /dev/null
+#ifndef SHAREDDATALAYER_CLI_COMMON_HPP
+#define SHAREDDATALAYER_CLI_COMMON_HPP
+
+#include <functional>
+#include <iostream>
+#include <sdl/syncstorage.hpp>
+
+namespace shareddatalayer
+{
+ namespace cli
+ {
+ inline std::ostream& operator<<(std::ostream &out, const SyncStorage::Data &data)
+ {
+ for (const auto& d : data)
+ out << d;
+ return out;
+ }
+
+ inline std::ostream& operator<<(std::ostream& out, const SyncStorage::DataMap& dataMap)
+ {
+ for (const auto& d : dataMap)
+ out << d.first << " " << d.second;
+ return out;
+ }
+ }
+}
+#endif
Name: sdl
-Version: 1.5.0
+Version: 1.5.1
Release: 1%{?dist}
Summary: C++ API library for Shared Data Layer clients
%{_includedir}/sdl
%changelog
+* Fri Sep 17 2021 Petri Ovaska <petri.ovaska@nokia.com> - 1.5.1-1
+- Add set, get and listKeys -sdltool CLI commands
+
* Fri Sep 17 2021 Petri Ovaska <petri.ovaska@nokia.com> - 1.5.0-1
- New listKeys API to support glob-style search pattern
- Deprecated old findKeys and findKeysAsync API
--- /dev/null
+#include <ostream>
+#include <cstdlib>
+#include "private/cli/commandmap.hpp"
+#include "private/cli/common.hpp"
+#include <sdl/syncstorage.hpp>
+
+using namespace shareddatalayer;
+using namespace shareddatalayer::cli;
+
+namespace
+{
+ std::shared_ptr<shareddatalayer::SyncStorage> createSyncStorage(const SyncStorage::Namespace& ns,
+ std::ostream& out)
+ {
+ try
+ {
+ auto sdl(shareddatalayer::SyncStorage::create());
+ sdl->waitReady(ns, std::chrono::minutes(1));
+ return sdl;
+ }
+ catch (const shareddatalayer::Exception& error)
+ {
+ out << "SyncStorage create failed: " << error.what() << std::endl;
+ }
+
+ return nullptr;
+ }
+
+ void get(shareddatalayer::SyncStorage& sdl,
+ const SyncStorage::Namespace& ns,
+ const SyncStorage::Key& key,
+ std::ostream& out)
+ {
+ try
+ {
+ auto data(sdl.get(ns, {key}));
+ out << data << std::endl;
+ }
+ catch (const shareddatalayer::Exception& error)
+ {
+ out << "get(" << ns << ", " << key << ") failed: "
+ << error.what() << std::endl;
+ }
+ }
+
+ int getCommand(std::ostream& out, const boost::program_options::variables_map& map)
+ {
+ auto ns(map["ns"].as<std::string>());
+ auto key(map["key"].as<std::string>());
+
+ auto sdl(createSyncStorage(ns, out));
+ if (nullptr == sdl)
+ return EXIT_FAILURE;
+ sdl->setOperationTimeout(std::chrono::seconds(5));
+
+ get(std::ref(*sdl), ns, key, out);
+
+ return EXIT_SUCCESS;
+ }
+}
+
+const char *longHelpGetCmd =
+ "Use get SDL API to read data from storage under the namespace.\n\n"
+ "Example: sdltool get --ns 'sdltool' --key 'key1'";
+
+AUTO_REGISTER_COMMAND(std::bind(getCommand, std::placeholders::_1, std::placeholders::_3),
+ "get",
+ "get data with SDL API under the namespace",
+ longHelpGetCmd,
+ CommandMap::Category::UTIL,
+ 30050,
+ ("ns,n", boost::program_options::value<std::string>()->default_value("sdltoolns"), "namespace to use")
+ ("key,k", boost::program_options::value<std::string>()->default_value("key1"), "key value")
+ );
+
--- /dev/null
+#include <ostream>
+#include <cstdlib>
+#include "private/cli/commandmap.hpp"
+#include "private/cli/common.hpp"
+#include <sdl/syncstorage.hpp>
+#include <sdl/asyncstorage.hpp>
+
+using namespace shareddatalayer;
+using namespace shareddatalayer::cli;
+
+namespace
+{
+ std::shared_ptr<shareddatalayer::SyncStorage> createSyncStorage(const SyncStorage::Namespace& ns,
+ std::ostream& out)
+ {
+ try
+ {
+ auto sdl(shareddatalayer::SyncStorage::create());
+ sdl->waitReady(ns, std::chrono::minutes(1));
+ return sdl;
+ }
+ catch (const shareddatalayer::Exception& error)
+ {
+ out << "SyncStorage create failed: " << error.what() << std::endl;
+ }
+
+ return nullptr;
+ }
+
+ void listkeys(shareddatalayer::SyncStorage& sdl,
+ const SyncStorage::Namespace& ns,
+ const std::string& pattern,
+ std::ostream& out)
+ {
+ try
+ {
+ auto keys(sdl.listKeys(ns, pattern));
+ for (auto key: keys)
+ out << key << std::endl;
+ }
+ catch (const shareddatalayer::Exception& error)
+ {
+ out << "listKeys(" << ns << ", " << pattern << ") failed: "
+ << error.what() << std::endl;
+ }
+ }
+
+ int listKeysCommand(std::ostream& out, const boost::program_options::variables_map& map)
+ {
+ auto ns(map["ns"].as<std::string>());
+ auto pattern(map["pattern"].as<std::string>());
+
+ auto sdl(createSyncStorage(ns, out));
+ if (nullptr == sdl)
+ return EXIT_FAILURE;
+ sdl->setOperationTimeout(std::chrono::seconds(5));
+
+ listkeys(std::ref(*sdl), ns, pattern, out);
+
+ return EXIT_SUCCESS;
+ }
+}
+
+const char *longHelpListkeysCmd =
+ "Use listKeys SDL API to list keys matching search pattern under the namespace.\n\n"
+ "Example: sdltool listkeys --ns 'sdltool' --pattern 'foo*'";
+
+AUTO_REGISTER_COMMAND(std::bind(listKeysCommand, std::placeholders::_1, std::placeholders::_3),
+ "listkeys",
+ "listKeys SDL API",
+ longHelpListkeysCmd,
+ CommandMap::Category::UTIL,
+ 30030,
+ ("ns,n", boost::program_options::value<std::string>()->default_value("sdltoolns"), "namespace to use")
+ ("pattern,p", boost::program_options::value<std::string>()->default_value("*"), "key search pattern")
+ );
+
--- /dev/null
+#include <ostream>
+#include <cstdlib>
+#include "private/cli/commandmap.hpp"
+#include "private/cli/common.hpp"
+#include <sdl/syncstorage.hpp>
+
+using namespace shareddatalayer;
+using namespace shareddatalayer::cli;
+
+namespace
+{
+ std::shared_ptr<shareddatalayer::SyncStorage> createSyncStorage(const SyncStorage::Namespace& ns,
+ std::ostream& out)
+ {
+ try
+ {
+ auto sdl(shareddatalayer::SyncStorage::create());
+ sdl->waitReady(ns, std::chrono::minutes(1));
+ return sdl;
+ }
+ catch (const shareddatalayer::Exception& error)
+ {
+ out << "SyncStorage create failed: " << error.what() << std::endl;
+ }
+
+ return nullptr;
+ }
+
+ void set(shareddatalayer::SyncStorage& sdl,
+ const SyncStorage::Namespace& ns,
+ const SyncStorage::DataMap& dataMap,
+ std::ostream& out)
+ {
+ try
+ {
+ sdl.set(ns, dataMap);
+ out << "set {" << ns << "}," << dataMap << std::endl;
+ }
+ catch (const shareddatalayer::Exception& error)
+ {
+ out << "Error in set(" << ns << ", " << dataMap << ") failed: "
+ << error.what() << std::endl;
+ }
+ }
+
+ int setCommand(std::ostream& out, const boost::program_options::variables_map& map)
+ {
+ auto ns(map["ns"].as<std::string>());
+ auto key(map["key"].as<std::string>());
+ auto data(map["data"].as<std::string>());
+ auto debug(map["debug"].as<bool>());
+ SyncStorage::Data dataVector(data.begin(), data.end());
+
+ auto sdl(createSyncStorage(ns, out));
+ if (nullptr == sdl)
+ return EXIT_FAILURE;
+ sdl->setOperationTimeout(std::chrono::seconds(5));
+
+ if (debug)
+ {
+ out << "DEBUG setCommand ns: " << ns
+ << " key: " << key << " data: " << data << std::endl;
+ }
+
+ SyncStorage::DataMap datamap({{key, dataVector}});
+ set(std::ref(*sdl), ns, datamap, out);
+
+ return EXIT_SUCCESS;
+ }
+}
+
+const char *longHelpSetCmd =
+ "Use set SDL API to write data to storage under the namespace.\n\n"
+ "Example: sdltool set --ns 'sdltool' --key 'key1' --data '1'";
+
+AUTO_REGISTER_COMMAND(std::bind(setCommand, std::placeholders::_1, std::placeholders::_3),
+ "set",
+ "set key value with SDL API",
+ longHelpSetCmd,
+ CommandMap::Category::UTIL,
+ 30040,
+ ("ns,n", boost::program_options::value<std::string>()->default_value("sdltoolns"), "namespace to use")
+ ("key,k", boost::program_options::value<std::string>()->default_value("key1"), "key value")
+ ("data,d", boost::program_options::value<std::string>()->default_value("1"), "data")
+ ("debug", boost::program_options::bool_switch()->default_value(false), "Enable debug logs")
+ );
+