Skip to content

Commit

Permalink
O-RAN V3 Compliant Producer Rest Api: Event Subscription
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Ding <[email protected]>
  • Loading branch information
jzding committed Jun 18, 2024
1 parent 19aa966 commit 6430c5d
Show file tree
Hide file tree
Showing 26 changed files with 3,429 additions and 18 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
// 400: badReq
// 204: noContent
func (s *Server) createSubscription(w http.ResponseWriter, r *http.Request) {
log.Printf("DZK in V1 createSubscription")
defer r.Body.Close()
var response *http.Response
bodyBytes, err := io.ReadAll(r.Body)
Expand Down
17 changes: 15 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
// Terms Of Service:
//
// Schemes: http, https
// Host: localhost:8080
// Host: localhost:8089
// basePath: /api/ocloudNotifications/v1
// Version: 1.0.0
// Contact: Aneesh Puttur<[email protected]>
//
Expand Down Expand Up @@ -186,6 +187,7 @@ func (s *Server) GetHostPath() *types.URI {

// Start will start res routes service
func (s *Server) Start() {
log.Infof("DZK starting V1 REST server at port %d", s.port)
if s.status == started || s.status == starting {
log.Infof("Server is already running at port %d", s.port)
return
Expand All @@ -196,7 +198,7 @@ func (s *Server) Start() {
api := r.PathPrefix(s.apiPath).Subrouter()

// createSubscription create subscription and send it to a channel that is shared by middleware to process
// swagger:operation POST /subscriptions/ subscription createSubscription
// swagger:operation POST /subscriptions subscription createSubscription
// ---
// summary: Creates a new subscription.
// description: If subscription creation is success(or if already exists), subscription will be returned with Created (201).
Expand Down Expand Up @@ -237,6 +239,17 @@ func (s *Server) Start() {
404 Subscription resources are not available (not created).
*/
api.HandleFunc("/subscriptions", s.getSubscriptions).Methods(http.MethodGet)
//publishers create publisher and send it to a channel that is shared by middleware to process
// swagger:operation GET /publishers/ publishers getPublishers
// ---
// summary: Get publishers.
// description: If publisher creation is success(or if already exists), publisher will be returned with Created (201).
// parameters:
// responses:
// "200":
// "$ref": "#/responses/publishers"
// "404":
// "$ref": "#/responses/notFound"
api.HandleFunc("/publishers", s.getPublishers).Methods(http.MethodGet)
// 200 and 404
api.HandleFunc("/subscriptions/{subscriptionid}", s.getSubscriptionByID).Methods(http.MethodGet)
Expand Down
78 changes: 62 additions & 16 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"version": "1.0.0"
},
"host": "localhost:8080",
"host": "localhost:8089",
"basePath": "/api/ocloudNotifications/v1",
"paths": {
"/create/event/": {
"post": {
Expand Down Expand Up @@ -50,6 +51,22 @@
}
},
"/publishers/": {
"get": {
"description": "If publisher creation is success(or if already exists), publisher will be returned with Created (201).",
"tags": [
"publishers"
],
"summary": "Get publishers.",
"operationId": "getPublishers",
"responses": {
"200": {
"$ref": "#/responses/publishers"
},
"404": {
"$ref": "#/responses/notFound"
}
}
},
"post": {
"description": "If publisher creation is success(or if already exists), publisher will be returned with Created (201).",
"tags": [
Expand Down Expand Up @@ -77,7 +94,7 @@
}
}
},
"/subscriptions/": {
"/subscriptions": {
"post": {
"description": "If subscription creation is success(or if already exists), subscription will be returned with Created (201).",
"tags": [
Expand All @@ -104,12 +121,37 @@
}
}
}
},
"/subscriptions/status": {
"post": {
"description": "If publisher status ping is success, call will be returned with status accepted.",
"tags": [
"subscriptions"
],
"summary": "Get status of publishing events.",
"operationId": "pingForSubscribedEventStatus",
"parameters": [
{
"description": "subscription id to check status for",
"name": "subscriptionid"
}
],
"responses": {
"201": {
"$ref": "#/responses/pubSubResp"
},
"400": {
"$ref": "#/responses/badReq"
}
}
}
}
},
"definitions": {
"Data": {
"description": "Data ... cloud native events data\nData Json payload is as follows,\n{\n\"version\": \"v1.0\",\n\"values\": [{\n\"resource\": \"/cluster/node/ptp\",\n\"dataType\": \"notification\",\n\"valueType\": \"enumeration\",\n\"value\": \"ACQUIRING-SYNC\"\n}, {\n\"resource\": \"/cluster/node/clock\",\n\"dataType\": \"metric\",\n\"valueType\": \"decimal64.3\",\n\"value\": 100.3\n}]\n}",
"description": "{\n\"version\": \"v1.0\",\n\"values\": [{\n\"resource\": \"/sync/sync-status/sync-state\",\n\"dataType\": \"notification\",\n\"valueType\": \"enumeration\",\n\"value\": \"ACQUIRING-SYNC\"\n}, {\n\"resource\": \"/sync/sync-status/sync-state\",\n\"dataType\": \"metric\",\n\"valueType\": \"decimal64.3\",\n\"value\": 100.3\n}, {\n\"resource\": \"/redfish/v1/Systems\",\n\"dataType\": \"notification\",\n\"valueType\": \"redfish-event\",\n\"value\": {\n\"@odata.context\": \"/redfish/v1/$metadata#Event.Event\",\n\"@odata.type\": \"#Event.v1_3_0.Event\",\n\"Context\": \"any string is valid\",\n\"Events\": [{\"EventId\": \"2162\", \"MemberId\": \"615703\", \"MessageId\": \"TMP0100\"}],\n\"Id\": \"5e004f5a-e3d1-11eb-ae9c-3448edf18a38\",\n\"Name\": \"Event Array\"\n}\n}]\n}",
"type": "object",
"title": "Data ... cloud native events data\nData Json payload is as follows,",
"properties": {
"values": {
"type": "array",
Expand All @@ -131,9 +173,9 @@
"x-go-package": "github.com/redhat-cne/sdk-go/pkg/event"
},
"DataValue": {
"description": "DataValue Json payload is as follows,\n{\n\"resource\": \"/cluster/node/ptp\",\n\"dataType\": \"notification\",\n\"valueType\": \"enumeration\",\n\"value\": \"ACQUIRING-SYNC\"\n}",
"description": "{\n\"resource\": \"/cluster/node/ptp\",\n\"dataType\": \"notification\",\n\"valueType\": \"enumeration\",\n\"value\": \"ACQUIRING-SYNC\"\n}",
"type": "object",
"title": "DataValue ...",
"title": "DataValue ...\nDataValue Json payload is as follows,",
"properties": {
"dataType": {
"$ref": "#/definitions/DataType"
Expand All @@ -143,7 +185,6 @@
"x-go-name": "Resource"
},
"value": {
"type": "object",
"x-go-name": "Value"
},
"valueType": {
Expand All @@ -153,9 +194,9 @@
"x-go-package": "github.com/redhat-cne/sdk-go/pkg/event"
},
"Event": {
"description": "Event Json payload is as follows,\n{\n\"id\": \"5ce55d17-9234-4fee-a589-d0f10cb32b8e\",\n\"type\": \"event.synchronization-state-chang\",\n\"time\": \"2021-02-05T17:31:00Z\",\n\"data\": {\n\"version\": \"v1.0\",\n\"values\": [{\n\"resource\": \"/cluster/node/ptp\",\n\"dataType\": \"notification\",\n\"valueType\": \"enumeration\",\n\"value\": \"ACQUIRING-SYNC\"\n}, {\n\"resource\": \"/cluster/node/clock\",\n\"dataType\": \"metric\",\n\"valueType\": \"decimal64.3\",\n\"value\": 100.3\n}]\n}\n}\nEvent request model",
"description": "{\n\"id\": \"5ce55d17-9234-4fee-a589-d0f10cb32b8e\",\n\"type\": \"event.sync.sync-status.synchronization-state-change\",\n\"source\": \"/cluster/node/example.com/ptp/clock_realtime\",\n\"time\": \"2021-02-05T17:31:00Z\",\n\"data\": {\n\"version\": \"v1.0\",\n\"values\": [{\n\"resource\": \"/sync/sync-status/sync-state\",\n\"dataType\": \"notification\",\n\"valueType\": \"enumeration\",\n\"value\": \"ACQUIRING-SYNC\"\n}, {\n\"resource\": \"/sync/sync-status/sync-state\",\n\"dataType\": \"metric\",\n\"valueType\": \"decimal64.3\",\n\"value\": 100.3\n}]\n}\n}\n\nEvent request model",
"type": "object",
"title": "Event represents the canonical representation of a Cloud Native Event.",
"title": "Event represents the canonical representation of a Cloud Native Event.\nEvent Json payload is as follows,",
"properties": {
"data": {
"$ref": "#/definitions/Data"
Expand All @@ -173,8 +214,15 @@
"type": "string",
"x-go-name": "ID"
},
"source": {
"description": "Source - The source of the occurrence which has happened.\n+required",
"type": "string",
"x-go-name": "Source"
},
"time": {
"$ref": "#/definitions/Timestamp"
"description": "Time - A Timestamp when the event happened.\n+required",
"type": "string",
"x-go-name": "Time"
},
"type": {
"description": "Type - The type of the occurrence which has happened.\n+required",
Expand All @@ -185,9 +233,9 @@
"x-go-package": "github.com/redhat-cne/sdk-go/pkg/event"
},
"PubSub": {
"description": "PubSub Json request payload is as follows,\n{\n\"id\": \"789be75d-7ac3-472e-bbbc-6d62878aad4a\",\n\"endpointUri\": \"http://localhost:9090/ack/event\",\n\"uriLocation\": \"http://localhost:8080/api/ocloudNotifications/v1/publishers/{publisherid}\",\n\"resource\": \"/east-edge-10/vdu3/o-ran-sync/sync-group/sync-status/sync-state\"\n}\nPubSub request model",
"description": "{\n\"id\": \"789be75d-7ac3-472e-bbbc-6d62878aad4a\",\n\"endpointUri\": \"http://localhost:9090/ack/event\",\n\"uriLocation\": \"http://localhost:8080/api/ocloudNotifications/v1/publishers/{publisherid}\",\n\"resource\": \"/east-edge-10/vdu3/o-ran-sync/sync-group/sync-status/sync-state\"\n}\n\nPubSub request model",
"type": "object",
"title": "PubSub represents the canonical representation of a Cloud Native Event Publisher and Subscribers .",
"title": "PubSub represents the canonical representation of a Cloud Native Event Publisher and Sender .\nPubSub Json request payload is as follows,",
"properties": {
"endpointUri": {
"$ref": "#/definitions/URI"
Expand All @@ -208,11 +256,6 @@
},
"x-go-package": "github.com/redhat-cne/sdk-go/pkg/pubsub"
},
"Timestamp": {
"description": "Timestamp wraps time.Time to normalize the time layout to RFC3339. It is\nintended to enforce compliance with the Cloud Native events spec for their\ndefinition of Timestamp. Custom marshal methods are implemented to ensure\nthe outbound Timestamp is a string in the RFC3339 layout.",
"type": "object",
"x-go-package": "github.com/redhat-cne/sdk-go/pkg/types"
},
"URI": {
"description": "URI is a wrapper to url.URL. It is intended to enforce compliance with\nthe Cloud Native Events spec for their definition of URI. Custom\nmarshal methods are implemented to ensure the outbound URI object\nis a flat string.",
"type": "object",
Expand All @@ -226,6 +269,9 @@
"Host": {
"type": "string"
},
"OmitHost": {
"type": "boolean"
},
"Opaque": {
"type": "string"
},
Expand Down
Loading

0 comments on commit 6430c5d

Please sign in to comment.