2020-01-16 22:14:00 +00:00
|
|
|
package api
|
|
|
|
|
2020-01-30 00:26:31 +00:00
|
|
|
// Scaling is used to query scaling-related API endpoints
|
|
|
|
type Scaling struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scaling returns a handle on the scaling endpoints.
|
|
|
|
func (c *Client) Scaling() *Scaling {
|
|
|
|
return &Scaling{client: c}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Scaling) ListPolicies(q *QueryOptions) ([]*ScalingPolicyListStub, *QueryMeta, error) {
|
|
|
|
var resp []*ScalingPolicyListStub
|
|
|
|
qm, err := s.client.query("/v1/scaling/policies", &resp, q)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return resp, qm, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Scaling) GetPolicy(ID string, q *QueryOptions) (*ScalingPolicy, *QueryMeta, error) {
|
|
|
|
var policy ScalingPolicy
|
|
|
|
qm, err := s.client.query("/v1/scaling/policy/"+ID, &policy, q)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return &policy, qm, nil
|
2020-01-16 22:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ScalingPolicy) Canonicalize() {
|
|
|
|
if p.Enabled == nil {
|
|
|
|
p.Enabled = boolToPtr(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 21:19:15 +00:00
|
|
|
// ScalingRequest is the payload for a generic scaling action
|
2020-01-16 22:14:00 +00:00
|
|
|
type ScalingRequest struct {
|
|
|
|
Value interface{}
|
|
|
|
Reason string
|
2020-02-03 20:27:28 +00:00
|
|
|
Error string
|
2020-01-16 22:14:00 +00:00
|
|
|
WriteRequest
|
2020-02-05 21:19:15 +00:00
|
|
|
// this is effectively a job update, so we need the ability to override policy.
|
|
|
|
PolicyOverride bool
|
2020-01-16 22:14:00 +00:00
|
|
|
}
|
2020-01-26 16:13:56 +00:00
|
|
|
|
2020-01-30 00:26:31 +00:00
|
|
|
// ScalingPolicy is the user-specified API object for an autoscaling policy
|
|
|
|
type ScalingPolicy struct {
|
|
|
|
ID string
|
|
|
|
Namespace string
|
|
|
|
Target string
|
|
|
|
JobID string
|
|
|
|
Policy map[string]interface{}
|
|
|
|
Enabled *bool
|
|
|
|
CreateIndex uint64
|
|
|
|
ModifyIndex uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
// ScalingPolicyListStub is used to return a subset of scaling policy information
|
|
|
|
// for the scaling policy list
|
|
|
|
type ScalingPolicyListStub struct {
|
|
|
|
ID string
|
|
|
|
JobID string
|
|
|
|
Target string
|
|
|
|
CreateIndex uint64
|
|
|
|
ModifyIndex uint64
|
|
|
|
}
|
|
|
|
|
2020-01-26 16:13:56 +00:00
|
|
|
// ScaleStatusResponse is the payload for a generic scaling action
|
|
|
|
type ScaleStatusResponse struct {
|
|
|
|
JobID string
|
|
|
|
JobModifyIndex uint64
|
2020-02-03 20:27:28 +00:00
|
|
|
Value interface{}
|
2020-01-26 16:13:56 +00:00
|
|
|
}
|