Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GET operations for DeviceGroups and Network Slices #81

Merged
merged 16 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/run-webconsole-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2023 Open Networking Foundation <info@opennetworking.org>
# SPDX-License-Identifier: Apache-2.0

name: Unit tests

on:
push:
branches:
- master
pull_request:

jobs:
unit-test-webconsole:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3

- name: Run unit tests for webconsole
run: |
make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ cscope.*
bin/
public/
!/frontend/public/*.license
.coverage/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
#

FROM golang:1.16.0-stretch AS builder
FROM golang:1.21-bookworm AS builder

LABEL maintainer="ONF <omec-dev@opennetworking.org>"

Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,16 @@ docker-push:
for target in $(DOCKER_TARGETS); do \
docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}5gc-$$target:${DOCKER_TAG}; \
done

.coverage:
rm -rf $(CURDIR)/.coverage
mkdir -p $(CURDIR)/.coverage

test: .coverage
docker run --rm -v $(CURDIR):/webconsole -w /webconsole golang:latest \
go test \
-failfast \
-coverprofile=.coverage/coverage-unit.txt \
-covermode=atomic \
-v \
./ ./...
75 changes: 75 additions & 0 deletions configapi/api_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,57 @@
package configapi

import (
"encoding/json"
"net/http"

"github.com/gin-gonic/gin"
"github.com/omec-project/MongoDBLibrary"
"github.com/omec-project/webconsole/backend/logger"
"github.com/omec-project/webconsole/configmodels"
"go.mongodb.org/mongo-driver/bson"
)

const (
devGroupDataColl = "webconsoleData.snapshots.devGroupData"
sliceDataColl = "webconsoleData.snapshots.sliceData"
)

var (
RestfulAPIGetMany = MongoDBLibrary.RestfulAPIGetMany
RestfulAPIGetOne = MongoDBLibrary.RestfulAPIGetOne
)

// GetDeviceGroups -
func GetDeviceGroups(c *gin.Context) {
setCorsHeader(c)
logger.WebUILog.Infoln("Get all Device Groups")

var deviceGroups []string = make([]string, 0)
rawDeviceGroups := RestfulAPIGetMany(devGroupDataColl, bson.M{})
for _, rawDeviceGroup := range rawDeviceGroups {
deviceGroups = append(deviceGroups, rawDeviceGroup["group-name"].(string))
}

c.JSON(http.StatusOK, deviceGroups)
}

// GetDeviceGroupsByName -
func GetDeviceGroupByName(c *gin.Context) {
setCorsHeader(c)
logger.WebUILog.Infoln("Get Device Group by name")

var deviceGroup configmodels.DeviceGroups
filter := bson.M{"group-name": c.Param("group-name")}
rawDeviceGroup := RestfulAPIGetOne(devGroupDataColl, filter)
json.Unmarshal(mapToByte(rawDeviceGroup), &deviceGroup)

if deviceGroup.DeviceGroupName == "" {
c.JSON(http.StatusNotFound, nil)
} else {
c.JSON(http.StatusOK, deviceGroup)
}
}

// DeviceGroupGroupNameDelete -
func DeviceGroupGroupNameDelete(c *gin.Context) {
logger.ConfigLog.Debugf("DeviceGroupGroupNameDelete")
Expand Down Expand Up @@ -58,6 +102,37 @@ func DeviceGroupGroupNamePost(c *gin.Context) {
}
}

// GetNetworkSlices -
func GetNetworkSlices(c *gin.Context) {
setCorsHeader(c)
logger.WebUILog.Infoln("Get all Network Slices")

var networkSlices []string = make([]string, 0)
rawNetworkSlices := RestfulAPIGetMany(sliceDataColl, bson.M{})
for _, rawNetworkSlice := range rawNetworkSlices {
networkSlices = append(networkSlices, rawNetworkSlice["SliceName"].(string))
}

c.JSON(http.StatusOK, networkSlices)
}

// GetNetworkSliceByName -
func GetNetworkSliceByName(c *gin.Context) {
setCorsHeader(c)
logger.WebUILog.Infoln("Get Network Slice by name")

var networkSlice configmodels.Slice
filter := bson.M{"SliceName": c.Param("slice-name")}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add check for query param presence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also a path parameter defined in the router.

rawNetworkSlice := RestfulAPIGetOne(sliceDataColl, filter)
json.Unmarshal(mapToByte(rawNetworkSlice), &networkSlice)

if networkSlice.SliceName == "" {
c.JSON(http.StatusNotFound, nil)
} else {
c.JSON(http.StatusOK, networkSlice)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share curl command output how it looks like both success & failure case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, in the case that the slice does not exist, we get:

curl -v ${WEBUI_IP}:5000/config/v1/network-slice/default
*   Trying 10.1.213.205:5000...
* Connected to 10.1.213.205 (10.1.213.205) port 5000 (#0)
> GET /config/v1/network-slice/default HTTP/1.1
> Host: 10.1.213.205:5000
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With
< Access-Control-Allow-Methods: POST, OPTIONS, GET, PUT, PATCH, DELETE
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=utf-8
< Date: Mon, 11 Sep 2023 20:57:59 GMT
< Content-Length: 4
<
* Connection #0 to host 10.1.213.205 left intact
null

In the case where it exists, we get this:

curl -v ${WEBUI_IP}:5000/config/v1/network-slice/default
*   Trying 10.1.213.205:5000...
* Connected to 10.1.213.205 (10.1.213.205) port 5000 (#0)
> GET /config/v1/network-slice/default HTTP/1.1
> Host: 10.1.213.205:5000
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With
< Access-Control-Allow-Methods: POST, OPTIONS, GET, PUT, PATCH, DELETE
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=utf-8
< Date: Mon, 11 Sep 2023 20:59:34 GMT
< Content-Length: 238
<
* Connection #0 to host 10.1.213.205 left intact
{"SliceName":"default","slice-id":{"sst":"1","sd":"010203"},"site-device-group":["cows"],"site-info":{"site-name":"demo","plmn":{"mcc":"208","mnc":"93"},"gNodeBs":[{"name":"demo-gnb1","tac":1}],"upf":{"upf-name":"upf","upf-port":"8805"}}}

}
}

// NetworkSliceSliceNameDelete -
func NetworkSliceSliceNameDelete(c *gin.Context) {
logger.ConfigLog.Debugf("Received NetworkSliceSliceNameDelete ")
Expand Down