From d044b1738488013960dc90289a947440e3e922cf Mon Sep 17 00:00:00 2001 From: Michal-Leszczynski <74614433+Michal-Leszczynski@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:02:16 +0200 Subject: [PATCH] feat(swagger): agent, add definitions for cpu pinning endpoints (#4072) * feat(swagger): agent, add cpu pinning endpoints Those endpoints will be used during restore to optionally unpin agent from cpus for its duration. * feat(cpuset): add function for checking pinned cpus This function will in the agent's endpoint getting cpus to which agent is pinned. --- v3/pkg/util/cpuset/cpuset_linux.go | 25 ++++ v3/swagger/agent.json | 80 +++++++++++ .../client/operations/get_cpu_parameters.go | 113 +++++++++++++++ .../client/operations/get_cpu_responses.go | 135 ++++++++++++++++++ .../client/operations/operations_client.go | 111 ++++++++++++++ .../client/operations/pin_cpu_parameters.go | 113 +++++++++++++++ .../client/operations/pin_cpu_responses.go | 133 +++++++++++++++++ .../client/operations/unpin_cpu_parameters.go | 113 +++++++++++++++ .../client/operations/unpin_cpu_responses.go | 133 +++++++++++++++++ v3/swagger/gen/agent/models/cpus.go | 43 ++++++ 10 files changed, 999 insertions(+) create mode 100644 v3/swagger/gen/agent/client/operations/get_cpu_parameters.go create mode 100644 v3/swagger/gen/agent/client/operations/get_cpu_responses.go create mode 100644 v3/swagger/gen/agent/client/operations/pin_cpu_parameters.go create mode 100644 v3/swagger/gen/agent/client/operations/pin_cpu_responses.go create mode 100644 v3/swagger/gen/agent/client/operations/unpin_cpu_parameters.go create mode 100644 v3/swagger/gen/agent/client/operations/unpin_cpu_responses.go create mode 100644 v3/swagger/gen/agent/models/cpus.go diff --git a/v3/pkg/util/cpuset/cpuset_linux.go b/v3/pkg/util/cpuset/cpuset_linux.go index 865c1b32ca..5c7b379e2a 100644 --- a/v3/pkg/util/cpuset/cpuset_linux.go +++ b/v3/pkg/util/cpuset/cpuset_linux.go @@ -53,6 +53,31 @@ func schedSetAffinityToMany(pids []int, set *unix.CPUSet) (err error) { return } +// SchedGetAffinity gets a union of CPUs used by this process threads. +func SchedGetAffinity() ([]int, error) { + pids, err := osTasks(os.Getpid()) + if err != nil { + return nil, errors.Wrap(err, "get tasks") + } + + union := make(map[int]struct{}) + for _, pid := range pids { + var cpus unix.CPUSet + if err := unix.SchedGetaffinity(pid, &cpus); err != nil { + return nil, errors.Wrap(err, "get affinity") + } + for _, cpu := range cpulist(&cpus) { + union[cpu] = struct{}{} + } + } + + var out []int + for cpu := range union { + out = append(out, cpu) + } + return out, nil +} + func cpuset(cpus []int) *unix.CPUSet { set := &unix.CPUSet{} set.Zero() diff --git a/v3/swagger/agent.json b/v3/swagger/agent.json index 5f3f62f9d5..40f63dd9b5 100644 --- a/v3/swagger/agent.json +++ b/v3/swagger/agent.json @@ -843,6 +843,74 @@ "security": [] } }, + "/pin_cpu": { + "get": { + "description": "Get CPUs to which agent is pinned", + "summary": "Get CPUs to which agent is pinned", + "operationId": "GetCpu", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "CPUs to which agent is pinned", + "schema": { + "$ref": "#/definitions/Cpus" + } + }, + "default": { + "description": "Server error", + "schema": { + "$ref": "#/definitions/ErrorResponse" + } + } + } + }, + "post": { + "description": "Pin agent to CPUs according to start-up logic", + "summary": "Pin agent to CPUs according to start-up logic", + "operationId": "PinCpu", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Empty object", + "schema": { + "type": "object" + } + }, + "default": { + "description": "Server error", + "schema": { + "$ref": "#/definitions/ErrorResponse" + } + } + } + }, + "delete": { + "description": "Unpin agent from CPUs", + "summary": "Unpin agent from CPUs", + "operationId": "UnpinCpu", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Empty object", + "schema": { + "type": "object" + } + }, + "default": { + "description": "Server error", + "schema": { + "$ref": "#/definitions/ErrorResponse" + } + } + } + } + }, "/terminate": { "post": { "description": "Reload agent config", @@ -901,6 +969,18 @@ } }, "definitions": { + "Cpus": { + "type": "object", + "properties": { + "cpu": { + "description": "List of cpus", + "type": "array", + "items": { + "type": "integer" + } + } + } + }, "Bandwidth": { "title": "bandwidth rate", "description": "Rate at witch to rate limit bandwidth", diff --git a/v3/swagger/gen/agent/client/operations/get_cpu_parameters.go b/v3/swagger/gen/agent/client/operations/get_cpu_parameters.go new file mode 100644 index 0000000000..1e48d3ae8c --- /dev/null +++ b/v3/swagger/gen/agent/client/operations/get_cpu_parameters.go @@ -0,0 +1,113 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" +) + +// NewGetCPUParams creates a new GetCPUParams object +// with the default values initialized. +func NewGetCPUParams() *GetCPUParams { + + return &GetCPUParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewGetCPUParamsWithTimeout creates a new GetCPUParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetCPUParamsWithTimeout(timeout time.Duration) *GetCPUParams { + + return &GetCPUParams{ + + timeout: timeout, + } +} + +// NewGetCPUParamsWithContext creates a new GetCPUParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetCPUParamsWithContext(ctx context.Context) *GetCPUParams { + + return &GetCPUParams{ + + Context: ctx, + } +} + +// NewGetCPUParamsWithHTTPClient creates a new GetCPUParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetCPUParamsWithHTTPClient(client *http.Client) *GetCPUParams { + + return &GetCPUParams{ + HTTPClient: client, + } +} + +/* +GetCPUParams contains all the parameters to send to the API endpoint +for the get Cpu operation typically these are written to a http.Request +*/ +type GetCPUParams struct { + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get Cpu params +func (o *GetCPUParams) WithTimeout(timeout time.Duration) *GetCPUParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get Cpu params +func (o *GetCPUParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get Cpu params +func (o *GetCPUParams) WithContext(ctx context.Context) *GetCPUParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get Cpu params +func (o *GetCPUParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get Cpu params +func (o *GetCPUParams) WithHTTPClient(client *http.Client) *GetCPUParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get Cpu params +func (o *GetCPUParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WriteToRequest writes these params to a swagger request +func (o *GetCPUParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/v3/swagger/gen/agent/client/operations/get_cpu_responses.go b/v3/swagger/gen/agent/client/operations/get_cpu_responses.go new file mode 100644 index 0000000000..aba30ba14b --- /dev/null +++ b/v3/swagger/gen/agent/client/operations/get_cpu_responses.go @@ -0,0 +1,135 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + "strconv" + "strings" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/scylladb/scylla-manager/v3/swagger/gen/agent/models" +) + +// GetCPUReader is a Reader for the GetCPU structure. +type GetCPUReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetCPUReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewGetCPUOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewGetCPUDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewGetCPUOK creates a GetCPUOK with default headers values +func NewGetCPUOK() *GetCPUOK { + return &GetCPUOK{} +} + +/* +GetCPUOK handles this case with default header values. + +CPUs to which agent is pinned +*/ +type GetCPUOK struct { + Payload *models.Cpus + JobID int64 +} + +func (o *GetCPUOK) GetPayload() *models.Cpus { + return o.Payload +} + +func (o *GetCPUOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.Cpus) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + if jobIDHeader := response.GetHeader("x-rclone-jobid"); jobIDHeader != "" { + jobID, err := strconv.ParseInt(jobIDHeader, 10, 64) + if err != nil { + return err + } + + o.JobID = jobID + } + return nil +} + +// NewGetCPUDefault creates a GetCPUDefault with default headers values +func NewGetCPUDefault(code int) *GetCPUDefault { + return &GetCPUDefault{ + _statusCode: code, + } +} + +/* +GetCPUDefault handles this case with default header values. + +Server error +*/ +type GetCPUDefault struct { + _statusCode int + + Payload *models.ErrorResponse + JobID int64 +} + +// Code gets the status code for the get Cpu default response +func (o *GetCPUDefault) Code() int { + return o._statusCode +} + +func (o *GetCPUDefault) GetPayload() *models.ErrorResponse { + return o.Payload +} + +func (o *GetCPUDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.ErrorResponse) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + if jobIDHeader := response.GetHeader("x-rclone-jobid"); jobIDHeader != "" { + jobID, err := strconv.ParseInt(jobIDHeader, 10, 64) + if err != nil { + return err + } + + o.JobID = jobID + } + return nil +} + +func (o *GetCPUDefault) Error() string { + return fmt.Sprintf("agent [HTTP %d] %s", o._statusCode, strings.TrimRight(o.Payload.Message, ".")) +} diff --git a/v3/swagger/gen/agent/client/operations/operations_client.go b/v3/swagger/gen/agent/client/operations/operations_client.go index 4c3f1546bb..d64a8fe645 100644 --- a/v3/swagger/gen/agent/client/operations/operations_client.go +++ b/v3/swagger/gen/agent/client/operations/operations_client.go @@ -35,6 +35,8 @@ type ClientService interface { FreeOSMemory(params *FreeOSMemoryParams) (*FreeOSMemoryOK, error) + GetCPU(params *GetCPUParams) (*GetCPUOK, error) + JobInfo(params *JobInfoParams) (*JobInfoOK, error) JobProgress(params *JobProgressParams) (*JobProgressOK, error) @@ -61,6 +63,8 @@ type ClientService interface { OperationsPurge(params *OperationsPurgeParams) (*OperationsPurgeOK, error) + PinCPU(params *PinCPUParams) (*PinCPUOK, error) + Reload(params *ReloadParams) (*ReloadOK, error) SyncCopyDir(params *SyncCopyDirParams) (*SyncCopyDirOK, error) @@ -69,6 +73,8 @@ type ClientService interface { SyncMoveDir(params *SyncMoveDirParams) (*SyncMoveDirOK, error) + UnpinCPU(params *UnpinCPUParams) (*UnpinCPUOK, error) + SetTransport(transport runtime.ClientTransport) } @@ -247,6 +253,41 @@ func (a *Client) FreeOSMemory(params *FreeOSMemoryParams) (*FreeOSMemoryOK, erro return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +GetCPU gets c p us to which agent is pinned + +Get CPUs to which agent is pinned +*/ +func (a *Client) GetCPU(params *GetCPUParams) (*GetCPUOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetCPUParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "GetCpu", + Method: "GET", + PathPattern: "/pin_cpu", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &GetCPUReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + success, ok := result.(*GetCPUOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*GetCPUDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* JobInfo transfers stats about the job @@ -702,6 +743,41 @@ func (a *Client) OperationsPurge(params *OperationsPurgeParams) (*OperationsPurg return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +PinCPU pins agent to c p us according to start up logic + +Pin agent to CPUs according to start-up logic +*/ +func (a *Client) PinCPU(params *PinCPUParams) (*PinCPUOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewPinCPUParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "PinCpu", + Method: "POST", + PathPattern: "/pin_cpu", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &PinCPUReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + success, ok := result.(*PinCPUOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*PinCPUDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* Reload reloads agent config @@ -842,6 +918,41 @@ func (a *Client) SyncMoveDir(params *SyncMoveDirParams) (*SyncMoveDirOK, error) return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +UnpinCPU unpins agent from c p us + +Unpin agent from CPUs +*/ +func (a *Client) UnpinCPU(params *UnpinCPUParams) (*UnpinCPUOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewUnpinCPUParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "UnpinCpu", + Method: "DELETE", + PathPattern: "/pin_cpu", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &UnpinCPUReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + success, ok := result.(*UnpinCPUOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*UnpinCPUDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + // SetTransport changes the transport on the client func (a *Client) SetTransport(transport runtime.ClientTransport) { a.transport = transport diff --git a/v3/swagger/gen/agent/client/operations/pin_cpu_parameters.go b/v3/swagger/gen/agent/client/operations/pin_cpu_parameters.go new file mode 100644 index 0000000000..7fa59de8a2 --- /dev/null +++ b/v3/swagger/gen/agent/client/operations/pin_cpu_parameters.go @@ -0,0 +1,113 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" +) + +// NewPinCPUParams creates a new PinCPUParams object +// with the default values initialized. +func NewPinCPUParams() *PinCPUParams { + + return &PinCPUParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewPinCPUParamsWithTimeout creates a new PinCPUParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewPinCPUParamsWithTimeout(timeout time.Duration) *PinCPUParams { + + return &PinCPUParams{ + + timeout: timeout, + } +} + +// NewPinCPUParamsWithContext creates a new PinCPUParams object +// with the default values initialized, and the ability to set a context for a request +func NewPinCPUParamsWithContext(ctx context.Context) *PinCPUParams { + + return &PinCPUParams{ + + Context: ctx, + } +} + +// NewPinCPUParamsWithHTTPClient creates a new PinCPUParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewPinCPUParamsWithHTTPClient(client *http.Client) *PinCPUParams { + + return &PinCPUParams{ + HTTPClient: client, + } +} + +/* +PinCPUParams contains all the parameters to send to the API endpoint +for the pin Cpu operation typically these are written to a http.Request +*/ +type PinCPUParams struct { + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the pin Cpu params +func (o *PinCPUParams) WithTimeout(timeout time.Duration) *PinCPUParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the pin Cpu params +func (o *PinCPUParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the pin Cpu params +func (o *PinCPUParams) WithContext(ctx context.Context) *PinCPUParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the pin Cpu params +func (o *PinCPUParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the pin Cpu params +func (o *PinCPUParams) WithHTTPClient(client *http.Client) *PinCPUParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the pin Cpu params +func (o *PinCPUParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WriteToRequest writes these params to a swagger request +func (o *PinCPUParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/v3/swagger/gen/agent/client/operations/pin_cpu_responses.go b/v3/swagger/gen/agent/client/operations/pin_cpu_responses.go new file mode 100644 index 0000000000..13e3e79c45 --- /dev/null +++ b/v3/swagger/gen/agent/client/operations/pin_cpu_responses.go @@ -0,0 +1,133 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + "strconv" + "strings" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/scylladb/scylla-manager/v3/swagger/gen/agent/models" +) + +// PinCPUReader is a Reader for the PinCPU structure. +type PinCPUReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *PinCPUReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewPinCPUOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewPinCPUDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewPinCPUOK creates a PinCPUOK with default headers values +func NewPinCPUOK() *PinCPUOK { + return &PinCPUOK{} +} + +/* +PinCPUOK handles this case with default header values. + +Empty object +*/ +type PinCPUOK struct { + Payload interface{} + JobID int64 +} + +func (o *PinCPUOK) GetPayload() interface{} { + return o.Payload +} + +func (o *PinCPUOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + if jobIDHeader := response.GetHeader("x-rclone-jobid"); jobIDHeader != "" { + jobID, err := strconv.ParseInt(jobIDHeader, 10, 64) + if err != nil { + return err + } + + o.JobID = jobID + } + return nil +} + +// NewPinCPUDefault creates a PinCPUDefault with default headers values +func NewPinCPUDefault(code int) *PinCPUDefault { + return &PinCPUDefault{ + _statusCode: code, + } +} + +/* +PinCPUDefault handles this case with default header values. + +Server error +*/ +type PinCPUDefault struct { + _statusCode int + + Payload *models.ErrorResponse + JobID int64 +} + +// Code gets the status code for the pin Cpu default response +func (o *PinCPUDefault) Code() int { + return o._statusCode +} + +func (o *PinCPUDefault) GetPayload() *models.ErrorResponse { + return o.Payload +} + +func (o *PinCPUDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.ErrorResponse) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + if jobIDHeader := response.GetHeader("x-rclone-jobid"); jobIDHeader != "" { + jobID, err := strconv.ParseInt(jobIDHeader, 10, 64) + if err != nil { + return err + } + + o.JobID = jobID + } + return nil +} + +func (o *PinCPUDefault) Error() string { + return fmt.Sprintf("agent [HTTP %d] %s", o._statusCode, strings.TrimRight(o.Payload.Message, ".")) +} diff --git a/v3/swagger/gen/agent/client/operations/unpin_cpu_parameters.go b/v3/swagger/gen/agent/client/operations/unpin_cpu_parameters.go new file mode 100644 index 0000000000..968e1b092e --- /dev/null +++ b/v3/swagger/gen/agent/client/operations/unpin_cpu_parameters.go @@ -0,0 +1,113 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" +) + +// NewUnpinCPUParams creates a new UnpinCPUParams object +// with the default values initialized. +func NewUnpinCPUParams() *UnpinCPUParams { + + return &UnpinCPUParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewUnpinCPUParamsWithTimeout creates a new UnpinCPUParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewUnpinCPUParamsWithTimeout(timeout time.Duration) *UnpinCPUParams { + + return &UnpinCPUParams{ + + timeout: timeout, + } +} + +// NewUnpinCPUParamsWithContext creates a new UnpinCPUParams object +// with the default values initialized, and the ability to set a context for a request +func NewUnpinCPUParamsWithContext(ctx context.Context) *UnpinCPUParams { + + return &UnpinCPUParams{ + + Context: ctx, + } +} + +// NewUnpinCPUParamsWithHTTPClient creates a new UnpinCPUParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewUnpinCPUParamsWithHTTPClient(client *http.Client) *UnpinCPUParams { + + return &UnpinCPUParams{ + HTTPClient: client, + } +} + +/* +UnpinCPUParams contains all the parameters to send to the API endpoint +for the unpin Cpu operation typically these are written to a http.Request +*/ +type UnpinCPUParams struct { + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the unpin Cpu params +func (o *UnpinCPUParams) WithTimeout(timeout time.Duration) *UnpinCPUParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the unpin Cpu params +func (o *UnpinCPUParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the unpin Cpu params +func (o *UnpinCPUParams) WithContext(ctx context.Context) *UnpinCPUParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the unpin Cpu params +func (o *UnpinCPUParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the unpin Cpu params +func (o *UnpinCPUParams) WithHTTPClient(client *http.Client) *UnpinCPUParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the unpin Cpu params +func (o *UnpinCPUParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WriteToRequest writes these params to a swagger request +func (o *UnpinCPUParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/v3/swagger/gen/agent/client/operations/unpin_cpu_responses.go b/v3/swagger/gen/agent/client/operations/unpin_cpu_responses.go new file mode 100644 index 0000000000..b4a31d1c47 --- /dev/null +++ b/v3/swagger/gen/agent/client/operations/unpin_cpu_responses.go @@ -0,0 +1,133 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + "strconv" + "strings" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/scylladb/scylla-manager/v3/swagger/gen/agent/models" +) + +// UnpinCPUReader is a Reader for the UnpinCPU structure. +type UnpinCPUReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *UnpinCPUReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewUnpinCPUOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewUnpinCPUDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewUnpinCPUOK creates a UnpinCPUOK with default headers values +func NewUnpinCPUOK() *UnpinCPUOK { + return &UnpinCPUOK{} +} + +/* +UnpinCPUOK handles this case with default header values. + +Empty object +*/ +type UnpinCPUOK struct { + Payload interface{} + JobID int64 +} + +func (o *UnpinCPUOK) GetPayload() interface{} { + return o.Payload +} + +func (o *UnpinCPUOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + if jobIDHeader := response.GetHeader("x-rclone-jobid"); jobIDHeader != "" { + jobID, err := strconv.ParseInt(jobIDHeader, 10, 64) + if err != nil { + return err + } + + o.JobID = jobID + } + return nil +} + +// NewUnpinCPUDefault creates a UnpinCPUDefault with default headers values +func NewUnpinCPUDefault(code int) *UnpinCPUDefault { + return &UnpinCPUDefault{ + _statusCode: code, + } +} + +/* +UnpinCPUDefault handles this case with default header values. + +Server error +*/ +type UnpinCPUDefault struct { + _statusCode int + + Payload *models.ErrorResponse + JobID int64 +} + +// Code gets the status code for the unpin Cpu default response +func (o *UnpinCPUDefault) Code() int { + return o._statusCode +} + +func (o *UnpinCPUDefault) GetPayload() *models.ErrorResponse { + return o.Payload +} + +func (o *UnpinCPUDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.ErrorResponse) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + if jobIDHeader := response.GetHeader("x-rclone-jobid"); jobIDHeader != "" { + jobID, err := strconv.ParseInt(jobIDHeader, 10, 64) + if err != nil { + return err + } + + o.JobID = jobID + } + return nil +} + +func (o *UnpinCPUDefault) Error() string { + return fmt.Sprintf("agent [HTTP %d] %s", o._statusCode, strings.TrimRight(o.Payload.Message, ".")) +} diff --git a/v3/swagger/gen/agent/models/cpus.go b/v3/swagger/gen/agent/models/cpus.go new file mode 100644 index 0000000000..9f463b04e2 --- /dev/null +++ b/v3/swagger/gen/agent/models/cpus.go @@ -0,0 +1,43 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// Cpus cpus +// +// swagger:model Cpus +type Cpus struct { + + // List of cpus + CPU []int64 `json:"cpu"` +} + +// Validate validates this cpus +func (m *Cpus) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *Cpus) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Cpus) UnmarshalBinary(b []byte) error { + var res Cpus + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +}