ric-plt/sdlgo.git
2 years agoSDL CLI 'get namespaces' -command key count 28/7128/2
Timo Tietavainen [Thu, 25 Nov 2021 22:57:59 +0000 (00:57 +0200)]
SDL CLI 'get namespaces' -command key count

Change existing -g,--group flag to -w,--wide flag. When the flag has
been set, command shows DB namespaces per SDL cluster group address
and how many DB keys there are per namespace.
New command syntax is:
    sdlcli get namespaces [flags]
Where supported flags are: -w, --wide, -h and --help.

Issue-Id: RIC-113

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: Iae0b044257a5e26e6cfaa48e2a5dca8441c23d5c

2 years agoShow help when no sdlcli arguments 27/7127/1
Timo Tietavainen [Thu, 25 Nov 2021 17:44:53 +0000 (19:44 +0200)]
Show help when no sdlcli arguments

Implement showing of the help text also when sdlcli tool is called
without any arguments.

Issue-Id: RIC-113

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I6ebd9844fe09debeeb24946ba55ebfb2d7b807c3

2 years agoImplement SDL CLI 'get namespaces' -command 03/7103/2
Timo Tietavainen [Tue, 23 Nov 2021 06:32:04 +0000 (08:32 +0200)]
Implement SDL CLI 'get namespaces' -command

Implement a new 'get namespaces' -command for 'sdlcli' -tool. With this
command user can list all the namespaces found in database. Command
syntax is:
  sdlcli get namespaces [flags]
Supported flags are -g, --group, -h and --help flags. With -g,--group
flag user can get a list of namespace per SDL cluster group address and
-h, --help flags shows the command help.

Issue-Id: RIC-113

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: If4d66497eeec94d479748c81cf0898c2fbc78364

2 years agoSDL CLI 'get' reads keys data in the given namespace 76/7076/3
Petri Ovaska [Tue, 16 Nov 2021 06:36:13 +0000 (08:36 +0200)]
SDL CLI 'get' reads keys data in the given namespace

Implement SDL CLI 'get' command that reads keys data in the given
namespace. The 'get' reads one or multiple keys data:

 sdlcli get <namespace> <key> [<key2> <key3>... <keyN>]

Issue-Id: RIC-113
Change-Id: Ibe2cad1a986fa48bee4dba20eb4e886f62b09bf0
Signed-off-by: Petri Ovaska <petri.ovaska@nokia.com>
2 years agoImplement SDL CLI 'remove' -command 68/7068/3
Timo Tietavainen [Mon, 15 Nov 2021 19:33:15 +0000 (21:33 +0200)]
Implement SDL CLI 'remove' -command

Implement a new 'remove' -command for 'sdlcli' -tool. With this
command single or many keys under given namespace can be removed
from SDL DB. Command syntax is:
  sdlcli remove <namespace> <key> [<key2>... <keyN>] [flags]
For the time being only -h and --help flags are supported with the
'remove' -command.

Issue-Id: RIC-113

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I4b68689ae9ec388372298f0445f714a5bdb23f3b

2 years agoImplement SDL CLI 'set' -command 35/7035/6
Timo Tietavainen [Thu, 11 Nov 2021 13:51:39 +0000 (15:51 +0200)]
Implement SDL CLI 'set' -command

Implement a new set -command to 'sdlcli' -tool. With this command one
string key-value pair can be set to SDL DB under given namespace.
Command syntax is:
  sdlcli set <namespace> <key> <value> [flags]
For the time being only -h and --help flags are supported with the
set -command.

Issue-Id: RIC-113

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: Ie124b93ded03600ed8eb3b7a31b407af0f60a18e

2 years agoHarmonize SDL CLI 'healthcheck' -command 65/7065/1
Timo Tietavainen [Mon, 15 Nov 2021 14:48:30 +0000 (16:48 +0200)]
Harmonize SDL CLI 'healthcheck' -command

