From: Mohamed Abukar Date: Tue, 18 Feb 2020 14:50:32 +0000 (+0200) Subject: Get interface for subscriptions X-Git-Tag: v0.0.27^0 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=9568a2d73b96516b27f54650e309f0d157fb97d9;p=ric-plt%2Fxapp-frame.git Get interface for subscriptions Change-Id: I11d351c6e3de9fcdc1f4e1a7937054c091bd870e Signed-off-by: Mohamed Abukar --- diff --git a/api/xapp_rest_api.yaml b/api/xapp_rest_api.yaml index dbdfced..f5a6f57 100755 --- a/api/xapp_rest_api.yaml +++ b/api/xapp_rest_api.yaml @@ -11,6 +11,21 @@ basePath: /ric/v1 schemes: - http paths: + /subscriptions: + get: + summary: Returns list of subscriptions + tags: + - "query" + operationId: getAllSubscriptions + produces: + - application/json + responses: + '200': + description: successful query of subscriptions + schema: + $ref: '#/definitions/SubscriptionList' + '500': + description: Internal error /subscriptions/report: post: tags: @@ -162,4 +177,20 @@ definitions: RequestorId: type: integer TBD: - type: string \ No newline at end of file + type: string + SubscriptionData: + type: object + properties: + SubscriptionId: + type: integer + Meid: + type: string + Endpoint: + type: array + items: + type: string + SubscriptionList: + type: array + description: A list of subscriptions + items: + $ref: '#/definitions/SubscriptionData' \ No newline at end of file diff --git a/pkg/clientapi/query/get_all_subscriptions_parameters.go b/pkg/clientapi/query/get_all_subscriptions_parameters.go new file mode 100644 index 0000000..94f3b84 --- /dev/null +++ b/pkg/clientapi/query/get_all_subscriptions_parameters.go @@ -0,0 +1,113 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package query + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetAllSubscriptionsParams creates a new GetAllSubscriptionsParams object +// with the default values initialized. +func NewGetAllSubscriptionsParams() *GetAllSubscriptionsParams { + + return &GetAllSubscriptionsParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewGetAllSubscriptionsParamsWithTimeout creates a new GetAllSubscriptionsParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetAllSubscriptionsParamsWithTimeout(timeout time.Duration) *GetAllSubscriptionsParams { + + return &GetAllSubscriptionsParams{ + + timeout: timeout, + } +} + +// NewGetAllSubscriptionsParamsWithContext creates a new GetAllSubscriptionsParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetAllSubscriptionsParamsWithContext(ctx context.Context) *GetAllSubscriptionsParams { + + return &GetAllSubscriptionsParams{ + + Context: ctx, + } +} + +// NewGetAllSubscriptionsParamsWithHTTPClient creates a new GetAllSubscriptionsParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetAllSubscriptionsParamsWithHTTPClient(client *http.Client) *GetAllSubscriptionsParams { + + return &GetAllSubscriptionsParams{ + HTTPClient: client, + } +} + +/*GetAllSubscriptionsParams contains all the parameters to send to the API endpoint +for the get all subscriptions operation typically these are written to a http.Request +*/ +type GetAllSubscriptionsParams struct { + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get all subscriptions params +func (o *GetAllSubscriptionsParams) WithTimeout(timeout time.Duration) *GetAllSubscriptionsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get all subscriptions params +func (o *GetAllSubscriptionsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get all subscriptions params +func (o *GetAllSubscriptionsParams) WithContext(ctx context.Context) *GetAllSubscriptionsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get all subscriptions params +func (o *GetAllSubscriptionsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get all subscriptions params +func (o *GetAllSubscriptionsParams) WithHTTPClient(client *http.Client) *GetAllSubscriptionsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get all subscriptions params +func (o *GetAllSubscriptionsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WriteToRequest writes these params to a swagger request +func (o *GetAllSubscriptionsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/pkg/clientapi/query/get_all_subscriptions_responses.go b/pkg/clientapi/query/get_all_subscriptions_responses.go new file mode 100644 index 0000000..801104a --- /dev/null +++ b/pkg/clientapi/query/get_all_subscriptions_responses.go @@ -0,0 +1,93 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package query + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + clientmodel "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientmodel" +) + +// GetAllSubscriptionsReader is a Reader for the GetAllSubscriptions structure. +type GetAllSubscriptionsReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetAllSubscriptionsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewGetAllSubscriptionsOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 500: + result := NewGetAllSubscriptionsInternalServerError() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewGetAllSubscriptionsOK creates a GetAllSubscriptionsOK with default headers values +func NewGetAllSubscriptionsOK() *GetAllSubscriptionsOK { + return &GetAllSubscriptionsOK{} +} + +/*GetAllSubscriptionsOK handles this case with default header values. + +successful query of subscriptions +*/ +type GetAllSubscriptionsOK struct { + Payload clientmodel.SubscriptionList +} + +func (o *GetAllSubscriptionsOK) Error() string { + return fmt.Sprintf("[GET /subscriptions][%d] getAllSubscriptionsOK %+v", 200, o.Payload) +} + +func (o *GetAllSubscriptionsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetAllSubscriptionsInternalServerError creates a GetAllSubscriptionsInternalServerError with default headers values +func NewGetAllSubscriptionsInternalServerError() *GetAllSubscriptionsInternalServerError { + return &GetAllSubscriptionsInternalServerError{} +} + +/*GetAllSubscriptionsInternalServerError handles this case with default header values. + +Internal error +*/ +type GetAllSubscriptionsInternalServerError struct { +} + +func (o *GetAllSubscriptionsInternalServerError) Error() string { + return fmt.Sprintf("[GET /subscriptions][%d] getAllSubscriptionsInternalServerError ", 500) +} + +func (o *GetAllSubscriptionsInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} diff --git a/pkg/clientapi/query/query_client.go b/pkg/clientapi/query/query_client.go new file mode 100644 index 0000000..a73fd7e --- /dev/null +++ b/pkg/clientapi/query/query_client.go @@ -0,0 +1,58 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package query + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" +) + +// New creates a new query API client. +func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client { + return &Client{transport: transport, formats: formats} +} + +/* +Client for query API +*/ +type Client struct { + transport runtime.ClientTransport + formats strfmt.Registry +} + +/* +GetAllSubscriptions returns list of subscriptions +*/ +func (a *Client) GetAllSubscriptions(params *GetAllSubscriptionsParams) (*GetAllSubscriptionsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetAllSubscriptionsParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "getAllSubscriptions", + Method: "GET", + PathPattern: "/subscriptions", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{""}, + Schemes: []string{"http"}, + Params: params, + Reader: &GetAllSubscriptionsReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*GetAllSubscriptionsOK), nil + +} + +// SetTransport changes the transport on the client +func (a *Client) SetTransport(transport runtime.ClientTransport) { + a.transport = transport +} diff --git a/pkg/clientapi/r_i_c_subscription_client.go b/pkg/clientapi/r_i_c_subscription_client.go index 91c32aa..7591e49 100644 --- a/pkg/clientapi/r_i_c_subscription_client.go +++ b/pkg/clientapi/r_i_c_subscription_client.go @@ -14,6 +14,7 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientapi/common" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientapi/control" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientapi/policy" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientapi/query" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientapi/report" ) @@ -66,6 +67,8 @@ func New(transport runtime.ClientTransport, formats strfmt.Registry) *RICSubscri cli.Policy = policy.New(transport, formats) + cli.Query = query.New(transport, formats) + cli.Report = report.New(transport, formats) return cli @@ -118,6 +121,8 @@ type RICSubscription struct { Policy *policy.Client + Query *query.Client + Report *report.Client Transport runtime.ClientTransport @@ -133,6 +138,8 @@ func (c *RICSubscription) SetTransport(transport runtime.ClientTransport) { c.Policy.SetTransport(transport) + c.Query.SetTransport(transport) + c.Report.SetTransport(transport) } diff --git a/pkg/clientmodel/subscription_data.go b/pkg/clientmodel/subscription_data.go new file mode 100644 index 0000000..8d22352 --- /dev/null +++ b/pkg/clientmodel/subscription_data.go @@ -0,0 +1,49 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package clientmodel + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// SubscriptionData subscription data +// swagger:model SubscriptionData +type SubscriptionData struct { + + // endpoint + Endpoint []string `json:"Endpoint"` + + // meid + Meid string `json:"Meid,omitempty"` + + // subscription Id + SubscriptionID int64 `json:"SubscriptionId,omitempty"` +} + +// Validate validates this subscription data +func (m *SubscriptionData) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *SubscriptionData) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *SubscriptionData) UnmarshalBinary(b []byte) error { + var res SubscriptionData + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/pkg/clientmodel/subscription_list.go b/pkg/clientmodel/subscription_list.go new file mode 100644 index 0000000..e5b7479 --- /dev/null +++ b/pkg/clientmodel/subscription_list.go @@ -0,0 +1,45 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package clientmodel + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "strconv" + + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" +) + +// SubscriptionList A list of subscriptions +// swagger:model SubscriptionList +type SubscriptionList []*SubscriptionData + +// Validate validates this subscription list +func (m SubscriptionList) Validate(formats strfmt.Registry) error { + var res []error + + for i := 0; i < len(m); i++ { + if swag.IsZero(m[i]) { // not required + continue + } + + if m[i] != nil { + if err := m[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName(strconv.Itoa(i)) + } + return err + } + } + + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/pkg/models/subscription_data.go b/pkg/models/subscription_data.go new file mode 100644 index 0000000..a297e62 --- /dev/null +++ b/pkg/models/subscription_data.go @@ -0,0 +1,49 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// SubscriptionData subscription data +// swagger:model SubscriptionData +type SubscriptionData struct { + + // endpoint + Endpoint []string `json:"Endpoint"` + + // meid + Meid string `json:"Meid,omitempty"` + + // subscription Id + SubscriptionID int64 `json:"SubscriptionId,omitempty"` +} + +// Validate validates this subscription data +func (m *SubscriptionData) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *SubscriptionData) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *SubscriptionData) UnmarshalBinary(b []byte) error { + var res SubscriptionData + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/pkg/models/subscription_list.go b/pkg/models/subscription_list.go new file mode 100644 index 0000000..5059e21 --- /dev/null +++ b/pkg/models/subscription_list.go @@ -0,0 +1,45 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "strconv" + + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" +) + +// SubscriptionList A list of subscriptions +// swagger:model SubscriptionList +type SubscriptionList []*SubscriptionData + +// Validate validates this subscription list +func (m SubscriptionList) Validate(formats strfmt.Registry) error { + var res []error + + for i := 0; i < len(m); i++ { + if swag.IsZero(m[i]) { // not required + continue + } + + if m[i] != nil { + if err := m[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName(strconv.Itoa(i)) + } + return err + } + } + + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/pkg/restapi/embedded_spec.go b/pkg/restapi/embedded_spec.go index 4498b5b..a4b2585 100644 --- a/pkg/restapi/embedded_spec.go +++ b/pkg/restapi/embedded_spec.go @@ -34,6 +34,29 @@ func init() { "host": "hostname", "basePath": "/ric/v1", "paths": { + "/subscriptions": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "query" + ], + "summary": "Returns list of subscriptions", + "operationId": "getAllSubscriptions", + "responses": { + "200": { + "description": "successful query of subscriptions", + "schema": { + "$ref": "#/definitions/SubscriptionList" + } + }, + "500": { + "description": "Internal error" + } + } + } + }, "/subscriptions/control": { "post": { "consumes": [ @@ -250,6 +273,30 @@ func init() { } } }, + "SubscriptionData": { + "type": "object", + "properties": { + "Endpoint": { + "type": "array", + "items": { + "type": "string" + } + }, + "Meid": { + "type": "string" + }, + "SubscriptionId": { + "type": "integer" + } + } + }, + "SubscriptionList": { + "description": "A list of subscriptions", + "type": "array", + "items": { + "$ref": "#/definitions/SubscriptionData" + } + }, "SubscriptionResult": { "description": "A list of unique IDs", "type": "array", @@ -285,6 +332,29 @@ func init() { "host": "hostname", "basePath": "/ric/v1", "paths": { + "/subscriptions": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "query" + ], + "summary": "Returns list of subscriptions", + "operationId": "getAllSubscriptions", + "responses": { + "200": { + "description": "successful query of subscriptions", + "schema": { + "$ref": "#/definitions/SubscriptionList" + } + }, + "500": { + "description": "Internal error" + } + } + } + }, "/subscriptions/control": { "post": { "consumes": [ @@ -501,6 +571,30 @@ func init() { } } }, + "SubscriptionData": { + "type": "object", + "properties": { + "Endpoint": { + "type": "array", + "items": { + "type": "string" + } + }, + "Meid": { + "type": "string" + }, + "SubscriptionId": { + "type": "integer" + } + } + }, + "SubscriptionList": { + "description": "A list of subscriptions", + "type": "array", + "items": { + "$ref": "#/definitions/SubscriptionData" + } + }, "SubscriptionResult": { "description": "A list of unique IDs", "type": "array", diff --git a/pkg/restapi/operations/query/get_all_subscriptions.go b/pkg/restapi/operations/query/get_all_subscriptions.go new file mode 100644 index 0000000..2a6a6e8 --- /dev/null +++ b/pkg/restapi/operations/query/get_all_subscriptions.go @@ -0,0 +1,58 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package query + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// GetAllSubscriptionsHandlerFunc turns a function with the right signature into a get all subscriptions handler +type GetAllSubscriptionsHandlerFunc func(GetAllSubscriptionsParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetAllSubscriptionsHandlerFunc) Handle(params GetAllSubscriptionsParams) middleware.Responder { + return fn(params) +} + +// GetAllSubscriptionsHandler interface for that can handle valid get all subscriptions params +type GetAllSubscriptionsHandler interface { + Handle(GetAllSubscriptionsParams) middleware.Responder +} + +// NewGetAllSubscriptions creates a new http.Handler for the get all subscriptions operation +func NewGetAllSubscriptions(ctx *middleware.Context, handler GetAllSubscriptionsHandler) *GetAllSubscriptions { + return &GetAllSubscriptions{Context: ctx, Handler: handler} +} + +/*GetAllSubscriptions swagger:route GET /subscriptions query getAllSubscriptions + +Returns list of subscriptions + +*/ +type GetAllSubscriptions struct { + Context *middleware.Context + Handler GetAllSubscriptionsHandler +} + +func (o *GetAllSubscriptions) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewGetAllSubscriptionsParams() + + 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) + +} diff --git a/pkg/restapi/operations/query/get_all_subscriptions_parameters.go b/pkg/restapi/operations/query/get_all_subscriptions_parameters.go new file mode 100644 index 0000000..a9aca80 --- /dev/null +++ b/pkg/restapi/operations/query/get_all_subscriptions_parameters.go @@ -0,0 +1,45 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package query + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" +) + +// NewGetAllSubscriptionsParams creates a new GetAllSubscriptionsParams object +// no default values defined in spec. +func NewGetAllSubscriptionsParams() GetAllSubscriptionsParams { + + return GetAllSubscriptionsParams{} +} + +// GetAllSubscriptionsParams contains all the bound params for the get all subscriptions operation +// typically these are obtained from a http.Request +// +// swagger:parameters getAllSubscriptions +type GetAllSubscriptionsParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetAllSubscriptionsParams() beforehand. +func (o *GetAllSubscriptionsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/pkg/restapi/operations/query/get_all_subscriptions_responses.go b/pkg/restapi/operations/query/get_all_subscriptions_responses.go new file mode 100644 index 0000000..485f1b8 --- /dev/null +++ b/pkg/restapi/operations/query/get_all_subscriptions_responses.go @@ -0,0 +1,85 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package query + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + models "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models" +) + +// GetAllSubscriptionsOKCode is the HTTP code returned for type GetAllSubscriptionsOK +const GetAllSubscriptionsOKCode int = 200 + +/*GetAllSubscriptionsOK successful query of subscriptions + +swagger:response getAllSubscriptionsOK +*/ +type GetAllSubscriptionsOK struct { + + /* + In: Body + */ + Payload models.SubscriptionList `json:"body,omitempty"` +} + +// NewGetAllSubscriptionsOK creates GetAllSubscriptionsOK with default headers values +func NewGetAllSubscriptionsOK() *GetAllSubscriptionsOK { + + return &GetAllSubscriptionsOK{} +} + +// WithPayload adds the payload to the get all subscriptions o k response +func (o *GetAllSubscriptionsOK) WithPayload(payload models.SubscriptionList) *GetAllSubscriptionsOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get all subscriptions o k response +func (o *GetAllSubscriptionsOK) SetPayload(payload models.SubscriptionList) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetAllSubscriptionsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if payload == nil { + // return empty array + payload = models.SubscriptionList{} + } + + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// GetAllSubscriptionsInternalServerErrorCode is the HTTP code returned for type GetAllSubscriptionsInternalServerError +const GetAllSubscriptionsInternalServerErrorCode int = 500 + +/*GetAllSubscriptionsInternalServerError Internal error + +swagger:response getAllSubscriptionsInternalServerError +*/ +type GetAllSubscriptionsInternalServerError struct { +} + +// NewGetAllSubscriptionsInternalServerError creates GetAllSubscriptionsInternalServerError with default headers values +func NewGetAllSubscriptionsInternalServerError() *GetAllSubscriptionsInternalServerError { + + return &GetAllSubscriptionsInternalServerError{} +} + +// WriteResponse to the client +func (o *GetAllSubscriptionsInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(500) +} diff --git a/pkg/restapi/operations/query/get_all_subscriptions_urlbuilder.go b/pkg/restapi/operations/query/get_all_subscriptions_urlbuilder.go new file mode 100644 index 0000000..7ef157a --- /dev/null +++ b/pkg/restapi/operations/query/get_all_subscriptions_urlbuilder.go @@ -0,0 +1,87 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package query + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// GetAllSubscriptionsURL generates an URL for the get all subscriptions operation +type GetAllSubscriptionsURL struct { + _basePath string +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetAllSubscriptionsURL) WithBasePath(bp string) *GetAllSubscriptionsURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetAllSubscriptionsURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetAllSubscriptionsURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/subscriptions" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/ric/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetAllSubscriptionsURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetAllSubscriptionsURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetAllSubscriptionsURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetAllSubscriptionsURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetAllSubscriptionsURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetAllSubscriptionsURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/pkg/restapi/operations/xapp_framework_api.go b/pkg/restapi/operations/xapp_framework_api.go index 28f71f2..5c85580 100644 --- a/pkg/restapi/operations/xapp_framework_api.go +++ b/pkg/restapi/operations/xapp_framework_api.go @@ -22,6 +22,7 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/common" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/control" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/policy" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/query" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/report" ) @@ -45,6 +46,9 @@ func NewXappFrameworkAPI(spec *loads.Document) *XappFrameworkAPI { CommonUnsubscribeHandler: common.UnsubscribeHandlerFunc(func(params common.UnsubscribeParams) middleware.Responder { return middleware.NotImplemented("operation CommonUnsubscribe has not yet been implemented") }), + QueryGetAllSubscriptionsHandler: query.GetAllSubscriptionsHandlerFunc(func(params query.GetAllSubscriptionsParams) middleware.Responder { + return middleware.NotImplemented("operation QueryGetAllSubscriptions has not yet been implemented") + }), ControlSubscribeControlHandler: control.SubscribeControlHandlerFunc(func(params control.SubscribeControlParams) middleware.Responder { return middleware.NotImplemented("operation ControlSubscribeControl has not yet been implemented") }), @@ -87,6 +91,8 @@ type XappFrameworkAPI struct { // CommonUnsubscribeHandler sets the operation handler for the unsubscribe operation CommonUnsubscribeHandler common.UnsubscribeHandler + // QueryGetAllSubscriptionsHandler sets the operation handler for the get all subscriptions operation + QueryGetAllSubscriptionsHandler query.GetAllSubscriptionsHandler // ControlSubscribeControlHandler sets the operation handler for the subscribe control operation ControlSubscribeControlHandler control.SubscribeControlHandler // PolicySubscribePolicyHandler sets the operation handler for the subscribe policy operation @@ -160,6 +166,10 @@ func (o *XappFrameworkAPI) Validate() error { unregistered = append(unregistered, "common.UnsubscribeHandler") } + if o.QueryGetAllSubscriptionsHandler == nil { + unregistered = append(unregistered, "query.GetAllSubscriptionsHandler") + } + if o.ControlSubscribeControlHandler == nil { unregistered = append(unregistered, "control.SubscribeControlHandler") } @@ -275,6 +285,11 @@ func (o *XappFrameworkAPI) initHandlerCache() { } o.handlers["DELETE"]["/subscriptions/{subscriptionId}"] = common.NewUnsubscribe(o.context, o.CommonUnsubscribeHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/subscriptions"] = query.NewGetAllSubscriptions(o.context, o.QueryGetAllSubscriptionsHandler) + if o.handlers["POST"] == nil { o.handlers["POST"] = make(map[string]http.Handler) } diff --git a/pkg/restapi/server.go b/pkg/restapi/server.go index 544be19..23fda83 100644 --- a/pkg/restapi/server.go +++ b/pkg/restapi/server.go @@ -489,7 +489,7 @@ func (s *Server) TLSListener() (net.Listener, error) { func handleInterrupt(once *sync.Once, s *Server) { once.Do(func() { - for _ = range s.interrupt { + for range s.interrupt { if s.interrupted { s.Logf("Server already shutting down") continue diff --git a/pkg/xapp/subscription.go b/pkg/xapp/subscription.go index 1cdce82..2090123 100755 --- a/pkg/xapp/subscription.go +++ b/pkg/xapp/subscription.go @@ -20,10 +20,14 @@ package xapp import ( + "encoding/json" + "fmt" "github.com/go-openapi/loads" httptransport "github.com/go-openapi/runtime/client" "github.com/go-openapi/runtime/middleware" "github.com/go-openapi/strfmt" + "io/ioutil" + "net/http" "time" apiclient "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientapi" @@ -37,10 +41,12 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/control" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/policy" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/query" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/report" ) -type SubscriptionReportHandler func(models.SubscriptionType, interface{}) (models.SubscriptionResult, error) +type SubscriptionHandler func(models.SubscriptionType, interface{}) (models.SubscriptionResult, error) +type SubscriptionQueryHandler func() (models.SubscriptionList, error) type Subscriber struct { localAddr string @@ -71,7 +77,7 @@ func NewSubscriber(host string, timo int) *Subscriber { } // Server interface: listen and receive subscription requests -func (r *Subscriber) Listen(handler SubscriptionReportHandler) error { +func (r *Subscriber) Listen(subHandler SubscriptionHandler, queryHandler SubscriptionQueryHandler) error { swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON) if err != nil { return err @@ -79,10 +85,19 @@ func (r *Subscriber) Listen(handler SubscriptionReportHandler) error { api := operations.NewXappFrameworkAPI(swaggerSpec) + // Subscription: query + api.QueryGetAllSubscriptionsHandler = query.GetAllSubscriptionsHandlerFunc( + func(p query.GetAllSubscriptionsParams) middleware.Responder { + if resp, err := queryHandler(); err == nil { + return query.NewGetAllSubscriptionsOK().WithPayload(resp) + } + return query.NewGetAllSubscriptionsInternalServerError() + }) + // SubscriptionType: Report api.ReportSubscribeReportHandler = report.SubscribeReportHandlerFunc( func(p report.SubscribeReportParams) middleware.Responder { - if resp, err := handler(models.SubscriptionTypeReport, p.ReportParams); err == nil { + if resp, err := subHandler(models.SubscriptionTypeReport, p.ReportParams); err == nil { return report.NewSubscribeReportCreated().WithPayload(resp) } return report.NewSubscribeReportInternalServerError() @@ -91,7 +106,7 @@ func (r *Subscriber) Listen(handler SubscriptionReportHandler) error { // SubscriptionType: Control api.ControlSubscribeControlHandler = control.SubscribeControlHandlerFunc( func(p control.SubscribeControlParams) middleware.Responder { - if resp, err := handler(models.SubscriptionTypeControl, p.ControlParams); err == nil { + if resp, err := subHandler(models.SubscriptionTypeControl, p.ControlParams); err == nil { return control.NewSubscribeControlCreated().WithPayload(resp) } return control.NewSubscribeControlInternalServerError() @@ -100,7 +115,7 @@ func (r *Subscriber) Listen(handler SubscriptionReportHandler) error { // SubscriptionType: policy api.PolicySubscribePolicyHandler = policy.SubscribePolicyHandlerFunc( func(p policy.SubscribePolicyParams) middleware.Responder { - if resp, err := handler(models.SubscriptionTypePolicy, p.PolicyParams); err == nil { + if resp, err := subHandler(models.SubscriptionTypePolicy, p.PolicyParams); err == nil { return policy.NewSubscribePolicyCreated().WithPayload(resp) } return policy.NewSubscribePolicyInternalServerError() @@ -151,6 +166,29 @@ func (r *Subscriber) SubscribePolicy(p *apimodel.PolicyParams) (apimodel.Subscri return result.Payload, err } -func (s *Subscriber) CreateTransport() *apiclient.RICSubscription { - return apiclient.New(httptransport.New(s.remoteHost, s.remoteUrl, s.remoteProt), strfmt.Default) +// Subscription interface for xApp: QUERY +func (r *Subscriber) QuerySubscriptions() (models.SubscriptionList, error) { + resp, err := http.Get(fmt.Sprintf("http://%s/%s/subscriptions", r.remoteHost, r.remoteUrl)) + if err != nil { + return models.SubscriptionList{}, err + } + + defer resp.Body.Close() + + contents, err := ioutil.ReadAll(resp.Body) + if err != nil { + return models.SubscriptionList{}, err + } + + subscriptions := models.SubscriptionList{} + err = json.Unmarshal([]byte(string(contents)), &subscriptions) + if err != nil { + return models.SubscriptionList{}, err + } + + return subscriptions, nil +} + +func (r *Subscriber) CreateTransport() *apiclient.RICSubscription { + return apiclient.New(httptransport.New(r.remoteHost, r.remoteUrl, r.remoteProt), strfmt.Default) } diff --git a/pkg/xapp/subscription_test.go b/pkg/xapp/subscription_test.go index 28549e7..5ebb9c2 100755 --- a/pkg/xapp/subscription_test.go +++ b/pkg/xapp/subscription_test.go @@ -59,14 +59,35 @@ func subscriptionHandler(stype models.SubscriptionType, params interface{}) (mod return models.SubscriptionResult{11, 22, 33}, nil } +func queryHandler() (models.SubscriptionList, error) { + resp := models.SubscriptionList{ + &models.SubscriptionData{ + SubscriptionID: 11, + Meid: "Test-Gnb", + Endpoint: []string{"127.0.0.1:4056"}, + }, + } + + return resp, nil +} + func TestSetup(t *testing.T) { suite = t // Start the server to simulate SubManager - go Subscription.Listen(subscriptionHandler) + go Subscription.Listen(subscriptionHandler, queryHandler) time.Sleep(time.Duration(2) * time.Second) } +func TestSubscriptionQueryHandling(t *testing.T) { + resp, err := Subscription.QuerySubscriptions() + + assert.Equal(t, err, nil) + assert.Equal(t, resp[0].SubscriptionID, int64(11)) + assert.Equal(t, resp[0].Meid, "Test-Gnb") + assert.Equal(t, resp[0].Endpoint, []string{"127.0.0.1:4056"}) +} + func TestSubscriptionReportHandling(t *testing.T) { result, err := Subscription.SubscribeReport(&reportParams) diff --git a/pkg/xapp/xapp_test.go b/pkg/xapp/xapp_test.go index 27fb445..f0e3070 100755 --- a/pkg/xapp/xapp_test.go +++ b/pkg/xapp/xapp_test.go @@ -102,6 +102,7 @@ func TestInjectQueryFailures(t *testing.T) { } func TestMessagesReceivedSuccessfully(t *testing.T) { + time.Sleep(time.Duration(5) * time.Second) for i := 0; i < 100; i++ { params := &RMRParams{} params.Mtype = 10004 @@ -118,11 +119,11 @@ func TestMessagesReceivedSuccessfully(t *testing.T) { waitForSdl := viper.GetBool("db.waitForSdl") stats := getMetrics(t) if !strings.Contains(stats, "ricxapp_RMR_Transmitted 100") { - t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect") + t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect: %v", stats) } if !strings.Contains(stats, "ricxapp_RMR_Received 100") { - t.Errorf("Error: ricxapp_RMR_Received value incorrect") + t.Errorf("Error: ricxapp_RMR_Received value incorrect: %v", stats) } if !strings.Contains(stats, "ricxapp_RMR_TransmitError 0") {