Skip to content

Commit

Permalink
Add deployment plan validation functionality (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitlayzer authored Jun 9, 2024
1 parent 3529acf commit f4dfa28
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/server/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ var (
Code: http.StatusNotFound,
Err: errors.ErrUserNotFound,
}
ErrNotAcceptable = Error{
Code: http.StatusNotAcceptable,
Err: errors.ErrNotAcceptable,
}
ErrUserExists = Error{
Code: http.StatusConflict,
Err: errors.UserExistError,
Expand Down
13 changes: 13 additions & 0 deletions pkg/controller/plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ func (p *plan) List(ctx context.Context) ([]types.Plan, error) {
}

func (p *plan) Start(ctx context.Context, pid int64) error {
tasks, err := p.factory.Plan().ListTasks(ctx, pid)
if err != nil {
klog.Errorf("failed to get tasks of plan %d: %v", pid, err)
return errors.ErrServerInternal
}

for _, task := range tasks {
if task.Status == model.RunningPlanStatus {
klog.Warningf("task %d of plan %d is already running", task.Id, pid)
return errors.ErrNotAcceptable
}
}

taskQueue.Add(pid)
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/util/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
ErrReqParams = errors.New("请求参数错误")
ErrCloudNotRegister = errors.New("cloud 集群未注册")
ErrUserNotFound = errors.New("用户不存在")
ErrNotAcceptable = errors.New("有任务正在执行,请稍后再试")
ErrClusterNotFound = errors.New("集群不存在")
ErrUserPassword = errors.New("密码错误")
ErrInternal = errors.New("服务器内部错误")
Expand Down

0 comments on commit f4dfa28

Please sign in to comment.