114 lines
3.7 KiB
Go
114 lines
3.7 KiB
Go
|
|
package basismpm
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"net/http"
|
||
|
|
"strconv"
|
||
|
|
|
||
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||
|
|
)
|
||
|
|
|
||
|
|
// UpdateRequest to update basis_mpm service configuration on a node
|
||
|
|
type UpdateRequest struct {
|
||
|
|
// Node ID
|
||
|
|
// Required: true
|
||
|
|
NodeID uint64 `url:"node_id" json:"node_id" validate:"required"`
|
||
|
|
|
||
|
|
// Memory pressure threshold (%)
|
||
|
|
// Required: false
|
||
|
|
// Default: 20
|
||
|
|
PressureThreshold uint64 `url:"pressure_threshold,omitempty" json:"pressure_threshold,omitempty" validate:"omitempty,pressureThreshold"`
|
||
|
|
|
||
|
|
// Deflate threshold (%)
|
||
|
|
// Required: false
|
||
|
|
// Default: 30
|
||
|
|
DeflateThreshold uint64 `url:"deflate_threshold,omitempty" json:"deflate_threshold,omitempty" validate:"omitempty,deflateThreshold"`
|
||
|
|
|
||
|
|
// Host reserved memory
|
||
|
|
// Required: false
|
||
|
|
// Default: "8GB+5%"
|
||
|
|
HostReserved string `url:"host_reserved,omitempty" json:"host_reserved,omitempty"`
|
||
|
|
|
||
|
|
// Buffer percentage (%)
|
||
|
|
// Required: false
|
||
|
|
// Default: 20
|
||
|
|
BufferPCT uint64 `url:"buffer_pct,omitempty" json:"buffer_pct,omitempty" validate:"omitempty,bufferPCT"`
|
||
|
|
|
||
|
|
// Guaranteed memory percentage (%)
|
||
|
|
// Required: false
|
||
|
|
// Default: 25
|
||
|
|
GuaranteedPCT uint64 `url:"guaranteed_pct,omitempty" json:"guaranteed_pct,omitempty" validate:"omitempty,guaranteedPCT"`
|
||
|
|
|
||
|
|
// Absolute minimum guaranteed memory (MB)
|
||
|
|
// Required: false
|
||
|
|
// Default: 512
|
||
|
|
GuaranteedABSMin uint64 `url:"guaranteed_abs_min,omitempty" json:"guaranteed_abs_min,omitempty" validate:"omitempty,guaranteedABSMin"`
|
||
|
|
|
||
|
|
// Shrink threshold percentage (%)
|
||
|
|
// Required: false
|
||
|
|
// Default: 50
|
||
|
|
ShrinkThresholdPCT uint64 `url:"shrink_threshold_pct,omitempty" json:"shrink_threshold_pct,omitempty" validate:"omitempty,shrinkThresholdPCT"`
|
||
|
|
|
||
|
|
// Max shrink percentage per cycle (%)
|
||
|
|
// Required: false
|
||
|
|
// Default: 10
|
||
|
|
BalloonMaxShrinkPCT uint64 `url:"balloon_max_shrink_pct,omitempty" json:"balloon_max_shrink_pct,omitempty" validate:"omitempty,balloonMaxShrinkPCT"`
|
||
|
|
|
||
|
|
// Max grow percentage per cycle (%)
|
||
|
|
// Required: false
|
||
|
|
// Default: 10
|
||
|
|
BalloonMaxGrowPCT uint64 `url:"balloon_max_grow_pct,omitempty" json:"balloon_max_grow_pct,omitempty" validate:"omitempty,balloonMaxGrowPCT"`
|
||
|
|
|
||
|
|
// VM change cooldown (seconds)
|
||
|
|
// Required: false
|
||
|
|
// Default: 60
|
||
|
|
VMChangeCooldown uint64 `url:"vm_change_cooldown,omitempty" json:"vm_change_cooldown,omitempty" validate:"omitempty,vmChangeCooldown"`
|
||
|
|
|
||
|
|
// Emergency return cooldown (seconds)
|
||
|
|
// Required: false
|
||
|
|
// Default: 300
|
||
|
|
EmergencyReturnCooldown uint64 `url:"emergency_return_cooldown,omitempty" json:"emergency_return_cooldown,omitempty" validate:"omitempty,emergencyReturnCooldown"`
|
||
|
|
|
||
|
|
// Major fault increase per cycle that triggers emergency memory return
|
||
|
|
// Required: false
|
||
|
|
// Default: 100
|
||
|
|
MajorFaultThreshold uint64 `url:"major_fault_threshold,omitempty" json:"major_fault_threshold,omitempty" validate:"omitempty,majorFaultThreshold"`
|
||
|
|
|
||
|
|
// Daemon log level
|
||
|
|
// Required: false
|
||
|
|
// Default: INFO
|
||
|
|
// Options:
|
||
|
|
// - DEBUG
|
||
|
|
// - INFO
|
||
|
|
// - WARNING
|
||
|
|
// - ERROR
|
||
|
|
// - CRITICAL
|
||
|
|
LogLevel string `url:"log_level,omitempty" json:"log_level,omitempty" validate:"omitempty,logLevel"`
|
||
|
|
|
||
|
|
// Daemon log file path (empty for stdout only)
|
||
|
|
// Required: false
|
||
|
|
LogFile string `url:"log_file,omitempty" json:"log_file,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (bm BasisMPM) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||
|
|
err := validators.ValidateRequest(req)
|
||
|
|
if err != nil {
|
||
|
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||
|
|
}
|
||
|
|
|
||
|
|
url := "/cloudbroker/basis_mpm/update"
|
||
|
|
|
||
|
|
res, err := bm.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||
|
|
if err != nil {
|
||
|
|
return false, err
|
||
|
|
}
|
||
|
|
|
||
|
|
result, err := strconv.ParseBool(string(res))
|
||
|
|
if err != nil {
|
||
|
|
return false, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return result, nil
|
||
|
|
}
|