Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
.vscode
.DS_Store
output
dist
Expand Down
1 change: 1 addition & 0 deletions cache/naming/DEFAULT_GROUP@@.atom_runtime_python_service
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"dom":"","cacheMillis":10000,"useSpecifiedUrl":false,"hosts":[],"checksum":"","lastRefTime":1644082855728,"env":"","clusters":"","metadata":null,"name":"DEFAULT_GROUP@@.atom_runtime_python_service"}
1 change: 1 addition & 0 deletions cache/naming/DEFAULT_GROUP@@atom_runtime_python_service
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"dom":"","cacheMillis":10000,"useSpecifiedUrl":false,"hosts":[{"valid":false,"marked":false,"instanceId":"127.0.1.1#9999#None#DEFAULT_GROUP@@atom_runtime_python_service","port":9999,"ip":"127.0.1.1","weight":1,"metadata":{},"clusterName":"None","serviceName":"DEFAULT_GROUP@@atom_runtime_python_service","enabled":true,"healthy":true,"ephemeral":true}],"checksum":"","lastRefTime":1644083204738,"env":"","clusters":"","metadata":null,"name":"DEFAULT_GROUP@@atom_runtime_python_service"}
Comment thread
githublaohu marked this conversation as resolved.
Outdated
15 changes: 13 additions & 2 deletions conf/api_server.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ StdOut = false
DBName = "open_bfe"
Addr = "127.0.0.1:3306"
Net = "tcp"
User = "{user}"
Passwd = "{password}"
User = "root"
Comment thread
githublaohu marked this conversation as resolved.
Outdated
Passwd = "root"
MultiStatements = true
MaxAllowedPacket = 67108864
ParseTime = true
Expand All @@ -49,6 +49,17 @@ MaxIdleConns = 100
ConnMaxIdleTimeMs = 500000
ConnMaxLifetimeMs = 5000000

# ---------------------------------
# NacosRegsiter Config
# see https://githublaohu/nacos-sdk-go/blob/master/README.md
Comment thread
githublaohu marked this conversation as resolved.
Outdated
# see https://githublaohu/nacos-sdk-go/blob/master/README_CN.md
[NacosRegsiter]
Comment thread
githublaohu marked this conversation as resolved.
Outdated
# [NacosRegsiter.ClientConfig]
# NamespaceId = "atom-dev"

# [[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://githublaohu/nacos-sdk-go/blob/master/README.md
Comment thread
githublaohu marked this conversation as resolved.
Outdated
# see https://githublaohu/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.PoolInstances{
Instances: product_pool.Instancesc2i(param.Instances),
})
if err != nil {
return nil, err
}

return product_pool.NewOneData(oneData), nil
pism, err := container.PoolInstancesManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{oneData})
Comment thread
githublaohu marked this conversation as resolved.
Outdated
if err != nil {
return nil, err
}

return product_pool.NewOneData(oneData, pism[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
pism, err := container.PoolInstancesManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{oldOne})
Comment thread
githublaohu marked this conversation as resolved.
Outdated
if err != nil {
return nil, err
}

return product_pool.NewOneData(oldOne, pism[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
pism, err := container.PoolInstancesManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{one})
Comment thread
githublaohu marked this conversation as resolved.
Outdated
if err != nil {
return nil, err
}
return product_pool.NewOneData(one, pism[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{
pi := &icluster_conf.PoolInstances{
Comment thread
githublaohu marked this conversation as resolved.
Outdated
Name: one.Name,
Instances: product_pool.Instancesc2i(param.Instances),
})

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

return product_pool.NewOneData(one), err
return product_pool.NewOneData(one, pi), 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.PoolInstancesTypeRDB),
}
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
pism, err := container.PoolInstancesManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{oneData})
Comment thread
githublaohu marked this conversation as resolved.
Outdated
if err != nil {
return nil, err
}

return NewOneData(oneData, pism[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.PoolInstances{
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
pism, err := container.PoolInstancesManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{oldOne})
Comment thread
githublaohu marked this conversation as resolved.
Outdated
if err != nil {
return nil, err
}

return NewOneData(oldOne, pism[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.PoolInstances) *OneData {
is := []*Instance{}

Copy link
Copy Markdown
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
pism, err := container.PoolInstancesManager.BatchFetchInstances(req.Context(), []*icluster_conf.Pool{one})
if err != nil {
return nil, err
}
return NewOneData(one, pism[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.PoolInstances{
Name: one.Name,
Instances: Instancesc2i(param.Instances),
})

one.Instances = Instancesc2i(param.Instances)
}
err = container.PoolInstancesManager.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