Skip to content

Commit

Permalink
[CONTROLLER/HTTP] code resource api service: all-ips
Browse files Browse the repository at this point in the history
  • Loading branch information
roryye committed Aug 21, 2023
1 parent ec178ca commit 6e859bd
Show file tree
Hide file tree
Showing 17 changed files with 837 additions and 22 deletions.
1 change: 1 addition & 0 deletions server/controller/common/resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ const (

// http api resource type
RESOURCE_TYPE_IP_EN = "ip"
RESOURCE_TYPE_ALL_IP_EN = "all_ip"
RESOURCE_TYPE_LB_RULE_EN = "lb_rule"
)
2 changes: 2 additions & 0 deletions server/controller/http/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const (
PATH_POD_NAMESPACE = "/v2/pod-namespaces"
PATH_VPC = "/v2/epcs"
PATH_NETWORK = "/v2/subnets"
PATH_DHCP_PORT = "/v2/dhcp-ports"
PATH_IP = "/v2/ips"
PATH_ALL_IP = "/v2/all-ips"
)

Expand Down
72 changes: 72 additions & 0 deletions server/controller/http/router/resource/all_ip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (c) 2023 Yunshan Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package resource

import (
"github.com/gin-gonic/gin"

"github.com/deepflowio/deepflow/server/controller/config"
dbredis "github.com/deepflowio/deepflow/server/controller/db/redis"
httpcommon "github.com/deepflowio/deepflow/server/controller/http/common"
httpCfg "github.com/deepflowio/deepflow/server/controller/http/config"
"github.com/deepflowio/deepflow/server/controller/http/model"
"github.com/deepflowio/deepflow/server/controller/http/router/common"
"github.com/deepflowio/deepflow/server/controller/http/service/resource"
)

type AllIP struct {
httpCfg httpCfg.Config
redisCfg dbredis.Config
fpermitCfg config.FPermit
}

func NewAllIP(hCfg httpCfg.Config, rCfg dbredis.Config, fCfg config.FPermit) *AllIP {
return &AllIP{httpCfg: hCfg, redisCfg: rCfg, fpermitCfg: fCfg}
}

func (p *AllIP) RegisterTo(ge *gin.Engine) {
ge.GET(httpcommon.PATH_ALL_IP, p.Get)
}

func (p *AllIP) Get(c *gin.Context) {
header := NewHeaderValidator(c.Request.Header, p.fpermitCfg)
query := NewQueryValidator[model.IPQuery](c.Request.URL.Query())
if err := NewValidators(header, query).Validate(); err != nil {
common.BadRequestResponse(c, httpcommon.INVALID_PARAMETERS, err.Error())
return
}
service := resource.NewAllIPGet(
NewURLInfo(
c.Request.URL.String(),
query.structData,
),
header.userInfo,
p.redisCfg,
p.fpermitCfg,
)
if query.structData.RefreshCache {
data, err := service.RefreshCache()
common.JsonResponse(c, data, err)
} else {
data, err := service.Get()
common.JsonResponse(c, data, err)
}
}

func (p *AllIP) Update(c *gin.Context) {

}
72 changes: 72 additions & 0 deletions server/controller/http/router/resource/dhcp_port.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (c) 2023 Yunshan Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package resource

import (
"github.com/gin-gonic/gin"

"github.com/deepflowio/deepflow/server/controller/config"
dbredis "github.com/deepflowio/deepflow/server/controller/db/redis"
httpcommon "github.com/deepflowio/deepflow/server/controller/http/common"
httpCfg "github.com/deepflowio/deepflow/server/controller/http/config"
"github.com/deepflowio/deepflow/server/controller/http/model"
"github.com/deepflowio/deepflow/server/controller/http/router/common"
"github.com/deepflowio/deepflow/server/controller/http/service/resource"
)

type DHCPPort struct {
httpCfg httpCfg.Config
redisCfg dbredis.Config
fpermitCfg config.FPermit
}

