|
|
|
@@ -639,6 +639,61 @@ sendjob: |
|
|
|
return &result, nil |
|
|
|
} |
|
|
|
|
|
|
|
func createTrainJobVersionUserImage(createJobVersionParams models.CreateTrainJobVersionUserImageParams, jobID string) (*models.CreateTrainJobResult, error) { |
|
|
|
checkSetting() |
|
|
|
client := getRestyClient() |
|
|
|
var result models.CreateTrainJobResult |
|
|
|
|
|
|
|
retry := 0 |
|
|
|
|
|
|
|
sendjob: |
|
|
|
res, err := client.R(). |
|
|
|
SetHeader("Content-Type", "application/json"). |
|
|
|
SetAuthToken(TOKEN). |
|
|
|
SetBody(createJobVersionParams). |
|
|
|
SetResult(&result). |
|
|
|
Post(HOST + "/v1/" + setting.ProjectID + urlTrainJob + "/" + jobID + "/versions") |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("resty create train-job version: %s", err) |
|
|
|
} |
|
|
|
|
|
|
|
req, _ := json.Marshal(createJobVersionParams) |
|
|
|
log.Info("%s", req) |
|
|
|
|
|
|
|
if res.StatusCode() == http.StatusUnauthorized && retry < 1 { |
|
|
|
retry++ |
|
|
|
_ = getToken() |
|
|
|
goto sendjob |
|
|
|
} |
|
|
|
|
|
|
|
if res.StatusCode() != http.StatusOK { |
|
|
|
var temp models.ErrorResult |
|
|
|
if err = json.Unmarshal([]byte(res.String()), &temp); err != nil { |
|
|
|
log.Error("json.Unmarshal failed(%s): %v", res.String(), err.Error()) |
|
|
|
return &result, fmt.Errorf("json.Unmarshal failed(%s): %v", res.String(), err.Error()) |
|
|
|
} |
|
|
|
BootFileErrorMsg := "Invalid OBS path '" + createJobVersionParams.Config.BootFileUrl + "'." |
|
|
|
DataSetErrorMsg := "Invalid OBS path '" + createJobVersionParams.Config.DataUrl + "'." |
|
|
|
if temp.ErrorMsg == BootFileErrorMsg { |
|
|
|
log.Error("启动文件错误!createTrainJobVersion failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) |
|
|
|
return &result, fmt.Errorf("启动文件错误!") |
|
|
|
} |
|
|
|
if temp.ErrorMsg == DataSetErrorMsg { |
|
|
|
log.Error("数据集错误!createTrainJobVersion failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) |
|
|
|
return &result, fmt.Errorf("数据集错误!") |
|
|
|
} |
|
|
|
return &result, fmt.Errorf("createTrainJobVersion failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) |
|
|
|
} |
|
|
|
|
|
|
|
if !result.IsSuccess { |
|
|
|
log.Error("createTrainJobVersion failed(%s): %s", result.ErrorCode, result.ErrorMsg) |
|
|
|
return &result, fmt.Errorf("createTrainJobVersion failed(%s): %s", result.ErrorCode, result.ErrorMsg) |
|
|
|
} |
|
|
|
|
|
|
|
return &result, nil |
|
|
|
} |
|
|
|
|
|
|
|
func GetResourceSpecs() (*models.GetResourceSpecsResult, error) { |
|
|
|
checkSetting() |
|
|
|
client := getRestyClient() |
|
|
|
|