RMR handler for A1-EI Query all 96/9896/6
authornaman.gupta <naman.gupta@samsung.com>
Thu, 1 Dec 2022 13:19:35 +0000 (18:49 +0530)
committernaman.gupta <naman.gupta@samsung.com>
Tue, 6 Dec 2022 08:47:03 +0000 (14:17 +0530)
RMR handler for A1-EI Query all (messagetype 20013)

Signed-off-by: naman.gupta <naman.gupta@samsung.com>
Change-Id: I2732c3fd8c2e66e01cd37658cb06fa9ea697c09d

a1-go/go.mod
a1-go/pkg/resthooks/resthooks.go
a1-go/pkg/resthooks/resthooks_test.go
a1-go/pkg/rmr/rmr.go

index 26b642f..f92abaf 100644 (file)
@@ -31,6 +31,7 @@ replace gerrit.o-ran-sc.org/r/ric-plt/xapp-frame => gerrit.o-ran-sc.org/r/ric-pl
 require (
        gerrit.o-ran-sc.org/r/com/golog v0.0.2
        gerrit.o-ran-sc.org/r/ric-plt/sdlgo v0.7.0
+       gerrit.o-ran-sc.org/r/ric-plt/xapp-frame v0.0.0-00010101000000-000000000000
        github.com/go-openapi/errors v0.19.9
        github.com/go-openapi/loads v0.19.7
        github.com/go-openapi/runtime v0.19.29
@@ -43,5 +44,5 @@ require (
        github.com/xeipuuv/gojsonschema v1.2.0
        golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
        k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
-       gerrit.o-ran-sc.org/r/ric-plt/xapp-frame v0.0.0-00010101000000-000000000000
+
 )
index 508bc49..cb87040 100644 (file)
@@ -394,7 +394,7 @@ func (rh *Resthook) CreatePolicyInstance(policyTypeId models.PolicyTypeID, polic
                }
 
                message := rmr.Message{}
-               rmrMessage, err = message.PolicyMessage(strconv.FormatInt((int64(policyTypeId)), 10), string(policyInstanceID), httpBodyString, operation)
+               rmrMessage, err := message.PolicyMessage(strconv.FormatInt((int64(policyTypeId)), 10), string(policyInstanceID), httpBodyString, operation)
                if err != nil {
                        a1.Logger.Error("error : %v", err)
                        return err
@@ -683,10 +683,10 @@ func (rh *Resthook) DeletePolicyInstance(policyTypeId models.PolicyTypeID, polic
        rh.storeDeletedPolicyInstanceMetadata(policyTypeId, policyInstanceID, creation_timestamp.(string))
 
        message := rmr.Message{}
-       rmrMessage, err = message.PolicyMessage(strconv.FormatInt((int64(policyTypeId)), 10), string(policyInstanceID), "", "DELETE")
-       if err != nil {
-               a1.Logger.Error("error : %v", err)
-               return err
+       rmrMessage, err1 := message.PolicyMessage(strconv.FormatInt((int64(policyTypeId)), 10), string(policyInstanceID), "", "DELETE")
+       if err1 != nil {
+               a1.Logger.Error("error : %v", err1)
+               return err1
        }
        isSent := rh.iRmrSenderInst.RmrSendToXapp(rmrMessage, a1PolicyRequest)
        if isSent {
index 6d7679e..8003df7 100644 (file)
@@ -51,9 +51,9 @@ func TestMain(m *testing.M) {
                "a1.policy_type.20000",
                "a1.policy_inst_metadata.1006001.qos",
        }, nil)
-       RMRclient = new(RMRClientMock)
+       rmrSenderInst = new(RmrSenderMock)
        a1.Init()
-       rh = createResthook(sdlInst, RMRclient)
+       rh = createResthook(sdlInst, rmrSenderInst)
        code := m.Run()
        os.Exit(code)
 }
index 993e90c..2bb2f1b 100644 (file)
@@ -23,6 +23,8 @@ package rmr
 
 import (
        "encoding/json"
+       "io/ioutil"
+       "net/http"
        "strconv"
 
        "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
@@ -32,7 +34,11 @@ import (
 )
 
 const (
-       a1SourceName = "service-ricplt-a1mediator-http"
+       a1SourceName     = "service-ricplt-a1mediator-http"
+       a1PolicyRequest  = 20010
+       ecsServiceHost   = "http://ecs-service:8083"
+       ecsEiTypePath    = ecsServiceHost + "/A1-EI/v1/eitypes"
+       a1EiQueryAllResp = 20014
 )
 
 type RmrSender struct {
@@ -68,6 +74,26 @@ func NewRMRSender(policyManager *policy.PolicyManager) IRmrSender {
        return rmrsender
 }
 
+var RICMessageTypes = map[string]int{
+       "A1_POLICY_REQ":         20010,
+       "A1_POLICY_RESP":        20011,
+       "A1_POLICY_QUERY":       20012,
+       "A1_EI_QUERY_ALL":       20013,
+       "AI_EI_QUERY_ALL_RESP":  20014,
+       "A1_EI_CREATE_JOB":      20015,
+       "A1_EI_CREATE_JOB_RESP": 20016,
+       "A1_EI_DATA_DELIVERY":   20017,
+}
+
+func (rmr *RmrSender) GetRicMessageName(id int) (s string) {
+       for k, v := range RICMessageTypes {
+               if id == v {
+                       return k
+               }
+       }
+       return
+}
+
 func (rmr *RmrSender) RmrSendToXapp(httpBodyString string, messagetype int) bool {
 
        params := &xapp.RMRParams{}
@@ -87,7 +113,7 @@ func (rmr *RmrSender) RmrSendToXapp(httpBodyString string, messagetype int) bool
 
 func (rmr *RmrSender) Consume(msg *xapp.RMRParams) (err error) {
        a1.Logger.Debug("In the Consume function")
-       id := xapp.Rmr.GetRicMessageName(msg.Mtype)
+       id := rmr.GetRicMessageName(msg.Mtype)
        a1.Logger.Debug("Message received: name=%s meid=%s subId=%d txid=%s len=%d", id, msg.Meid.RanName, msg.SubId, msg.Xid, msg.PayloadLen)
 
        switch id {
@@ -140,6 +166,34 @@ func (rmr *RmrSender) Consume(msg *xapp.RMRParams) (err error) {
                                a1.Logger.Error("rmrSendToXapp : message not sent")
                        }
                }
+
+       case "A1_EI_QUERY_ALL":
+               a1.Logger.Debug("message recieved ", msg.Payload)
+               resp, err := http.Get(ecsEiTypePath)
+               if err != nil {
+                       a1.Logger.Error("Received error while fetching health info: %v", err)
+               }
+               if resp.StatusCode != http.StatusOK {
+                       a1.Logger.Warning("Received no reponse from A1-EI service1")
+               }
+               a1.Logger.Debug("response from A1-EI service : ", resp)
+
+               defer resp.Body.Close()
+               respByte, err := ioutil.ReadAll(resp.Body)
+
+               if err != nil {
+                       a1.Logger.Debug("error in response: %+v", respByte)
+               }
+
+               a1.Logger.Debug("response : %+v", string(respByte))
+
+               isSent := rmr.RmrSendToXapp(string(respByte), a1EiQueryAllResp)
+               if isSent {
+                       a1.Logger.Debug("rmrSendToXapp : message sent")
+               } else {
+                       a1.Logger.Error("rmrSendToXapp : message not sent")
+               }
+
        default:
                xapp.Logger.Error("Unknown message type '%d', discarding", msg.Mtype)
        }