Init commit of jobs output/error message peek project.
This commit is contained in:
parent
c772d7e601
commit
d2b47e3985
38 changed files with 2267 additions and 21 deletions
|
|
@ -170,6 +170,45 @@ func (c *APIClient) SubmitJob(token string, req *models.JobSubmitRequest) (*mode
|
|||
return &resp, nil
|
||||
}
|
||||
|
||||
// GetJobOutput retrieves job output from the API server.
|
||||
func (c *APIClient) GetJobOutput(token, certPath, jobID string, params map[string]string) (*models.JobOutputResponse, error) {
|
||||
var resp models.JobOutputResponse
|
||||
baseURL := c.BaseURL
|
||||
if strings.HasPrefix(baseURL, "https://") {
|
||||
c.Client.SetTLSClientConfig(&tls.Config{
|
||||
RootCAs: loadRootCAs(certPath),
|
||||
})
|
||||
}
|
||||
if idx := strings.Index(baseURL, "/xce/v1"); idx != -1 {
|
||||
baseURL = baseURL[:idx]
|
||||
}
|
||||
url := baseURL + "/xce/v1/jobs/" + jobID + "/output"
|
||||
|
||||
req := c.Client.R().
|
||||
SetHeader("Authorization", token).
|
||||
SetResult(&resp)
|
||||
|
||||
for k, v := range params {
|
||||
req.SetQueryParam(k, v)
|
||||
}
|
||||
|
||||
httpResp, err := req.Get(url)
|
||||
if err != nil {
|
||||
errMsg := ExtractErrorMessage(err)
|
||||
return nil, fmt.Errorf("get job output request failed: [%s]", errMsg)
|
||||
}
|
||||
|
||||
if httpResp.StatusCode() != http.StatusOK {
|
||||
logger.Info("get job output failed", zap.Any("resp", resp), zap.Int("status", httpResp.StatusCode()))
|
||||
if resp.Msg != "" {
|
||||
return &resp, fmt.Errorf("get job output failed: %s", resp.Msg)
|
||||
}
|
||||
return &resp, fmt.Errorf("get job output failed: status %d", httpResp.StatusCode())
|
||||
}
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// extractErrorMessage extracts a user-friendly error message from various error types
|
||||
func ExtractErrorMessage(err error) string {
|
||||
if err == nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue