|
|
|
@@ -25,6 +25,7 @@ const ( |
|
|
|
urlNotebook = "/demanager/instances" |
|
|
|
urlTrainJob = "/training-jobs" |
|
|
|
urlResourceSpecs = "/job/resource-specs" |
|
|
|
urlTrainJobConfig = "/training-job-configs" |
|
|
|
|
|
|
|
errorCodeExceedLimit = "ModelArts.0118" |
|
|
|
) |
|
|
|
@@ -86,7 +87,6 @@ func getToken() error { |
|
|
|
} |
|
|
|
|
|
|
|
TOKEN = res.Header().Get("X-Subject-Token") |
|
|
|
log.Info(TOKEN) |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
@@ -296,8 +296,6 @@ func createTrainJob(createJobParams models.CreateTrainJobParams) (*models.Create |
|
|
|
client := getRestyClient() |
|
|
|
var result models.CreateTrainJobResult |
|
|
|
|
|
|
|
log.Info("%+v",createJobParams) |
|
|
|
|
|
|
|
retry := 0 |
|
|
|
|
|
|
|
sendjob: |
|
|
|
@@ -323,8 +321,13 @@ sendjob: |
|
|
|
} |
|
|
|
|
|
|
|
if res.StatusCode() != http.StatusOK { |
|
|
|
log.Error("createTrainJob failed", res.StatusCode(), res.RawResponse.Body, result.ErrorCode, result.ErrorMsg) |
|
|
|
return &result, fmt.Errorf("createTrainJob failed(%d)", res.StatusCode()) |
|
|
|
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()) |
|
|
|
} |
|
|
|
log.Error("createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) |
|
|
|
return &result, fmt.Errorf("createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) |
|
|
|
} |
|
|
|
|
|
|
|
if !result.IsSuccess { |
|
|
|
@@ -360,8 +363,13 @@ sendjob: |
|
|
|
} |
|
|
|
|
|
|
|
if res.StatusCode() != http.StatusOK { |
|
|
|
log.Error("GetResourceSpecs failed(%d)", res.StatusCode()) |
|
|
|
return &result, fmt.Errorf("GetResourceSpecs failed(%d)", res.StatusCode()) |
|
|
|
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()) |
|
|
|
} |
|
|
|
log.Error("GetResourceSpecs failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) |
|
|
|
return &result, fmt.Errorf("GetResourceSpecs failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) |
|
|
|
} |
|
|
|
|
|
|
|
if !result.IsSuccess { |
|
|
|
@@ -371,3 +379,49 @@ sendjob: |
|
|
|
|
|
|
|
return &result, nil |
|
|
|
} |
|
|
|
|
|
|
|
func CreateTrainJobConfig(req models.CreateConfigParams) (*models.CreateTrainJobConfigResult, error) { |
|
|
|
checkSetting() |
|
|
|
client := getRestyClient() |
|
|
|
var result models.CreateTrainJobConfigResult |
|
|
|
|
|
|
|
retry := 0 |
|
|
|
|
|
|
|
sendjob: |
|
|
|
res, err := client.R(). |
|
|
|
SetHeader("Content-Type", "application/json"). |
|
|
|
SetAuthToken(TOKEN). |
|
|
|
SetBody(req). |
|
|
|
SetResult(&result). |
|
|
|
Post(HOST + "/v1/" + setting.ProjectID + urlTrainJobConfig) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("resty CreateTrainJobConfig: %s", err) |
|
|
|
} |
|
|
|
|
|
|
|
if res.StatusCode() == http.StatusUnauthorized && retry < 1 { |
|
|
|
retry++ |
|
|
|
_ = getToken() |
|
|
|
goto sendjob |
|
|
|
} |
|
|
|
|
|
|
|
temp, _ := json.Marshal(req) |
|
|
|
log.Info("%s", temp) |
|
|
|
|
|
|
|
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()) |
|
|
|
} |
|
|
|
log.Error("CreateTrainJobConfig failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) |
|
|
|
return &result, fmt.Errorf("CreateTrainJobConfig failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) |
|
|
|
} |
|
|
|
|
|
|
|
if !result.IsSuccess { |
|
|
|
log.Error("CreateTrainJobConfig failed(%s): %s", result.ErrorCode, result.ErrorMsg) |
|
|
|
return &result, fmt.Errorf("CreateTrainJobConfig failed(%s): %s", result.ErrorCode, result.ErrorMsg) |
|
|
|
} |
|
|
|
|
|
|
|
return &result, nil |
|
|
|
} |