Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
log
cache
.vscode
.DS_Store
output
dist
Expand Down
11 changes: 11 additions & 0 deletions conf/api_server.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ MaxIdleConns = 100
ConnMaxIdleTimeMs = 500000
ConnMaxLifetimeMs = 5000000

# ---------------------------------
# NacosRegsiter Config
# see https://github.com/nacos-group/nacos-sdk-go/blob/master/README.md
# see https://github.com/nacos-group/nacos-sdk-go/blob/master/README_CN.md
#[NacosRegsiter]
# [NacosRegsiter.ClientConfig]
# NamespaceId = "{NamespaceId}"

# [[NacosRegsiter.ServerConfig]]
# IpAddr = "127.0.0.1"
# Port = 8848

# ---------------------------------
# Dependence Config
Expand Down
12 changes: 12 additions & 0 deletions docs/zh_cn/config_param.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ MaxIdleConns = 100
ConnMaxIdleTimeMs = 50000
ConnMaxLifetimeMs = 50000

# ---------------------------------
# NacosRegsiter Config
# see https://github.com/nacos-group/nacos-sdk-go/blob/master/README.md
# see https://github.com/nacos-group/nacos-sdk-go/blob/master/README_CN.md
[NacosRegsiter]
[NacosRegsiter.ClientConfig]
NamespaceId = "test-dev"

[[NacosRegsiter.ServerConfig]]
IpAddr = "127.0.0.1"
Port = 8848


# ---------------------------------
# Dependence Config
Expand Down
13 changes: 10 additions & 3 deletions endpoints/openapi_v1/bfe_pool/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var _ xreq.Handler = CreateAction
// CreateAction action
// AUTO GEN BY ctrl, MODIFY AS U NEED
func CreateAction(req *http.Request) (interface{}, error) {
param, err := product_pool.NewUpsertParam(req)
param, err := product_pool.NewCreateParam(req)
if err != nil {
return nil, err
}
Expand All @@ -54,12 +54,19 @@ func CreateAction(req *http.Request) (interface{}, error) {
}

oneData, err := container.PoolManager.CreateBFEPool(req.Context(), &icluster_conf.PoolParam{
Name: param.Name,
Name: param.Name,
Type: param.Type,
}, &icluster_conf.InstancePool{
Instances: product_pool.Instancesc2i(param.Instances),
})
if err != nil {
return nil, err
}

return product_pool.NewOneData(oneData), nil
manager, err := container.InstancePoolManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{oneData})
if err != nil {
return nil, err
}

return product_pool.NewOneData(oneData, manager[oneData.Name]), nil
}
8 changes: 7 additions & 1 deletion endpoints/openapi_v1/bfe_pool/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/bfenetworks/api-server/endpoints/openapi_v1/product_pool"
"github.com/bfenetworks/api-server/lib/xreq"
"github.com/bfenetworks/api-server/model/iauth"
"github.com/bfenetworks/api-server/model/icluster_conf"
"github.com/bfenetworks/api-server/stateful/container"
)

Expand All @@ -46,5 +47,10 @@ func DeleteAction(req *http.Request) (interface{}, error) {
return nil, err
}

return product_pool.NewOneData(oldOne), nil
manager, err := container.InstancePoolManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{oldOne})
if err != nil {
return nil, err
}

return product_pool.NewOneData(oldOne, manager[oldOne.Name]), nil
}
7 changes: 6 additions & 1 deletion endpoints/openapi_v1/bfe_pool/one.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/bfenetworks/api-server/lib/xerror"
"github.com/bfenetworks/api-server/lib/xreq"
"github.com/bfenetworks/api-server/model/iauth"
"github.com/bfenetworks/api-server/model/icluster_conf"
"github.com/bfenetworks/api-server/stateful/container"
)

Expand Down Expand Up @@ -51,6 +52,10 @@ func OneAction(req *http.Request) (interface{}, error) {
return nil, xerror.WrapRecordNotExist("Instance Pool")
}

