merge code 20160830

This commit is contained in:
yhua 2016-08-30 12:35:38 +08:00
parent 944ad04982
commit c69fffcca6
2 changed files with 10 additions and 10 deletions

View File

@ -73,8 +73,8 @@ before_script:
script:
- sudo ./tests/testprepare.sh
- docker-compose -f Deploy/docker-compose.test.yml up -d
- go list ./... | grep -v -E 'vendor|tests|api' | xargs -L1 fgt golint
- go list ./... | grep -v -E 'vendor|tests|api' | xargs -L1 go vet
- go list ./... | grep -v -E 'vendor|tests' | xargs -L1 fgt golint
- go list ./... | grep -v -E 'vendor|tests' | xargs -L1 go vet
- IP=`ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}'`
- export MYSQL_HOST=$IP
- export REGISTRY_URL=http://$IP:5000

View File

@ -352,38 +352,38 @@ func (pa *RepPolicyAPI) UpdateEnablement() {
// Delete : policies which are disabled and have no running jobs
// can be deleted
func (r *RepPolicyAPI) Delete() {
id := r.GetIDFromURL()
func (pa *RepPolicyAPI) Delete() {
id := pa.GetIDFromURL()
policy, err := dao.GetRepPolicy(id)
if err != nil {
log.Errorf("failed to get policy %d: %v", id, err)
r.CustomAbort(http.StatusInternalServerError, "")
pa.CustomAbort(http.StatusInternalServerError, "")
}
if policy == nil || policy.Deleted == 1 {
r.CustomAbort(http.StatusNotFound, "")
pa.CustomAbort(http.StatusNotFound, "")
}
if policy.Enabled == 1 {
r.CustomAbort(http.StatusPreconditionFailed, "plicy is enabled, can not be deleted")
pa.CustomAbort(http.StatusPreconditionFailed, "plicy is enabled, can not be deleted")
}
jobs, err := dao.GetRepJobByPolicy(id)
if err != nil {
log.Errorf("failed to get jobs of policy %d: %v", id, err)
r.CustomAbort(http.StatusInternalServerError, "")
pa.CustomAbort(http.StatusInternalServerError, "")
}
for _, job := range jobs {
if job.Status == models.JobRunning ||
job.Status == models.JobRetrying ||
job.Status == models.JobPending {
r.CustomAbort(http.StatusPreconditionFailed, "policy has running/retrying/pending jobs, can not be deleted")
pa.CustomAbort(http.StatusPreconditionFailed, "policy has running/retrying/pending jobs, can not be deleted")
}
}
if err = dao.DeleteRepPolicy(id); err != nil {
log.Errorf("failed to delete policy %d: %v", id, err)
r.CustomAbort(http.StatusInternalServerError, "")
pa.CustomAbort(http.StatusInternalServerError, "")
}
}