Skip to content

Commit

Permalink
Merge pull request #14 from omec-project/dev-grpc-messages1
Browse files Browse the repository at this point in the history
ConfigPod to handle PUT and DELETE APIs
  • Loading branch information
thakurajayL authored Jul 16, 2021
2 parents a07061b + b977fd7 commit 935305f
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 77 deletions.
40 changes: 36 additions & 4 deletions configapi/api_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,40 @@ package configapi
import (
"github.com/gin-gonic/gin"
"github.com/omec-project/webconsole/backend/logger"
"github.com/omec-project/webconsole/configmodels"
"net/http"
)

// DeviceGroupGroupNameDelete -
func DeviceGroupGroupNameDelete(c *gin.Context) {
logger.ConfigLog.Infof("DeviceGroupGroupNameDelete")
if ret := DeviceGroupDeleteHandler(c); ret == true {
c.JSON(http.StatusOK, gin.H{})
} else {
c.JSON(http.StatusBadRequest, gin.H{})
}
}

// DeviceGroupGroupNamePut -
func DeviceGroupGroupNamePut(c *gin.Context) {
logger.ConfigLog.Infof("DeviceGroupGroupNamePut")
if ret := DeviceGroupPostHandler(c, configmodels.Put_op); ret == true {
c.JSON(http.StatusOK, gin.H{})
} else {
c.JSON(http.StatusBadRequest, gin.H{})
}
}

// DeviceGroupGroupNamePatch -
func DeviceGroupGroupNamePatch(c *gin.Context) {
logger.ConfigLog.Infof("DeviceGroupGroupNamePatch")
c.JSON(http.StatusOK, gin.H{})
}

