Files
decort-golang-sdk/pkg/cloudapi/lb/backend_update.go

91 lines
3.1 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package lb
import (
"context"
"net/http"
"strconv"
2023-03-24 17:09:30 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-10-03 16:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// BackendUpdateRequest struct to update backend
2022-10-03 16:56:47 +03:00
type BackendUpdateRequest struct {
2022-12-22 17:56:47 +03:00
// ID of the load balancer instance to backendCreate
// Required: true
2023-03-24 17:09:30 +03:00
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
2022-12-22 17:56:47 +03:00
// Must be unique among all backends of this load balancer - name of the new backend to create
// Required: true
2023-03-24 17:09:30 +03:00
BackendName string `url:"backendName" json:"backendName" validate:"required"`
2022-12-22 17:56:47 +03:00
// Algorithm
// Should be one of:
// - roundrobin
// - static-rr
// - leastconn
// Required: false
2023-03-24 17:09:30 +03:00
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty" validate:"omitempty,lbAlgorithm"`
2022-12-22 17:56:47 +03:00
// Interval in milliseconds between two consecutive availability
// checks of the server that is considered available
// Required: false
2023-03-01 19:05:53 +03:00
Inter uint64 `url:"inter,omitempty" json:"inter,omitempty"`
2022-12-22 17:56:47 +03:00
// Interval in milliseconds between two consecutive checks to
// restore the availability of a server that is currently considered unavailable
// Required: false
2023-03-01 19:05:53 +03:00
DownInter uint64 `url:"downinter,omitempty" json:"downinter,omitempty"`
2022-12-22 17:56:47 +03:00
// Number of checks that the server must pass in order to get the available status
// and be included in the balancing scheme again
// Required: false
2023-03-01 19:05:53 +03:00
Rise uint64 `url:"rise,omitempty" json:"rise,omitempty"`
2022-12-22 17:56:47 +03:00
// Number of consecutive failed availability checks,
// after which the previously considered available server receives the status of
// unavailable and is temporarily excluded from the balancing scheme
// Required: false
2023-03-01 19:05:53 +03:00
Fall uint64 `url:"fall,omitempty" json:"fall,omitempty"`
2022-12-22 17:56:47 +03:00
// Interval in milliseconds from the moment the server receives the available status,
// after which the number of actually allowed connections to this server will be returned to 100% of the set limit
// Required: false
2023-03-01 19:05:53 +03:00
SlowStart uint64 `url:"slowstart,omitempty" json:"slowstart,omitempty"`
2022-12-22 17:56:47 +03:00
// Limit of simultaneous connections to the server. When this limit is reached,
// the server is temporarily excluded from the balancing scheme
// Required: false
2023-03-01 19:05:53 +03:00
MaxConn uint64 `url:"maxconn,omitempty" json:"maxconn,omitempty"`
2022-12-22 17:56:47 +03:00
// Limit of connections waiting in the queue.
// When this limit is reached, all subsequent connections will be forwarded to other servers
// Required: false
2023-03-01 19:05:53 +03:00
MaxQueue uint64 `url:"maxqueue,omitempty" json:"maxqueue,omitempty"`
2022-12-22 17:56:47 +03:00
// Server weight for use in weight balancing algorithms
// Required: false
2023-03-01 19:05:53 +03:00
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
2022-10-03 16:56:47 +03:00
}
2022-12-22 17:56:47 +03:00
// BackendUpdate updates existing backend on the specified load balancer. Note that backend name cannot be changed
2022-10-03 16:56:47 +03:00
func (l LB) BackendUpdate(ctx context.Context, req BackendUpdateRequest) (bool, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-10-03 16:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return false, validators.ValidationErrors(validators.GetErrors(err))
2022-10-03 16:56:47 +03:00
}
url := "/cloudapi/lb/backendUpdate"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}