X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ricsdl-package%2Fexamples%2Fnotify.py;h=7495bfec94fb40f808820070735a155ba0008a85;hb=db7753971931247abf7fed67921074e518ec1f6d;hp=3041d80cbcf3a09f2955b4a7ad2bb41310fb5e79;hpb=6589d4db658073c411c1e9e419e7770d45ed0a66;p=ric-plt%2Fsdlpy.git diff --git a/ricsdl-package/examples/notify.py b/ricsdl-package/examples/notify.py index 3041d80..7495bfe 100755 --- a/ricsdl-package/examples/notify.py +++ b/ricsdl-package/examples/notify.py @@ -37,11 +37,19 @@ Execution of these examples requires: running Redis. * Following environment variables are needed to set to the pod/container where the application utilizing SDL is going to be run. - DBAAS_SERVICE_HOST = [redis server address] - DBAAS_SERVICE_PORT= [redis server port] - DBAAS_MASTER_NAME = [master Redis sentinel name]. Needed to set only if sentinel is in use. - DBAAS_SERVICE_SENTINEL_PORT = [Redis sentinel port number]. Needed to set only if sentinel - is in use. + DBAAS_SERVICE_HOST = [DB service address] + DBAAS_SERVICE_PORT= [DB service port] + DBAAS_MASTER_NAME = [DB name]. Needed to set only if Redis sentinel is used to provide high + availability for Redis DB solution. + DBAAS_SERVICE_SENTINEL_PORT = [Redis sentinel port number]. Needed to set only if Redis + sentinel is in use. + DBASS_CLUSTER_ADDR_LIST = [list of DB service addresses]. Is set only if more than one + Redis sentinel groups are in use. + In official RIC deployments four first environment variables are defined in Helm configMaps + of the DBaaS and these configurations can be loaded automatically as environment variables + into application pods via `envFrom dbaas-appconfig` statement in an application Helm Charts. + The last environment variable is not for time being in use in official RIC deployments, only + in Nokia SEP deployments. """ import threading @@ -49,13 +57,14 @@ import time from ricsdl.syncstorage import SyncStorage from ricsdl.exceptions import RejectedByBackend, NotConnected, BackendError +from typing import (Union, List) # There are two available methods for applications to handle notifications: # - EVENT_LISTENER (true): # - User calls sdl.start_event_listener() which will create an SDL managed # event loop for handling messages. # - EVENT_LISTENER (false): -# - User need to call sdl.handle_messages() which will return the message +# - User need to call sdl.handle_events() which will return the message # # Note: In both cases, the given callback function will be executed. EVENT_LISTENER = True @@ -106,8 +115,9 @@ last_cb_message = "" stop_thread = False -def cb(channel: str, message: str): - """An example of function that will be called when an event is received. +def cb(channel: str, message: Union[str, List[str]]): + """An example of function that will be called when a single event or list of + events are received. This function sets last_cb_channel and last_cb_message as channel and message respectively. This also unlocks the global lock variable. @@ -152,6 +162,13 @@ _try_func_callback_return( lambda: mysdl.set_and_publish(MY_NS, {MY_CHANNEL: "SET PUBLISH"}, {'my_key': b'my_value'})) assert last_cb_channel == MY_CHANNEL and last_cb_message == "SET PUBLISH" +# Sets a value 'my_value' for a key 'my_key' under given namespace. Note that value +# type must be bytes and multiple key values can be set in one set function call. +# Function publishes two events into one channel. +_try_func_callback_return( + lambda: mysdl.set_and_publish(MY_NS, {MY_CHANNEL: ["SET PUBLISH1", "SET PUBLISH2"]}, {'my_key': b'my_value'})) +assert last_cb_channel == MY_CHANNEL and last_cb_message == ["SET PUBLISH1", "SET PUBLISH2"] + # Sets a value 'my_value2' for a key 'my_key' under given namespace only if the old value is # 'my_value'. was_set = _try_func_callback_return(lambda: mysdl.set_if_and_publish(