Policy status notification handling - initial rollup 24/11324/2
authorpwpmurthy <pmurthy@parallelwireless.com>
Mon, 12 Jun 2023 17:17:07 +0000 (17:17 +0000)
committerpwpmurthy <pmurthy@parallelwireless.com>
Mon, 12 Jun 2023 17:19:30 +0000 (17:19 +0000)
Issue-ID: RIC-973
Change-Id: I313ec9fdeb0850c9b00cb124f74aa0428456f85e
Signed-off-by: pwpmurthy <pmurthy@parallelwireless.com>
44 files changed:
api/swagger.yaml
pkg/models/policy_instance_id.go
pkg/models/policy_type_id.go
pkg/models/policy_type_schema.go
pkg/notification/notification.go [new file with mode: 0755]
pkg/policy/policyManager.go
pkg/policy/policyManager_test.go
pkg/restapi/embedded_spec.go
pkg/restapi/operations/a1_api.go
pkg/restapi/operations/a1_e_i_data_delivery/a1_controller_data_delivery.go
pkg/restapi/operations/a1_e_i_data_delivery/a1_controller_data_delivery_parameters.go
pkg/restapi/operations/a1_mediator/a1_controller_create_or_replace_policy_instance.go
pkg/restapi/operations/a1_mediator/a1_controller_create_or_replace_policy_instance_parameters.go
pkg/restapi/operations/a1_mediator/a1_controller_create_or_replace_policy_instance_urlbuilder.go
pkg/restapi/operations/a1_mediator/a1_controller_create_policy_type.go
pkg/restapi/operations/a1_mediator/a1_controller_create_policy_type_parameters.go
pkg/restapi/operations/a1_mediator/a1_controller_delete_policy_instance.go
pkg/restapi/operations/a1_mediator/a1_controller_delete_policy_instance_parameters.go
pkg/restapi/operations/a1_mediator/a1_controller_delete_policy_instance_urlbuilder.go
pkg/restapi/operations/a1_mediator/a1_controller_delete_policy_type.go
pkg/restapi/operations/a1_mediator/a1_controller_delete_policy_type_parameters.go
pkg/restapi/operations/a1_mediator/a1_controller_get_all_instances_for_type.go
pkg/restapi/operations/a1_mediator/a1_controller_get_all_instances_for_type_parameters.go
pkg/restapi/operations/a1_mediator/a1_controller_get_all_instances_for_type_responses.go
pkg/restapi/operations/a1_mediator/a1_controller_get_all_policy_types.go
pkg/restapi/operations/a1_mediator/a1_controller_get_all_policy_types_parameters.go
pkg/restapi/operations/a1_mediator/a1_controller_get_all_policy_types_responses.go
pkg/restapi/operations/a1_mediator/a1_controller_get_healthcheck.go
pkg/restapi/operations/a1_mediator/a1_controller_get_healthcheck_parameters.go
pkg/restapi/operations/a1_mediator/a1_controller_get_healthcheck_responses.go
pkg/restapi/operations/a1_mediator/a1_controller_get_policy_instance.go
pkg/restapi/operations/a1_mediator/a1_controller_get_policy_instance_parameters.go
pkg/restapi/operations/a1_mediator/a1_controller_get_policy_instance_status.go
pkg/restapi/operations/a1_mediator/a1_controller_get_policy_instance_status_parameters.go
pkg/restapi/operations/a1_mediator/a1_controller_get_policy_instance_urlbuilder.go
pkg/restapi/operations/a1_mediator/a1_controller_get_policy_type.go
pkg/restapi/operations/a1_mediator/a1_controller_get_policy_type_parameters.go
pkg/restapi/operations/a1_mediator/a1_controller_get_policy_type_responses.go
pkg/restapi/server.go
pkg/restful/restful.go
pkg/restful/types.go
pkg/resthooks/resthooks.go
pkg/resthooks/resthooks_test.go
pkg/rmr/rmr.go

index b7ca526..3214506 100644 (file)
@@ -170,6 +170,11 @@ paths:
         description: >
           represents a policy instance identifier. UUIDs are advisable but can
           be any string
+      - name: notificationDestination
+        in: query
+        type: string
+        description: >
+          URL send by non-RT RIC. This where non-RT RIC expects status updates on the policy creation
     get:
       description: |
         Retrieve the policy instance
@@ -281,16 +286,17 @@ paths:
           schema:
             type: object
             properties:
-              instance_status:
+              enforceStatus:
                 type: string
                 enum:
-                  - IN EFFECT
-                  - NOT IN EFFECT
-              has_been_deleted:
-                type: boolean
-              created_at:
+                  - ENFORCED
+                  - NOT_ENFORCED
+              enforceReason:
                 type: string
-                format: date-time
+                enum:
+                 - SCOPE_NOT_APPLICABLE
+                 - STATEMENT_NOT_APPLICABLE
+                 - OTHER_REASON
         '404':
           description: >
             there is no policy instance with this policy_instance_id or there is
index 111e02e..83e1c14 100644 (file)
@@ -26,11 +26,14 @@ package models
 // Editing this file might prove futile when you re-run the swagger generate command
 
 import (
+       "context"
+
        "github.com/go-openapi/strfmt"
 )
 
 // PolicyInstanceID represents a policy instance identifier. UUIDs are advisable but can be any string
 //
+// Example: 3d2157af-6a8f-4a7c-810f-38c2f824bf12
 //
 // swagger:model policy_instance_id
 type PolicyInstanceID string
@@ -39,3 +42,8 @@ type PolicyInstanceID string
 func (m PolicyInstanceID) Validate(formats strfmt.Registry) error {
        return nil
 }
+
+// ContextValidate validates this policy instance id based on context it is used
+func (m PolicyInstanceID) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
+       return nil
+}
index 6e67d41..3ddd43b 100644 (file)
@@ -26,6 +26,8 @@ package models
 // Editing this file might prove futile when you re-run the swagger generate command
 
 import (
+       "context"
+
        "github.com/go-openapi/errors"
        "github.com/go-openapi/strfmt"
        "github.com/go-openapi/validate"
@@ -54,3 +56,8 @@ func (m PolicyTypeID) Validate(formats strfmt.Registry) error {
        }
        return nil
 }