Harmonize 'healthcheck' -command help and error log not to have
'SDL CLI error' prefix as there is no such a prefix in 'set' and 'get'
-commands either.
Add 'healthcheck' -command line arguments count check.

Issue-Id: RIC-113

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I5e039edd9cdd3d70a9a13a1f116d7f0309618ef5

2 years agoImplement 'get' and 'get keys' -SDL CLI commands 17/7017/4
Petri Ovaska [Tue, 9 Nov 2021 06:28:48 +0000 (08:28 +0200)]
Implement 'get' and 'get keys' -SDL CLI commands

sdlcli get -command is used to display one or many resources.

 Usage:
   sdlcli get [command]

sdlcli get keys -subcommand is used to list keys in the given
namespace matching key search pattern.

 Usage:
   sdlcli get keys <namespace> [pattern|default '*'] [flags]

Issue-Id: RIC-113
Change-Id: I86b81ff8d8d2cdc0e959e285b19f93696ebe377e
Signed-off-by: Petri Ovaska <petri.ovaska@nokia.com>
2 years agoSentinel check to SDL CLI 'healthcheck' -command 06/7006/3
Timo Tietavainen [Sun, 7 Nov 2021 20:25:46 +0000 (22:25 +0200)]
Sentinel check to SDL CLI 'healthcheck' -command

In addition to the existing Redis master and slave healthiness
validation, add Redis sentinel healthiness validation to be done when
SDL CLI 'healthcheck' -command is ran. Validation is done by calling
Redis client's 'Sentinels' API call and parsing 'flags' field from its
output. In SDL CLI sentinel healthiness status is shown only if status
is not ok. This is done not to show too much information in CLI
interface for users.

Issue-Id: RIC-113

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I8960ec9813e06aa88217c29bac56707b38052ae7

2 years agoImplement SDL CLI 'healthcheck' -command 58/6958/10
Timo Tietavainen [Tue, 26 Oct 2021 06:11:53 +0000 (09:11 +0300)]
Implement SDL CLI 'healthcheck' -command

Implement a new 'healthcheck' -command for SDL CLI to validate
healthiness of the SDL database. Under the hood 'healthcheck' -command
calls Redis client's 'Master' and 'Slaves' APIs and parses from the
responses master and slave Redis servers related fields to show the
overall healthiness of the SDL database backend.

Redis client's version was upgraded from v6.15.9 to v7 v7.4.1,
because old client didn't support 'Master' and 'Slaves' Redis
sentinel APIs. Also implement usage of Redis client's
'NewSentinelClient' client connection to read state information via
'Master' and 'Slaves' APIs. In case of standalone Redis server
deployment state information is read via Redis client's 'Info' API.

Issue-Id: RIC-113

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I7d964ac5c3d10cc90075977e2b11da7a9c11949d

2 years agoDraft version of SDLCLI command line tool 87/6887/2
Timo Tietavainen [Tue, 19 Oct 2021 10:22:06 +0000 (13:22 +0300)]
Draft version of SDLCLI command line tool

Add SDLCLI source codes to build command line tool, which can be used
for troubleshooting SDL/DB. With this commit draft version of the tool
has been implemented, shows only help.

Issue-Id: RIC-113

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: Ied47ce68bcbc065c21c53fd2a326b91c32506204

2 years agoMerge "New ListKeys API in syncstorage"
Timo Tietavainen [Mon, 4 Oct 2021 10:41:41 +0000 (10:41 +0000)]
Merge "New ListKeys API in syncstorage"

2 years agoNew ListKeys API in syncstorage 65/6765/3 v0.8.0
Petri Ovaska [Wed, 22 Sep 2021 05:09:53 +0000 (08:09 +0300)]
New ListKeys API in syncstorage

The ListKeys API returns all keys in the given namespace matching
key search pattern.

Also update sdltester -tool to test ListKeys api:
  listkeys
    - List keys in the given namespace matching key search pattern.