return product_pool.NewOneData(one), nil
manager, err := container.InstancePoolManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{one})
if err != nil {
return nil, err
}
return product_pool.NewOneData(one, manager[one.Name]), nil

}
15 changes: 9 additions & 6 deletions endpoints/openapi_v1/bfe_pool/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var _ xreq.Handler = UpdateAction
// UpdateAction action
// AUTO GEN BY ctrl, MODIFY AS U NEED
func UpdateAction(req *http.Request) (interface{}, error) {
param, err := product_pool.NewUpsertParam(req)
param, err := product_pool.NewUpdateParam(req)
if err != nil {
return nil, err
}
Expand All @@ -52,11 +52,14 @@ func UpdateAction(req *http.Request) (interface{}, error) {
return nil, xerror.WrapRecordNotExist("Instance Pool")
}

err = container.PoolManager.UpdateBFEPool(req.Context(), one, &icluster_conf.PoolParam{
p := &icluster_conf.InstancePool{
Name: one.Name,
Instances: product_pool.Instancesc2i(param.Instances),
})

one.Instances = product_pool.Instancesc2i(param.Instances)
}
err = container.InstancePoolManager.UpdateInstances(req.Context(), one, p)
if err != nil {
return nil, err
}

return product_pool.NewOneData(one), err
return product_pool.NewOneData(one, p), err
}
37 changes: 24 additions & 13 deletions endpoints/openapi_v1/product_pool/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"net/http"
"strings"

"github.com/bfenetworks/api-server/lib"
"github.com/bfenetworks/api-server/lib/xerror"
"github.com/bfenetworks/api-server/lib/xreq"
"github.com/bfenetworks/api-server/model/iauth"
Expand All @@ -26,13 +27,6 @@ import (
"github.com/bfenetworks/api-server/stateful/container"
)

// UpsertParam Request Param
// AUTO GEN BY ctrl, MODIFY AS U NEED
type UpsertParam struct {
Name *string `json:"name" uri:"instance_pool_name" validate:"required,min=2"`
Instances []*Instance `json:"instances" uri:"instances" validate:"min=1,dive"`
}

