Compare commits

...

4 Commits

Author SHA1 Message Date
afcbc7e749 1.6.0-beta 2023-09-14 15:05:38 +03:00
0b3de4df7f 1.6.0-alfa 2023-09-11 13:11:33 +03:00
c0608d08b9 1.5.8-gostech 2023-09-07 18:11:25 +03:00
4d9b8fc9d8 v1.5.7 2023-09-04 18:48:22 +03:00
11 changed files with 62 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
## Version 1.5.6 ## Version 1.6.0-beta
### Bugfix ### Bugfix
- Fix the RecordLB field, add the RecordLBList field to cloudbroker/lb/models to correctly receive information on get and list requests - Fixed RoudTrip bug in HTTP transport, made it concurrent safe

View File

@@ -3,6 +3,7 @@ package client
import ( import (
"crypto/tls" "crypto/tls"
"net/http" "net/http"
"sync"
"time" "time"
"repository.basistech.ru/BASIS/decort-golang-sdk/config" "repository.basistech.ru/BASIS/decort-golang-sdk/config"
@@ -32,6 +33,7 @@ func NewHttpClient(cfg config.Config) *http.Client {
ssoURL: cfg.SSOURL, ssoURL: cfg.SSOURL,
token: cfg.Token, token: cfg.Token,
expiryTime: expiredTime, expiryTime: expiredTime,
mutex: &sync.Mutex{},
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}, },

View File

@@ -4,6 +4,7 @@ import (
"crypto/tls" "crypto/tls"
"net/http" "net/http"
"net/url" "net/url"
"sync"
"time" "time"
"repository.basistech.ru/BASIS/decort-golang-sdk/config" "repository.basistech.ru/BASIS/decort-golang-sdk/config"
@@ -33,6 +34,7 @@ func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
token: cfg.Token, token: cfg.Token,
decortURL: cfg.DecortURL, decortURL: cfg.DecortURL,
expiryTime: expiredTime, expiryTime: expiredTime,
mutex: &sync.Mutex{},
}, },
Timeout: cfg.Timeout.Get(), Timeout: cfg.Timeout.Get(),

View File

