v1.5.0-delta

This commit is contained in:
Никита Сорокин
2023-07-13 15:28:07 +03:00
parent 7c787f6fce
commit 5025a17ea4
71 changed files with 1602 additions and 936 deletions

View File

@@ -67,7 +67,7 @@ type BackendCreateRequest struct {
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
}
// BackendCreate creates new backend on the specified load balancer
// BackendCreate creates new backend on the specified load balancer
func (lb LB) BackendCreate(ctx context.Context, req BackendCreateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {

View File

@@ -19,10 +19,6 @@ type CreateRequest struct {
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// OS image ID to create load balancer from
// Required: false
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
// External network to connect this load balancer to
// Required: true
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`

View File

@@ -44,7 +44,7 @@ func (ll ListLB) FilterByImageID(imageID uint64) ListLB {
}
// FilterByK8SID returns ListLB used by specified K8S cluster.
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListLB, error) {
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListLB, error) {
caller := k8s.New(decortClient)
req := k8s.GetRequest{
@@ -60,28 +60,32 @@ func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient i
return cluster.LBID == rlb.ID
}
return ll.FilterFunc(predicate), nil
res := ll.FilterFunc(predicate)
return &res, nil
}
// FilterFunc allows filtering ListLB based on a user-specified predicate.
func (ll ListLB) FilterFunc(predicate func(RecordLB) bool) ListLB {
var result ListLB
for _, item := range ll {
for _, item := range ll.Data {
if predicate(item) {
result = append(result, item)
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found RecordLB
// If none was found, returns an empty struct.
func (ll ListLB) FindOne() RecordLB {
if len(ll) == 0 {
if len(ll.Data) == 0 {
return RecordLB{}
}
return ll[0]
return ll.Data[0]
}

View File

@@ -3,99 +3,102 @@ package lb
import "testing"
var lbs = ListLB{
RecordLB{
HAMode: true,
CKey: "",
Meta: []interface{}{},
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "test_user_1",
CreatedTime: 1636667448,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIPassword: "0000",
DPAPIUser: "api_user",
ExtNetID: 2522,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 1,
ID: 1,
ImageID: 2121,
Milestones: 129000,
Name: "k8s-lb-test-1",
PrimaryNode: Node{},
RGID: 25090,
RGName: "",
SecondaryNode: Node{},
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 101,
},
RecordLB{
HAMode: false,
CKey: "",
Meta: []interface{}{},
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "test_user_2",
CreatedTime: 1636667506,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIPassword: "0000",
DPAPIUser: "api_user_2",
ExtNetID: 2524,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 2,
ID: 2,
ImageID: 2129,
Milestones: 129013,
Name: "k8s-lb-test-2",
PrimaryNode: Node{},
RGID: 25092,
RGName: "",
SecondaryNode: Node{},
Status: "ENABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 102,
},
RecordLB{
HAMode: true,
CKey: "",
Meta: []interface{}{},
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "te2t_user_3",
CreatedTime: 1636667534,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIPassword: "0000",
DPAPIUser: "api_user_3",
ExtNetID: 2536,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 3,
ID: 3,
ImageID: 2139,
Milestones: 129025,
Name: "k8s-lb-test-3",
PrimaryNode: Node{},
RGID: 25106,
RGName: "",
SecondaryNode: Node{},
Status: "DISABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 118,
Data: []RecordLB{
{
HAMode: true,
CKey: "",
Meta: []interface{}{},
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "test_user_1",
CreatedTime: 1636667448,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIPassword: "0000",
DPAPIUser: "api_user",
ExtNetID: 2522,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 1,
ID: 1,
ImageID: 2121,
Milestones: 129000,
Name: "k8s-lb-test-1",
PrimaryNode: Node{},
RGID: 25090,
RGName: "",
SecondaryNode: Node{},
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 101,
},
{
HAMode: false,
CKey: "",
Meta: []interface{}{},
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "test_user_2",
CreatedTime: 1636667506,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIPassword: "0000",
DPAPIUser: "api_user_2",
ExtNetID: 2524,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 2,
ID: 2,
ImageID: 2129,
Milestones: 129013,
Name: "k8s-lb-test-2",
PrimaryNode: Node{},
RGID: 25092,
RGName: "",
SecondaryNode: Node{},
Status: "ENABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 102,
},
{
HAMode: true,
CKey: "",
Meta: []interface{}{},
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "te2t_user_3",
CreatedTime: 1636667534,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIPassword: "0000",
DPAPIUser: "api_user_3",
ExtNetID: 2536,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 3,
ID: 3,
ImageID: 2139,
Milestones: 129025,
Name: "k8s-lb-test-3",
PrimaryNode: Node{},
RGID: 25106,
RGName: "",
SecondaryNode: Node{},
Status: "DISABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 118,
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
@@ -135,7 +138,7 @@ func TestFilterFunc(t *testing.T) {
return rl.Status == "DISABLED"
})
for _, item := range actual {
for _, item := range actual.Data {
if item.Status != "DISABLED" {
t.Fatal("expected Status 'DISABLED', found: ", item.Status)
}
@@ -145,7 +148,7 @@ func TestFilterFunc(t *testing.T) {
func TestSortByCreatedTime(t *testing.T) {
actual := lbs.SortByCreatedTime(true)
if actual[0].CreatedTime != 1636667534 || actual[2].CreatedTime != 1636667448 {
if actual.Data[0].CreatedTime != 1636667534 || actual.Data[2].CreatedTime != 1636667448 {
t.Fatal("expected descending order, found ascending")
}
}

View File

@@ -8,6 +8,38 @@ import (
// Request struct for get list of load balancers
type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"`
// Find by resource group ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by tech status
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by frontend Ip
// Required: false
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
// Find by backend Ip
// Required: false
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
// Included deleted load balancers
// Required: false
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
@@ -22,7 +54,7 @@ type ListRequest struct {
}
// List gets list all load balancers
func (lb LB) List(ctx context.Context, req ListRequest) (ListLB, error) {
func (lb LB) List(ctx context.Context, req ListRequest) (*ListLB, error) {
url := "/cloudbroker/lb/list"
res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -37,6 +69,6 @@ func (lb LB) List(ctx context.Context, req ListRequest) (ListLB, error) {
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -8,6 +8,34 @@ import (
// Request struct for get list of deleted load balancers
type ListDeletedRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"`
// Find by resource group ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by tech status
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Find by frontend Ip
// Required: false
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
// Find by backend Ip
// Required: false
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -18,7 +46,7 @@ type ListDeletedRequest struct {
}
// ListDeleted gets list of deleted load balancers
func (lb LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListLB, error) {
func (lb LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListLB, error) {
url := "/cloudbroker/lb/listDeleted"
res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -33,6 +61,6 @@ func (lb LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListLB, e
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -134,7 +134,13 @@ type Node struct {
}
// List of load balancers
type ListLB []RecordLB
type ListLB struct {
// Data
Data []RecordLB `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Detailed information about load balancer
type RecordLB struct {

View File

@@ -12,7 +12,7 @@ import (
// - First argument -> prefix
// - Second argument -> indent
func (ll ListLB) Serialize(params ...string) (serialization.Serialized, error) {
if len(ll) == 0 {
if len(ll.Data) == 0 {
return []byte{}, nil
}

View File

@@ -6,16 +6,16 @@ import "sort"
//
// If inverse param is set to true, the order is reversed.
func (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
if len(ll) < 2 {
if len(ll.Data) < 2 {
return ll
}
sort.Slice(ll, func(i, j int) bool {
sort.Slice(ll.Data, func(i, j int) bool {
if inverse {
return ll[i].CreatedTime > ll[j].CreatedTime
return ll.Data[i].CreatedTime > ll.Data[j].CreatedTime
}
return ll[i].CreatedTime < ll[j].CreatedTime
return ll.Data[i].CreatedTime < ll.Data[j].CreatedTime
})
return ll
@@ -25,16 +25,16 @@ func (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
//
// If inverse param is set to true, the order is reversed.
func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
if len(ll) < 2 {
if len(ll.Data) < 2 {
return ll
}
sort.Slice(ll, func(i, j int) bool {
sort.Slice(ll.Data, func(i, j int) bool {
if inverse {
return ll[i].UpdatedTime > ll[j].UpdatedTime
return ll.Data[i].UpdatedTime > ll.Data[j].UpdatedTime
}
return ll[i].UpdatedTime < ll[j].UpdatedTime
return ll.Data[i].UpdatedTime < ll.Data[j].UpdatedTime
})
return ll
@@ -44,16 +44,16 @@ func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
//
// If inverse param is set to true, the order is reversed.
func (ll ListLB) SortByDeletedTime(inverse bool) ListLB {
if len(ll) < 2 {
if len(ll.Data) < 2 {
return ll
}
sort.Slice(ll, func(i, j int) bool {
sort.Slice(ll.Data, func(i, j int) bool {
if inverse {
return ll[i].DeletedTime > ll[j].DeletedTime
return ll.Data[i].DeletedTime > ll.Data[j].DeletedTime
}
return ll[i].DeletedTime < ll[j].DeletedTime
return ll.Data[i].DeletedTime < ll.Data[j].DeletedTime
})
return ll