X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fusecases%2Foruclosedlooprecovery%2Fgoversion%2Finternal%2Flinkfailure%2Flinkfailurehandler.go;h=26b3ab32d3a410d564935e8736a139e8cdef7ecf;hb=36acb0c596211d3d771deb421eb71a05b3489e84;hp=ebcf31253fc7a5100a360a75bd6c6f1c2c84ca85;hpb=856d55d6413fe66c05b42a3c5e98d0b0f20743e3;p=nonrtric.git diff --git a/test/usecases/oruclosedlooprecovery/goversion/internal/linkfailure/linkfailurehandler.go b/test/usecases/oruclosedlooprecovery/goversion/internal/linkfailure/linkfailurehandler.go index ebcf3125..26b3ab32 100644 --- a/test/usecases/oruclosedlooprecovery/goversion/internal/linkfailure/linkfailurehandler.go +++ b/test/usecases/oruclosedlooprecovery/goversion/internal/linkfailure/linkfailurehandler.go @@ -21,8 +21,6 @@ package linkfailure import ( - "encoding/json" - "io/ioutil" "net/http" "strings" @@ -34,32 +32,31 @@ import ( ) type Configuration struct { - ConsumerAddress string - InfoCoordAddress string - SDNRAddress string - SDNRUser string - SDNRPassword string + SDNRAddress string + SDNRUser string + SDNRPassword string } -const rawSdnrPath = "/rests/data/network-topology:network-topology/topology=topology-netconf/node=[O-DU-ID]/yang-ext:mount/o-ran-sc-du-hello-world:network-function/du-to-ru-connection=[O-RU-ID]" - -const unlockMessage = `{"o-ran-sc-du-hello-world:du-to-ru-connection": [{"name":"[O-RU-ID]","administrative-state":"UNLOCKED"}]}` +const rawSdnrPath = "/rests/data/network-topology:network-topology/topology=topology-netconf/node=[O-DU-ID]/yang-ext:mount/o-ran-sc-du-hello-world:network-function/distributed-unit-functions=[O-DU-ID]/radio-resource-management-policy-ratio=rrm-pol-1" +const unlockMessage = `{"o-ran-sc-du-hello-world:radio-resource-management-policy-ratio":[{"id":"rrm-pol-1","radio-resource-management-policy-max-ratio":25,"radio-resource-management-policy-members":[{"mobile-country-code":"310","mobile-network-code":"150","slice-differentiator":1,"slice-service-type":1}],"radio-resource-management-policy-min-ratio":15,"user-label":"rrm-pol-1","resource-type":"prb","radio-resource-management-policy-dedicated-ratio":20,"administrative-state":"unlocked"}]}` type LinkFailureHandler struct { lookupService repository.LookupService config Configuration + client restclient.HTTPClient } -func NewLinkFailureHandler(ls repository.LookupService, conf Configuration) *LinkFailureHandler { +func NewLinkFailureHandler(ls repository.LookupService, conf Configuration, client restclient.HTTPClient) *LinkFailureHandler { return &LinkFailureHandler{ lookupService: ls, config: conf, + client: client, } } func (lfh LinkFailureHandler) MessagesHandler(w http.ResponseWriter, r *http.Request) { log.Debug("Handling messages") - if messages := lfh.getVesMessages(r); messages != nil { + if messages := ves.GetVesMessages(r.Body); messages != nil { faultMessages := ves.GetFaultMessages(messages) for _, message := range faultMessages { @@ -74,40 +71,19 @@ func (lfh LinkFailureHandler) MessagesHandler(w http.ResponseWriter, r *http.Req func (lfh LinkFailureHandler) sendUnlockMessage(oRuId string) { if oDuId, err := lfh.lookupService.GetODuID(oRuId); err == nil { - sdnrPath := getSdnrPath(oRuId, oDuId) - unlockMessage := lfh.getUnlockMessage(oRuId) - if error := restclient.Put(lfh.config.SDNRAddress+sdnrPath, unlockMessage, lfh.config.SDNRUser, lfh.config.SDNRPassword); error == nil { + sdnrPath := getSdnrPath(oDuId) + if error := restclient.Put(lfh.config.SDNRAddress+sdnrPath, unlockMessage, lfh.client, lfh.config.SDNRUser, lfh.config.SDNRPassword); error == nil { log.Debugf("Sent unlock message for O-RU: %v to O-DU: %v.", oRuId, oDuId) } else { - log.Warn(error) + log.Warn("Send of unlock message failed due to ", error) } } else { - log.Warn(err) + log.Warn("Send of unlock message failed due to ", err) } } -func getSdnrPath(oRuId string, oDuId string) string { - sdnrPath := strings.Replace(rawSdnrPath, "[O-DU-ID]", oDuId, 1) - sdnrPath = strings.Replace(sdnrPath, "[O-RU-ID]", oRuId, 1) +func getSdnrPath(oDuId string) string { + sdnrPath := strings.Replace(rawSdnrPath, "[O-DU-ID]", oDuId, -1) return sdnrPath } - -func (lfh LinkFailureHandler) getUnlockMessage(oRuId string) string { - return strings.Replace(unlockMessage, "[O-RU-ID]", oRuId, 1) -} - -func (lfh LinkFailureHandler) getVesMessages(r *http.Request) *[]string { - var messages []string - body, err := ioutil.ReadAll(r.Body) - if err != nil { - log.Warn(err) - return nil - } - err = json.Unmarshal(body, &messages) - if err != nil { - log.Warn(err) - return nil - } - return &messages -}