Add REST interface for testing purpose
Change-Id: I32416cd314b70258b5b5c21bed8d127701696938
Signed-off-by: Mohamed Abukar <abukar.mohamed@nokia.com>
diff --git a/adapter/cmd/adapter.go b/adapter/cmd/adapter.go
index 3f24dce..bd491a5 100755
--- a/adapter/cmd/adapter.go
+++ b/adapter/cmd/adapter.go
@@ -65,17 +65,21 @@
// Main function
func main() {
- NewAlarmAdapter(0).Run(true)
+ NewAlarmAdapter("", 0).Run(true)
}
-func NewAlarmAdapter(alertInterval int) *AlarmAdapter {
+func NewAlarmAdapter(amHost string, alertInterval int) *AlarmAdapter {
if alertInterval == 0 {
alertInterval = viper.GetInt("promAlertManager.alertInterval")
}
+ if amHost == "" {
+ amHost = viper.GetString("promAlertManager.address")
+ }
+
return &AlarmAdapter{
rmrReady: false,
- amHost: viper.GetString("promAlertManager.address"),
+ amHost: amHost,
amBaseUrl: viper.GetString("promAlertManager.baseUrl"),
amSchemes: []string{viper.GetString("promAlertManager.schemes")},
alertInterval: alertInterval,
@@ -88,6 +92,9 @@
app.SetReadyCB(func(d interface{}) { a.rmrReady = true }, true)
app.Resource.InjectStatusCb(a.StatusCB)
+ app.Resource.InjectRoute("/ric/v1/alarm", a.GetActiveAlarms, "GET")
+ app.Resource.InjectRoute("/ric/v1/alarm", a.GenerateAlarm, "POST")
+
// Start background timer for re-raising alerts
go a.StartAlertTimer()
diff --git a/adapter/cmd/adapter_test.go b/adapter/cmd/adapter_test.go
index 27fe8ce..a2348b7 100755
--- a/adapter/cmd/adapter_test.go
+++ b/adapter/cmd/adapter_test.go
@@ -45,7 +45,7 @@
// Test cases
func TestMain(M *testing.M) {
- alarmAdapter = NewAlarmAdapter(500)
+ alarmAdapter = NewAlarmAdapter("localhost:9093", 500)
go alarmAdapter.Run(false)
time.Sleep(time.Duration(2) * time.Second)
diff --git a/adapter/cmd/restapi.go b/adapter/cmd/restapi.go
new file mode 100755
index 0000000..542e69d
--- /dev/null
+++ b/adapter/cmd/restapi.go
@@ -0,0 +1,48 @@
+/*
+ * 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).
+ */
+
+package main
+
+import (
+ "encoding/json"
+ "net/http"
+
+ "gerrit.o-ran-sc.org/r/ric-plt/alarm-go/alarm"
+)
+
+func (a *AlarmAdapter) GetActiveAlarms(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ response, _ := json.Marshal(a.activeAlarms)
+ w.Write(response)
+}
+
+func (a *AlarmAdapter) GenerateAlarm(w http.ResponseWriter, r *http.Request) {
+ if r.Body == nil {
+ return
+ }
+ defer r.Body.Close()
+
+ var alarmData alarm.Alarm
+ if err := json.NewDecoder(r.Body).Decode(&alarmData); err == nil {
+ a.UpdateActiveAlarms(alarmData)
+ a.PostAlert(a.GenerateAlertLabels(alarmData))
+ }
+}
diff --git a/adapter/run_adapter.sh b/adapter/run_adapter.sh
index 1aaacd2..d41596f 100755
--- a/adapter/run_adapter.sh
+++ b/adapter/run_adapter.sh
@@ -22,7 +22,7 @@
# Abstract: Starts the alarm adapter service
# Date: 10 March 2020
#
-export RMR_SEED_RT=/opt/nokia/ric/ueec/uta_rtg.rt
+export RMR_SEED_RT=./uta_rtg.rt
export RMR_SRC_ID="service-ricplt-alarmadapter-rmr.ricplt"
-exec ./alarm-adapter -f config-file.json
+exec ./alarm-adapter -f ./config-file.json
diff --git a/alarm/alarm_test.go b/alarm/alarm_test.go
index 6af23e9..d5eb740 100755
--- a/alarm/alarm_test.go
+++ b/alarm/alarm_test.go
@@ -25,7 +25,7 @@
"testing"
"time"
- "gerrit.o-ran-sc.org/r/ric-plt/alarm-go/alarm"
+ "gerrit.o-ran-sc.org/r/ric-plt/alarm-go.git/alarm"
)
var alarmer *alarm.RICAlarm
diff --git a/alarm/go.mod b/alarm/go.mod
new file mode 100644
index 0000000..e9e9b07
--- /dev/null
+++ b/alarm/go.mod
@@ -0,0 +1,17 @@
+module gerrit.o-ran-sc.org/r/ric-plt/alarm-go.git/alarm
+
+go 1.13
+
+replace gerrit.o-ran-sc.org/r/ric-plt/alarm-go.git/alarm => ../alarm
+
+replace gerrit.o-ran-sc.org/r/ric-plt/sdlgo => gerrit.o-ran-sc.org/r/ric-plt/sdlgo.git v0.5.2
+
+replace gerrit.o-ran-sc.org/r/com/golog => gerrit.o-ran-sc.org/r/com/golog.git v0.0.1
+
+require (
+ github.com/davecgh/go-spew v1.1.1 // indirect
+ github.com/kr/pretty v0.1.0 // indirect
+ github.com/stretchr/testify v1.5.1
+ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
+ gopkg.in/yaml.v2 v2.2.4 // indirect
+)
diff --git a/alarm/go.sum b/alarm/go.sum
new file mode 100644
index 0000000..fe80ebc
--- /dev/null
+++ b/alarm/go.sum
@@ -0,0 +1,21 @@
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
+github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
+github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
+github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
+github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
+github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
+gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/config/config-file.json b/config/config-file.json
index ffee9e9..5d6186a 100755
--- a/config/config-file.json
+++ b/config/config-file.json
@@ -14,7 +14,7 @@
"numWorkers": 1
},
"promAlertManager": {
- "address": "localhost:9093",
+ "address": "service-ricplt-alertmanager-http:9093",
"baseUrl": "/api/v2",
"schemes": "http",
"alertInterval": 30000
diff --git a/go.mod b/go.mod
old mode 100755
new mode 100644
index 2f19f6c..a46c5ce
--- a/go.mod
+++ b/go.mod
@@ -2,7 +2,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/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
@@ -12,6 +12,7 @@
require (
gerrit.o-ran-sc.org/r/com/golog v0.0.1
+ gerrit.o-ran-sc.org/r/ric-plt/alarm-go/alarm v0.0.0-00010101000000-000000000000
gerrit.o-ran-sc.org/r/ric-plt/xapp-frame v0.0.0-00010101000000-000000000000
github.com/go-openapi/runtime v0.19.11
github.com/go-openapi/strfmt v0.19.4