// CreateRoute route
// AUTO GEN BY ctrl, MODIFY AS U NEED
var CreateEndpoint = &xreq.Endpoint{
Expand All @@ -42,9 +36,19 @@ var CreateEndpoint = &xreq.Endpoint{
Authorizer: iauth.FAP(iauth.FeatureProductPool, iauth.ActionCreate),
}

// CreateParam Request Param
// AUTO GEN BY ctrl, MODIFY AS U NEED
type CreateParam struct {
Name *string `json:"name" validate:"required,min=2"`
Type *int8 `json:"type" validate:"oneof=1"`
Instances []*Instance `json:"instances" validate:"min=1,dive"`
}

// AUTO GEN BY ctrl, MODIFY AS U NEED
func NewUpsertParam(req *http.Request) (*UpsertParam, error) {
param := &UpsertParam{}
func NewCreateParam(req *http.Request) (*CreateParam, error) {
param := &CreateParam{
Type: lib.PInt8(icluster_conf.InstancePoolTypeRDB),
}
err := xreq.Bind(req, param)
if err != nil {
return nil, err
Expand All @@ -58,7 +62,7 @@ var _ xreq.Handler = CreateAction
// CreateAction action
// AUTO GEN BY ctrl, MODIFY AS U NEED
func CreateAction(req *http.Request) (interface{}, error) {
param, err := NewUpsertParam(req)
param, err := NewCreateParam(req)
if err != nil {
return nil, err
}
Expand All @@ -80,7 +84,12 @@ func CreateAction(req *http.Request) (interface{}, error) {
return nil, err
}

return NewOneData(oneData), nil
manager, err := container.InstancePoolManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{oneData})
if err != nil {
return nil, err
}

return NewOneData(oneData, manager[oneData.Name]), nil
}

func Instancesc2i(is []*Instance) []icluster_conf.Instance {
Expand All @@ -103,9 +112,11 @@ func Instancesc2i(is []*Instance) []icluster_conf.Instance {
return rst
}

func CreateProcess(req *http.Request, product *ibasic.Product, param *UpsertParam) (*icluster_conf.Pool, error) {
func CreateProcess(req *http.Request, product *ibasic.Product, param *CreateParam) (*icluster_conf.Pool, error) {
return container.PoolManager.CreateProductPool(req.Context(), product, &icluster_conf.PoolParam{
Name: param.Name,
Name: param.Name,
Type: param.Type,
}, &icluster_conf.InstancePool{
Instances: Instancesc2i(param.Instances),
})
}
8 changes: 7 additions & 1 deletion endpoints/openapi_v1/product_pool/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/bfenetworks/api-server/lib/xreq"
"github.com/bfenetworks/api-server/model/iauth"
"github.com/bfenetworks/api-server/model/ibasic"
"github.com/bfenetworks/api-server/model/icluster_conf"
"github.com/bfenetworks/api-server/stateful/container"
)

Expand Down Expand Up @@ -52,5 +53,10 @@ func DeleteAction(req *http.Request) (interface{}, error) {
return nil, err
}

return NewOneData(oldOne), nil
manager, err := container.InstancePoolManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{oldOne})
if err != nil {
return nil, err
}

return NewOneData(oldOne, manager[oldOne.Name]), nil
}
26 changes: 16 additions & 10 deletions endpoints/openapi_v1/product_pool/one.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ type OneData struct {
Instances []*Instance `json:"instances" uri:"instances"`
}

func NewOneData(pool *icluster_conf.Pool) *OneData {
func NewOneData(pool *icluster_conf.Pool, pis *icluster_conf.InstancePool) *OneData {
Copy link
Member

Choose a reason for hiding this comment

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

pis => iPool

is := []*Instance{}
Copy link
Member

Choose a reason for hiding this comment

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

is => instances

for _, one := range pool.Instances {
is = append(is, &Instance{
Hostname: one.HostName,
IP: one.IP,
Weight: one.Weight,
Ports: one.Ports,
Tags: one.Tags,
})
if pis != nil {
for _, one := range pis.Instances {
is = append(is, &Instance{
Hostname: one.HostName,
IP: one.IP,
Weight: one.Weight,
Ports: one.Ports,
Tags: one.Tags,
})
}
}

return &OneData{
Expand Down Expand Up @@ -105,5 +107,9 @@ func OneAction(req *http.Request) (interface{}, error) {
return nil, xerror.WrapRecordNotExist("Instance Pool")
}

return NewOneData(one), nil
manager, err := container.InstancePoolManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{one})
if err != nil {
return nil, err
}
return NewOneData(one, manager[one.Name]), nil
}
33 changes: 27 additions & 6 deletions endpoints/openapi_v1/product_pool/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ import (
"github.com/bfenetworks/api-server/stateful/container"
)

// UpdateParam Request Param
// AUTO GEN BY ctrl, MODIFY AS U NEED
type UpdateParam struct {
Name *string `uri:"instance_pool_name" validate:"required,min=2"`
Instances []*Instance `json:"instances" validate:"min=1,dive"`
}

// AUTO GEN BY ctrl, MODIFY AS U NEED
func NewUpdateParam(req *http.Request) (*UpdateParam, error) {
param := &UpdateParam{}
err := xreq.Bind(req, param)
if err != nil {
return nil, err
}

return param, err
}

// UpdateRoute route
// AUTO GEN BY ctrl, MODIFY AS U NEED
var UpdateEndpoint = &xreq.Endpoint{
Expand All @@ -39,7 +57,7 @@ var _ xreq.Handler = UpdateAction
// UpdateAction action
// AUTO GEN BY ctrl, MODIFY AS U NEED
func UpdateAction(req *http.Request) (interface{}, error) {
param, err := NewUpsertParam(req)
param, err := NewCreateParam(req)
if err != nil {
return nil, err
}
Expand All @@ -56,11 +74,14 @@ func UpdateAction(req *http.Request) (interface{}, error) {
return nil, xerror.WrapRecordNotExist("Instance Pool")
}

err = container.PoolManager.UpdateProductPool(req.Context(), product, one, &icluster_conf.PoolParam{
pi := &icluster_conf.InstancePool{
Copy link
Member

Choose a reason for hiding this comment

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

pi => pool

Name: one.Name,
Instances: Instancesc2i(param.Instances),
})

one.Instances = Instancesc2i(param.Instances)
}
err = container.InstancePoolManager.UpdateInstances(req.Context(), one, pi)
if err != nil {
return nil, err
}

return NewOneData(one), err
return NewOneData(one, pi), nil
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/go-playground/validator/v10 v10.9.0
github.com/go-sql-driver/mysql v1.6.0
github.com/gorilla/mux v1.8.0
github.com/nacos-group/nacos-sdk-go v1.0.9
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
github.com/rs/cors v1.8.0
Expand Down
Loading