+
+// ContextValidate validates this policy type id based on context it is used
+func (m PolicyTypeID) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
+       return nil
+}
index 1a23d80..4a79388 100644 (file)
@@ -26,6 +26,8 @@ package models
 // Editing this file might prove futile when you re-run the swagger generate command
 
 import (
+       "context"
+
        "github.com/go-openapi/errors"
        "github.com/go-openapi/strfmt"
        "github.com/go-openapi/swag"
@@ -83,8 +85,8 @@ func (m *PolicyTypeSchema) Validate(formats strfmt.Registry) error {
 
 func (m *PolicyTypeSchema) validateCreateSchema(formats strfmt.Registry) error {
 
-       if err := validate.Required("create_schema", "body", m.CreateSchema); err != nil {
-               return err
+       if m.CreateSchema == nil {
+               return errors.Required("create_schema", "body", nil)
        }
 
        return nil
@@ -117,6 +119,11 @@ func (m *PolicyTypeSchema) validatePolicyTypeID(formats strfmt.Registry) error {
        return nil
 }
 
+// ContextValidate validates this policy type schema based on context it is used
+func (m *PolicyTypeSchema) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
+       return nil
+}
+
 // MarshalBinary interface implementation
 func (m *PolicyTypeSchema) MarshalBinary() ([]byte, error) {
        if m == nil {
diff --git a/pkg/notification/notification.go b/pkg/notification/notification.go
new file mode 100755 (executable)
index 0000000..5763a15
--- /dev/null
@@ -0,0 +1,25 @@
+package notification
+
+import (
+       "bytes"
+       "net/http"
+
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
+)
+
+func SendNotification(notificationDestination string, body string) error {
+       a1.Logger.Debug("In SendNotification")
+       client := &http.Client{}
+       req, err := http.NewRequest("POST", notificationDestination, bytes.NewBuffer([]byte(body)))
+       if err != nil {
+               return err
+       }
+       req.Header.Set("User-Agent", "a1mediator")
+       res, err := client.Do(req)
+       if err != nil {
+               a1.Logger.Debug("Error sending POST message to %v+", notificationDestination)
+               return err
+       }
+       a1.Logger.Debug("Notification response %s received from far-end", res.Status)
+       return nil
+}
index 15f325b..17ba7a8 100644 (file)
@@ -22,6 +22,7 @@
 package policy
 
 import (
+       "encoding/json"
        "errors"
        "fmt"
        "strconv"
@@ -29,6 +30,8 @@ import (
 
        "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
        "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/notification"
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_mediator"
        "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
 )
 
@@ -36,10 +39,11 @@ var policyTypeNotFoundError = errors.New("Policy Type Not Found")
 var policyInstanceNotFoundError = errors.New("Policy Instance Not Found")
 
 const (
-       a1HandlerPrefix  = "a1.policy_handler."
-       a1PolicyPrefix   = "a1.policy_type."
-       a1MediatorNs     = "A1m_ns"
-       a1InstancePrefix = "a1.policy_instance."
+       a1HandlerPrefix                 = "a1.policy_handler."
+       a1PolicyPrefix                  = "a1.policy_type."
+       a1MediatorNs                    = "A1m_ns"
+       a1InstancePrefix                = "a1.policy_instance."
+       a1NotificationDestinationPrefix = "a1.policy_notification_destination."
 )
 
 func NewPolicyManager(sdl *sdlgo.SyncStorage) *PolicyManager {
@@ -52,9 +56,9 @@ func createPolicyManager(sdlInst iSdl) *PolicyManager {
        }
        return pm
 }
-func (pm *PolicyManager) SetPolicyInstanceStatus(policyTypeId int, policyInstanceID int, status string) error {
-       a1.Logger.Debug("message recieved for %d and %d", policyTypeId, policyInstanceID)
-       instancehandlerKey := a1HandlerPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + strconv.FormatInt((int64(policyInstanceID)), 10)
+func (pm *PolicyManager) SetPolicyInstanceStatus(policyTypeId int, policyInstanceID string, status string) error {
+       a1.Logger.Debug("In SetPolicyInstanceStatus message recieved for %d and %s", policyTypeId, policyInstanceID)
+       instancehandlerKey := a1HandlerPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + policyInstanceID
        err := pm.db.Set(a1MediatorNs, instancehandlerKey, status)
        if err != nil {
                a1.Logger.Error("error1 :%+v", err)
@@ -63,10 +67,69 @@ func (pm *PolicyManager) SetPolicyInstanceStatus(policyTypeId int, policyInstanc
        return nil
 }
 
+func (pm *PolicyManager) GetPolicyInstanceStatus(policyTypeId int, policyInstanceID string) (bool, error) {
+       a1.Logger.Debug("In GetPolicyInstanceStatus message recieved for %d and %s", policyTypeId, policyInstanceID)
+       instancehandlerKey := a1HandlerPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + policyInstanceID
+       keys := []string{instancehandlerKey}
+       resp, err := pm.db.Get(a1MediatorNs, keys)
+       if err != nil {
+               a1.Logger.Error("error1 :%+v", err)
+               return false, err
+       }
+       for _, key := range resp {
+               if key == "OK" {
+                       return true, nil
+               }
+       }
+       return false, nil
+}
+
+func (pm *PolicyManager) SendPolicyStatusNotification(policyTypeId int, policyInstanceID string, handler string, status string) error {
+       a1.Logger.Debug("In SendPolicyStatusNotification status message recieved for %d and %s", policyTypeId, policyInstanceID)
+       notificationDestinationkey := a1NotificationDestinationPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + fmt.Sprint(policyInstanceID)
+       keys := [1]string{notificationDestinationkey}
+       data, err := pm.db.Get(a1MediatorNs, keys[:])
+       if err != nil {
+               a1.Logger.Error("error1 :%+v", err)
+               return err
+       }
+
+       if data[notificationDestinationkey] == nil {
+               // notificationDestination URL is not available. Not an error, non-RT RIC
+               // possibly not expecting any callback.
+               return nil
+       }
+
+       notificationDestination, ok := data[notificationDestinationkey].(string)
+       if !ok {
+               return errors.New("failed to process notificationDestination URL")
+       }
+
+       policyInstanceStatus := a1_mediator.A1ControllerGetPolicyInstanceStatusOKBody{EnforceStatus: "ENFORCED"}
+       enforced, err := pm.GetPolicyInstanceStatus(policyTypeId, policyInstanceID)
+       if err != nil {
+               return err
+       }
+
+       if !enforced {
+               policyInstanceStatus.EnforceStatus = "NOT ENFORCED"
+               policyInstanceStatus.EnforceReason = "OTHER_REASON"
+       }
+
+       jsonbody, err := json.Marshal(policyInstanceStatus)
+       if err != nil {
+               return err
+       }
+       err = notification.SendNotification(notificationDestination, string(jsonbody))
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
 func (im *PolicyManager) GetAllPolicyInstance(policyTypeId int) ([]models.PolicyInstanceID, error) {
        a1.Logger.Debug("GetAllPolicyInstance")
        var policyTypeInstances = []models.PolicyInstanceID{}
-
        keys, err := im.db.GetAll("A1m_ns")
 
        if err != nil {
index 003cd67..0eae6d3 100644 (file)
@@ -48,11 +48,10 @@ func TestMain(m *testing.M) {
 func TestSetPolicyInstance(t *testing.T) {
        var policyTypeId int
        policyTypeId = 20001
-       var policyInstanceID int
-       policyInstanceID = 123456
+       policyInstanceID := "123456"
        var status string
        status = "OK"
-       instancehandlerKey := a1HandlerPrefix + strconv.FormatInt(20001, 10) + "." + strconv.FormatInt(int64(policyInstanceID), 10)
+       instancehandlerKey := a1HandlerPrefix + strconv.FormatInt(20001, 10) + "." + policyInstanceID
        instancearr := []interface{}{instancehandlerKey, status}
        sdlInst.On("Set", "A1m_ns", instancearr).Return(nil)
        errresp := pm.SetPolicyInstanceStatus(policyTypeId, policyInstanceID, status)
index 067d41d..77ad658 100644 (file)
@@ -314,6 +314,12 @@ func init() {
           "name": "policy_instance_id",
           "in": "path",
           "required": true
+        },
+        {
+          "type": "string",
+          "description": "URL send by non-RT RIC. This where non-RT RIC expects status updates on the policy creation\n",
+          "name": "notificationDestination",
+          "in": "query"
         }
       ]
     },
@@ -333,18 +339,19 @@ func init() {
             "schema": {
               "type": "object",
               "properties": {
-                "created_at": {
+                "enforceReason": {
                   "type": "string",
-                  "format": "date-time"
-                },
-                "has_been_deleted": {
-                  "type": "boolean"
+                  "enum": [
+                    "SCOPE_NOT_APPLICABLE",
+                    "STATEMENT_NOT_APPLICABLE",
+                    "OTHER_REASON"
+                  ]
                 },
-                "instance_status": {
+                "enforceStatus": {
                   "type": "string",
                   "enum": [
-                    "IN EFFECT",
-                    "NOT IN EFFECT"
+                    "ENFORCED",
+                    "NOT_ENFORCED"
                   ]
                 }
               }
@@ -728,6 +735,12 @@ func init() {
           "name": "policy_instance_id",
           "in": "path",
           "required": true
+        },
+        {
+          "type": "string",
+          "description": "URL send by non-RT RIC. This where non-RT RIC expects status updates on the policy creation\n",
+          "name": "notificationDestination",
+          "in": "query"
         }
       ]
     },
@@ -747,18 +760,19 @@ func init() {
             "schema": {
               "type": "object",
               "properties": {
-                "created_at": {
+                "enforceReason": {
                   "type": "string",
-                  "format": "date-time"
-                },
-                "has_been_deleted": {
-                  "type": "boolean"
+                  "enum": [
+                    "SCOPE_NOT_APPLICABLE",
+                    "STATEMENT_NOT_APPLICABLE",
+                    "OTHER_REASON"
+                  ]
                 },
-                "instance_status": {
+                "enforceStatus": {
                   "type": "string",
                   "enum": [
-                    "IN EFFECT",
-                    "NOT IN EFFECT"
+                    "ENFORCED",
+                    "NOT_ENFORCED"
                   ]
                 }
               }
index c8a14b1..a526e99 100644 (file)
@@ -39,8 +39,8 @@ import (
        "github.com/go-openapi/strfmt"
        "github.com/go-openapi/swag"
 
-       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_e_i_data_delivery"
-       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_mediator"
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_e_i_data_delivery"
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_mediator"
 )
 
 // NewA1API creates a new A1 instance
@@ -55,6 +55,7 @@ func NewA1API(spec *loads.Document) *A1API {
                PreServerShutdown:   func() {},
                ServerShutdown:      func() {},
                spec:                spec,
+               useSwaggerUI:        false,
                ServeError:          errors.ServeError,
                BasicAuthenticator:  security.BasicAuth,
                APIKeyAuthenticator: security.APIKeyAuth,
@@ -111,13 +112,16 @@ type A1API struct {
        defaultConsumes string
        defaultProduces string
        Middleware      func(middleware.Builder) http.Handler
+       useSwaggerUI    bool
 
        // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
        // It has a default implementation in the security package, however you can replace it for your particular usage.
        BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
+
        // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
        // It has a default implementation in the security package, however you can replace it for your particular usage.
        APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
+
        // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
        // It has a default implementation in the security package, however you can replace it for your particular usage.
        BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
@@ -152,6 +156,7 @@ type A1API struct {
        A1MediatorA1ControllerGetPolicyInstanceStatusHandler a1_mediator.A1ControllerGetPolicyInstanceStatusHandler
        // A1MediatorA1ControllerGetPolicyTypeHandler sets the operation handler for the a1 controller get policy type operation
        A1MediatorA1ControllerGetPolicyTypeHandler a1_mediator.A1ControllerGetPolicyTypeHandler
+
        // ServeError is called when an error is received, there is a default handler
        // but you can set your own with this
        ServeError func(http.ResponseWriter, *http.Request, error)
@@ -171,6 +176,16 @@ type A1API struct {
        Logger func(string, ...interface{})
 }
 
+// UseRedoc for documentation at /docs
+func (o *A1API) UseRedoc() {
+       o.useSwaggerUI = false
+}
+
+// UseSwaggerUI for documentation at /docs
+func (o *A1API) UseSwaggerUI() {
+       o.useSwaggerUI = true
+}
+
 // SetDefaultProduces sets the default produces media type
 func (o *A1API) SetDefaultProduces(mediaType string) {
        o.defaultProduces = mediaType
@@ -393,6 +408,9 @@ func (o *A1API) Serve(builder middleware.Builder) http.Handler {
        if o.Middleware != nil {
                return o.Middleware(builder)
        }
+       if o.useSwaggerUI {
+               return o.context.APIHandlerSwaggerUI(builder)
+       }
        return o.context.APIHandler(builder)
 }
 
index f2617d2..3742757 100644 (file)
@@ -49,7 +49,7 @@ func NewA1ControllerDataDelivery(ctx *middleware.Context, handler A1ControllerDa
        return &A1ControllerDataDelivery{Context: ctx, Handler: handler}
 }
 
-/*A1ControllerDataDelivery swagger:route POST /data-delivery A1 EI Data Delivery a1ControllerDataDelivery
+/* A1ControllerDataDelivery swagger:route POST /data-delivery A1 EI Data Delivery a1ControllerDataDelivery
 
 Deliver data produced by data producer.
 
@@ -63,17 +63,15 @@ type A1ControllerDataDelivery struct {
 func (o *A1ControllerDataDelivery) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
        route, rCtx, _ := o.Context.RouteInfo(r)
        if rCtx != nil {
-               r = rCtx
+               *r = *rCtx
        }
        var Params = NewA1ControllerDataDeliveryParams()
-
        if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
                o.Context.Respond(rw, r, route.Produces, route, err)
                return
        }
 
        res := o.Handler.Handle(Params) // actually handle the request
-
        o.Context.Respond(rw, r, route.Produces, route, res)
 
 }
index c7c1e21..041d853 100644 (file)
@@ -34,7 +34,8 @@ import (
 )
 
 // NewA1ControllerDataDeliveryParams creates a new A1ControllerDataDeliveryParams object
-// no default values defined in spec.
+//
+// There are no default values defined in the spec.
 func NewA1ControllerDataDeliveryParams() A1ControllerDataDeliveryParams {
 
        return A1ControllerDataDeliveryParams{}
index 23e1f04..7ab9556 100644 (file)
@@ -49,7 +49,7 @@ func NewA1ControllerCreateOrReplacePolicyInstance(ctx *middleware.Context, handl
        return &A1ControllerCreateOrReplacePolicyInstance{Context: ctx, Handler: handler}
 }
 
-/*A1ControllerCreateOrReplacePolicyInstance swagger:route PUT /a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id} A1 Mediator a1ControllerCreateOrReplacePolicyInstance
+/* A1ControllerCreateOrReplacePolicyInstance swagger:route PUT /a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id} A1 Mediator a1ControllerCreateOrReplacePolicyInstance
 
 Create or replace a policy instance of type policy_type_id. The schema of the PUT body is defined by the create_schema field of the policy type.
 
@@ -63,17 +63,15 @@ type A1ControllerCreateOrReplacePolicyInstance struct {
 func (o *A1ControllerCreateOrReplacePolicyInstance) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
        route, rCtx, _ := o.Context.RouteInfo(r)
        if rCtx != nil {
-               r = rCtx
+               *r = *rCtx
        }
        var Params = NewA1ControllerCreateOrReplacePolicyInstanceParams()
-
        if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
                o.Context.Respond(rw, r, route.Produces, route, err)
                return
        }
 
        res := o.Handler.Handle(Params) // actually handle the request
-
        o.Context.Respond(rw, r, route.Produces, route, res)
 
 }
index e9b8498..9bc2307 100644 (file)
@@ -37,7 +37,8 @@ import (
 )
 
 // NewA1ControllerCreateOrReplacePolicyInstanceParams creates a new A1ControllerCreateOrReplacePolicyInstanceParams object
-// no default values defined in spec.
+//
+// There are no default values defined in the spec.
 func NewA1ControllerCreateOrReplacePolicyInstanceParams() A1ControllerCreateOrReplacePolicyInstanceParams {
 
        return A1ControllerCreateOrReplacePolicyInstanceParams{}
@@ -56,6 +57,11 @@ type A1ControllerCreateOrReplacePolicyInstanceParams struct {
          In: body
        */
        Body interface{}
+       /*URL send by non-RT RIC. This where non-RT RIC expects status updates on the policy creation
+
+         In: query
+       */
+       NotificationDestination *string
        /*represents a policy instance identifier. UUIDs are advisable but can be any string
 
          Required: true
@@ -81,6 +87,8 @@ func (o *A1ControllerCreateOrReplacePolicyInstanceParams) BindRequest(r *http.Re
 
        o.HTTPRequest = r
 
+       qs := runtime.Values(r.URL.Query())
+
        if runtime.HasBody(r) {
                defer r.Body.Close()
                var body interface{}
@@ -91,6 +99,12 @@ func (o *A1ControllerCreateOrReplacePolicyInstanceParams) BindRequest(r *http.Re
                        o.Body = body
                }
        }
+
+       qNotificationDestination, qhkNotificationDestination, _ := qs.GetOK("notificationDestination")
+       if err := o.bindNotificationDestination(qNotificationDestination, qhkNotificationDestination, route.Formats); err != nil {
+               res = append(res, err)
+       }
+
        rPolicyInstanceID, rhkPolicyInstanceID, _ := route.Params.GetOK("policy_instance_id")
        if err := o.bindPolicyInstanceID(rPolicyInstanceID, rhkPolicyInstanceID, route.Formats); err != nil {
                res = append(res, err)
@@ -100,13 +114,30 @@ func (o *A1ControllerCreateOrReplacePolicyInstanceParams) BindRequest(r *http.Re
        if err := o.bindPolicyTypeID(rPolicyTypeID, rhkPolicyTypeID, route.Formats); err != nil {
                res = append(res, err)
        }
-
        if len(res) > 0 {
                return errors.CompositeValidationError(res...)
        }
        return nil
 }
 
+// bindNotificationDestination binds and validates parameter NotificationDestination from query.
+func (o *A1ControllerCreateOrReplacePolicyInstanceParams) bindNotificationDestination(rawData []string, hasKey bool, formats strfmt.Registry) error {
+       var raw string
+       if len(rawData) > 0 {
+               raw = rawData[len(rawData)-1]
+       }
+
+       // Required: false
+       // AllowEmptyValue: false
+
+       if raw == "" { // empty values pass all other validations
+               return nil
+       }
+       o.NotificationDestination = &raw
+
+       return nil
+}
+
 // bindPolicyInstanceID binds and validates parameter PolicyInstanceID from path.
 func (o *A1ControllerCreateOrReplacePolicyInstanceParams) bindPolicyInstanceID(rawData []string, hasKey bool, formats strfmt.Registry) error {
        var raw string
@@ -116,7 +147,6 @@ func (o *A1ControllerCreateOrReplacePolicyInstanceParams) bindPolicyInstanceID(r
 
        // Required: true
        // Parameter is provided by construction from the route
-
        o.PolicyInstanceID = raw
 
        return nil
@@ -148,11 +178,11 @@ func (o *A1ControllerCreateOrReplacePolicyInstanceParams) bindPolicyTypeID(rawDa
 // validatePolicyTypeID carries on validations for parameter PolicyTypeID
 func (o *A1ControllerCreateOrReplacePolicyInstanceParams) validatePolicyTypeID(formats strfmt.Registry) error {
 
-       if err := validate.MinimumInt("policy_type_id", "path", int64(o.PolicyTypeID), 1, false); err != nil {
+       if err := validate.MinimumInt("policy_type_id", "path", o.PolicyTypeID, 1, false); err != nil {
                return err
        }
 
-       if err := validate.MaximumInt("policy_type_id", "path", int64(o.PolicyTypeID), 2.147483647e+09, false); err != nil {
+       if err := validate.MaximumInt("policy_type_id", "path", o.PolicyTypeID, 2.147483647e+09, false); err != nil {
                return err
        }
 
index 4c28a69..df6bd5e 100644 (file)
@@ -39,6 +39,8 @@ type A1ControllerCreateOrReplacePolicyInstanceURL struct {
        PolicyInstanceID string
        PolicyTypeID     int64
 
+       NotificationDestination *string
+
        _basePath string
        // avoid unkeyed usage
        _ struct{}
@@ -82,6 +84,18 @@ func (o *A1ControllerCreateOrReplacePolicyInstanceURL) Build() (*url.URL, error)
        _basePath := o._basePath
        _result.Path = golangswaggerpaths.Join(_basePath, _path)
 
+       qs := make(url.Values)
+
+       var notificationDestinationQ string
+       if o.NotificationDestination != nil {
+               notificationDestinationQ = *o.NotificationDestination
+       }
+       if notificationDestinationQ != "" {
+               qs.Set("notificationDestination", notificationDestinationQ)
+       }
+
+       _result.RawQuery = qs.Encode()
+
        return &_result, nil
 }
 
index 28aef97..7430978 100644 (file)
@@ -49,7 +49,7 @@ func NewA1ControllerCreatePolicyType(ctx *middleware.Context, handler A1Controll
        return &A1ControllerCreatePolicyType{Context: ctx, Handler: handler}
 }
 
-/*A1ControllerCreatePolicyType swagger:route PUT /a1-p/policytypes/{policy_type_id} A1 Mediator a1ControllerCreatePolicyType
+/* A1ControllerCreatePolicyType swagger:route PUT /a1-p/policytypes/{policy_type_id} A1 Mediator a1ControllerCreatePolicyType
 
 Create a new policy type . Replace is not currently allowed; to replace, for now do a DELETE and then a PUT again.
 
@@ -63,17 +63,15 @@ type A1ControllerCreatePolicyType struct {
 func (o *A1ControllerCreatePolicyType) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
        route, rCtx, _ := o.Context.RouteInfo(r)
        if rCtx != nil {
-               r = rCtx
+               *r = *rCtx
        }
        var Params = NewA1ControllerCreatePolicyTypeParams()
-
        if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
                o.Context.Respond(rw, r, route.Produces, route, err)
                return
        }
 
        res := o.Handler.Handle(Params) // actually handle the request
-
        o.Context.Respond(rw, r, route.Produces, route, res)
 
 }
index 6c6f318..6ab13af 100644 (file)
@@ -26,6 +26,7 @@ package a1_mediator
 // Editing this file might prove futile when you re-run the swagger generate command
 
 import (
+       "context"
        "net/http"
 
        "github.com/go-openapi/errors"
@@ -35,11 +36,12 @@ import (
        "github.com/go-openapi/swag"
        "github.com/go-openapi/validate"
 
-       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
 )
 
 // NewA1ControllerCreatePolicyTypeParams creates a new A1ControllerCreatePolicyTypeParams object
-// no default values defined in spec.
+//
+// There are no default values defined in the spec.
 func NewA1ControllerCreatePolicyTypeParams() A1ControllerCreatePolicyTypeParams {
 
        return A1ControllerCreatePolicyTypeParams{}
@@ -88,16 +90,21 @@ func (o *A1ControllerCreatePolicyTypeParams) BindRequest(r *http.Request, route
                                res = append(res, err)
                        }
 
+                       ctx := validate.WithOperationRequest(context.Background())
+                       if err := body.ContextValidate(ctx, route.Formats); err != nil {
+                               res = append(res, err)
+                       }
+
                        if len(res) == 0 {
                                o.Body = &body
                        }
                }
        }
+
        rPolicyTypeID, rhkPolicyTypeID, _ := route.Params.GetOK("policy_type_id")
        if err := o.bindPolicyTypeID(rPolicyTypeID, rhkPolicyTypeID, route.Formats); err != nil {
                res = append(res, err)
        }
-
        if len(res) > 0 {
                return errors.CompositeValidationError(res...)
        }
@@ -130,11 +137,11 @@ func (o *A1ControllerCreatePolicyTypeParams) bindPolicyTypeID(rawData []string,
 // validatePolicyTypeID carries on validations for parameter PolicyTypeID
 func (o *A1ControllerCreatePolicyTypeParams) validatePolicyTypeID(formats strfmt.Registry) error {
 
-       if err := validate.MinimumInt("policy_type_id", "path", int64(o.PolicyTypeID), 1, false); err != nil {
+       if err := validate.MinimumInt("policy_type_id", "path", o.PolicyTypeID, 1, false); err != nil {
                return err
        }
 
-       if err := validate.MaximumInt("policy_type_id", "path", int64(o.PolicyTypeID), 2.147483647e+09, false); err != nil {
+       if err := validate.MaximumInt("policy_type_id", "path", o.PolicyTypeID, 2.147483647e+09, false); err != nil {
                return err
        }
 
index f75ceee..fae0c39 100644 (file)
@@ -49,7 +49,7 @@ func NewA1ControllerDeletePolicyInstance(ctx *middleware.Context, handler A1Cont
        return &A1ControllerDeletePolicyInstance{Context: ctx, Handler: handler}
 }
 
-/*A1ControllerDeletePolicyInstance swagger:route DELETE /a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id} A1 Mediator a1ControllerDeletePolicyInstance
+/* A1ControllerDeletePolicyInstance swagger:route DELETE /a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id} A1 Mediator a1ControllerDeletePolicyInstance
 
 Delete this policy instance
 
@@ -63,17 +63,15 @@ type A1ControllerDeletePolicyInstance struct {
 func (o *A1ControllerDeletePolicyInstance) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
        route, rCtx, _ := o.Context.RouteInfo(r)
        if rCtx != nil {
-               r = rCtx
+               *r = *rCtx
        }
        var Params = NewA1ControllerDeletePolicyInstanceParams()
-
        if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
                o.Context.Respond(rw, r, route.Produces, route, err)
                return
        }
 
        res := o.Handler.Handle(Params) // actually handle the request
-
        o.Context.Respond(rw, r, route.Produces, route, res)
 
 }
index b1afbec..140190f 100644 (file)
@@ -29,6 +29,7 @@ import (
        "net/http"
 
        "github.com/go-openapi/errors"
+       "github.com/go-openapi/runtime"
        "github.com/go-openapi/runtime/middleware"
        "github.com/go-openapi/strfmt"
        "github.com/go-openapi/swag"
@@ -36,7 +37,8 @@ import (
 )
 
 // NewA1ControllerDeletePolicyInstanceParams creates a new A1ControllerDeletePolicyInstanceParams object
-// no default values defined in spec.
+//
+// There are no default values defined in the spec.
 func NewA1ControllerDeletePolicyInstanceParams() A1ControllerDeletePolicyInstanceParams {
 
        return A1ControllerDeletePolicyInstanceParams{}
@@ -51,6 +53,11 @@ type A1ControllerDeletePolicyInstanceParams struct {
        // HTTP Request Object
        HTTPRequest *http.Request `json:"-"`
 
+       /*URL send by non-RT RIC. This where non-RT RIC expects status updates on the policy creation
+
+         In: query
+       */
+       NotificationDestination *string
        /*represents a policy instance identifier. UUIDs are advisable but can be any string
 
          Required: true
@@ -76,6 +83,13 @@ func (o *A1ControllerDeletePolicyInstanceParams) BindRequest(r *http.Request, ro
 
        o.HTTPRequest = r
 
+       qs := runtime.Values(r.URL.Query())
+
+       qNotificationDestination, qhkNotificationDestination, _ := qs.GetOK("notificationDestination")
+       if err := o.bindNotificationDestination(qNotificationDestination, qhkNotificationDestination, route.Formats); err != nil {
+               res = append(res, err)
+       }
+
        rPolicyInstanceID, rhkPolicyInstanceID, _ := route.Params.GetOK("policy_instance_id")
        if err := o.bindPolicyInstanceID(rPolicyInstanceID, rhkPolicyInstanceID, route.Formats); err != nil {
                res = append(res, err)
@@ -85,13 +99,30 @@ func (o *A1ControllerDeletePolicyInstanceParams) BindRequest(r *http.Request, ro
        if err := o.bindPolicyTypeID(rPolicyTypeID, rhkPolicyTypeID, route.Formats); err != nil {
                res = append(res, err)
        }
-
        if len(res) > 0 {
                return errors.CompositeValidationError(res...)
        }
        return nil
 }
 
+// bindNotificationDestination binds and validates parameter NotificationDestination from query.
+func (o *A1ControllerDeletePolicyInstanceParams) bindNotificationDestination(rawData []string, hasKey bool, formats strfmt.Registry) error {
+       var raw string
+       if len(rawData) > 0 {
+               raw = rawData[len(rawData)-1]
+       }
+
+       // Required: false
+       // AllowEmptyValue: false
+
+       if raw == "" { // empty values pass all other validations
+               return nil
+       }
+       o.NotificationDestination = &raw
+
+       return nil
+}
+
 // bindPolicyInstanceID binds and validates parameter PolicyInstanceID from path.
 func (o *A1ControllerDeletePolicyInstanceParams) bindPolicyInstanceID(rawData []string, hasKey bool, formats strfmt.Registry) error {
        var raw string
@@ -101,7 +132,6 @@ func (o *A1ControllerDeletePolicyInstanceParams) bindPolicyInstanceID(rawData []
 
        // Required: true
        // Parameter is provided by construction from the route
-
        o.PolicyInstanceID = raw
 
        return nil
@@ -133,11 +163,11 @@ func (o *A1ControllerDeletePolicyInstanceParams) bindPolicyTypeID(rawData []stri
 // validatePolicyTypeID carries on validations for parameter PolicyTypeID
 func (o *A1ControllerDeletePolicyInstanceParams) validatePolicyTypeID(formats strfmt.Registry) error {
 
-       if err := validate.MinimumInt("policy_type_id", "path", int64(o.PolicyTypeID), 1, false); err != nil {
+       if err := validate.MinimumInt("policy_type_id", "path", o.PolicyTypeID, 1, false); err != nil {
                return err
        }
 
-       if err := validate.MaximumInt("policy_type_id", "path", int64(o.PolicyTypeID), 2.147483647e+09, false); err != nil {
+       if err := validate.MaximumInt("policy_type_id", "path", o.PolicyTypeID, 2.147483647e+09, false); err != nil {
                return err
        }
 
index 145fe1e..ccced04 100644 (file)
@@ -39,6 +39,8 @@ type A1ControllerDeletePolicyInstanceURL struct {
        PolicyInstanceID string
        PolicyTypeID     int64
 
+       NotificationDestination *string
+
        _basePath string
        // avoid unkeyed usage
        _ struct{}
@@ -82,6 +84,18 @@ func (o *A1ControllerDeletePolicyInstanceURL) Build() (*url.URL, error) {
        _basePath := o._basePath
        _result.Path = golangswaggerpaths.Join(_basePath, _path)
 
+       qs := make(url.Values)
+
+       var notificationDestinationQ string
+       if o.NotificationDestination != nil {
+               notificationDestinationQ = *o.NotificationDestination
+       }
+       if notificationDestinationQ != "" {
+               qs.Set("notificationDestination", notificationDestinationQ)
+       }
+
+       _result.RawQuery = qs.Encode()
+
        return &_result, nil
 }
 
index c01e905..cb3782e 100644 (file)
@@ -49,7 +49,7 @@ func NewA1ControllerDeletePolicyType(ctx *middleware.Context, handler A1Controll
        return &A1ControllerDeletePolicyType{Context: ctx, Handler: handler}
 }
 
-/*A1ControllerDeletePolicyType swagger:route DELETE /a1-p/policytypes/{policy_type_id} A1 Mediator a1ControllerDeletePolicyType
+/* A1ControllerDeletePolicyType swagger:route DELETE /a1-p/policytypes/{policy_type_id} A1 Mediator a1ControllerDeletePolicyType
 
 Delete this policy type. Can only be performed if there are no instances of this type
 
@@ -63,17 +63,15 @@ type A1ControllerDeletePolicyType struct {
 func (o *A1ControllerDeletePolicyType) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
        route, rCtx, _ := o.Context.RouteInfo(r)
        if rCtx != nil {
-               r = rCtx
+               *r = *rCtx
        }
        var Params = NewA1ControllerDeletePolicyTypeParams()
-
        if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
                o.Context.Respond(rw, r, route.Produces, route, err)
                return
        }
 
        res := o.Handler.Handle(Params) // actually handle the request
-
        o.Context.Respond(rw, r, route.Produces, route, res)
 
 }
index 5916580..7984774 100644 (file)
@@ -36,7 +36,8 @@ import (
 )
 
 // NewA1ControllerDeletePolicyTypeParams creates a new A1ControllerDeletePolicyTypeParams object
-// no default values defined in spec.
+//
+// There are no default values defined in the spec.
 func NewA1ControllerDeletePolicyTypeParams() A1ControllerDeletePolicyTypeParams {
 
        return A1ControllerDeletePolicyTypeParams{}
@@ -74,7 +75,6 @@ func (o *A1ControllerDeletePolicyTypeParams) BindRequest(r *http.Request, route
        if err := o.bindPolicyTypeID(rPolicyTypeID, rhkPolicyTypeID, route.Formats); err != nil {
                res = append(res, err)
        }
-
        if len(res) > 0 {
                return errors.CompositeValidationError(res...)
        }
@@ -107,11 +107,11 @@ func (o *A1ControllerDeletePolicyTypeParams) bindPolicyTypeID(rawData []string,
 // validatePolicyTypeID carries on validations for parameter PolicyTypeID
 func (o *A1ControllerDeletePolicyTypeParams) validatePolicyTypeID(formats strfmt.Registry) error {
 
-       if err := validate.MinimumInt("policy_type_id", "path", int64(o.PolicyTypeID), 1, false); err != nil {
+       if err := validate.MinimumInt("policy_type_id", "path", o.PolicyTypeID, 1, false); err != nil {
                return err
        }
 
-       if err := validate.MaximumInt("policy_type_id", "path", int64(o.PolicyTypeID), 2.147483647e+09, false); err != nil {
+       if err := validate.MaximumInt("policy_type_id", "path", o.PolicyTypeID, 2.147483647e+09, false); err != nil {
                return err
        }
 
index 4080233..01350b7 100644 (file)
@@ -49,7 +49,7 @@ func NewA1ControllerGetAllInstancesForType(ctx *middleware.Context, handler A1Co
        return &A1ControllerGetAllInstancesForType{Context: ctx, Handler: handler}
 }
 
-/*A1ControllerGetAllInstancesForType swagger:route GET /a1-p/policytypes/{policy_type_id}/policies A1 Mediator a1ControllerGetAllInstancesForType
+/* A1ControllerGetAllInstancesForType swagger:route GET /a1-p/policytypes/{policy_type_id}/policies A1 Mediator a1ControllerGetAllInstancesForType
 
 get a list of all policy instance ids for this policy type id
 
@@ -62,17 +62,15 @@ type A1ControllerGetAllInstancesForType struct {
 func (o *A1ControllerGetAllInstancesForType) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
        route, rCtx, _ := o.Context.RouteInfo(r)
        if rCtx != nil {
-               r = rCtx
+               *r = *rCtx
        }
        var Params = NewA1ControllerGetAllInstancesForTypeParams()
-
        if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
                o.Context.Respond(rw, r, route.Produces, route, err)
                return
        }
 
        res := o.Handler.Handle(Params) // actually handle the request
-
        o.Context.Respond(rw, r, route.Produces, route, res)
 
 }
index 6a4e4b6..1a86070 100644 (file)
@@ -36,7 +36,8 @@ import (
 )
 
 // NewA1ControllerGetAllInstancesForTypeParams creates a new A1ControllerGetAllInstancesForTypeParams object
-// no default values defined in spec.
+//
+// There are no default values defined in the spec.
 func NewA1ControllerGetAllInstancesForTypeParams() A1ControllerGetAllInstancesForTypeParams {
 
        return A1ControllerGetAllInstancesForTypeParams{}
@@ -74,7 +75,6 @@ func (o *A1ControllerGetAllInstancesForTypeParams) BindRequest(r *http.Request,
        if err := o.bindPolicyTypeID(rPolicyTypeID, rhkPolicyTypeID, route.Formats); err != nil {
                res = append(res, err)
        }
-
        if len(res) > 0 {
                return errors.CompositeValidationError(res...)
        }
@@ -107,11 +107,11 @@ func (o *A1ControllerGetAllInstancesForTypeParams) bindPolicyTypeID(rawData []st
 // validatePolicyTypeID carries on validations for parameter PolicyTypeID
 func (o *A1ControllerGetAllInstancesForTypeParams) validatePolicyTypeID(formats strfmt.Registry) error {
 
-       if err := validate.MinimumInt("policy_type_id", "path", int64(o.PolicyTypeID), 1, false); err != nil {
+       if err := validate.MinimumInt("policy_type_id", "path", o.PolicyTypeID, 1, false); err != nil {
                return err
        }
 
-       if err := validate.MaximumInt("policy_type_id", "path", int64(o.PolicyTypeID), 2.147483647e+09, false); err != nil {
+       if err := validate.MaximumInt("policy_type_id", "path", o.PolicyTypeID, 2.147483647e+09, false); err != nil {
                return err
        }
 
index 4c7b1c0..4fa8906 100644 (file)
@@ -30,7 +30,7 @@ import (
 
        "github.com/go-openapi/runtime"
 
-       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
 )
 
 // A1ControllerGetAllInstancesForTypeOKCode is the HTTP code returned for type A1ControllerGetAllInstancesForTypeOK
index 70758b3..eeef4ae 100644 (file)
@@ -49,7 +49,7 @@ func NewA1ControllerGetAllPolicyTypes(ctx *middleware.Context, handler A1Control
        return &A1ControllerGetAllPolicyTypes{Context: ctx, Handler: handler}
 }
 
-/*A1ControllerGetAllPolicyTypes swagger:route GET /a1-p/policytypes A1 Mediator a1ControllerGetAllPolicyTypes
+/* A1ControllerGetAllPolicyTypes swagger:route GET /a1-p/policytypes A1 Mediator a1ControllerGetAllPolicyTypes
 
 Get a list of all registered policy type ids
 
@@ -62,17 +62,15 @@ type A1ControllerGetAllPolicyTypes struct {
 func (o *A1ControllerGetAllPolicyTypes) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
        route, rCtx, _ := o.Context.RouteInfo(r)
        if rCtx != nil {
-               r = rCtx
+               *r = *rCtx
        }
        var Params = NewA1ControllerGetAllPolicyTypesParams()
-
        if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
                o.Context.Respond(rw, r, route.Produces, route, err)
                return
        }
 
        res := o.Handler.Handle(Params) // actually handle the request
-
        o.Context.Respond(rw, r, route.Produces, route, res)
 
 }
index 1f622ac..f6313a5 100644 (file)
@@ -33,7 +33,8 @@ import (
 )
 
 // NewA1ControllerGetAllPolicyTypesParams creates a new A1ControllerGetAllPolicyTypesParams object
-// no default values defined in spec.
+//
+// There are no default values defined in the spec.
 func NewA1ControllerGetAllPolicyTypesParams() A1ControllerGetAllPolicyTypesParams {
 
        return A1ControllerGetAllPolicyTypesParams{}
index 95868f1..d6974ea 100644 (file)
@@ -30,7 +30,7 @@ import (
 
        "github.com/go-openapi/runtime"
 
-       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
 )
 
 // A1ControllerGetAllPolicyTypesOKCode is the HTTP code returned for type A1ControllerGetAllPolicyTypesOK
index 7ddacf2..1294781 100644 (file)
@@ -49,7 +49,7 @@ func NewA1ControllerGetHealthcheck(ctx *middleware.Context, handler A1Controller
        return &A1ControllerGetHealthcheck{Context: ctx, Handler: handler}
 }
 
-/*A1ControllerGetHealthcheck swagger:route GET /a1-p/healthcheck A1 Mediator a1ControllerGetHealthcheck
+/* A1ControllerGetHealthcheck swagger:route GET /a1-p/healthcheck A1 Mediator a1ControllerGetHealthcheck
 
 Perform a healthcheck on a1
 
@@ -63,17 +63,15 @@ type A1ControllerGetHealthcheck struct {
 func (o *A1ControllerGetHealthcheck) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
        route, rCtx, _ := o.Context.RouteInfo(r)
        if rCtx != nil {
-               r = rCtx
+               *r = *rCtx
        }
        var Params = NewA1ControllerGetHealthcheckParams()
-
        if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
                o.Context.Respond(rw, r, route.Produces, route, err)
                return
        }
 
        res := o.Handler.Handle(Params) // actually handle the request
-
        o.Context.Respond(rw, r, route.Produces, route, res)
 
 }
index 0af3c35..a6cb2a7 100644 (file)
@@ -33,7 +33,8 @@ import (
 )
 
 // NewA1ControllerGetHealthcheckParams creates a new A1ControllerGetHealthcheckParams object
-// no default values defined in spec.
+//
+// There are no default values defined in the spec.
 func NewA1ControllerGetHealthcheckParams() A1ControllerGetHealthcheckParams {
 
        return A1ControllerGetHealthcheckParams{}
index 84f3630..3c4c37c 100644 (file)
@@ -34,8 +34,8 @@ import (
 // A1ControllerGetHealthcheckOKCode is the HTTP code returned for type A1ControllerGetHealthcheckOK
 const A1ControllerGetHealthcheckOKCode int = 200
 
-/*A1ControllerGetHealthcheckOK A1 is healthy. Anything other than a 200 should be considered a1 as failing
-
+/*
+A1ControllerGetHealthcheckOK A1 is healthy. Anything other than a 200 should be considered a1 as failing
 
 swagger:response a1ControllerGetHealthcheckOK
 */
@@ -55,7 +55,6 @@ func (o *A1ControllerGetHealthcheckOK) WriteResponse(rw http.ResponseWriter, pro
 
        rw.WriteHeader(200)
 }
-
 // A1ControllerGetHealthcheckInternalServerErrorCode is the HTTP code returned for type A1ControllerGetHealthcheckInternalServerError
 const A1ControllerGetHealthcheckInternalServerErrorCode int = 500
 
@@ -79,3 +78,4 @@ func (o *A1ControllerGetHealthcheckInternalServerError) WriteResponse(rw http.Re
 
        rw.WriteHeader(500)
 }
+
index 12adc98..bae1056 100644 (file)
@@ -49,7 +49,7 @@ func NewA1ControllerGetPolicyInstance(ctx *middleware.Context, handler A1Control
        return &A1ControllerGetPolicyInstance{Context: ctx, Handler: handler}
 }
 
-/*A1ControllerGetPolicyInstance swagger:route GET /a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id} A1 Mediator a1ControllerGetPolicyInstance
+/* A1ControllerGetPolicyInstance swagger:route GET /a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id} A1 Mediator a1ControllerGetPolicyInstance
 
 Retrieve the policy instance
 
@@ -63,17 +63,15 @@ type A1ControllerGetPolicyInstance struct {
 func (o *A1ControllerGetPolicyInstance) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
        route, rCtx, _ := o.Context.RouteInfo(r)
        if rCtx != nil {
-               r = rCtx
+               *r = *rCtx
        }
        var Params = NewA1ControllerGetPolicyInstanceParams()
-
        if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
                o.Context.Respond(rw, r, route.Produces, route, err)
                return
        }
 
        res := o.Handler.Handle(Params) // actually handle the request
-
        o.Context.Respond(rw, r, route.Produces, route, res)
 
 }
index 9645421..27df52f 100644 (file)
@@ -29,6 +29,7 @@ import (
        "net/http"
 
        "github.com/go-openapi/errors"
+       "github.com/go-openapi/runtime"
        "github.com/go-openapi/runtime/middleware"
        "github.com/go-openapi/strfmt"
        "github.com/go-openapi/swag"
@@ -36,7 +37,8 @@ import (
 )
 
 // NewA1ControllerGetPolicyInstanceParams creates a new A1ControllerGetPolicyInstanceParams object
-// no default values defined in spec.
+//
+// There are no default values defined in the spec.
 func NewA1ControllerGetPolicyInstanceParams() A1ControllerGetPolicyInstanceParams {
 
        return A1ControllerGetPolicyInstanceParams{}
@@ -51,6 +53,11 @@ type A1ControllerGetPolicyInstanceParams struct {
        // HTTP Request Object
        HTTPRequest *http.Request `json:"-"`
 
+       /*URL send by non-RT RIC. This where non-RT RIC expects status updates on the policy creation
+
+         In: query
+       */
+       NotificationDestination *string
        /*represents a policy instance identifier. UUIDs are advisable but can be any string
 
          Required: true
@@ -76,6 +83,13 @@ func (o *A1ControllerGetPolicyInstanceParams) BindRequest(r *http.Request, route
 
        o.HTTPRequest = r
 
+       qs := runtime.Values(r.URL.Query())
+
+       qNotificationDestination, qhkNotificationDestination, _ := qs.GetOK("notificationDestination")
+       if err := o.bindNotificationDestination(qNotificationDestination, qhkNotificationDestination, route.Formats); err != nil {
+               res = append(res, err)
+       }
+
        rPolicyInstanceID, rhkPolicyInstanceID, _ := route.Params.GetOK("policy_instance_id")
        if err := o.bindPolicyInstanceID(rPolicyInstanceID, rhkPolicyInstanceID, route.Formats); err != nil {
                res = append(res, err)
@@ -85,13 +99,30 @@ func (o *A1ControllerGetPolicyInstanceParams) BindRequest(r *http.Request, route
        if err := o.bindPolicyTypeID(rPolicyTypeID, rhkPolicyTypeID, route.Formats); err != nil {
                res = append(res, err)
        }
-
        if len(res) > 0 {
                return errors.CompositeValidationError(res...)
        }
        return nil
 }
 
+// bindNotificationDestination binds and validates parameter NotificationDestination from query.
+func (o *A1ControllerGetPolicyInstanceParams) bindNotificationDestination(rawData []string, hasKey bool, formats strfmt.Registry) error {
+       var raw string
+       if len(rawData) > 0 {
+               raw = rawData[len(rawData)-1]
+       }
+
+       // Required: false
+       // AllowEmptyValue: false
+
+       if raw == "" { // empty values pass all other validations
+               return nil
+       }
+       o.NotificationDestination = &raw
+
+       return nil
+}
+
 // bindPolicyInstanceID binds and validates parameter PolicyInstanceID from path.
 func (o *A1ControllerGetPolicyInstanceParams) bindPolicyInstanceID(rawData []string, hasKey bool, formats strfmt.Registry) error {
        var raw string
@@ -101,7 +132,6 @@ func (o *A1ControllerGetPolicyInstanceParams) bindPolicyInstanceID(rawData []str
 
        // Required: true
        // Parameter is provided by construction from the route
-
        o.PolicyInstanceID = raw
 
        return nil
@@ -133,11 +163,11 @@ func (o *A1ControllerGetPolicyInstanceParams) bindPolicyTypeID(rawData []string,
 // validatePolicyTypeID carries on validations for parameter PolicyTypeID
 func (o *A1ControllerGetPolicyInstanceParams) validatePolicyTypeID(formats strfmt.Registry) error {
 
-       if err := validate.MinimumInt("policy_type_id", "path", int64(o.PolicyTypeID), 1, false); err != nil {
+       if err := validate.MinimumInt("policy_type_id", "path", o.PolicyTypeID, 1, false); err != nil {
                return err
        }
 
-       if err := validate.MaximumInt("policy_type_id", "path", int64(o.PolicyTypeID), 2.147483647e+09, false); err != nil {
+       if err := validate.MaximumInt("policy_type_id", "path", o.PolicyTypeID, 2.147483647e+09, false); err != nil {
                return err
        }
 
index d5bdfb3..4729b41 100644 (file)
@@ -26,6 +26,7 @@ package a1_mediator
 // Editing this file might prove futile when you re-run the generate command
 
 import (
+       "context"
        "encoding/json"
        "net/http"
 
@@ -54,7 +55,7 @@ func NewA1ControllerGetPolicyInstanceStatus(ctx *middleware.Context, handler A1C
        return &A1ControllerGetPolicyInstanceStatus{Context: ctx, Handler: handler}
 }
 
-/*A1ControllerGetPolicyInstanceStatus swagger:route GET /a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}/status A1 Mediator a1ControllerGetPolicyInstanceStatus
+/* A1ControllerGetPolicyInstanceStatus swagger:route GET /a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}/status A1 Mediator a1ControllerGetPolicyInstanceStatus
 
 Retrieve the policy instance status across all handlers of the policy If this endpoint returns successfully (200), it is either IN EFFECT or NOT IN EFFECT. IN EFFECT is returned if at least one policy handler in the RIC is implementing the policy NOT IN EFFECT is returned otherwise If a policy instance is successfully deleted, this endpoint will return a 404 (not a 200)
 
@@ -68,17 +69,15 @@ type A1ControllerGetPolicyInstanceStatus struct {
 func (o *A1ControllerGetPolicyInstanceStatus) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
        route, rCtx, _ := o.Context.RouteInfo(r)
        if rCtx != nil {
-               r = rCtx
+               *r = *rCtx
        }
        var Params = NewA1ControllerGetPolicyInstanceStatusParams()
-
        if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
                o.Context.Respond(rw, r, route.Produces, route, err)
                return
        }
 
        res := o.Handler.Handle(Params) // actually handle the request
-
        o.Context.Respond(rw, r, route.Produces, route, res)
 
 }
@@ -88,27 +87,24 @@ func (o *A1ControllerGetPolicyInstanceStatus) ServeHTTP(rw http.ResponseWriter,
 // swagger:model A1ControllerGetPolicyInstanceStatusOKBody
 type A1ControllerGetPolicyInstanceStatusOKBody struct {
 
-       // created at
-       // Format: date-time
-       CreatedAt strfmt.DateTime `json:"created_at,omitempty"`
+       // enforce reason
+       // Enum: [SCOPE_NOT_APPLICABLE STATEMENT_NOT_APPLICABLE OTHER_REASON]
+       EnforceReason string `json:"enforceReason,omitempty"`
 
-       // has been deleted
-       HasBeenDeleted bool `json:"has_been_deleted,omitempty"`
-
-       // instance status
-       // Enum: [IN EFFECT NOT IN EFFECT]
-       InstanceStatus string `json:"instance_status,omitempty"`
+       // enforce status
+       // Enum: [ENFORCED NOT_ENFORCED]
+       EnforceStatus string `json:"enforceStatus,omitempty"`
 }
 
 // Validate validates this a1 controller get policy instance status o k body
 func (o *A1ControllerGetPolicyInstanceStatusOKBody) Validate(formats strfmt.Registry) error {
        var res []error
 
-       if err := o.validateCreatedAt(formats); err != nil {
+       if err := o.validateEnforceReason(formats); err != nil {
                res = append(res, err)
        }
 
-       if err := o.validateInstanceStatus(formats); err != nil {
+       if err := o.validateEnforceStatus(formats); err != nil {
                res = append(res, err)
        }
 
@@ -118,62 +114,98 @@ func (o *A1ControllerGetPolicyInstanceStatusOKBody) Validate(formats strfmt.Regi
        return nil
 }
 
-func (o *A1ControllerGetPolicyInstanceStatusOKBody) validateCreatedAt(formats strfmt.Registry) error {
+var a1ControllerGetPolicyInstanceStatusOKBodyTypeEnforceReasonPropEnum []interface{}
+
+func init() {
+       var res []string
+       if err := json.Unmarshal([]byte(`["SCOPE_NOT_APPLICABLE","STATEMENT_NOT_APPLICABLE","OTHER_REASON"]`), &res); err != nil {
+               panic(err)
+       }
+       for _, v := range res {
+               a1ControllerGetPolicyInstanceStatusOKBodyTypeEnforceReasonPropEnum = append(a1ControllerGetPolicyInstanceStatusOKBodyTypeEnforceReasonPropEnum, v)
+       }
+}
+
+const (
+
+       // A1ControllerGetPolicyInstanceStatusOKBodyEnforceReasonSCOPENOTAPPLICABLE captures enum value "SCOPE_NOT_APPLICABLE"
+       A1ControllerGetPolicyInstanceStatusOKBodyEnforceReasonSCOPENOTAPPLICABLE string = "SCOPE_NOT_APPLICABLE"
 
-       if swag.IsZero(o.CreatedAt) { // not required
+       // A1ControllerGetPolicyInstanceStatusOKBodyEnforceReasonSTATEMENTNOTAPPLICABLE captures enum value "STATEMENT_NOT_APPLICABLE"
+       A1ControllerGetPolicyInstanceStatusOKBodyEnforceReasonSTATEMENTNOTAPPLICABLE string = "STATEMENT_NOT_APPLICABLE"
+
+       // A1ControllerGetPolicyInstanceStatusOKBodyEnforceReasonOTHERREASON captures enum value "OTHER_REASON"
+       A1ControllerGetPolicyInstanceStatusOKBodyEnforceReasonOTHERREASON string = "OTHER_REASON"
+)
+
+// prop value enum
+func (o *A1ControllerGetPolicyInstanceStatusOKBody) validateEnforceReasonEnum(path, location string, value string) error {
+       if err := validate.EnumCase(path, location, value, a1ControllerGetPolicyInstanceStatusOKBodyTypeEnforceReasonPropEnum, true); err != nil {
+               return err
+       }
+       return nil
+}
+
+func (o *A1ControllerGetPolicyInstanceStatusOKBody) validateEnforceReason(formats strfmt.Registry) error {
+       if swag.IsZero(o.EnforceReason) { // not required
                return nil
        }
 
-       if err := validate.FormatOf("a1ControllerGetPolicyInstanceStatusOK"+"."+"created_at", "body", "date-time", o.CreatedAt.String(), formats); err != nil {
+       // value enum
+       if err := o.validateEnforceReasonEnum("a1ControllerGetPolicyInstanceStatusOK"+"."+"enforceReason", "body", o.EnforceReason); err != nil {
                return err
        }
 
        return nil
 }
 
-var a1ControllerGetPolicyInstanceStatusOKBodyTypeInstanceStatusPropEnum []interface{}
+var a1ControllerGetPolicyInstanceStatusOKBodyTypeEnforceStatusPropEnum []interface{}
 
 func init() {
        var res []string
-       if err := json.Unmarshal([]byte(`["IN EFFECT","NOT IN EFFECT"]`), &res); err != nil {
+       if err := json.Unmarshal([]byte(`["ENFORCED","NOT_ENFORCED"]`), &res); err != nil {
                panic(err)
        }
        for _, v := range res {
-               a1ControllerGetPolicyInstanceStatusOKBodyTypeInstanceStatusPropEnum = append(a1ControllerGetPolicyInstanceStatusOKBodyTypeInstanceStatusPropEnum, v)
+               a1ControllerGetPolicyInstanceStatusOKBodyTypeEnforceStatusPropEnum = append(a1ControllerGetPolicyInstanceStatusOKBodyTypeEnforceStatusPropEnum, v)
        }
 }
 
 const (
 
-       // A1ControllerGetPolicyInstanceStatusOKBodyInstanceStatusINEFFECT captures enum value "IN EFFECT"
-       A1ControllerGetPolicyInstanceStatusOKBodyInstanceStatusINEFFECT string = "IN EFFECT"
+       // A1ControllerGetPolicyInstanceStatusOKBodyEnforceStatusENFORCED captures enum value "ENFORCED"
+       A1ControllerGetPolicyInstanceStatusOKBodyEnforceStatusENFORCED string = "ENFORCED"
 
-       // A1ControllerGetPolicyInstanceStatusOKBodyInstanceStatusNOTINEFFECT captures enum value "NOT IN EFFECT"
-       A1ControllerGetPolicyInstanceStatusOKBodyInstanceStatusNOTINEFFECT string = "NOT IN EFFECT"
+       // A1ControllerGetPolicyInstanceStatusOKBodyEnforceStatusNOTENFORCED captures enum value "NOT_ENFORCED"
+       A1ControllerGetPolicyInstanceStatusOKBodyEnforceStatusNOTENFORCED string = "NOT_ENFORCED"
 )
 
 // prop value enum
-func (o *A1ControllerGetPolicyInstanceStatusOKBody) validateInstanceStatusEnum(path, location string, value string) error {
-       if err := validate.Enum(path, location, value, a1ControllerGetPolicyInstanceStatusOKBodyTypeInstanceStatusPropEnum); err != nil {
+func (o *A1ControllerGetPolicyInstanceStatusOKBody) validateEnforceStatusEnum(path, location string, value string) error {
+       if err := validate.EnumCase(path, location, value, a1ControllerGetPolicyInstanceStatusOKBodyTypeEnforceStatusPropEnum, true); err != nil {
                return err
        }
        return nil
 }
 
-func (o *A1ControllerGetPolicyInstanceStatusOKBody) validateInstanceStatus(formats strfmt.Registry) error {
-
-       if swag.IsZero(o.InstanceStatus) { // not required
+func (o *A1ControllerGetPolicyInstanceStatusOKBody) validateEnforceStatus(formats strfmt.Registry) error {
+       if swag.IsZero(o.EnforceStatus) { // not required
                return nil
        }
 
        // value enum
-       if err := o.validateInstanceStatusEnum("a1ControllerGetPolicyInstanceStatusOK"+"."+"instance_status", "body", o.InstanceStatus); err != nil {
+       if err := o.validateEnforceStatusEnum("a1ControllerGetPolicyInstanceStatusOK"+"."+"enforceStatus", "body", o.EnforceStatus); err != nil {
                return err
        }
 
        return nil
 }
 
+// ContextValidate validates this a1 controller get policy instance status o k body based on context it is used
+func (o *A1ControllerGetPolicyInstanceStatusOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
+       return nil
+}
+
 // MarshalBinary interface implementation
 func (o *A1ControllerGetPolicyInstanceStatusOKBody) MarshalBinary() ([]byte, error) {
        if o == nil {
index 3ae0780..dbd35e3 100644 (file)
@@ -36,7 +36,8 @@ import (
 )
 
 // NewA1ControllerGetPolicyInstanceStatusParams creates a new A1ControllerGetPolicyInstanceStatusParams object
-// no default values defined in spec.
+//
+// There are no default values defined in the spec.
 func NewA1ControllerGetPolicyInstanceStatusParams() A1ControllerGetPolicyInstanceStatusParams {
 
        return A1ControllerGetPolicyInstanceStatusParams{}
@@ -85,7 +86,6 @@ func (o *A1ControllerGetPolicyInstanceStatusParams) BindRequest(r *http.Request,
        if err := o.bindPolicyTypeID(rPolicyTypeID, rhkPolicyTypeID, route.Formats); err != nil {
                res = append(res, err)
        }
-
        if len(res) > 0 {
                return errors.CompositeValidationError(res...)
        }
@@ -101,7 +101,6 @@ func (o *A1ControllerGetPolicyInstanceStatusParams) bindPolicyInstanceID(rawData
 
        // Required: true
        // Parameter is provided by construction from the route
-
        o.PolicyInstanceID = raw
 
        return nil
@@ -133,11 +132,11 @@ func (o *A1ControllerGetPolicyInstanceStatusParams) bindPolicyTypeID(rawData []s
 // validatePolicyTypeID carries on validations for parameter PolicyTypeID
 func (o *A1ControllerGetPolicyInstanceStatusParams) validatePolicyTypeID(formats strfmt.Registry) error {
 
-       if err := validate.MinimumInt("policy_type_id", "path", int64(o.PolicyTypeID), 1, false); err != nil {
+       if err := validate.MinimumInt("policy_type_id", "path", o.PolicyTypeID, 1, false); err != nil {
                return err
        }
 
-       if err := validate.MaximumInt("policy_type_id", "path", int64(o.PolicyTypeID), 2.147483647e+09, false); err != nil {
+       if err := validate.MaximumInt("policy_type_id", "path", o.PolicyTypeID, 2.147483647e+09, false); err != nil {
                return err
        }
 
index 856e61b..2bad387 100644 (file)
@@ -39,6 +39,8 @@ type A1ControllerGetPolicyInstanceURL struct {
        PolicyInstanceID string
        PolicyTypeID     int64
 
+       NotificationDestination *string
+
        _basePath string
        // avoid unkeyed usage
        _ struct{}
@@ -82,6 +84,18 @@ func (o *A1ControllerGetPolicyInstanceURL) Build() (*url.URL, error) {
        _basePath := o._basePath
        _result.Path = golangswaggerpaths.Join(_basePath, _path)
 
+       qs := make(url.Values)
+
+       var notificationDestinationQ string
+       if o.NotificationDestination != nil {
+               notificationDestinationQ = *o.NotificationDestination
+       }
+       if notificationDestinationQ != "" {
+               qs.Set("notificationDestination", notificationDestinationQ)
+       }
+
+       _result.RawQuery = qs.Encode()
+
        return &_result, nil
 }
 
index 4ab7c05..89bac68 100644 (file)
@@ -49,7 +49,7 @@ func NewA1ControllerGetPolicyType(ctx *middleware.Context, handler A1ControllerG
        return &A1ControllerGetPolicyType{Context: ctx, Handler: handler}
 }
 
-/*A1ControllerGetPolicyType swagger:route GET /a1-p/policytypes/{policy_type_id} A1 Mediator a1ControllerGetPolicyType
+/* A1ControllerGetPolicyType swagger:route GET /a1-p/policytypes/{policy_type_id} A1 Mediator a1ControllerGetPolicyType
 
 Get this policy type
 
@@ -63,17 +63,15 @@ type A1ControllerGetPolicyType struct {
 func (o *A1ControllerGetPolicyType) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
        route, rCtx, _ := o.Context.RouteInfo(r)
        if rCtx != nil {
-               r = rCtx
+               *r = *rCtx
        }
        var Params = NewA1ControllerGetPolicyTypeParams()
-
        if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
                o.Context.Respond(rw, r, route.Produces, route, err)
                return
        }
 
        res := o.Handler.Handle(Params) // actually handle the request
-
        o.Context.Respond(rw, r, route.Produces, route, res)
 
 }
index 9c39fcb..d8a5919 100644 (file)
@@ -36,7 +36,8 @@ import (
 )
 
 // NewA1ControllerGetPolicyTypeParams creates a new A1ControllerGetPolicyTypeParams object
-// no default values defined in spec.
+//
+// There are no default values defined in the spec.
 func NewA1ControllerGetPolicyTypeParams() A1ControllerGetPolicyTypeParams {
 
        return A1ControllerGetPolicyTypeParams{}
@@ -74,7 +75,6 @@ func (o *A1ControllerGetPolicyTypeParams) BindRequest(r *http.Request, route *mi
        if err := o.bindPolicyTypeID(rPolicyTypeID, rhkPolicyTypeID, route.Formats); err != nil {
                res = append(res, err)
        }
-
        if len(res) > 0 {
                return errors.CompositeValidationError(res...)
        }
@@ -107,11 +107,11 @@ func (o *A1ControllerGetPolicyTypeParams) bindPolicyTypeID(rawData []string, has
 // validatePolicyTypeID carries on validations for parameter PolicyTypeID
 func (o *A1ControllerGetPolicyTypeParams) validatePolicyTypeID(formats strfmt.Registry) error {
 
-       if err := validate.MinimumInt("policy_type_id", "path", int64(o.PolicyTypeID), 1, false); err != nil {
+       if err := validate.MinimumInt("policy_type_id", "path", o.PolicyTypeID, 1, false); err != nil {
                return err
        }
 
-       if err := validate.MaximumInt("policy_type_id", "path", int64(o.PolicyTypeID), 2.147483647e+09, false); err != nil {
+       if err := validate.MaximumInt("policy_type_id", "path", o.PolicyTypeID, 2.147483647e+09, false); err != nil {
                return err
        }
 
index 3b278d2..76bce5a 100644 (file)
@@ -30,7 +30,7 @@ import (
 
        "github.com/go-openapi/runtime"
 
-       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
 )
 
 // A1ControllerGetPolicyTypeOKCode is the HTTP code returned for type A1ControllerGetPolicyTypeOK
index 978fbee..8a6edbb 100644 (file)
@@ -45,7 +45,7 @@ import (
        flags "github.com/jessevdk/go-flags"
        "golang.org/x/net/netutil"
 
-       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations"
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations"
 )
 
 const (
@@ -325,9 +325,6 @@ func (s *Server) Serve() (err error) {
                        s.Fatalf("no certificate was configured for TLS")
                }
 
-               // must have at least one certificate or panics
-               httpsServer.TLSConfig.BuildNameToCertificate()
-
                configureServer(httpsServer, "https", s.httpsServerL.Addr().String())
 
                servers = append(servers, httpsServer)
index 44b3422..f7ce15b 100644 (file)
@@ -1,21 +1,23 @@
 /*
 ==================================================================================
-  Copyright (c) 2021 Samsung
 
-   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
+       Copyright (c) 2021 Samsung
 
-       http://www.apache.org/licenses/LICENSE-2.0
+        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
 
-   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.
+            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).
 
-   This source code is part of the near-RT RIC (RAN Intelligent Controller)
-   platform project (RICP).
 ==================================================================================
 */
 package restful
@@ -85,7 +87,12 @@ func (r *Restful) setupHandler() *operations.A1API {
 
        api.A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler = a1_mediator.A1ControllerCreateOrReplacePolicyInstanceHandlerFunc(func(params a1_mediator.A1ControllerCreateOrReplacePolicyInstanceParams) middleware.Responder {
                a1.Logger.Debug("handler for create policy type instance ")
-               if err = r.rh.CreatePolicyInstance(models.PolicyTypeID(params.PolicyTypeID), models.PolicyInstanceID(params.PolicyInstanceID), params.Body); err == nil {
+               var notificationDestination string
+               if params.NotificationDestination != nil {
+                       notificationDestination = *params.NotificationDestination
+               }
+               if err = r.rh.CreatePolicyInstance(models.PolicyTypeID(params.PolicyTypeID), models.PolicyInstanceID(params.PolicyInstanceID), params.Body, notificationDestination); err == nil {
+
                        return a1_mediator.NewA1ControllerCreateOrReplacePolicyInstanceAccepted()
                }
                if r.rh.IsValidJson(err) {
@@ -137,8 +144,7 @@ func (r *Restful) setupHandler() *operations.A1API {
                a1.Logger.Debug("handler for get policy instance status")
                if resp, err := r.rh.GetPolicyInstanceStatus(models.PolicyTypeID(params.PolicyTypeID), models.PolicyInstanceID(params.PolicyInstanceID)); err == nil {
                        return a1_mediator.NewA1ControllerGetPolicyInstanceStatusOK().WithPayload(resp)
-               }
-               if r.rh.IsPolicyInstanceNotFound(err) {
+               } else if r.rh.IsPolicyInstanceNotFound(err) {
                        return a1_mediator.NewA1ControllerGetPolicyInstanceStatusNotFound()
                }
                return a1_mediator.NewA1ControllerGetPolicyInstanceStatusServiceUnavailable()
index 0ab7f5f..8d91933 100644 (file)
@@ -1,28 +1,30 @@
 /*
 ==================================================================================
-  Copyright (c) 2021 Samsung
 
-   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
+       Copyright (c) 2021 Samsung
 
-       http://www.apache.org/licenses/LICENSE-2.0
+        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
 
-   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.
+            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).
 
-   This source code is part of the near-RT RIC (RAN Intelligent Controller)
-   platform project (RICP).
 ==================================================================================
 */
 package restful
 
 import (
-       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations"
-       resthook "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/resthooks"
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations"
+       resthook "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/resthooks"
 )
 
 type Restful struct {
index 733726f..803f1b7 100644 (file)
@@ -1,21 +1,23 @@
 /*
 ==================================================================================
-  Copyright (c) 2021 Samsung
 
-   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
+       Copyright (c) 2021 Samsung
 
-       http://www.apache.org/licenses/LICENSE-2.0
+        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
 
-   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.
+            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).
 
-   This source code is part of the near-RT RIC (RAN Intelligent Controller)
-   platform project (RICP).
 ==================================================================================
 */
 package resthooks
@@ -39,13 +41,14 @@ import (
 )
 
 const (
-       a1PolicyPrefix           = "a1.policy_type."
-       a1MediatorNs             = "A1m_ns"
-       a1InstancePrefix         = "a1.policy_instance."
-       a1InstanceMetadataPrefix = "a1.policy_inst_metadata."
-       a1HandlerPrefix          = "a1.policy_handler."
-       a1PolicyRequest          = 20010
-       a1EIDataDelivery         = 20017
+       a1PolicyPrefix                  = "a1.policy_type."
+       a1MediatorNs                    = "A1m_ns"
+       a1InstancePrefix                = "a1.policy_instance."
+       a1NotificationDestinationPrefix = "a1.policy_notification_destination."
+       a1InstanceMetadataPrefix        = "a1.policy_inst_metadata."
+       a1HandlerPrefix                 = "a1.policy_handler."
+       a1PolicyRequest                 = 20010
+       a1EIDataDelivery                = 20017
 )
 
 var typeAlreadyError = errors.New("Policy Type already exists")
@@ -65,7 +68,7 @@ func (rh *Resthook) CanPolicyTypeBeDeleted(err error) bool {
        return err == policyTypeCanNotBeDeletedError
 }
 
-func (rh *Resthook) IsPolicyTypePresent(err error) bool {
+func (rh *Resthook) IsPolicyTypeNotFound(err error) bool {
        return err == policyTypeNotFoundError
 }
 
@@ -272,7 +275,7 @@ func validate(httpBodyString string, schemaString string) bool {
        return true
 }
 
-func (rh *Resthook) storePolicyInstance(policyTypeId models.PolicyTypeID, policyInstanceID models.PolicyInstanceID, httpBody interface{}) (string, error) {
+func (rh *Resthook) storePolicyInstance(policyTypeId models.PolicyTypeID, policyInstanceID models.PolicyInstanceID, httpBody interface{}, notificationDestination string) (string, error) {
        var keys [1]string
        operation := "CREATE"
        typekey := a1PolicyPrefix + strconv.FormatInt((int64(policyTypeId)), 10)
@@ -292,6 +295,7 @@ func (rh *Resthook) storePolicyInstance(policyTypeId models.PolicyTypeID, policy
        // TODO : rmr creation_timestamp := time.Now() // will be needed for rmr to notify the creation of instance
 
        instancekey := a1InstancePrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + string(policyInstanceID)
+       notificationDestinationkey := a1NotificationDestinationPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + string(policyInstanceID)
        keys[0] = typekey
        instanceMap, err := rh.db.Get(a1MediatorNs, keys[:])
        if err != nil {
@@ -305,15 +309,22 @@ func (rh *Resthook) storePolicyInstance(policyTypeId models.PolicyTypeID, policy
                data, _ := json.Marshal(httpBody)
                a1.Logger.Debug("Marshaled String : %+v", string(data))
                a1.Logger.Debug("key   : %+v", instancekey)
-               success, err1 := rh.db.SetIf(a1MediatorNs, instancekey, instanceMap[instancekey], string(data))
-               if err1 != nil {
-                       a1.Logger.Error("error2 :%+v", err1)
-                       return operation, err1
+               success, err := rh.db.SetIf(a1MediatorNs, instancekey, instanceMap[instancekey], string(data))
+               if err != nil {
+                       a1.Logger.Error("error2 :%+v", err)
+                       return operation, err
                }
                if !success {
                        a1.Logger.Debug("Policy instance %+v already exist", policyInstanceID)
                        return operation, InstanceAlreadyError
                }
+
+               if len(notificationDestination) > 0 {
+                       if err = rh.db.Set(a1MediatorNs, notificationDestinationkey, notificationDestination); err != nil {
+                               a1.Logger.Error("error3 :%+v", err)
+                               return operation, err
+                       }
+               }
        } else {
                data, _ := json.Marshal(httpBody)
                a1.Logger.Debug("Marshaled String : %+v", string(data))
@@ -324,10 +335,15 @@ func (rh *Resthook) storePolicyInstance(policyTypeId models.PolicyTypeID, policy
                a1.Logger.Debug("policyinstancetype map : %+v", instance_map[1])
                a1.Logger.Debug("policyinstancetype to create : %+v", instance_map)
 
-               err1 := rh.db.Set(a1MediatorNs, instancekey, string(data))
-               if err1 != nil {
-                       a1.Logger.Error("error1 :%+v", err1)
-                       return operation, err1
+               if err = rh.db.Set(a1MediatorNs, instancekey, string(data)); err != nil {
+                       a1.Logger.Error("error4 :%+v", err)
+                       return operation, err
+               }
+               if len(notificationDestination) > 0 {
+                       if err := rh.db.Set(a1MediatorNs, notificationDestinationkey, notificationDestination); err != nil {
+                               a1.Logger.Error("error :%+v", err)
+                               return operation, err
+                       }
                }
        }
        a1.Logger.Debug("Policy Instance created ")
@@ -359,7 +375,7 @@ func (rh *Resthook) storePolicyInstanceMetadata(policyTypeId models.PolicyTypeID
        return true, nil
 }
 
-func (rh *Resthook) CreatePolicyInstance(policyTypeId models.PolicyTypeID, policyInstanceID models.PolicyInstanceID, httpBody interface{}) error {
+func (rh *Resthook) CreatePolicyInstance(policyTypeId models.PolicyTypeID, policyInstanceID models.PolicyInstanceID, httpBody interface{}, notificationDestination string) error {
        a1.Logger.Debug("CreatePolicyInstance function")
        //  validate the PUT against the schema
        var policyTypeSchema *models.PolicyTypeSchema
@@ -379,7 +395,7 @@ func (rh *Resthook) CreatePolicyInstance(policyTypeId models.PolicyTypeID, polic
        isvalid := validate(httpBodyString, schemaString)
        if isvalid {
                var operation string
-               operation, err = rh.storePolicyInstance(policyTypeId, policyInstanceID, httpBody)
+               operation, err = rh.storePolicyInstance(policyTypeId, policyInstanceID, httpBody, notificationDestination)
                if err != nil {
                        a1.Logger.Error("error :%+v", err)
                        return err
@@ -593,8 +609,9 @@ func (rh *Resthook) getPolicyInstanceStatus(policyTypeId models.PolicyTypeID, po
 func (rh *Resthook) GetPolicyInstanceStatus(policyTypeId models.PolicyTypeID, policyInstanceID models.PolicyInstanceID) (*a1_mediator.A1ControllerGetPolicyInstanceStatusOKBody, error) {
        err := rh.instanceValidity(policyTypeId, policyInstanceID)
        policyInstanceStatus := a1_mediator.A1ControllerGetPolicyInstanceStatusOKBody{}
-       policyInstanceStatus.InstanceStatus = "NOT IN EFFECT"
-       if err != nil && err == policyInstanceNotFoundError || err == policyTypeNotFoundError {
+       policyInstanceStatus.EnforceStatus = "NOT_ENFORCED"
+       policyInstanceStatus.EnforceReason = "OTHER_REASON"
+       if err != nil && (err == policyInstanceNotFoundError || err == policyTypeNotFoundError) {
                return &policyInstanceStatus, err
        }
        metadata, err := rh.getMetaData(policyTypeId, policyInstanceID)
@@ -614,13 +631,13 @@ func (rh *Resthook) GetPolicyInstanceStatus(policyTypeId models.PolicyTypeID, po
                //this error maps to 503 error but can be mapped to 500: internal error
                return &policyInstanceStatus, err
        }
-       resp, err := rh.getPolicyInstanceStatus(policyTypeId, policyInstanceID)
-       if err != nil || (err == nil && resp == false) {
+       enforced, err := rh.getPolicyInstanceStatus(policyTypeId, policyInstanceID)
+       if err != nil || (err == nil && !enforced) {
                a1.Logger.Error("marshal error : %v", err)
                return &policyInstanceStatus, err
-       } else if policyInstanceStatus.HasBeenDeleted == true {
-               policyInstanceStatus.InstanceStatus = "IN EFFECT"
        }
+       policyInstanceStatus.EnforceStatus = "ENFORCED"
+       policyInstanceStatus.EnforceReason = ""
        return &policyInstanceStatus, nil
 }
 
@@ -656,12 +673,25 @@ func (rh *Resthook) deleteInstancedata(policyTypeId models.PolicyTypeID, policyI
        keys[0] = instancekey
        err := rh.db.Remove(a1MediatorNs, keys[:])
        if err != nil {
-               a1.Logger.Error("error in deleting policy type err: %v", err)
+               a1.Logger.Error("error in deleting policy instance err: %v", err)
                return err
        }
        return nil
 }
 
+func (rh *Resthook) deleteNotificationDestination(policyTypeId models.PolicyTypeID, policyInstanceID models.PolicyInstanceID) error {
+       var keys [1]string
+       notificationDestinationkey := a1NotificationDestinationPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + string(policyInstanceID)
+       keys[0] = notificationDestinationkey
+       err := rh.db.Remove(a1MediatorNs, keys[:])
+       if err != nil {
+               a1.Logger.Error("error in deleting notificationDestination err: %v", err)
+               return err
+       }
+
+       return nil
+}
+
 func (rh *Resthook) deleteMetadata(policyTypeId models.PolicyTypeID, policyInstanceID models.PolicyInstanceID) error {
        var keys [1]string
        instanceMetadataKey := a1InstanceMetadataPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + string(policyInstanceID)
@@ -709,6 +739,8 @@ func (rh *Resthook) DeletePolicyInstance(policyTypeId models.PolicyTypeID, polic
 
        rh.deleteInstancedata(policyTypeId, policyInstanceID)
 
+       rh.deleteNotificationDestination(policyTypeId, policyInstanceID)
+
        rh.storeDeletedPolicyInstanceMetadata(policyTypeId, policyInstanceID, creation_timestamp.(string))
 
        message := rmr.Message{}
index 11afe47..db5b5ab 100644 (file)
@@ -1,21 +1,23 @@
 /*
 ==================================================================================
-  Copyright (c) 2021 Samsung
 
-   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
+       Copyright (c) 2021 Samsung
 
-       http://www.apache.org/licenses/LICENSE-2.0
+        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
 
-   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.
+            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).
 
-   This source code is part of the near-RT RIC (RAN Intelligent Controller)
-   platform project (RICP).
 ==================================================================================
 */
 package resthooks
@@ -157,7 +159,7 @@ func TestCreatePolicyTypeInstance(t *testing.T) {
        sdlInst.On("Set", "A1m_ns", metadatainstancearr).Return(nil)
        rmrSenderInst.On("RmrSendToXapp", "httpBodyString", 20010, int(policyTypeId)).Return(true)
 
-       errresp := rh.CreatePolicyInstance(policyTypeId, policyInstanceID, instancedata)
+       errresp := rh.CreatePolicyInstance(policyTypeId, policyInstanceID, instancedata, "")
 
        assert.Nil(t, errresp)
        sdlInst.AssertExpectations(t)
@@ -254,7 +256,9 @@ func TestDeletePolicyInstance(t *testing.T) {
        description := "various parameters to control admission of dual connection"
        policyTypeSchema.Description = &description
        schema := `{"$schema": "http://json-schema.org/draft-07/schema#","type":"object","properties": {"enforce": {"type":"boolean","default":"true",},"window_length": {"type":        "integer","default":1,"minimum":1,"maximum":60,"description": "Sliding window length (in minutes)",},
+
 "blocking_rate": {"type":"number","default":10,"minimum":1,"maximum":100,"description": "% Connections to block",},"additionalProperties": false,},}`
+
        policyTypeSchema.CreateSchema = schema
 
        key := a1PolicyPrefix + strconv.FormatInt((int64(policyTypeId)), 10)
@@ -264,11 +268,11 @@ func TestDeletePolicyInstance(t *testing.T) {
        sdlInst.On("Get", a1MediatorNs, policytypekeys[:]).Return(map[string]interface{}{key: policyTypeSchema}, nil)
 
        httpBody := `{
-               "enforce":true,
-               "window_length":20,
-          "blocking_rate":20,
-               "trigger_threshold":10
-               }`
+                       "enforce":true,
+                       "window_length":20,
+                  "blocking_rate":20,
+                       "trigger_threshold":10
+                       }`
        instancekey := a1InstancePrefix + strconv.FormatInt(20001, 10) + "." + string(policyInstanceID)
        var instancekeys [1]string
        instancekeys[0] = instancekey
@@ -279,9 +283,9 @@ func TestDeletePolicyInstance(t *testing.T) {
        instanceMetadataKey := a1InstanceMetadataPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + string(policyInstanceID)
        instanceMetadataKeys[0] = instanceMetadataKey
        httpBody = `{
-               "created_at":"2022-11-02 10:30:20",
-                       "instance_status":"NOT IN EFFECT"
-               }`
+                       "created_at":"2022-11-02 10:30:20",
+                               "instance_status":"NOT IN EFFECT"
+                       }`
 
        sdlInst.On("Get", a1MediatorNs, instanceMetadataKeys[:]).Return(httpBody, nil)
 
@@ -304,7 +308,10 @@ func TestDeletePolicyInstance(t *testing.T) {
        httpBodyString := `{"operation":"DELETE","payload":"","policy_instance_id":"123456","policy_type_id":"20001"}`
 
        rmrSenderInst.On("RmrSendToXapp", httpBodyString, 20010, int(policyTypeId)).Return(true)
-
+       notificationDestinationkey := a1NotificationDestinationPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + string(policyInstanceID)
+       var notificationDestinationkeys [1]string
+       notificationDestinationkeys[0] = notificationDestinationkey
+       sdlInst.On("Remove", a1MediatorNs, notificationDestinationkeys[:]).Return(nil)
        errresp := rh.DeletePolicyInstance(policyTypeId, policyInstanceID)
 
        assert.Nil(t, errresp)
index d9ec0f0..c112b20 100644 (file)
@@ -136,8 +136,18 @@ func (rmr *RmrSender) Consume(msg *xapp.RMRParams) (err error) {
                        a1.Logger.Error("Unmarshal error : %+v", err)
                        return err
                }
-               a1.Logger.Debug("message recieved for %d and %d with status : %s", result["policy_type_id"], result["policy_instance_id"], result["status"])
-               rmr.policyManager.SetPolicyInstanceStatus(int(result["policy_type_id"].(float64)), int(result["policy_instance_id"].(float64)), result["status"].(string))
+               policyTypeId := int(result["policy_type_id"].(float64))
+               policyInstanceId := result["policy_instance_id"].(string)
+               policyHandlerId := result["handler_id"].(string)
+               policyStatus := result["status"].(string)
+
+               a1.Logger.Debug("message recieved for %d and %s with status : %s", policyTypeId, policyInstanceId, policyStatus)
+               rmr.policyManager.SetPolicyInstanceStatus(policyTypeId, policyInstanceId, policyStatus)
+               err = rmr.policyManager.SendPolicyStatusNotification(policyTypeId, policyInstanceId, policyHandlerId, policyStatus)
+               if err != nil {
+                       a1.Logger.Debug("failed to send policy status notification %v+", err)
+               }
+
        case "A1_POLICY_QUERY":
                a1.Logger.Debug("Recived policy query")
                a1.Logger.Debug("message recieved ", msg.Payload)