Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add size and offset for ListMachines #214

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ type ClientInterface interface {
ListMachineGroup(project string, offset, size int) (m []string, total int, err error)
// ListMachines list all machines in machineGroupName
ListMachines(project, machineGroupName string) (ms []*Machine, total int, err error)
ListMachinesV2(project, machineGroupName string, offset, size int) (ms []*Machine, total int, err error)
// CheckMachineGroupExist check machine group exist or not
CheckMachineGroupExist(project string, machineGroup string) (bool, error)
// GetMachineGroup retruns machine group according by machine group name.
Expand Down
41 changes: 41 additions & 0 deletions client_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,47 @@ func (c *Client) ListMachines(project, machineGroupName string) (ms []*Machine,
return
}

func (c *Client) ListMachinesV2(project, machineGroupName string, offset, size int) (ms []*Machine, total int, err error) {
h := map[string]string{
"x-log-bodyrawsize": "0",
}
uri := fmt.Sprintf("/machinegroups/%v/machines?offset=%v&size=%v", machineGroupName, offset, size)
r, err := c.request(project, "GET", uri, h, nil)
if err != nil {
return
}
defer r.Body.Close()
buf, err := ioutil.ReadAll(r.Body)
if err != nil {
return
}

if r.StatusCode != http.StatusOK {
errMsg := &Error{}
err = json.Unmarshal(buf, errMsg)
if err != nil {
err = fmt.Errorf("failed to unmarshal list machines response: %v", err)
if IsDebugLevelMatched(1) {
dump, _ := httputil.DumpResponse(r, true)
level.Error(Logger).Log("msg", string(dump))
}
return
}
err = fmt.Errorf("%v:%v", errMsg.Code, errMsg.Message)
return
}

body := &MachineList{}
err = json.Unmarshal(buf, body)
if err != nil {
return
}

ms = body.Machines
total = body.Total
return
}

// CheckLogstoreExist check logstore exist or not
func (c *Client) CheckLogstoreExist(project string, logstore string) (bool, error) {
proj := convert(c, project)
Expand Down
10 changes: 10 additions & 0 deletions token_auto_update_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ func (c *TokenAutoUpdateClient) ListMachines(project, machineGroupName string) (
return
}

func (c *TokenAutoUpdateClient) ListMachinesV2(project, machineGroupName string, offset, size int) (ms []*Machine, total int, err error) {
for i := 0; i < c.maxTryTimes; i++ {
ms, total, err = c.logClient.ListMachinesV2(project, machineGroupName, offset, size)
if !c.processError(err) {
return
}
}
return
}

func (c *TokenAutoUpdateClient) CheckLogstoreExist(project string, logstore string) (ok bool, err error) {
for i := 0; i < c.maxTryTimes; i++ {
ok, err = c.logClient.CheckLogstoreExist(project, logstore)
Expand Down