X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fusecases%2Fodusliceassurance%2Fgoversion%2Finternal%2Fsliceassurance%2Fapp.go;h=c4a4d65b7af266ea90c44eddb890d3fdb106641e;hb=5e92b2132b2300080d8a928b7d9c44906724fd78;hp=7dc84b1fc8a309601c2a36fe8c6bfa37a8a4b7cd;hpb=07a4236558e3876add50a8a080a431b5b7f366b4;p=nonrtric.git diff --git a/test/usecases/odusliceassurance/goversion/internal/sliceassurance/app.go b/test/usecases/odusliceassurance/goversion/internal/sliceassurance/app.go index 7dc84b1f..c4a4d65b 100644 --- a/test/usecases/odusliceassurance/goversion/internal/sliceassurance/app.go +++ b/test/usecases/odusliceassurance/goversion/internal/sliceassurance/app.go @@ -21,9 +21,12 @@ package sliceassurance import ( + "encoding/json" + "fmt" "net/http" "time" + "oransc.org/usecase/oduclosedloop/internal/config" "oransc.org/usecase/oduclosedloop/internal/restclient" "oransc.org/usecase/oduclosedloop/internal/structures" "oransc.org/usecase/oduclosedloop/messages" @@ -32,25 +35,29 @@ import ( ) const ( - THRESHOLD_TPUT = 700 - DEFAULT_DEDICATED_RATIO = 40 - NEW_DEDICATED_RATIO = 50 - NODE_ID = "O-DU-1211" + THRESHOLD_TPUT = 7000 + DEFAULT_DEDICATED_RATIO = 15 + NEW_DEDICATED_RATIO = 25 + NODE_ID = "O-DU-1122" ) type App struct { - client restclient.HTTPClient + client *restclient.Client metricsPolicies *structures.SliceAssuranceMeas } var dmaapMRUrl string var sDNRUrl string +var sDNRUsername string +var sDNRPassword string -func (a *App) Initialize(dmaapUrl string, sdnrUrl string) { - dmaapMRUrl = dmaapUrl - sDNRUrl = sdnrUrl +func (a *App) Initialize(config *config.Config) { + dmaapMRUrl = config.MRHost + ":" + config.MRPort + sDNRUrl = config.SDNRAddress + sDNRUsername = config.SDNRUser + sDNRPassword = config.SDNPassword - a.client = restclient.New(&http.Client{}) + a.client = restclient.New(&http.Client{}, false) a.metricsPolicies = structures.NewSliceAssuranceMeas() } @@ -67,38 +74,63 @@ func (a *App) Run(topic string, pollTime int) { } } -func (a *App) getMessagesFromDmaap(url string) { - var stdMessage messages.StdDefinedMessage +func (a *App) getMessagesFromDmaap(path string) { + log.Infof("Polling new messages from DmaapMR %v", path) - a.client.Get(url, &stdMessage) - log.Infof("Polling new messages from DmaapMR: %v", stdMessage) - for _, meas := range stdMessage.GetMeasurements() { - //Create sliceMetric and check if metric exist and update existing one or create new one - if _, err := a.metricsPolicies.AddOrUpdateMetric(meas); err != nil { - log.Error("Metric could not be added ", err) + //Added to work with onap-Dmaap + var messageStrings []string + if error := a.client.Get(path, &messageStrings); error != nil { + log.Warn("Send of Get messages from DmaapMR failed! ", error) + } + + for _, msgString := range messageStrings { + var message messages.StdDefinedMessage + if err := json.Unmarshal([]byte(msgString), &message); err == nil { + for _, meas := range message.GetMeasurements() { + log.Infof("Create sliceMetric and check if metric exist and update existing one or create new one measurement: %+v\n", meas) + //Create sliceMetric and check if metric exist and update existing one or create new one + if _, err := a.metricsPolicies.AddOrUpdateMetric(meas); err != nil { + log.Error("Metric could not be added ", err) + } + } + } else { + log.Warn(err) } } } func (a *App) getRRMInformation(duid string) { var duRRMPolicyRatio messages.ORanDuRestConf - a.client.Get(getUrlForDistributedUnitFunctions(sDNRUrl, duid), &duRRMPolicyRatio) - policies := duRRMPolicyRatio.DistributedUnitFunction.RRMPolicyRatio - for _, policy := range policies { - a.metricsPolicies.AddNewPolicy(duid, policy) + log.Infof("Get RRM Information from SDNR url: %v", sDNRUrl) + if error := a.client.Get(getUrlForDistributedUnitFunctions(sDNRUrl, duid), &duRRMPolicyRatio, sDNRUsername, sDNRPassword); error == nil { + prettyPrint(duRRMPolicyRatio.DistributedUnitFunction) + } else { + log.Warn("Send of Get RRM Information failed! ", error) + } + + for _, odu := range duRRMPolicyRatio.DistributedUnitFunction { + for _, policy := range odu.RRMPolicyRatio { + log.Infof("Add or Update policy: %+v from DU id: %v", policy.Id, duid) + a.metricsPolicies.AddNewPolicy(duid, policy) + } } } func (a *App) updateDedicatedRatio() { - for _, metric := range a.metricsPolicies.Metrics { policy, check := a.metricsPolicies.Policies[metric.RRMPolicyRatioId] //TODO What happened if dedicated ratio is already higher that default and threshold is exceed? if check && policy.PolicyDedicatedRatio <= DEFAULT_DEDICATED_RATIO { - log.Infof("Send Post Request to update DedicatedRatio for DU id: %v Policy id: %v", metric.DUId, policy.PolicyRatioId) - url := getUrlUpdatePolicyDedicatedRatio(sDNRUrl, metric.DUId, policy.PolicyRatioId) - a.client.Post(url, policy.GetUpdateDedicatedRatioMessage(metric.SliceDiff, metric.SliceServiceType, NEW_DEDICATED_RATIO), nil) + log.Infof("Send Request to update DedicatedRatio for DU id: %v Policy id: %v", metric.DUId, policy.PolicyRatioId) + path := getUrlUpdatePolicyDedicatedRatio(sDNRUrl, metric.DUId, policy.PolicyRatioId) + updatePolicyMessage := policy.GetUpdateDedicatedRatioMessage(metric.SliceDiff, metric.SliceServiceType, NEW_DEDICATED_RATIO) + prettyPrint(updatePolicyMessage) + if error := a.client.Put(path, updatePolicyMessage, nil, sDNRUsername, sDNRPassword); error == nil { + log.Infof("Policy Dedicated Ratio for PolicyId: %v was updated to %v", policy.PolicyRatioId, NEW_DEDICATED_RATIO) + } else { + log.Warn("Send of Put Request to update DedicatedRatio failed! ", error) + } } } } @@ -110,3 +142,11 @@ func getUrlForDistributedUnitFunctions(host string, duid string) string { func getUrlUpdatePolicyDedicatedRatio(host string, duid string, policyid string) string { return host + "/rests/data/network-topology:network-topology/topology=topology-netconf/node=" + NODE_ID + "/yang-ext:mount/o-ran-sc-du-hello-world:network-function/distributed-unit-functions=" + duid + "/radio-resource-management-policy-ratio=" + policyid } + +func prettyPrint(jsonStruct interface{}) { + b, err := json.MarshalIndent(jsonStruct, "", " ") + if err != nil { + fmt.Println("error:", err) + } + fmt.Print(string(b)) +}