| @@ -213,8 +213,9 @@ func getQueryString(page int, size int, name string) string { | |||||
| } | } | ||||
| func CommitImage(jobID string, params models.CommitImageParams) error { | func CommitImage(jobID string, params models.CommitImageParams) error { | ||||
| imageTag := strings.TrimSpace(params.ImageTag) | |||||
| dbImage, err := models.GetImageByTag(params.ImageTag) | |||||
| dbImage, err := models.GetImageByTag(imageTag) | |||||
| if err != nil && !models.IsErrImageNotExist(err) { | if err != nil && !models.IsErrImageNotExist(err) { | ||||
| return fmt.Errorf("resty CommitImage: %v", err) | return fmt.Errorf("resty CommitImage: %v", err) | ||||
| @@ -224,12 +225,12 @@ func CommitImage(jobID string, params models.CommitImageParams) error { | |||||
| if dbImage != nil { | if dbImage != nil { | ||||
| if dbImage.UID != params.UID { | if dbImage.UID != params.UID { | ||||
| return models.ErrorImageTagExist{ | return models.ErrorImageTagExist{ | ||||
| Tag: params.ImageTag, | |||||
| Tag: imageTag, | |||||
| } | } | ||||
| } else { | } else { | ||||
| if dbImage.Status == models.IMAGE_STATUS_COMMIT { | if dbImage.Status == models.IMAGE_STATUS_COMMIT { | ||||
| return models.ErrorImageCommitting{ | return models.ErrorImageCommitting{ | ||||
| Tag: params.ImageTag, | |||||
| Tag: imageTag, | |||||
| } | } | ||||
| } else { //覆盖提交 | } else { //覆盖提交 | ||||
| @@ -282,9 +283,9 @@ sendjob: | |||||
| CloudbrainType: params.CloudBrainType, | CloudbrainType: params.CloudBrainType, | ||||
| UID: params.UID, | UID: params.UID, | ||||
| IsPrivate: params.IsPrivate, | IsPrivate: params.IsPrivate, | ||||
| Tag: params.ImageTag, | |||||
| Tag: imageTag, | |||||
| Description: params.ImageDescription, | Description: params.ImageDescription, | ||||
| Place: setting.Cloudbrain.ImageURLPrefix + params.ImageTag, | |||||
| Place: setting.Cloudbrain.ImageURLPrefix + imageTag, | |||||
| Status: models.IMAGE_STATUS_COMMIT, | Status: models.IMAGE_STATUS_COMMIT, | ||||
| } | } | ||||
| @@ -318,15 +319,15 @@ sendjob: | |||||
| } | } | ||||
| func CommitAdminImage(params models.CommitImageParams) error { | func CommitAdminImage(params models.CommitImageParams) error { | ||||
| exist, err := models.IsImageExist(params.ImageTag) | |||||
| imageTag := strings.TrimSpace(params.ImageTag) | |||||
| exist, err := models.IsImageExist(imageTag) | |||||
| if err != nil { | if err != nil { | ||||
| return fmt.Errorf("resty CommitImage: %v", err) | return fmt.Errorf("resty CommitImage: %v", err) | ||||
| } | } | ||||
| if exist { | if exist { | ||||
| return models.ErrorImageTagExist{ | return models.ErrorImageTagExist{ | ||||
| Tag: params.ImageTag, | |||||
| Tag: imageTag, | |||||
| } | } | ||||
| } | } | ||||
| @@ -334,7 +335,7 @@ func CommitAdminImage(params models.CommitImageParams) error { | |||||
| CloudbrainType: params.CloudBrainType, | CloudbrainType: params.CloudBrainType, | ||||
| UID: params.UID, | UID: params.UID, | ||||
| IsPrivate: params.IsPrivate, | IsPrivate: params.IsPrivate, | ||||
| Tag: params.ImageTag, | |||||
| Tag: imageTag, | |||||
| Description: params.ImageDescription, | Description: params.ImageDescription, | ||||
| Place: params.Place, | Place: params.Place, | ||||
| Status: models.IMAGE_STATUS_SUCCESS, | Status: models.IMAGE_STATUS_SUCCESS, | ||||
| @@ -362,13 +363,11 @@ func updateImageStatus(image models.Image, isSetCreatedUnix bool, createTime tim | |||||
| commitSuccess := false | commitSuccess := false | ||||
| time.Sleep(5 * time.Second) | time.Sleep(5 * time.Second) | ||||
| for i := 0; i < attemps; i++ { | for i := 0; i < attemps; i++ { | ||||
| if commitSuccess { | |||||
| break | |||||
| } | |||||
| log.Info("the " + strconv.Itoa(i) + " times query cloudbrain images.Imagetag:" + image.Tag + "isSetCreate:" + strconv.FormatBool(isSetCreatedUnix)) | |||||
| result, err := GetImagesPageable(1, pageSize, Custom, "") | result, err := GetImagesPageable(1, pageSize, Custom, "") | ||||
| if err == nil && result.Code == "S000" { | if err == nil && result.Code == "S000" { | ||||
| log.Info("images count:" + strconv.Itoa(result.Payload.Count)) | |||||
| for _, v := range result.Payload.ImageInfo { | for _, v := range result.Payload.ImageInfo { | ||||
| if v.Place == image.Place && (!isSetCreatedUnix || (isSetCreatedUnix && createTimeUpdated(v, createTime))) { | if v.Place == image.Place && (!isSetCreatedUnix || (isSetCreatedUnix && createTimeUpdated(v, createTime))) { | ||||
| image.Status = models.IMAGE_STATUS_SUCCESS | image.Status = models.IMAGE_STATUS_SUCCESS | ||||
| @@ -380,6 +379,10 @@ func updateImageStatus(image models.Image, isSetCreatedUnix bool, createTime tim | |||||
| } | } | ||||
| } | } | ||||
| if commitSuccess { | |||||
| break | |||||
| } | |||||
| //第一次循环等待4秒,第二次等待4的2次方16秒,...,第5次。。。 ,总共大概是20多分钟内进行5次重试 | //第一次循环等待4秒,第二次等待4的2次方16秒,...,第5次。。。 ,总共大概是20多分钟内进行5次重试 | ||||
| var sleepTime = time.Duration(int(math.Pow(4, (float64(i + 1))))) | var sleepTime = time.Duration(int(math.Pow(4, (float64(i + 1))))) | ||||