From eac4451ac1e5434b5ae4ee4fd41208a3b2edcf79 Mon Sep 17 00:00:00 2001 From: Mohamed Abukar Date: Tue, 31 Mar 2020 09:46:04 +0300 Subject: [PATCH] Non-blocking RMR init ... Change-Id: Ibe051b2601e0947e93742b20aaa4ebeffc7aaadb Signed-off-by: Mohamed Abukar --- adapter/build_adapter_ubuntu.sh | 6 +++--- adapter/cmd/adapter_test.go | 1 + adapter/container-tag.yaml | 2 +- alarm/alarm.go | 31 ++++++++++++++++++++----------- alarm/alarm_test.go | 1 + alarm/types.go | 9 +++++---- alarm/utils.c | 4 ++-- go.mod | 2 +- 8 files changed, 34 insertions(+), 22 deletions(-) diff --git a/adapter/build_adapter_ubuntu.sh b/adapter/build_adapter_ubuntu.sh index d1a8a10..b6e5dcc 100755 --- a/adapter/build_adapter_ubuntu.sh +++ b/adapter/build_adapter_ubuntu.sh @@ -22,11 +22,11 @@ set -eux echo "--> build_adapter_ubuntu.sh starts" # Install RMR from deb packages at packagecloud.io -rmr=rmr_3.2.4_amd64.deb +rmr=rmr_3.6.3_amd64.deb wget --content-disposition https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/$rmr/download.deb sudo dpkg -i $rmr rm $rmr -rmrdev=rmr-dev_3.2.4_amd64.deb +rmrdev=rmr-dev_3.6.3_amd64.deb wget --content-disposition https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/$rmrdev/download.deb sudo dpkg -i $rmrdev rm $rmrdev @@ -63,4 +63,4 @@ cd ../alarm && RMR_SEED_RT=../config/uta_rtg_lib.rt go test . -v -coverprofile c # And for the Alarm Adapter cd ../adapter && go test -v -p 1 -coverprofile cover.out ./cmd/ -c -o ./adapter_test && ./adapter_test -echo "--> build_adapter_ubuntu.sh ends" \ No newline at end of file +echo "--> build_adapter_ubuntu.sh ends" diff --git a/adapter/cmd/adapter_test.go b/adapter/cmd/adapter_test.go index dbb53e7..0dbc387 100755 --- a/adapter/cmd/adapter_test.go +++ b/adapter/cmd/adapter_test.go @@ -55,6 +55,7 @@ func TestMain(M *testing.M) { } alarmer, _ = alarm.InitAlarm("my-pod", "my-app") + time.Sleep(time.Duration(5) * time.Second) eventChan = make(chan string) os.Exit(M.Run()) diff --git a/adapter/container-tag.yaml b/adapter/container-tag.yaml index 2af355a..cfdbfb8 100644 --- a/adapter/container-tag.yaml +++ b/adapter/container-tag.yaml @@ -2,4 +2,4 @@ # By default this file is in the docker build directory, # but the location can configured in the JJB template. --- -tag: 0.4.3 +tag: 0.4.4 diff --git a/alarm/alarm.go b/alarm/alarm.go index 3291621..cb18dd7 100755 --- a/alarm/alarm.go +++ b/alarm/alarm.go @@ -31,7 +31,7 @@ import ( /* #cgo CFLAGS: -I../ -#cgo LDFLAGS: -lrmr_nng -lnng +#cgo LDFLAGS: -lrmr_si #include "utils.h" */ @@ -41,17 +41,13 @@ import "C" // The MO and APP identities are given as a parameters. // The identities are used when raising/clearing alarms, unless provided by the applications. func InitAlarm(mo, id string) (*RICAlarm, error) { - if ctx := C.rmrInit(); ctx != nil { - r := &RICAlarm{ - moId: mo, - appId: id, - rmrCtx: ctx, - } - - return r, nil + r := &RICAlarm{ + moId: mo, + appId: id, } + go InitRMR(r) - return nil, errors.New("rmrInit failed!") + return r, nil } // Create a new Alarm instance @@ -128,8 +124,11 @@ func (r *RICAlarm) AlarmString(a AlarmMessage) string { } func (r *RICAlarm) sendAlarmUpdateReq(a AlarmMessage) error { - log.Println("Sending alarm: ", r.AlarmString(a)) + if r.rmrCtx == nil || !r.rmrReady { + return errors.New("RMR no ready yet!") + } + log.Println("Sending alarm: ", r.AlarmString(a)) payload, err := json.Marshal(a) if err != nil { return err @@ -157,3 +156,13 @@ func (r *RICAlarm) ReceiveMessage(cb func(AlarmMessage)) error { } return errors.New("rmrRcv failed!") } + +func InitRMR(r *RICAlarm) error { + if ctx := C.rmrInit(); ctx != nil { + r.rmrCtx = ctx + r.rmrReady = true + return nil + } + + return errors.New("rmrInit failed!") +} diff --git a/alarm/alarm_test.go b/alarm/alarm_test.go index ab5953c..1f7a071 100755 --- a/alarm/alarm_test.go +++ b/alarm/alarm_test.go @@ -37,6 +37,7 @@ func TestAlarmInitSuccess(t *testing.T) { assert.Equal(t, false, a == nil) alarmer = a + time.Sleep(time.Duration(5 * time.Second)) } func TestAlarmRaiseSuccess(t *testing.T) { diff --git a/alarm/types.go b/alarm/types.go index 54a681b..ffe5d39 100755 --- a/alarm/types.go +++ b/alarm/types.go @@ -69,10 +69,11 @@ type AlarmMessage struct { // RICAlarm is an alarm instance type RICAlarm struct { - moId string - appId string - rmrCtx unsafe.Pointer - mutex sync.Mutex + moId string + appId string + rmrCtx unsafe.Pointer + rmrReady bool + mutex sync.Mutex } const ( diff --git a/alarm/utils.c b/alarm/utils.c index 7f29260..0869282 100755 --- a/alarm/utils.c +++ b/alarm/utils.c @@ -30,8 +30,8 @@ void * rmrInit(void) { // Must have a route table before we can send, so wait til RMR is ready while(!rmr_ready(mrc)) { - fprintf(stderr, "Waiting for RMR to be ready ...\n"); - sleep(1); + //fprintf(stderr, "Waiting for RMR to be ready ...\n"); + sleep(2); } fprintf(stderr, "RMR is ready now ...\n"); diff --git a/go.mod b/go.mod index 811a353..cc1fa1d 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.13 replace gerrit.o-ran-sc.org/r/ric-plt/alarm-go/alarm => ./alarm/ -replace gerrit.o-ran-sc.org/r/ric-plt/xapp-frame => gerrit.o-ran-sc.org/r/ric-plt/xapp-frame.git v0.0.30 +replace gerrit.o-ran-sc.org/r/ric-plt/xapp-frame => gerrit.o-ran-sc.org/r/ric-plt/xapp-frame.git v0.4.0 replace gerrit.o-ran-sc.org/r/ric-plt/sdlgo => gerrit.o-ran-sc.org/r/ric-plt/sdlgo.git v0.5.2 -- 2.16.6