Add Dockerfile to support unit testing alarm-go 69/3969/6
authorLott, Christopher (cl778h) <cl778h@att.com>
Wed, 3 Jun 2020 12:52:14 +0000 (08:52 -0400)
committerLott, Christopher (cl778h) <cl778h@att.com>
Fri, 5 Jun 2020 15:05:48 +0000 (11:05 -0400)
This dockerfile installs the prerequisites to compile the alarm-go
library and run the golang unit tests.
Add logging statements to dump AlarmMessage as struct and as marshalled
to JSON.
Add JSON schema that can be used to validate payloads.

Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
Change-Id: Ib46c524e2e0593124f79be64afa23847612897c8

adapter/build_adapter_ubuntu.sh
adapter/cmd/adapter.go
alarm-schema.json [new file with mode: 0644]
alarm/Dockerfile-Unit-Test [new file with mode: 0644]
alarm/alarm.go

index 390e208..5edd93d 100755 (executable)
@@ -61,6 +61,6 @@ go build -a -installsuffix cgo -ldflags "-X main.Version=$tag -X main.Hash=$hash
 #cd ../alarm && go test . -v -coverprofile cover.out
 
 # And for the Alarm Adapter
-#cd ../adapter && go test -v -p 1 -coverprofile cover.out ./cmd/ -c -o ./adapter_test && ./adapter_test
+cd ../adapter && go test -v -p 1 -coverprofile cover.out ./cmd/ -c -o ./adapter_test && ./adapter_test
 
 echo "--> build_adapter_ubuntu.sh ends"
index 7fa1f3b..0b2ddce 100755 (executable)
@@ -126,6 +126,7 @@ func (a *AlarmAdapter) Consume(rp *app.RMRParams) (err error) {
 
 func (a *AlarmAdapter) HandleAlarms(rp *app.RMRParams) (*alert.PostAlertsOK, error) {
        var m alarm.AlarmMessage
+       app.Logger.Info("Received JSON: %s", rp.Payload)
        if err := json.Unmarshal(rp.Payload, &m); err != nil {
                app.Logger.Error("json.Unmarshal failed: %v", err)
                return nil, err
diff --git a/alarm-schema.json b/alarm-schema.json
new file mode 100644 (file)
index 0000000..5e999ad
--- /dev/null
@@ -0,0 +1,94 @@
+{
+  "$schema": "http://json-schema.org/draft-07/schema",
+  "$id": "https://gerrit.o-ran-sc.org/r/admin/repos/ric-plt/alarm-go.json",
+  "type": "object",
+  "title": "Alarm schema",
+  "description": "Schema for RIC alarm messages.",
+  "default": {},
+  "examples": [
+    {
+      "managedObjectId": "my-pod-lib",
+      "applicationId": "my-app",
+      "specificProblem": 1234,
+      "perceivedSeverity": "MAJOR",
+      "additionalInfo": "Some App data",
+      "identifyingInfo": "eth 0 1",
+      "AlarmAction": "RAISE",
+      "AlarmTime": 1591188407505707
+    }
+  ],
+  "required": [
+    "managedObjectId",
+    "applicationId",
+    "specificProblem",
+    "perceivedSeverity",
+    "identifyingInfo",
+    "AlarmAction",
+    "AlarmTime"
+  ],
+  "additionalProperties": true,
+  "properties": {
+    "managedObjectId": {
+      "type": "string",
+      "title": "The managedObjectId schema",
+      "description": "The name of the managed object that is the cause of the fault.",
+      "default": ""
+    },
+    "applicationId": {
+      "type": "string",
+      "title": "The applicationId schema",
+      "description": "The name of the process that raised the alarm.",
+      "default": ""
+    },
+    "specificProblem": {
+      "type": "integer",
+      "title": "The specificProblem schema",
+      "description": "The problem that is the cause of the alarm.",
+      "default": 0
+    },
+    "perceivedSeverity": {
+      "type": "string",
+      "enum": [
+        "UNSPECIFIED",
+        "CRITICAL",
+        "MAJOR",
+        "MINOR",
+        "WARNING",
+        "CLEARED",
+        "DEFAULT"
+      ],
+      "title": "The perceivedSeverity schema",
+      "description": "The severity of the alarm.",
+      "default": ""
+    },
+    "additionalInfo": {
+      "type": "string",
+      "title": "The additionalInfo schema",
+      "description": "Additional information given by the application (optional).",
+      "default": ""
+    },
+    "identifyingInfo": {
+      "type": "string",
+      "title": "The identifyingInfo schema",
+      "description": "Identifying additional information, which is part of alarm identity.",
+      "default": ""
+    },
+    "AlarmAction": {
+      "type": "string",
+      "enum": [
+        "RAISE",
+        "CLEAR",
+        "CLEARALL"
+      ],
+      "title": "The AlarmAction schema",
+      "description": "Action to perform on the alarm.",
+      "default": ""
+    },
+    "AlarmTime": {
+      "type": "integer",
+      "title": "The AlarmTime schema",
+      "description": "Current system time in milliseconds since the Epoch.",
+      "default": 0
+    }
+  }
+}
diff --git a/alarm/Dockerfile-Unit-Test b/alarm/Dockerfile-Unit-Test
new file mode 100644 (file)
index 0000000..a530771
--- /dev/null
@@ -0,0 +1,35 @@
+# Copyright (c) 2020 AT&T Intellectual Property.
+# Copyright (c) 2020 Nokia.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# This source code is part of the near-RT RIC (RAN Intelligent Controller)
+# platform project (RICP).
+#
+# Test the alarm library by issuing this command from the alarm/ subdirectory:
+#    docker build -f Dockerfile-Unit-Test .
+
+FROM golang:1.12
+
+# install rmr headers and libraries
+ARG RMRVERSION=4.0.5
+RUN wget -nv --content-disposition https://packagecloud.io/o-ran-sc/release/packages/debian/stretch/rmr_${RMRVERSION}_amd64.deb/download.deb \
+    && dpkg -i rmr_${RMRVERSION}_amd64.deb \
+    && rm -rf rmr_${RMRVERSION}_amd64.deb
+RUN wget -nv --content-disposition https://packagecloud.io/o-ran-sc/release/packages/debian/stretch/rmr-dev_${RMRVERSION}_amd64.deb/download.deb \
+    && dpkg -i rmr-dev_${RMRVERSION}_amd64.deb \
+    && rm -rf rmr-dev_${RMRVERSION}_amd64.deb
+RUN ldconfig
+RUN mkdir -p /tmp/alarm
+COPY . /tmp/alarm
+RUN cd /tmp/alarm && go test . -v
index dddccb1..38e2134 100644 (file)
@@ -130,12 +130,14 @@ func (r *RICAlarm) sendAlarmUpdateReq(a AlarmMessage) error {
                return errors.New("RMR no ready yet!")
        }
 
+    log.Printf("Alarm message: %+v\n", a)
        log.Println("Sending alarm: ", r.AlarmString(a))
        payload, err := json.Marshal(a)
        if err != nil {
                return err
        }
 
+       log.Println("JSON payload: ", fmt.Sprintf("%s", payload))
        datap := C.CBytes(payload)
        defer C.free(datap)
        meid := C.CString("ric")