@@ -5,6 +5,7 @@ import (
"io" "io"
"net/http" "net/http"
"strings" "strings"
"sync"
"time" "time"
) )
@@ -15,6 +16,7 @@ type transportLegacy struct {
retries uint64 retries uint64
token string token string
decortURL string decortURL string
mutex *sync.Mutex
expiryTime time.Time expiryTime time.Time
} }
@@ -56,7 +58,9 @@ func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, erro
var resp *http.Response var resp *http.Response
var err error var err error
for i := uint64(0); i < t.retries; i++ { for i := uint64(0); i < t.retries; i++ {
t.mutex.Lock()
resp, err = t.base.RoundTrip(req) resp, err = t.base.RoundTrip(req)
t.mutex.Unlock()
if err == nil { if err == nil {
if resp.StatusCode == 200 { if resp.StatusCode == 200 {
return resp, nil return resp, nil

View File

@@ -5,6 +5,7 @@ import (
"io" "io"
"net/http" "net/http"
"strings" "strings"
"sync"
"time" "time"
) )
@@ -16,6 +17,7 @@ type transport struct {
token string token string
ssoURL string ssoURL string
expiryTime time.Time expiryTime time.Time
mutex *sync.Mutex
} }
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
@@ -53,7 +55,9 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
var resp *http.Response var resp *http.Response
var err error var err error
for i := uint64(0); i < t.retries; i++ { for i := uint64(0); i < t.retries; i++ {
t.mutex.Lock()
resp, err = t.base.RoundTrip(req) resp, err = t.base.RoundTrip(req)
t.mutex.Unlock()
if err == nil { if err == nil {
if resp.StatusCode == 200 { if resp.StatusCode == 200 {
return resp, nil return resp, nil
@@ -65,5 +69,6 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
//logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries) //logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries)
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
} }
return nil, fmt.Errorf("could not execute request: %w", err) return nil, fmt.Errorf("could not execute request: %w", err)
} }

View File

@@ -106,6 +106,10 @@ type CreateRequest struct {
// Text description of this Kubernetes cluster // Text description of this Kubernetes cluster
// Required: false // Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"` Description string `url:"desc,omitempty" json:"desc,omitempty"`
//Use only selected ExtNet for infrastructure connections
// Required: false
ExtNetOnly bool `url:"extnetOnly,omitempty" json:"extnetOnly,omitempty"`
} }
// Create creates a new Kubernetes cluster in the specified Resource Group // Create creates a new Kubernetes cluster in the specified Resource Group

View File

@@ -2,6 +2,7 @@ package lb
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strings" "strings"
@@ -20,16 +21,16 @@ type CreateRequest struct {
Name string `url:"name" json:"name" validate:"required"` Name string `url:"name" json:"name" validate:"required"`
// External network to connect this load balancer to // External network to connect this load balancer to
// Required: true // Required: false
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"` ExtNetID uint64 `url:"extnetId" json:"extnetId"`
// Internal network (VINS) to connect this load balancer to // Internal network (VINS) to connect this load balancer to
// Required: true // Required: false
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"` VINSID uint64 `url:"vinsId" json:"vinsId"`
// Start now Load balancer // Start now Load balancer
// Required: true // Required: false
Start bool `url:"start" json:"start" validate:"required"` Start bool `url:"start" json:"start"`
// Text description of this load balancer // Text description of this load balancer
// Required: false // Required: false
@@ -45,6 +46,10 @@ func (l LB) Create(ctx context.Context, req CreateRequest) (string, error) {
} }
} }
if req.ExtNetID == 0 && req.VINSID == 0 {
return "", errors.New ("vinsId and extNetId cannot be both in the value 0")
}
url := "/cloudapi/lb/create" url := "/cloudapi/lb/create"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -2,7 +2,7 @@ package grid
// FilterByID returns ListGrids with specified ID. // FilterByID returns ListGrids with specified ID.
func (lg ListGrids) FilterByID(id uint64) ListGrids { func (lg ListGrids) FilterByID(id uint64) ListGrids {
predicate := func(rg RecordGrid) bool { predicate := func(rg ItemGridList) bool {
return rg.ID == id return rg.ID == id
} }
@@ -11,7 +11,7 @@ func (lg ListGrids) FilterByID(id uint64) ListGrids {
// FilterByName returns ListGrids with specified Name. // FilterByName returns ListGrids with specified Name.
func (lg ListGrids) FilterByName(name string) ListGrids { func (lg ListGrids) FilterByName(name string) ListGrids {
predicate := func(rg RecordGrid) bool { predicate := func(rg ItemGridList) bool {
return rg.Name == name return rg.Name == name
} }
@@ -20,7 +20,7 @@ func (lg ListGrids) FilterByName(name string) ListGrids {
// FilterByLocationCode returns ListGrids with specified LocationCode. // FilterByLocationCode returns ListGrids with specified LocationCode.
func (lg ListGrids) FilterByLocationCode(locationCode string) ListGrids { func (lg ListGrids) FilterByLocationCode(locationCode string) ListGrids {
predicate := func(rg RecordGrid) bool { predicate := func(rg ItemGridList) bool {
return rg.LocationCode == locationCode return rg.LocationCode == locationCode
} }
@@ -28,7 +28,7 @@ func (lg ListGrids) FilterByLocationCode(locationCode string) ListGrids {
} }
// FilterFunc allows filtering ListGrids based on a user-specified predicate. // FilterFunc allows filtering ListGrids based on a user-specified predicate.
func (lg ListGrids) FilterFunc(predicate func(RecordGrid) bool) ListGrids { func (lg ListGrids) FilterFunc(predicate func(ItemGridList) bool) ListGrids {
var result ListGrids var result ListGrids
for _, item := range lg.Data { for _, item := range lg.Data {
@@ -44,9 +44,9 @@ func (lg ListGrids) FilterFunc(predicate func(RecordGrid) bool) ListGrids {
// FindOne returns first found RecordGrid. // FindOne returns first found RecordGrid.
// If none was found, returns an empty struct. // If none was found, returns an empty struct.
func (lg ListGrids) FindOne() RecordGrid { func (lg ListGrids) FindOne() ItemGridList {
if len(lg.Data) == 0 { if len(lg.Data) == 0 {
return RecordGrid{} return ItemGridList{}
} }
return lg.Data[0] return lg.Data[0]

View File

@@ -3,7 +3,7 @@ package grid
import "testing" import "testing"
var grids = ListGrids{ var grids = ListGrids{
Data: []RecordGrid{ Data: []ItemGridList{
{ {
Resources: Resources{ Resources: Resources{
Current: RecordResource{ Current: RecordResource{
@@ -123,7 +123,7 @@ func TestFilterByLocationCode(t *testing.T) {
} }
func TestFilterFunc(t *testing.T) { func TestFilterFunc(t *testing.T) {
actual := grids.FilterFunc(func(rg RecordGrid) bool { actual := grids.FilterFunc(func(rg ItemGridList) bool {
return rg.GID == 777 return rg.GID == 777
}). }).
FindOne() FindOne()

View File

@@ -18,7 +18,7 @@ type RecordResourcesConsumption struct {
Reserved RecordResource `json:"Reserved"` Reserved RecordResource `json:"Reserved"`
// GID // GID
GID uint64 `json:"gid"` GID uint64 `json:"id"`
} }
type ListResourceConsumption struct { type ListResourceConsumption struct {
@@ -67,6 +67,27 @@ type DiskUsage struct {
// Detailed information about grid // Detailed information about grid
type RecordGrid struct { type RecordGrid struct {
// Flag
Flag string `json:"flag"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Location code
LocationCode string `json:"locationCode"`
// Name
Name string `json:"name"`
}
// Information about grid
type ItemGridList struct {
// Resource information // Resource information
Resources Resources `json:"Resources"` Resources Resources `json:"Resources"`
@@ -92,7 +113,7 @@ type RecordGrid struct {
// List Grids // List Grids
type ListGrids struct { type ListGrids struct {
//Data //Data
Data []RecordGrid `json:"data"` Data []ItemGridList `json:"data"`
// Entry count // Entry count
EntryCount uint64 `json:"entryCount"` EntryCount uint64 `json:"entryCount"`

View File

@@ -29,7 +29,7 @@ type CreateRequest struct {
// Start now Load balancer // Start now Load balancer
// Required: false // Required: false
Start bool `url:"start" json:"start" validate:"required"` Start bool `url:"start" json:"start"`
// Text description of this load balancer // Text description of this load balancer
// Required: false // Required: false