Skip to content

Commit

Permalink
feat(backingimage): backingimage ha eviction enhancement
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn 2856

Signed-off-by: Jack Lin <jack.lin@suse.com>
  • Loading branch information
ChanYiLin committed Apr 29, 2024
1 parent f63611c commit d17ffbf
Show file tree
Hide file tree
Showing 21 changed files with 613 additions and 61 deletions.
17 changes: 17 additions & 0 deletions api/backingimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,20 @@ func (s *Server) BackingImageProxyFallback(rw http.ResponseWriter, req *http.Req

return fmt.Errorf("failed to proxy the request to other servers for backing image %v(%v)", bi.Name, bi.Status.UUID)
}

func (s *Server) UpdateMinNumberOfCopies(w http.ResponseWriter, req *http.Request) error {
var input UpdateMinNumberOfCopiesInput
apiContext := api.GetApiContext(req)

id := mux.Vars(req)["name"]
if err := apiContext.Read(&input); err != nil {
return err
}

bi, err := s.m.UpdateBackingImageMinNumberOfCopies(id, input.MinNumberOfCopies)
if err != nil {
return errors.Wrapf(err, "failed to update backing image %v minNumberOfCopies to %v", bi.Name, input.MinNumberOfCopies)
}
apiContext.Write(toBackingImageResource(bi, apiContext))
return nil
}
23 changes: 18 additions & 5 deletions api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,14 @@ type EngineImage struct {
type BackingImage struct {
client.Resource

Name string `json:"name"`
UUID string `json:"uuid"`
SourceType string `json:"sourceType"`
Parameters map[string]string `json:"parameters"`
ExpectedChecksum string `json:"expectedChecksum"`
Name string `json:"name"`
UUID string `json:"uuid"`
SourceType string `json:"sourceType"`
Parameters map[string]string `json:"parameters"`
DiskSelector []string `json:"diskSelector"`
NodeSelector []string `json:"nodeSelector"`
MinNumberOfCopies int `json:"minNumberOfCopies"`
ExpectedChecksum string `json:"expectedChecksum"`

DiskFileStatusMap map[string]longhorn.BackingImageDiskFileStatus `json:"diskFileStatusMap"`
Size int64 `json:"size"`
Expand All @@ -262,6 +265,10 @@ type BackingImageCleanupInput struct {
Disks []string `json:"disks"`
}

type UpdateMinNumberOfCopiesInput struct {
MinNumberOfCopies int `json:"minNumberOfCopies"`
}

type AttachInput struct {
HostID string `json:"hostId"`
DisableFrontend bool `json:"disableFrontend"`
Expand Down Expand Up @@ -638,6 +645,7 @@ func NewSchema() *client.Schemas {

schemas.AddType("backingImageDiskFileStatus", longhorn.BackingImageDiskFileStatus{})
schemas.AddType("backingImageCleanupInput", BackingImageCleanupInput{})
schemas.AddType("updateMinNumberOfCopiesInput", UpdateMinNumberOfCopiesInput{})

attachmentSchema(schemas.AddType("attachment", Attachment{}))
volumeAttachmentSchema(schemas.AddType("volumeAttachment", VolumeAttachment{}))
Expand Down Expand Up @@ -732,6 +740,10 @@ func backingImageSchema(backingImage *client.Schema) {
},
BackingImageUpload: {},
"backupBackingImageCreate": {},
"updateMinNumberOfCopies": {
Input: "updateMinNumberOfCopiesInput",
Output: "backingImage",
},
}

name := backingImage.ResourceFields["name"]
Expand Down Expand Up @@ -1927,6 +1939,7 @@ func toBackingImageResource(bi *longhorn.BackingImage, apiContext *api.ApiContex
"backingImageCleanup": apiContext.UrlBuilder.ActionLink(res.Resource, "backingImageCleanup"),
BackingImageUpload: apiContext.UrlBuilder.ActionLink(res.Resource, BackingImageUpload),
"backupBackingImageCreate": apiContext.UrlBuilder.ActionLink(res.Resource, "backupBackingImageCreate"),
"updateMinNumberOfCopies": apiContext.UrlBuilder.ActionLink(res.Resource, "updateMinNumberOfCopies"),
}
return res
}
Expand Down
1 change: 1 addition & 0 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func NewRouter(s *Server) *mux.Router {
"backingImageCleanup": s.BackingImageCleanup,
BackingImageUpload: s.fwd.Handler(s.fwd.HandleProxyRequestForBackingImageUpload, UploadParametersForBackingImage(s.m), s.BackingImageGet),
"backupBackingImageCreate": s.BackupBackingImageCreate,
"updateMinNumberOfCopies": s.UpdateMinNumberOfCopies,
}
for name, action := range backingImageActions {
r.Methods("POST").Path("/v1/backingimages/{name}").Queries("action", name).Handler(f(schemas, action))
Expand Down
19 changes: 18 additions & 1 deletion client/generated_backing_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ type BackingImage struct {

DeletionTimestamp string `json:"deletionTimestamp,omitempty" yaml:"deletion_timestamp,omitempty"`

DiskFileStatusMap map[string]BackingImageDiskFileStatus `json:"diskFileStatusMap,omitempty" yaml:"disk_file_status_map,omitempty"`
DiskFileStatusMap map[string]interface{} `json:"diskFileStatusMap,omitempty" yaml:"disk_file_status_map,omitempty"`

DiskSelector []string `json:"diskSelector,omitempty" yaml:"disk_selector,omitempty"`

ExpectedChecksum string `json:"expectedChecksum,omitempty" yaml:"expected_checksum,omitempty"`

MinNumberOfCopies int64 `json:"minNumberOfCopies,omitempty" yaml:"min_number_of_copies,omitempty"`

Name string `json:"name,omitempty" yaml:"name,omitempty"`

NodeSelector []string `json:"nodeSelector,omitempty" yaml:"node_selector,omitempty"`

Parameters map[string]string `json:"parameters,omitempty" yaml:"parameters,omitempty"`

Size int64 `json:"size,omitempty" yaml:"size,omitempty"`
Expand Down Expand Up @@ -44,6 +50,8 @@ type BackingImageOperations interface {
Delete(container *BackingImage) error

ActionBackingImageCleanup(*BackingImage, *BackingImageCleanupInput) (*BackingImage, error)

ActionUpdateMinNumberOfCopies(*BackingImage, *UpdateMinNumberOfCopiesInput) (*BackingImage, error)
}

func newBackingImageClient(rancherClient *RancherClient) *BackingImageClient {
Expand Down Expand Up @@ -104,3 +112,12 @@ func (c *BackingImageClient) ActionBackingImageCleanup(resource *BackingImage, i

return resp, err
}

func (c *BackingImageClient) ActionUpdateMinNumberOfCopies(resource *BackingImage, input *UpdateMinNumberOfCopiesInput) (*BackingImage, error) {

resp := &BackingImage{}

err := c.rancherClient.doAction(BACKING_IMAGE_TYPE, "updateMinNumberOfCopies", &resource.Resource, input, resp)

return resp, err
}
1 change: 1 addition & 0 deletions client/generated_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type RancherClient struct {
InstanceManager InstanceManagerOperations
BackingImageDiskFileStatus BackingImageDiskFileStatusOperations
BackingImageCleanupInput BackingImageCleanupInputOperations
UpdateMinNumberOfCopiesInput UpdateMinNumberOfCopiesInputOperations
Attachment AttachmentOperations
VolumeAttachment VolumeAttachmentOperations
Volume VolumeOperations
Expand Down
79 changes: 79 additions & 0 deletions client/generated_update_min_number_of_copies_input.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package client

const (
UPDATE_MIN_NUMBER_OF_COPIES_INPUT_TYPE = "updateMinNumberOfCopiesInput"
)

type UpdateMinNumberOfCopiesInput struct {
Resource `yaml:"-"`

MinNumberOfCopies int64 `json:"minNumberOfCopies,omitempty" yaml:"min_number_of_copies,omitempty"`
}

type UpdateMinNumberOfCopiesInputCollection struct {
Collection
Data []UpdateMinNumberOfCopiesInput `json:"data,omitempty"`
client *UpdateMinNumberOfCopiesInputClient
}

type UpdateMinNumberOfCopiesInputClient struct {
rancherClient *RancherClient
}

type UpdateMinNumberOfCopiesInputOperations interface {
List(opts *ListOpts) (*UpdateMinNumberOfCopiesInputCollection, error)
Create(opts *UpdateMinNumberOfCopiesInput) (*UpdateMinNumberOfCopiesInput, error)
Update(existing *UpdateMinNumberOfCopiesInput, updates interface{}) (*UpdateMinNumberOfCopiesInput, error)
ById(id string) (*UpdateMinNumberOfCopiesInput, error)
Delete(container *UpdateMinNumberOfCopiesInput) error
}

func newUpdateMinNumberOfCopiesInputClient(rancherClient *RancherClient) *UpdateMinNumberOfCopiesInputClient {
return &UpdateMinNumberOfCopiesInputClient{
rancherClient: rancherClient,
}
}

func (c *UpdateMinNumberOfCopiesInputClient) Create(container *UpdateMinNumberOfCopiesInput) (*UpdateMinNumberOfCopiesInput, error) {
resp := &UpdateMinNumberOfCopiesInput{}
err := c.rancherClient.doCreate(UPDATE_MIN_NUMBER_OF_COPIES_INPUT_TYPE, container, resp)
return resp, err
}

func (c *UpdateMinNumberOfCopiesInputClient) Update(existing *UpdateMinNumberOfCopiesInput, updates interface{}) (*UpdateMinNumberOfCopiesInput, error) {
resp := &UpdateMinNumberOfCopiesInput{}
err := c.rancherClient.doUpdate(UPDATE_MIN_NUMBER_OF_COPIES_INPUT_TYPE, &existing.Resource, updates, resp)
return resp, err
}

func (c *UpdateMinNumberOfCopiesInputClient) List(opts *ListOpts) (*UpdateMinNumberOfCopiesInputCollection, error) {
resp := &UpdateMinNumberOfCopiesInputCollection{}
err := c.rancherClient.doList(UPDATE_MIN_NUMBER_OF_COPIES_INPUT_TYPE, opts, resp)
resp.client = c
return resp, err
}

func (cc *UpdateMinNumberOfCopiesInputCollection) Next() (*UpdateMinNumberOfCopiesInputCollection, error) {
if cc != nil && cc.Pagination != nil && cc.Pagination.Next != "" {
resp := &UpdateMinNumberOfCopiesInputCollection{}
err := cc.client.rancherClient.doNext(cc.Pagination.Next, resp)
resp.client = cc.client
return resp, err
}
return nil, nil
}

func (c *UpdateMinNumberOfCopiesInputClient) ById(id string) (*UpdateMinNumberOfCopiesInput, error) {
resp := &UpdateMinNumberOfCopiesInput{}
err := c.rancherClient.doById(UPDATE_MIN_NUMBER_OF_COPIES_INPUT_TYPE, id, resp)
if apiError, ok := err.(*ApiError); ok {
if apiError.StatusCode == 404 {
return nil, nil
}
}
return resp, err
}

func (c *UpdateMinNumberOfCopiesInputClient) Delete(container *UpdateMinNumberOfCopiesInput) error {
return c.rancherClient.doResourceDelete(UPDATE_MIN_NUMBER_OF_COPIES_INPUT_TYPE, &container.Resource)
}
Loading

0 comments on commit d17ffbf

Please sign in to comment.