Upgraded ci/Dockerfile golang image version tag to 1.16. This is
due to expired Root CA certificates in golang:1.12 image which
result an error when building docker image:
  fatal: unable to access 'https://gopkg.in/tomb.v1/': server
  certificate verification failed. CAfile: none CRLfile: none

Version: 0.8.0

Issue-Id: RIC-110
Signed-off-by: Petri Ovaska <petri.ovaska@nokia.com>
Change-Id: Ic02a3f127934a1e02e01a36c573d035db34dbd6f

2 years agoAdd Ovaska and Maki-aijala, remove Badorek and Tallskog 40/6740/2
Timo Tietavainen [Thu, 23 Sep 2021 08:45:15 +0000 (11:45 +0300)]
Add Ovaska and Maki-aijala, remove Badorek and Tallskog

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: Id416062bc78873f738b1b1bbf3c1e8e657610bb1

2 years agoAdd deprecation warnings for SdlInstance APIs 90/6690/3
Timo Tietavainen [Tue, 14 Sep 2021 12:10:03 +0000 (15:10 +0300)]
Add deprecation warnings for SdlInstance APIs

Add 'Deprecated:' warning texts to SdlInstance struct type and all
of its receiver API functions. SDL repository contains SyncStorage
struct type with its receiver API functions and it should be used
instead of SdlInstance. With this commit there is added deprecation
warnings and these warnings should be a heads up for SDL API users not
to use anymore  SdlInstance API. After some reasonable time has passed
SdlInstance will be removed completely from the SDL repository.

Issue-Id: RIC-805

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I69d2e9fcfc42111c2e660cc451026c6d713cff70

3 years agoImplement sentinel based DB capacity scaling 62/6062/1 dawn v0.7.0
Timo Tietavainen [Tue, 11 May 2021 13:38:33 +0000 (16:38 +0300)]
Implement sentinel based DB capacity scaling

For time being SDL has supported standalone DBAAS DB and DBAAS HA DB deployment
with Redis sentinel. With this commit extent SDL functionality to support Redis
sentinel based DB cluster where we have multiple DBAAS Redis sentinel groups
and these groups can be used to spread out SDL DB write and read operations to
different DB instances.
Implement cluster DBAAS DB service addresses reading from environment variable
'DBAAS_CLUSTER_ADDR_LIST'.
Implement crc32 hash value calculation from namespace string and selection of
a DB instance from DB cluster based on calculated hash.

Issue-ID: RIC-699

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I8999c3c03d2d80d32a57d8ec051632b975bf9dc2

3 years agoImplement SDL multi-namespace API 61/6061/2 v0.6.0
Timo Tietavainen [Tue, 11 May 2021 12:28:57 +0000 (15:28 +0300)]
Implement SDL multi-namespace API

Add 'SyncStorage' with its write and read APIs to support multi-namespace API
what has been implemented already in Python and C++ SDL APIs. In Multi-
namespace API, at SyncStorage' creation time, connection to database backend is
created but namespace is not defined. Namespace is given later as a parameter
to every SDL read and write API calls what makes it easy to write and read from
different namespaces in single SDL instance of type 'SyncStorage'.

This multi-namespace implementation is a prerequisite to have before sentinel
based DB capacity scaling feature RIC-699 can be implemented properly.

Issue-ID: RIC-699

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I018dde1f016630d6b6e44e66a2f276a04e38505a

3 years agoTake DBAAS multi-channel publishing Redis modules into use 45/5745/1 v0.5.5
Timo Tietavainen [Tue, 9 Mar 2021 14:17:31 +0000 (16:17 +0200)]
Take DBAAS multi-channel publishing Redis modules into use

Following SDL APIs are defined so that multiple channel-event pairs can be
given as function argument but actual SDL implementation utilized such a DBAAS
(Redis) module what expect to get only one channel-event pair. Fix the
implementation of these SDL APIs to use the correct DBAAS module what support
multiple channel-event pairs:
* SetIfAndPublish()
* SetIfNotExistsAndPublish()
* RemoveIfAndPublish()

Please note that in runtime environment DBAAS service needs to run on DBAAS
image version 0.4.0 or newer. Older images do not have multiple channel-event
pairs support as a Redis module.

Fixed also potential type conversion issue in SDL APIs RemoveIf() and
RemoveIfAndPublish() what can lead to SDL application crash.

Issue-ID: RIC-759

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I74f483bb31e0c6aed10983a83d70a45272d71fa4

3 years agoFix Go routine race condition in DB notification map 15/4815/3 cherry v0.5.4
Timo Tietavainen [Wed, 7 Oct 2020 04:07:24 +0000 (07:07 +0300)]
Fix Go routine race condition in DB notification map

Map cbMap was accessible by the main Go routine and also by a Go routine, which
handled incoming notifications from database (Redis). Problem was visible, when
unit tests were run with '-race' flag. Fix the issue by adding a mutex lock to
guard cbMap accesses. Go routine what handles incoming notification has a local
lockless copy of the cbMap to make sure that notification handling speed won't
be suffering from mutex locks. Local copy of cbMap is updated whenever the
cbMap has been updated.

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I066ff1d71340db2240a7ea6aeeb575f098488608

3 years agoTake Redis client version 6.15.9 into use 53/4553/2 v0.5.3
Timo Tietavainen [Mon, 17 Aug 2020 11:48:06 +0000 (14:48 +0300)]
Take Redis client version 6.15.9 into use

Take newer Redis client version 6.15.9 into use from:
https://github.com/go-redis/redis

Reasoning was to get bug fixes, especially fix for this one:
https://github.com/go-redis/redis/issues/1149

Updated also go.sum file after running 'go mod tidy' command.

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I694282e669a9ae70040e9d95ea0c19d8c94bceea

3 years agoRephrase release notes introduction 38/4138/1 bronze
Timo Tietavainen [Tue, 16 Jun 2020 17:01:18 +0000 (20:01 +0300)]
Rephrase release notes introduction

Remove release name from introduction section to make it
unaltered for release changes.

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: If5dcb2c18b8568b670bd1198c72e1753b350bb70

4 years agoAdd extra line about src files are part of RIC platform project 31/1831/1 Amber v0.5.2
Timo Tietavainen [Thu, 28 Nov 2019 07:58:48 +0000 (09:58 +0200)]
Add extra line about src files are part of RIC platform project

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: Id38667ce1a1f109db284802d50baf28f1780bc58

4 years agoMerge "Add documentation files"
Timo Tietavainen [Wed, 13 Nov 2019 10:18:10 +0000 (10:18 +0000)]
Merge "Add documentation files"

4 years agoAdd documentation files 42/1542/1
Timo Tietavainen [Wed, 13 Nov 2019 06:01:10 +0000 (08:01 +0200)]
Add documentation files

Added mandatory documentation files for the RIC Amber release.

Change-Id: Ib61949c1dc6b7302de7adb907158caf1ca905dea
Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
4 years agoAutomation adds INFO.yaml 42/1442/2
Aric Gardner [Fri, 8 Nov 2019 16:02:22 +0000 (16:02 +0000)]
Automation adds INFO.yaml

Change-Id: I9134d022dce524eac8b49afb5bc740fd7957cdae
Signed-off-by: Aric Gardner <agardner@linuxfoundation.org>
4 years agoAdd support for CI jobs 16/1316/1 v0.5.1
Marco Tallskog [Fri, 1 Nov 2019 14:23:12 +0000 (16:23 +0200)]
Add support for CI jobs

Ad ci directory containing a Dockerfile where unit tests shall be
executed.

Change-Id: Ica50888d24b7cdd4326a632a408619ed17be08c0
Signed-off-by: Marco Tallskog <marco.tallskog@nokia.com>
4 years agoMake DB instance visible 39/1139/5 v0.5.0
Marco Tallskog [Fri, 11 Oct 2019 10:24:04 +0000 (13:24 +0300)]
Make DB instance visible

