Merge pull request #11309 from ywk253100/200326_error

Fix bugs of replication
This commit is contained in:
Wenkai Yin(尹文开) 2020-03-27 10:31:03 +08:00 committed by GitHub
commit e8cc84738a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 8 deletions

View File

@ -193,12 +193,11 @@ func (b *BaseAPI) ParseAndHandleError(text string, err error) {
if err == nil {
return
}
log.Errorf("%s: %v", text, err)
if e, ok := err.(*commonhttp.Error); ok {
b.RenderError(e.Code, e.Message)
b.RenderError(e.Code, fmt.Sprintf("%s: %s", text, e.Message))
return
}
b.SendInternalServerError(errors.New(""))
b.SendInternalServerError(fmt.Errorf("%s: %v", text, err))
}
// SendUnAuthorizedError sends unauthorized error to the client.
@ -226,7 +225,7 @@ func (b *BaseAPI) SendBadRequestError(err error) {
// When you send an internal server error to the client, you expect user to check the log
// to find out the root cause.
func (b *BaseAPI) SendInternalServerError(err error) {
b.RenderError(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
b.RenderError(http.StatusInternalServerError, err.Error())
}
// SendForbiddenError sends forbidden error to the client.

View File

@ -416,7 +416,7 @@ func (t *RegistryAPI) GetInfo() {
}
info, err := adp.Info()
if err != nil {
t.SendInternalServerError(fmt.Errorf("failed to get registry info %d: %v", id, err))
t.ParseAndHandleError(fmt.Sprintf("failed to get registry info %d", id), err)
return
}
// currently, only the local Harbor registry supports the event based trigger, append it here

View File

@ -19,6 +19,7 @@ import (
"net/http"
"os"
"github.com/goharbor/harbor/src/common/api"
common_http "github.com/goharbor/harbor/src/common/http"
"github.com/goharbor/harbor/src/common/http/modifier/auth"
"github.com/goharbor/harbor/src/jobservice/job"
@ -56,7 +57,7 @@ func (s *Scheduler) Run(ctx job.Context, params job.Parameters) error {
logger := ctx.GetLogger()
url := params["url"].(string)
url = fmt.Sprintf("%s/api/replication/executions?trigger=%s", url, model.TriggerTypeScheduled)
url = fmt.Sprintf("%s/api/%s/replication/executions?trigger=%s", url, api.APIVersion, model.TriggerTypeScheduled)
policyID := (int64)(params["policy_id"].(float64))
cred := auth.NewSecretAuthorizer(os.Getenv("JOBSERVICE_SECRET"))
client := common_http.NewClient(&http.Client{

View File

@ -16,7 +16,7 @@ package scheduler
import (
"fmt"
"net/http"
"strings"
"time"
commonHttp "github.com/goharbor/harbor/src/common/http"
@ -104,7 +104,8 @@ func (s *scheduler) Unschedule(policyID int64) error {
if err = s.jobservice.PostAction(sj.JobID, job.JobActionStop); err != nil {
// if the job specified by jobID is not found in jobservice, just delete
// the record from database
if e, ok := err.(*commonHttp.Error); !ok || e.Code != http.StatusNotFound {
if e, ok := err.(*commonHttp.Error); !ok ||
!strings.Contains(e.Message, "no valid periodic job policy found") {
return err
}
log.Debugf("the stop action for schedule job %s submitted to the jobservice", sj.JobID)