Merge "Remove rApp Catalogue"
[nonrtric.git] / test / usecases / odusliceassurance / goversion / internal / structures / sliceassurance.go
index c243d18..d7c2556 100644 (file)
@@ -25,6 +25,7 @@ import (
        "regexp"
        "strconv"
 
+       log "github.com/sirupsen/logrus"
        "oransc.org/usecase/oduclosedloop/messages"
 )
 
@@ -51,8 +52,13 @@ func (sa *SliceAssuranceMeas) AddNewPolicy(duid string, rrmPolicyRatio messages.
                metric := sa.GetSliceMetric(duid, policyMember.SliceDifferentiator, policyMember.SliceServiceType)
                if metric != nil {
                        pr := NewPolicyRatio(rrmPolicyRatio.Id, rrmPolicyRatio.RRMPolicyMaxRatio, rrmPolicyRatio.RRMPolicyMinRatio, rrmPolicyRatio.RRMPolicyDedicatedRatio)
+                       _, check := sa.Policies[pr.PolicyRatioId]
+                       if !check {
+                               log.Infof(" new policy has been added %+v", *pr)
+                       }
                        sa.Policies[pr.PolicyRatioId] = pr
                        metric.RRMPolicyRatioId = rrmPolicyRatio.Id
+
                }
        }
 }
@@ -73,19 +79,19 @@ func (sa *SliceAssuranceMeas) AddOrUpdateMetric(meas messages.Measurement) (stri
        var duid string
        var sd, sst int
 
-       regex := *regexp.MustCompile(`\/network-function\/distributed-unit-functions\[id=\'(.*)\'\]/cell\[id=\'(.*)\'\]/supported-measurements\/performance-measurement-type\[\.=\'(.*)\'\]\/supported-snssai-subcounter-instances\/slice-differentiator\[\.=(\d)\]\[slice-service-type=(\d+)\]`)
+       regex := *regexp.MustCompile(`\/(.*)network-function\/distributed-unit-functions\[id=\'(.*)\'\]\/cell\[id=\'(.*)\'\]\/supported-measurements\[performance-measurement-type=\'(.*)\'\]\/supported-snssai-subcounter-instances\[slice-differentiator=\'(\d+)\'\]\[slice-service-type=\'(\d+)\'\]`)
        res := regex.FindAllStringSubmatch(meas.MeasurementTypeInstanceReference, -1)
 
-       if res != nil && len(res[0]) == 6 {
-               duid = res[0][1]
-               sd = toInt(res[0][4])
-               sst = toInt(res[0][5])
+       if res != nil && len(res[0]) == 7 {
+               duid = res[0][2]
+               sd = toInt(res[0][5])
+               sst = toInt(res[0][6])
 
                key := MapKey{duid, sd, sst}
                value, check := sa.Metrics[key]
 
                if check {
-                       sa.updateMetric(key, value, res[0][3], meas.Value)
+                       sa.updateMetric(key, value, res[0][4], meas.Value)
                } else {
                        // Only add new one if value exceeds threshold
                        sa.addMetric(res, meas.Value)
@@ -98,18 +104,21 @@ func (sa *SliceAssuranceMeas) AddOrUpdateMetric(meas messages.Measurement) (stri
 
 func (sa *SliceAssuranceMeas) addMetric(res [][]string, metricValue int) {
        if metricValue > 700 {
-               metric := NewSliceMetric(res[0][1], res[0][2], toInt(res[0][4]), toInt(res[0][5]))
+               metric := NewSliceMetric(res[0][2], res[0][3], toInt(res[0][5]), toInt(res[0][6]))
                metric.PM[res[0][3]] = metricValue
-               key := MapKey{res[0][1], toInt(res[0][4]), toInt(res[0][5])}
+               key := MapKey{res[0][2], toInt(res[0][5]), toInt(res[0][6])}
                sa.Metrics[key] = metric
+               log.Infof(" new metric has been added %+v", *metric)
        }
 }
 
 func (sa *SliceAssuranceMeas) updateMetric(key MapKey, value *SliceMetric, metricName string, metricValue int) {
        if metricValue < 700 {
                delete(sa.Metrics, key)
+               log.Infof(" metric with key %+v has been deleted", key)
        } else {
                value.PM[metricName] = metricValue
+               log.Infof(" metric value has been updated, new value: %v", metricValue)
        }
 }