// DeviceGroupGroupNamePost -
func DeviceGroupGroupNamePost(c *gin.Context) {
logger.ConfigLog.Infof("DeviceGroupGroupNamePost")
if ret := DeviceGroupPostHandler(c); ret == true {
if ret := DeviceGroupPostHandler(c, configmodels.Post_op); ret == true {
c.JSON(http.StatusOK, gin.H{})
} else {
c.JSON(http.StatusBadRequest, gin.H{})
Expand All @@ -32,13 +54,18 @@ func DeviceGroupGroupNamePost(c *gin.Context) {

// NetworkSliceSliceNameDelete -
func NetworkSliceSliceNameDelete(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
logger.ConfigLog.Infof("Received NetworkSliceSliceNameDelete ")
if ret := NetworkSliceDeleteHandler(c); ret == true {
c.JSON(http.StatusOK, gin.H{})
} else {
c.JSON(http.StatusBadRequest, gin.H{})
}
}

// NetworkSliceSliceNamePost -
func NetworkSliceSliceNamePost(c *gin.Context) {
logger.ConfigLog.Infof("Received NetworkSliceSliceNamePost ")
if ret := NetworkSlicePostHandler(c); ret == true {
if ret := NetworkSlicePostHandler(c, configmodels.Post_op); ret == true {
c.JSON(http.StatusOK, gin.H{})
} else {
c.JSON(http.StatusBadRequest, gin.H{})
Expand All @@ -47,5 +74,10 @@ func NetworkSliceSliceNamePost(c *gin.Context) {

// NetworkSliceSliceNamePut -
func NetworkSliceSliceNamePut(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
logger.ConfigLog.Infof("Received NetworkSliceSliceNamePut ")
if ret := NetworkSlicePostHandler(c, configmodels.Put_op); ret == true {
c.JSON(http.StatusOK, gin.H{})
} else {
c.JSON(http.StatusBadRequest, gin.H{})
}
}
81 changes: 57 additions & 24 deletions configapi/api_slice_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package configapi

import (
"github.com/free5gc/http_wrapper"
"github.com/omec-project/webconsole/backend/logger"
"github.com/gin-gonic/gin"
"github.com/omec-project/webconsole/backend/logger"
"github.com/omec-project/webconsole/configmodels"
"github.com/sirupsen/logrus"
"github.com/omec-project/webconsole/configmodels"
"strings"
)


const (
device_group = iota
network_slice
Expand All @@ -18,18 +17,35 @@ const (
var configChannel chan *configmodels.ConfigMessage

var configLog *logrus.Entry

func init() {
configLog = logger.ConfigLog
}

func SetChannel(cfgChannel chan *configmodels.ConfigMessage) {
configLog.Infof("Setting configChannel")
configChannel = cfgChannel
configLog.Infof("Setting configChannel")
configChannel = cfgChannel
}

func DeviceGroupPostHandler(c *gin.Context) bool {
var groupName string
var exists bool
func DeviceGroupDeleteHandler(c *gin.Context) bool {
var groupName string
var exists bool
if groupName, exists = c.Params.Get("group-name"); exists {
configLog.Infof("Received group %v", groupName)
}
var msg configmodels.ConfigMessage
msg.MsgType = device_group
msg.MsgMethod = configmodels.Delete_op
msg.DevGroupName = groupName
configChannel <- &msg
configLog.Infof("Successfully posted message for device group %v to main config thread", groupName)
return true

}

func DeviceGroupPostHandler(c *gin.Context, msgOp int) bool {
var groupName string
var exists bool
if groupName, exists = c.Params.Get("group-name"); exists {
configLog.Infof("Received group %v", groupName)
}
Expand Down Expand Up @@ -69,19 +85,35 @@ func DeviceGroupPostHandler(c *gin.Context) bool {
configLog.Infof(" dns Primary : %v", ipdomain.DnsPrimary)
configLog.Infof(" ip mtu : %v", ipdomain.Mtu)

var msg configmodels.ConfigMessage
msg.MsgType = device_group
msg.DevGroup = &request
configLog.Infof("Group %v ", groupName)
msg.DevGroupName = groupName
configChannel <- &msg
configLog.Infof("Successfully posted message for device group %v to main config thread", groupName)
var msg configmodels.ConfigMessage
msg.MsgType = device_group
msg.MsgMethod = msgOp
msg.DevGroup = &request
configLog.Infof("Group %v ", groupName)
msg.DevGroupName = groupName
configChannel <- &msg
configLog.Infof("Successfully posted message for device group %v to main config thread", groupName)
return true
}

func NetworkSliceDeleteHandler(c *gin.Context) bool {
var sliceName string
var exists bool
if sliceName, exists = c.Params.Get("slice-name"); exists {
configLog.Infof("Received slice : %v", sliceName)
}
var msg configmodels.ConfigMessage
msg.MsgMethod = configmodels.Delete_op
msg.MsgType = network_slice
msg.SliceName = sliceName
configChannel <- &msg
configLog.Infof("Slice Delete - Successfully posted message for slice %v to main config thread", sliceName)
return true
}

func NetworkSlicePostHandler(c *gin.Context) bool {
var sliceName string
var exists bool
func NetworkSlicePostHandler(c *gin.Context, msgOp int) bool {
var sliceName string
var exists bool
if sliceName, exists = c.Params.Get("slice-name"); exists {
configLog.Infof("Received slice : %v", sliceName)
}
Expand Down Expand Up @@ -162,11 +194,12 @@ func NetworkSlicePostHandler(c *gin.Context) bool {
configLog.Infof(" upf-name : %v", site.Upf["upf-name"])
configLog.Infof(" upf-port : %v", site.Upf["upf-port"])

var msg configmodels.ConfigMessage
msg.MsgType = network_slice
msg.Slice = &request
msg.SliceName = sliceName
configChannel <- &msg
configLog.Infof("Successfully posted message for slice %v to main config thread", sliceName)
var msg configmodels.ConfigMessage
msg.MsgMethod = msgOp
msg.MsgType = network_slice
msg.Slice = &request
msg.SliceName = sliceName
configChannel <- &msg
configLog.Infof("Successfully posted message for slice %v to main config thread", sliceName)
return true
}
24 changes: 19 additions & 5 deletions configapi/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
package configapi

import (
"net/http"
"github.com/gin-gonic/gin"
"net/http"
)

// Route is the information for every URI.
type Route struct {
// Name is the name of this Route.
Name string
Name string
// Method is the string for the HTTP method. ex) GET, POST etc..
Method string
Method string
// Pattern is the pattern of the URI.
Pattern string
Pattern string
// HandlerFunc is the handler function of this route.
HandlerFunc gin.HandlerFunc
}
Expand All @@ -48,7 +48,7 @@ func NewRouter() *gin.Engine {
return router
}

// This function is not autogenerated
// This function is not autogenerated
func AddService(engine *gin.Engine) *gin.RouterGroup {
group := engine.Group("/config/v1")

Expand Down Expand Up @@ -82,13 +82,27 @@ var routes = Routes{
Index,
},

{
"DeviceGroupGroupNameDelete",
http.MethodDelete,
"/device-group/:group-name",
DeviceGroupGroupNameDelete,
},

{
"DeviceGroupGroupNamePatch",
http.MethodPatch,
"/device-group/:group-name",
DeviceGroupGroupNamePatch,
},

{
"DeviceGroupGroupNamePut",
http.MethodPut,
"/device-group/:group-name",
DeviceGroupGroupNamePut,
},

{
"DeviceGroupGroupNamePost",
http.MethodPost,
Expand Down
7 changes: 7 additions & 0 deletions configmodels/config_msg.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package configmodels

const (
Post_op = iota
Put_op
Delete_op
)

type ConfigMessage struct {
MsgType int
MsgMethod int
DevGroup *DeviceGroups
Slice *Slice
DevGroupName string
Expand Down
6 changes: 6 additions & 0 deletions proto/config.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// SPDX-FileCopyrightText: 2021 Open Networking Foundation <[email protected]>
//
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0

syntax = "proto3";
package sdcoreConfig;
option go_package = "./sdcoreConfig";
Expand Down Expand Up @@ -87,4 +92,5 @@ message NetworkSliceRequest {
message NetworkSliceResponse {
uint32 RestartCounter = 1;
repeated NetworkSlice NetworkSlice = 2;
uint32 ConfigUpdated = 3;
}
59 changes: 37 additions & 22 deletions proto/sdcoreConfig/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions proto/sdcoreConfig/config_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 935305f

Please sign in to comment.