func NewDHCPPort(hCfg httpCfg.Config, rCfg dbredis.Config, fCfg config.FPermit) *DHCPPort {
return &DHCPPort{httpCfg: hCfg, redisCfg: rCfg, fpermitCfg: fCfg}
}

func (p *DHCPPort) RegisterTo(ge *gin.Engine) {
ge.GET(httpcommon.PATH_DHCP_PORT, p.Get)
}

func (p *DHCPPort) Get(c *gin.Context) {
header := NewHeaderValidator(c.Request.Header, p.fpermitCfg)
query := NewQueryValidator[model.DHCPPortQuery](c.Request.URL.Query())
if err := NewValidators(header, query).Validate(); err != nil {
common.BadRequestResponse(c, httpcommon.INVALID_PARAMETERS, err.Error())
return
}
service := resource.NewDHCPPortGet(
NewURLInfo(
c.Request.URL.String(),
query.structData,
),
header.userInfo,
p.redisCfg,
p.fpermitCfg,
)
if query.structData.RefreshCache {
data, err := service.RefreshCache()
common.JsonResponse(c, data, err)
} else {
data, err := service.Get()
common.JsonResponse(c, data, err)
}
}

func (p *DHCPPort) Update(c *gin.Context) {

}
2 changes: 1 addition & 1 deletion server/controller/http/router/resource/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewIP(hCfg httpCfg.Config, rCfg dbredis.Config, fCfg config.FPermit) *IP {
}

func (p *IP) RegisterTo(ge *gin.Engine) {
ge.GET(httpcommon.PATH_ALL_IP, p.Get)
ge.GET(httpcommon.PATH_IP, p.Get)
}

func (p *IP) Get(c *gin.Context) {
Expand Down
2 changes: 2 additions & 0 deletions server/controller/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ func (s *Server) RegisterRouters() {
resource.NewVInterface(s.controllerConfig.HTTPCfg, s.controllerConfig.RedisCfg, s.controllerConfig.FPermit),
resource.NewVPC(s.controllerConfig.HTTPCfg, s.controllerConfig.RedisCfg, s.controllerConfig.FPermit),
resource.NewNetwork(s.controllerConfig.HTTPCfg, s.controllerConfig.RedisCfg, s.controllerConfig.FPermit),
resource.NewDHCPPort(s.controllerConfig.HTTPCfg, s.controllerConfig.RedisCfg, s.controllerConfig.FPermit),
resource.NewIP(s.controllerConfig.HTTPCfg, s.controllerConfig.RedisCfg, s.controllerConfig.FPermit),
resource.NewAllIP(s.controllerConfig.HTTPCfg, s.controllerConfig.RedisCfg, s.controllerConfig.FPermit),
resource.NewVRouter(s.controllerConfig.HTTPCfg, s.controllerConfig.FPermit),
resource.NewRoutingTable(s.controllerConfig.HTTPCfg, s.controllerConfig.FPermit),
resource.NewSecurityGroup(s.controllerConfig.HTTPCfg, s.controllerConfig.FPermit),
Expand Down
4 changes: 4 additions & 0 deletions server/controller/http/service/resource/data/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ func GetDataProvider(resourceType string, cfg *RequiredConfigs) provider.DataPro
return redisdp.GetPodNamespace(cfg.Redis)
case common.RESOURCE_TYPE_VPC_EN:
return mysql.NewVPC()
case common.RESOURCE_TYPE_DHCP_PORT_EN:
return mysql.NewDHCPPort()
case common.RESOURCE_TYPE_NETWORK_EN:
return mysql.NewNetwork()
case common.RESOURCE_TYPE_IP_EN:
return redisdp.GetIP(cfg.Redis)
case common.RESOURCE_TYPE_ALL_IP_EN:
return redisdp.GetAllIP(cfg.Redis)

default:
return nil
Expand Down
Loading

0 comments on commit 6e859bd

Please sign in to comment.