Skip to content

Commit

Permalink
Merge remote-tracking branch 'github-bk-bcs/master'
Browse files Browse the repository at this point in the history
* github-bk-bcs/master:
  fix: 修复解压文件时编码转换以及配置项路径校验 (#3510)
  feat: 文件型配置服务创建配置文件时提示文件权限对Windows客户端提示--story=119622492  (#3509)
  fix: 修复批量导入文件时路径规则错误问题 (#3508)
  fix: 更改校验文件路径和名称规则 (#3506)
  fix: powershell 环境变量格式问题修复--bug=130444637  (#3504)
  feat: 配置示例真实路径服务id改为业务id--story=115998324 (#3505)
  fix: 修复aks扩容实例ip获取问题 (#3501)
  feat: 配置示例新增:临时目录tooltip调整、增加说明文案和复制功能--story=115998324 (#3499)
  feat: 服务管理页面添加“配置客户端”引导--story=119561674 (#3502)
  fix: 配置文件路径限制优化 (#3500)
  fix: 配置文件打包下载按钮禁用 (#3498)
  fix: bcs-task not update task when AddCommonParam (#3495)
  fix: 敏感信息 -“不可见”属性不允许用户编辑--bug=130157573 (#3493)
  fix: 修复无权限页面切换显示不正确的问题 --bug=128795439 (#3490)
  fix: bcs-task mysql store limit index length and add step recover (#3488)
  • Loading branch information
evanlixin committed Sep 10, 2024
2 parents 981585a + c5d3220 commit baee26b
Show file tree
Hide file tree
Showing 60 changed files with 1,402 additions and 1,130 deletions.
7 changes: 3 additions & 4 deletions bcs-common/common/task/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ func NewByTaskBuilder(builder types.TaskBuilder, opts ...types.TaskOption) (*typ
task.Steps = steps
task.CurrentStep = steps[0].GetName()

// 自定义extraJson等
newTask, err := builder.BuildTask(*task)
if err != nil {
// 自定义任务超时, commonParams, commonPayload等
if err := builder.FinalizeTask(task); err != nil {
return nil, err
}

return &newTask, nil
return task, nil
}
8 changes: 8 additions & 0 deletions bcs-common/common/task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"errors"
"fmt"
"runtime/debug"
"sync"
"time"

Expand Down Expand Up @@ -359,6 +360,13 @@ func (m *TaskManager) doWork(taskID string, stepName string) error { // nolint

tmpCh := make(chan error, 1)
go func() {
defer func() {
if r := recover(); r != nil {
log.ERROR.Printf("[%s-%s][recover] panic: %v, stack %s", taskID, stepName, r, debug.Stack())
tmpCh <- fmt.Errorf("%w by a panic: %v", istep.ErrRevoked, r)
}
}()

// call step worker
execCtx := istep.NewContext(stepCtx, GetGlobalStorage(), state.GetTask(), step)
tmpCh <- stepExecutor.Execute(execCtx)
Expand Down
1 change: 0 additions & 1 deletion bcs-common/common/task/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* limitations under the License.
*/

// Package task is a package for task management
package task

import (
Expand Down
37 changes: 0 additions & 37 deletions bcs-common/common/task/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* limitations under the License.
*/

// Package task is a package for task management
package task

import (
Expand Down Expand Up @@ -325,43 +324,7 @@ func (s *State) isLastStep(step *types.Step) bool {
return step.IsCompleted()
}

// GetCommonParam get common params by key
func (s *State) GetCommonParam(key string) (string, bool) {
return s.task.GetCommonParam(key)
}

// AddCommonParam add common params
func (s *State) AddCommonParam(key, value string) *State {
s.task.AddCommonParam(key, value)
return s
}

// GetCommonPayload get extra params by obj
func (s *State) GetCommonPayload(obj interface{}) error {
return s.task.GetCommonPayload(obj)
}

// SetCommonPayload set extra params by obj
func (s *State) SetCommonPayload(obj interface{}) error {
return s.task.SetCommonPayload(obj)
}

// GetStepParam get step params by key
func (s *State) GetStepParam(stepName, key string) (string, bool) {
return s.task.GetStepParam(stepName, key)
}

// AddStepParams add step params
func (s *State) AddStepParams(stepName, key, value string) error {
return s.task.AddStepParams(stepName, key, value)
}

// GetTask get task
func (s *State) GetTask() *types.Task {
return s.task
}

// GetStep get step by stepName
func (s *State) GetStep(stepName string) (*types.Step, bool) {
return s.task.GetStep(stepName)
}
108 changes: 54 additions & 54 deletions bcs-common/common/task/steps/iface/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,112 +45,112 @@ func NewContext(ctx context.Context, store istore.Store, task *types.Task, curre
}

// Context returns the step's context
func (t *Context) Context() context.Context {
return t.ctx
func (c *Context) Context() context.Context {
return c.ctx
}

// GetTaskID get task id
func (t *Context) GetTaskID() string {
return t.task.GetTaskID()
func (c *Context) GetTaskID() string {
return c.task.GetTaskID()
}

// GetTaskName get task name
func (t *Context) GetTaskName() string {
return t.task.GetTaskID()
func (c *Context) GetTaskName() string {
return c.task.GetTaskName()
}

// GetTaskType get task type
func (t *Context) GetTaskType() string {
return t.task.GetTaskType()
func (c *Context) GetTaskType() string {
return c.task.GetTaskType()
}

// GetTaskIndex get task index
func (t *Context) GetTaskIndex() string {
return t.task.GetTaskIndex()
func (c *Context) GetTaskIndex() string {
return c.task.GetTaskIndex()
}

// GetTaskStatus get task status
func (t *Context) GetTaskStatus() string {
return t.task.GetStatus()
func (c *Context) GetTaskStatus() string {
return c.task.GetStatus()
}

// GetCommonParam get current task param
func (t *Context) GetCommonParam(key string) (string, bool) {
return t.task.GetCommonParam(key)
func (c *Context) GetCommonParam(key string) (string, bool) {
return c.task.GetCommonParam(key)
}

// AddCommonParam add task common params
func (t *Context) AddCommonParam(k, v string) error {
_ = t.task.AddCommonParam(k, v)
return nil
// AddCommonParam add task common param and save to store
func (c *Context) AddCommonParam(k, v string) error {
_ = c.task.AddCommonParam(k, v)
return c.store.UpdateTask(c.ctx, c.task)
}

// GetCommonPayload get task extra json
func (t *Context) GetCommonPayload(obj interface{}) error {
return t.task.GetCommonPayload(obj)
// GetCommonPayload unmarshal task common payload to struct obj
func (c *Context) GetCommonPayload(obj any) error {
return c.task.GetCommonPayload(obj)
}

// SetCommonPayload set task extra json
func (t *Context) SetCommonPayload(obj interface{}) error {
if err := t.task.SetCommonPayload(obj); err != nil {
// SetCommonPayload marshal struct obj to task common payload and save to store
func (c *Context) SetCommonPayload(obj any) error {
if err := c.task.SetCommonPayload(obj); err != nil {
return err
}

return t.store.UpdateTask(t.ctx, t.task)
return c.store.UpdateTask(c.ctx, c.task)
}

// GetName get current step name
func (t *Context) GetName() string {
return t.currentStep.GetName()
func (c *Context) GetName() string {
return c.currentStep.GetName()
}

// GetStatus get current step status
func (t *Context) GetStatus() string {
return t.currentStep.GetStatus()
func (c *Context) GetStatus() string {
return c.currentStep.GetStatus()
}

// GetRetryCount get current step retrycount
func (t *Context) GetRetryCount() uint32 {
return t.currentStep.GetRetryCount()
// GetRetryCount get current step retry count
func (c *Context) GetRetryCount() uint32 {
return c.currentStep.GetRetryCount()
}

// GetParam get current step param
func (t *Context) GetParam(key string) (string, bool) {
return t.currentStep.GetParam(key)
// GetParam get current step param by key
func (c *Context) GetParam(key string) (string, bool) {
return c.currentStep.GetParam(key)
}

// AddParam set step param by key,value
func (t *Context) AddParam(key string, value string) error {
_ = t.currentStep.AddParam(key, value)
return t.store.UpdateTask(t.ctx, t.task)
// AddParam set step param by key,value and save to store
func (c *Context) AddParam(key string, value string) error {
_ = c.currentStep.AddParam(key, value)
return c.store.UpdateTask(c.ctx, c.task)
}

// GetParams return all step params
func (t *Context) GetParams() map[string]string {
return t.currentStep.GetParams()
func (c *Context) GetParams() map[string]string {
return c.currentStep.GetParams()
}

// SetParams return all step params
func (t *Context) SetParams(params map[string]string) error {
t.currentStep.SetParams(params)
return t.store.UpdateTask(t.ctx, t.task)
// SetParams set all step params and save to store
func (c *Context) SetParams(params map[string]string) error {
c.currentStep.SetParams(params)
return c.store.UpdateTask(c.ctx, c.task)
}

// GetPayload return unmarshal step extras
func (t *Context) GetPayload(obj interface{}) error {
return t.currentStep.GetPayload(obj)
// GetPayload return unmarshal step payload
func (c *Context) GetPayload(obj any) error {
return c.currentStep.GetPayload(obj)
}

// GetStartTime return step start time
func (t *Context) GetStartTime() time.Time {
return t.currentStep.Start
func (c *Context) GetStartTime() time.Time {
return c.currentStep.Start
}

// SetPayload set step extras by json string
func (t *Context) SetPayload(obj interface{}) error {
if err := t.currentStep.SetPayload(obj); err != nil {
// SetPayload marshal struct obj to step payload and save to store
func (c *Context) SetPayload(obj any) error {
if err := c.currentStep.SetPayload(obj); err != nil {
return err
}

return t.store.UpdateTask(t.ctx, t.task)
return c.store.UpdateTask(c.ctx, c.task)
}
1 change: 0 additions & 1 deletion bcs-common/common/task/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* limitations under the License.
*/

// Package task is a package for task management
package task

import istore "github.com/Tencent/bk-bcs/bcs-common/common/task/stores/iface"
Expand Down
9 changes: 5 additions & 4 deletions bcs-common/common/task/stores/mysql/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
字段规范:
1. 字段名使用驼峰命名法,表字段使用 _ 分隔
2. bool/int/float/datetime 等类型使用默认字段类型
3. string 类型必须指定类型和长度,字段是索引的,设置为 varchar(191)
3. string 类型必须指定类型和长度
4. index 固定varchar(191), (mysql 5.6索引长度限制767byte, utf8mb4下最长191)
**/

var (
Expand All @@ -36,7 +37,7 @@ var (
// TaskRecord 任务记录
type TaskRecord struct {
gorm.Model
TaskID string `json:"taskID" gorm:"type:varchar(255);uniqueIndex:idx_task_id"` // 唯一索引
TaskID string `json:"taskID" gorm:"type:varchar(191);uniqueIndex:idx_task_id"` // 唯一索引
TaskType string `json:"taskType" gorm:"type:varchar(255)"`
TaskIndex string `json:"TaskIndex" gorm:"type:varchar(255)"`
TaskIndexType string `json:"TaskIndexType" gorm:"type:varchar(255)"`
Expand Down Expand Up @@ -86,8 +87,8 @@ func (t *TaskRecord) BeforeUpdate(tx *gorm.DB) error {
// StepRecord 步骤记录
type StepRecord struct {
gorm.Model
TaskID string `json:"taskID" gorm:"type:varchar(255);uniqueIndex:idx_task_id_step_name"`
Name string `json:"name" gorm:"type:varchar(255);uniqueIndex:idx_task_id_step_name"`
TaskID string `json:"taskID" gorm:"type:varchar(191);uniqueIndex:idx_task_id_step_name"`
Name string `json:"name" gorm:"type:varchar(191);uniqueIndex:idx_task_id_step_name"`
Alias string `json:"alias" gorm:"type:varchar(255)"`
Executor string `json:"executor" gorm:"type:varchar(255)"`
Params map[string]string `json:"input" gorm:"type:text;serializer:json"`
Expand Down
8 changes: 4 additions & 4 deletions bcs-common/common/task/types/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ func (s *Step) SetNewParams(params map[string]string) *Step {
return s
}

// GetPayload return unmarshal step extras
func (s *Step) GetPayload(obj interface{}) error {
// GetPayload unmarshal step payload to struct obj
func (s *Step) GetPayload(obj any) error {
if len(s.Payload) == 0 {
s.Payload = DefaultPayloadContent
}
return json.Unmarshal([]byte(s.Payload), obj)
}

// SetPayload set step extras by json string
func (s *Step) SetPayload(obj interface{}) error {
// SetPayload marshal struct obj to step payload
func (s *Step) SetPayload(obj any) error {
result, err := json.Marshal(obj)
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions bcs-common/common/task/types/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
// TaskBuilder ...
type TaskBuilder interface { // nolint
TaskInfo() TaskInfo
Steps() ([]*Step, error) // Steps init step and define StepSequence
BuildTask(t Task) (Task, error)
Steps() ([]*Step, error) // Steps init step and define StepSequence
FinalizeTask(t *Task) error // FinalizeTask for custom task
}

// TaskOptions xxx
Expand Down Expand Up @@ -159,16 +159,16 @@ func (t *Task) SetCallback(callBackName string) *Task {
return t
}

// GetCommonPayload get extra json
func (t *Task) GetCommonPayload(obj interface{}) error {
// GetCommonPayload unmarshal common payload to struct obj
func (t *Task) GetCommonPayload(obj any) error {
if len(t.CommonPayload) == 0 {
t.CommonPayload = DefaultPayloadContent
}
return json.Unmarshal([]byte(t.CommonPayload), obj)
}

// SetCommonPayload set extra json
func (t *Task) SetCommonPayload(obj interface{}) error {
// SetCommonPayload marshal struct obj to common payload
func (t *Task) SetCommonPayload(obj any) error {
result, err := json.Marshal(obj)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion bcs-common/common/task/types/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var (
type Task struct {
TaskIndex string `json:"taskIndex"`
TaskIndexType string `json:"taskIndexType"`
TaskID string `json:"taskId"`
TaskID string `json:"taskID"`
TaskType string `json:"taskType"`
TaskName string `json:"taskName"`
CurrentStep string `json:"currentStep"`
Expand Down
3 changes: 1 addition & 2 deletions bcs-common/common/task/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* limitations under the License.
*/

// Package task xxx
package task

import (
Expand All @@ -26,7 +25,7 @@ import (
// RecoverPrintStack capture panic and print stack
func RecoverPrintStack(proc string) {
if r := recover(); r != nil {
log.ERROR.Printf("[%s][recover] panic: %v, stack %v\n", proc, r, string(debug.Stack()))
log.ERROR.Printf("[%s][recover] panic: %v, stack %s", proc, r, debug.Stack())
return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (c *configImport) ConfigFileImport(w http.ResponseWriter, r *http.Request)
Items: batch,
})
if errC != nil {
_ = render.Render(w, r, rest.BadRequest(errors.New(i18n.T(kt, "list config item failed, err: %v", err))))
_ = render.Render(w, r, rest.BadRequest(errors.New(i18n.T(kt, "list config item failed, err: %v", errC))))
return
}
for _, item := range tuple.GetDetails() {
Expand Down
Loading

0 comments on commit baee26b

Please sign in to comment.