Make underlying DB instance visible to clients. This change makes it
easier for the clients to e.g. share the same DB instance between
multiple SDL instances (multiple namespaces is used). The DB instance
can be created once and reuse it every time a new SDL instance is
created. The DB instance is created with Newdatabase() method.

Update the documentation so that it is mentioned that subscribing the
channels is not safe for concurrent usage.

Change-Id: I1b09500eda44b6b095a3bf564c38e794d02f9d95
Signed-off-by: Marco Tallskog <marco.tallskog@nokia.com>
4 years agoSupport redis sentinel configuration 18/1018/1 v0.4.0
Marco Tallskog [Thu, 26 Sep 2019 12:51:29 +0000 (15:51 +0300)]
Support redis sentinel configuration

Based on environment variables set, sdl will select either to connect to
standalone redis or sentinel redis. The underlying redis-go
implementation takes care of how connection to master is handled and
what happens if there is a switcover in redis.

Change-Id: Ib413b61e6a7e26e8ad2bd7f83331554271a93c69
Signed-off-by: Marco Tallskog <marco.tallskog@nokia.com>
4 years agoSet MaxRetries count 35/935/2 v0.3.1
Marco Tallskog [Wed, 11 Sep 2019 09:53:04 +0000 (12:53 +0300)]
Set MaxRetries count

When redis client is created, set the MaxRetries count to 2. This
defines the number of times the command is tried to execute. In cases
where redis server is dead but the client hasn't noticed that yet, an
EOF error is returned from the first try. With the second attempt, a
proper error is returned indicating that the connection was refused.

Change-Id: I28ffcf83666edda9b715dafe6055cef4c633f757
Signed-off-by: Marco Tallskog <marco.tallskog@nokia.com>
4 years agoAdd resource locking 06/706/1 v0.3.0
Marco Tallskog [Wed, 14 Aug 2019 11:50:23 +0000 (14:50 +0300)]
Add resource locking

Implement methods that enable applications to create locks for
a resources. Resource locks are plain keys with a random value
with an expiration time. Only the holder of a lock can release it either
by removing the lock or by letting it expire (after it will be
automatically removed). By using a random value (that only lock holder
knows), it can be ensured that others can't remove it. Resource locks
are per namespace.

Implemented methods are:
LockResource: this method will check if the lock already exists and if
not, it will create it with an expiration time. It is possible for the
client to define with options how many times the lock will be tried and
the interval how often it is tried. If retry is used, this method will
block.
ReleaseResource: remove the lock. If removing is tried after the
expiration, an error will be returned.
RefreshResource: with this method, it is possible to set a new
expiration time for the lock. If the lock has already expired, an error
will be returned.
CheckResource: application can query the remaining expiration time with
this method, regardless it is the owner of the lock or not.

Change-Id: Ic6f5274c1740c7e36ddaba564024cffcc4c5de3d
Signed-off-by: Marco Tallskog <marco.tallskog@nokia.com>
4 years agoSupport multiple event publishing 57/457/4 v0.2.1
Marco Tallskog [Wed, 3 Jul 2019 07:25:20 +0000 (10:25 +0300)]
Support multiple event publishing

Support for publishing multiple events at once.
Originally it was possible to give multiple channels and
events as parameter to SetAndPublish() and RemoveAndPublish() API
functions. However, only the first event was published as
used Redis didn't support multiple event publishing. This
commit takes new Redis commands into use enabling the
support for multiple event publishing.

Add unit tests for internal sdlgoredis package. To be able
to stub external redisgo module, the Create() function is
splitted so that in unit tests it is possible to provide
a stub interface instead of the real one when building
the redisgo instance. Also Subscribe() function is wrapped,
and wrapper function is provided during setup as calling
the Subscribe() for the first time in code execution,
a new interface is provided that needs to be able to mock
in unit tests.

