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

Refactor k8s and nlb parts #1776

Merged
merged 1 commit into from
Aug 27, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2216,13 +2216,13 @@ const docTemplate = `{
"schema": {
"allOf": [
{
"$ref": "#/definitions/infra.JSONResult"
"$ref": "#/definitions/resource.JSONResult"
},
{
"type": "object",
"properties": {
"[DEFAULT]": {
"$ref": "#/definitions/infra.RestGetAllK8sClusterResponse"
"$ref": "#/definitions/resource.RestGetAllK8sClusterResponse"
},
"[ID]": {
"$ref": "#/definitions/model.IdList"
Expand Down Expand Up @@ -9340,17 +9340,6 @@ const docTemplate = `{
}
}
},
"infra.RestGetAllK8sClusterResponse": {
"type": "object",
"properties": {
"cluster": {
"type": "array",
"items": {
"$ref": "#/definitions/model.TbK8sClusterInfo"
}
}
}
},
"infra.RestGetAllMciPolicyResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -13754,6 +13743,17 @@ const docTemplate = `{
}
}
},
"resource.RestGetAllK8sClusterResponse": {
"type": "object",
"properties": {
"cluster": {
"type": "array",
"items": {
"$ref": "#/definitions/model.TbK8sClusterInfo"
}
}
}
},
"resource.RestGetAllSecurityGroupResponse": {
"type": "object",
"properties": {
Expand Down
26 changes: 13 additions & 13 deletions src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2209,13 +2209,13 @@
"schema": {
"allOf": [
{
"$ref": "#/definitions/infra.JSONResult"
"$ref": "#/definitions/resource.JSONResult"
},
{
"type": "object",
"properties": {
"[DEFAULT]": {
"$ref": "#/definitions/infra.RestGetAllK8sClusterResponse"
"$ref": "#/definitions/resource.RestGetAllK8sClusterResponse"
},
"[ID]": {
"$ref": "#/definitions/model.IdList"
Expand Down Expand Up @@ -9333,17 +9333,6 @@
}
}
},
"infra.RestGetAllK8sClusterResponse": {
"type": "object",
"properties": {
"cluster": {
"type": "array",
"items": {
"$ref": "#/definitions/model.TbK8sClusterInfo"
}
}
}
},
"infra.RestGetAllMciPolicyResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -13747,6 +13736,17 @@
}
}
},
"resource.RestGetAllK8sClusterResponse": {
"type": "object",
"properties": {
"cluster": {
"type": "array",
"items": {
"$ref": "#/definitions/model.TbK8sClusterInfo"
}
}
}
},
"resource.RestGetAllSecurityGroupResponse": {
"type": "object",
"properties": {
Expand Down
18 changes: 9 additions & 9 deletions src/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ definitions:
host:
type: string
type: object
infra.RestGetAllK8sClusterResponse:
properties:
cluster:
items:
$ref: '#/definitions/model.TbK8sClusterInfo'
type: array
type: object
infra.RestGetAllMciPolicyResponse:
properties:
mciPolicy:
Expand Down Expand Up @@ -3210,6 +3203,13 @@ definitions:
$ref: '#/definitions/model.TbImageInfo'
type: array
type: object
resource.RestGetAllK8sClusterResponse:
properties:
cluster:
items:
$ref: '#/definitions/model.TbK8sClusterInfo'
type: array
type: object
resource.RestGetAllSecurityGroupResponse:
properties:
securityGroup:
Expand Down Expand Up @@ -4802,10 +4802,10 @@ paths:
description: Different return structures by the given option param
schema:
allOf:
- $ref: '#/definitions/infra.JSONResult'
- $ref: '#/definitions/resource.JSONResult'
- properties:
'[DEFAULT]':
$ref: '#/definitions/infra.RestGetAllK8sClusterResponse'
$ref: '#/definitions/resource.RestGetAllK8sClusterResponse'
'[ID]':
$ref: '#/definitions/model.IdList'
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package mci is to handle REST API for mci
package infra
// Package resource is to handle REST API for resource
package resource

import (
"net/http"

"github.com/cloud-barista/cb-tumblebug/src/core/common"
"github.com/cloud-barista/cb-tumblebug/src/core/infra"
"github.com/cloud-barista/cb-tumblebug/src/core/model"
"github.com/cloud-barista/cb-tumblebug/src/core/resource"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
)
Expand Down Expand Up @@ -128,7 +128,7 @@ func RestPostK8sCluster(c echo.Context) error {

log.Debug().Msg("[POST K8sCluster]")

content, err := infra.CreateK8sCluster(nsId, u, optionFlag)
content, err := resource.CreateK8sCluster(nsId, u, optionFlag)

if err != nil {
log.Error().Err(err).Msg("")
Expand Down Expand Up @@ -190,7 +190,7 @@ func RestPostK8sNodeGroup(c echo.Context) error {

log.Debug().Msg("[POST K8sNodeGroup]")

content, err := infra.AddK8sNodeGroup(nsId, k8sClusterId, u)
content, err := resource.AddK8sNodeGroup(nsId, k8sClusterId, u)

if err != nil {
log.Error().Err(err).Msg("")
Expand Down Expand Up @@ -223,7 +223,7 @@ func RestDeleteK8sNodeGroup(c echo.Context) error {

forceFlag := c.QueryParam("force")

res, err := infra.RemoveK8sNodeGroup(nsId, k8sClusterId, k8sNodeGroupName, forceFlag)
res, err := resource.RemoveK8sNodeGroup(nsId, k8sClusterId, k8sNodeGroupName, forceFlag)
if err != nil {
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
Expand Down Expand Up @@ -269,7 +269,7 @@ func RestPutSetK8sNodeGroupAutoscaling(c echo.Context) error {

log.Debug().Msg("[PUT K8s Set AutoScaling]")

content, err := infra.SetK8sNodeGroupAutoscaling(nsId, k8sClusterId, k8sNodeGroupName, u)
content, err := resource.SetK8sNodeGroupAutoscaling(nsId, k8sClusterId, k8sNodeGroupName, u)

if err != nil {
log.Error().Err(err).Msg("")
Expand Down Expand Up @@ -309,7 +309,7 @@ func RestPutChangeK8sNodeGroupAutoscaleSize(c echo.Context) error {

log.Debug().Msg("[PUT K8s Change AutoScale Size]")

content, err := infra.ChangeK8sNodeGroupAutoscaleSize(nsId, k8sClusterId, k8sNodeGroupName, u)
content, err := resource.ChangeK8sNodeGroupAutoscaleSize(nsId, k8sClusterId, k8sNodeGroupName, u)

if err != nil {
log.Error().Err(err).Msg("")
Expand Down Expand Up @@ -339,7 +339,7 @@ func RestGetK8sCluster(c echo.Context) error {
nsId := c.Param("nsId")
k8sClusterId := c.Param("k8sClusterId")

res, err := infra.GetK8sCluster(nsId, k8sClusterId)
res, err := resource.GetK8sCluster(nsId, k8sClusterId)
if err != nil {
mapA := map[string]string{"message": "Failed to find the K8sCluster " + k8sClusterId + ": " + err.Error()}
return c.JSON(http.StatusNotFound, &mapA)
Expand Down Expand Up @@ -379,7 +379,7 @@ func RestGetAllK8sCluster(c echo.Context) error {
if optionFlag == "id" {
content := model.IdList{}
var err error
content.IdList, err = infra.ListK8sClusterId(nsId)
content.IdList, err = resource.ListK8sClusterId(nsId)
if err != nil {
mapA := map[string]string{"message": "Failed to list K8sClusters' ID; " + err.Error()}
return c.JSON(http.StatusNotFound, &mapA)
Expand All @@ -388,7 +388,7 @@ func RestGetAllK8sCluster(c echo.Context) error {
return c.JSON(http.StatusOK, &content)
} else {

resourceList, err := infra.ListK8sCluster(nsId, filterKey, filterVal)
resourceList, err := resource.ListK8sCluster(nsId, filterKey, filterVal)
if err != nil {
mapA := map[string]string{"message": "Failed to list K8sClusters; " + err.Error()}
return c.JSON(http.StatusNotFound, &mapA)
Expand Down Expand Up @@ -423,7 +423,7 @@ func RestDeleteK8sCluster(c echo.Context) error {

forceFlag := c.QueryParam("force")

res, err := infra.DeleteK8sCluster(nsId, k8sClusterId, forceFlag)
res, err := resource.DeleteK8sCluster(nsId, k8sClusterId, forceFlag)
if err != nil {
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
Expand Down Expand Up @@ -459,7 +459,7 @@ func RestDeleteAllK8sCluster(c echo.Context) error {
forceFlag := c.QueryParam("force")
subString := c.QueryParam("match")

output, err := infra.DeleteAllK8sCluster(nsId, subString, forceFlag)
output, err := resource.DeleteAllK8sCluster(nsId, subString, forceFlag)
if err != nil {
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
Expand Down Expand Up @@ -496,7 +496,7 @@ func RestPutUpgradeK8sCluster(c echo.Context) error {

log.Debug().Msg("[PUT Upgrade K8sCluster]")

content, err := infra.UpgradeK8sCluster(nsId, k8sClusterId, u)
content, err := resource.UpgradeK8sCluster(nsId, k8sClusterId, u)

if err != nil {
log.Error().Err(err).Msg("")
Expand Down
26 changes: 13 additions & 13 deletions src/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,21 @@ func RunServer(port string) {
g.PUT("/:nsId/monitoring/status/mci/:mciId/vm/:vmId", rest_infra.RestPutMonitorAgentStatusInstalled)

// K8sCluster
e.GET("/tumblebug/availableK8sClusterVersion", rest_infra.RestGetAvailableK8sClusterVersion)
e.GET("/tumblebug/availableK8sClusterNodeImage", rest_infra.RestGetAvailableK8sClusterNodeImage)
e.GET("/tumblebug/checkNodeGroupsOnK8sCreation", rest_infra.RestCheckNodeGroupsOnK8sCreation)
g.POST("/:nsId/k8scluster", rest_infra.RestPostK8sCluster)
g.POST("/:nsId/k8scluster/:k8sClusterId/k8snodegroup", rest_infra.RestPostK8sNodeGroup)
g.DELETE("/:nsId/k8scluster/:k8sClusterId/k8snodegroup/:k8sNodeGroupName", rest_infra.RestDeleteK8sNodeGroup)
g.PUT("/:nsId/k8scluster/:k8sClusterId/k8snodegroup/:k8sNodeGroupName/onautoscaling", rest_infra.RestPutSetK8sNodeGroupAutoscaling)
g.PUT("/:nsId/k8scluster/:k8sClusterId/k8snodegroup/:k8sNodeGroupName/autoscalesize", rest_infra.RestPutChangeK8sNodeGroupAutoscaleSize)
g.GET("/:nsId/k8scluster/:k8sClusterId", rest_infra.RestGetK8sCluster, middleware.TimeoutWithConfig(timeoutConfig),
e.GET("/tumblebug/availableK8sClusterVersion", rest_resource.RestGetAvailableK8sClusterVersion)
e.GET("/tumblebug/availableK8sClusterNodeImage", rest_resource.RestGetAvailableK8sClusterNodeImage)
e.GET("/tumblebug/checkNodeGroupsOnK8sCreation", rest_resource.RestCheckNodeGroupsOnK8sCreation)
g.POST("/:nsId/k8scluster", rest_resource.RestPostK8sCluster)
g.POST("/:nsId/k8scluster/:k8sClusterId/k8snodegroup", rest_resource.RestPostK8sNodeGroup)
g.DELETE("/:nsId/k8scluster/:k8sClusterId/k8snodegroup/:k8sNodeGroupName", rest_resource.RestDeleteK8sNodeGroup)
g.PUT("/:nsId/k8scluster/:k8sClusterId/k8snodegroup/:k8sNodeGroupName/onautoscaling", rest_resource.RestPutSetK8sNodeGroupAutoscaling)
g.PUT("/:nsId/k8scluster/:k8sClusterId/k8snodegroup/:k8sNodeGroupName/autoscalesize", rest_resource.RestPutChangeK8sNodeGroupAutoscaleSize)
g.GET("/:nsId/k8scluster/:k8sClusterId", rest_resource.RestGetK8sCluster, middleware.TimeoutWithConfig(timeoutConfig),
middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(2)))
g.GET("/:nsId/k8scluster", rest_infra.RestGetAllK8sCluster, middleware.TimeoutWithConfig(timeoutConfig),
g.GET("/:nsId/k8scluster", rest_resource.RestGetAllK8sCluster, middleware.TimeoutWithConfig(timeoutConfig),
middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(2)))
g.DELETE("/:nsId/k8scluster/:k8sClusterId", rest_infra.RestDeleteK8sCluster)
g.DELETE("/:nsId/k8scluster", rest_infra.RestDeleteAllK8sCluster)
g.PUT("/:nsId/k8scluster/:k8sClusterId/upgrade", rest_infra.RestPutUpgradeK8sCluster)
g.DELETE("/:nsId/k8scluster/:k8sClusterId", rest_resource.RestDeleteK8sCluster)
g.DELETE("/:nsId/k8scluster", rest_resource.RestDeleteAllK8sCluster)
g.PUT("/:nsId/k8scluster/:k8sClusterId/upgrade", rest_resource.RestPutUpgradeK8sCluster)

// Network Load Balancer
g.POST("/:nsId/mci/:mciId/mcSwNlb", rest_infra.RestPostMcNLB)
Expand Down
File renamed without changes.
Loading
Loading