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

added func for PQA-1848 #109

Merged
merged 4 commits into from
Jun 3, 2024
Merged
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
44 changes: 44 additions & 0 deletions client/cluster.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package client

import (
"bytes"
"fmt"
"io"
"os"
"path/filepath"
"strings"

clientV1 "github.com/spectrocloud/palette-api-go/client/v1"
Expand Down Expand Up @@ -247,3 +251,43 @@ func clusterNameEqFilter(name string) *models.V1SearchFilterItem {
Type: models.V1SearchFilterPropertyTypeString,
}
}

func (h *V1Client) GetLogFetcherStatus(uid string, logFetcherUid *string) (*models.V1ClusterLogFetcher, error) {
params := clientV1.NewV1ClusterFeatureLogFetcherGetParamsWithContext(h.ctx).WithUID(uid).WithRequestID(logFetcherUid)
resp, err := h.Client.V1ClusterFeatureLogFetcherGet(params)
if err != nil {
return nil, err
}
return resp.Payload, nil
}

func (h *V1Client) InitiateDownloadOfClusterLogs(uid string, V1ClusterLogFetcherRequestObj *models.V1ClusterLogFetcherRequest) (*string, error) {
params := clientV1.NewV1ClusterFeatureLogFetcherCreateParamsWithContext(h.ctx).WithUID(uid).WithBody(V1ClusterLogFetcherRequestObj)
resp, err := h.Client.V1ClusterFeatureLogFetcherCreate(params)
if err != nil {
return nil, err
}
return resp.GetPayload().UID, nil
}

func (h *V1Client) DownloadLogs(uid string, logFetcherUid string) (io.Writer, error) {
filename := "logs-" + uid + ".zip"
params := clientV1.NewV1ClusterFeatureLogFetcherLogDownloadParamsWithContext(h.ctx).WithUID(logFetcherUid).WithFileName(&filename)
var buf bytes.Buffer
writer := io.Writer(&buf)
resp, err := h.Client.V1ClusterFeatureLogFetcherLogDownload(params, writer)
if err != nil {
return nil, err
}
logfile := resp.GetPayload()
file_location := "/tmp/" + filename
fo, err := os.Create(filepath.Clean(file_location))
if err != nil {
return nil, fmt.Errorf("error while creating a file %v", err)
}
_, err = buf.WriteTo(fo)
if err != nil {
return nil, fmt.Errorf("error while writing log content to a file %v", err)
}
return logfile, nil
}
Loading