Improve documentation. Add doc.go which provides a better
documentation how to use SDL.

Change-Id: Id072d9397fa92ea37bcc78df7db54edadf4d9e7c
Signed-off-by: Marco Tallskog <marco.tallskog@nokia.com>
4 years agoAdd support for SDL groups 94/194/3 v0.2.0
Marco Tallskog [Fri, 24 May 2019 13:17:02 +0000 (16:17 +0300)]
Add support for SDL groups

SDL group is an unordered collection of members where each member is
unique.

Add the following methods to do operations with groups:
-AddMember: adds number of members into a given group. It is possible to
give already existing members to be added but that doesn't have an
effect to group.
-RemoveMember: Remove number of members from a group. It is possible to
try to remove non-existing members from a group without an error.
-RemoveGroup: Remove the whole group along with its members.
-GetMembers: Get all members from a group.
-IsMember: Check if a specific member is part of the group.
-GroupSize: Return the number of members in group.

Change-Id: I9005ffe584aa0872c5a3fab170d0ac37d9b9f30a
Signed-off-by: Marco Tallskog <marco.tallskog@nokia.com>
5 years agoAllow byte array/slice be given as value 71/171/3 v0.1.1
Marco Tallskog [Fri, 17 May 2019 10:05:00 +0000 (13:05 +0300)]
Allow byte array/slice be given as value

An error was given if byte slice or array was given as a value, now they
are allowed. However, other types or slices are not allowed as value.

Change-Id: Ia0c4515498a1b0e03a002a7d4357adb6d262213a
Signed-off-by: Marco Tallskog <marco.tallskog@nokia.com>
5 years agoAdd support for notifications 49/149/5 v0.1.0
Marco Tallskog [Tue, 14 May 2019 12:09:19 +0000 (15:09 +0300)]
Add support for notifications

Add new API function to subscribe/unsubscribe  notifications
from a channel. With SubscribeChannel function it is possible to
subscribe one or many channels and attach a callback function taht will
be called when the notification (event) is received from a channel. It
is possible to have separate callback functions to different channels
but then subscription must be done separately. With UnsubscribeChannel
one can unsubscribe one or many subsribed channels.

Each function, that modifies database (sets or removes) will have
another API function that will cause an event to be sent to given
channel. E.g. the following two functions:

Set(pairs ...interface{})
SetAndPublish(channelsAndEvents []string, pairs ...interface{})

The first function just sets a value to key, whereas the second function
does the same thing and also sends an event to channel. The channels and
events are given as pairs in channelsAndEvents slice e.g.
[]string{"channel", "event"}
Although it is possible to give several channel event pairs, only
sending an event to one channel is supported at the moment due to
missing support in Redis DB.

Change-Id: I4fc96cd4c8a59410700f670ad5588fe71509fd03
Signed-off-by: Marco Tallskog <marco.tallskog@nokia.com>
5 years agoFix Close API call 05/105/1 v0.0.2
Marco Tallskog [Fri, 3 May 2019 08:45:22 +0000 (11:45 +0300)]
Fix Close API call

Calling Close function from API caused a recursive call to itself as the
underlying module was using a function with same name. Rename the
internal close function to avoid this.

Change-Id: I05c3ca8e79fb5f30cae81917f56efacbd1797768
Signed-off-by: Marco Tallskog <marco.tallskog@nokia.com>
5 years agoInitial commit 55/55/2 v0.0.1
Marco Tallskog [Wed, 17 Apr 2019 10:19:22 +0000 (13:19 +0300)]
Initial commit

Change-Id: Iaf5456d3f1b8b59a727d7df46fe556fe00ac4c0e
Signed-off-by: Marco Tallskog <marco.tallskog@nokia.com>
5 years agoInitial empty repository
Andrew Grimberg [Mon, 8 Apr 2019 19:44:49 +0000 (19:44 +0000)]
Initial empty repository