Add scheduling_map field to ParameterSchema so Application creators can declare that a parameter (e.g. NP) maps to a scheduling field (e.g. cpus). The backend auto-injects the scheduling value into script template variables before rendering, eliminating duplicate user input. The frontend hides mapped parameters from the form and injects their values on submit.
78 lines
4.1 KiB
Go
78 lines
4.1 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
// 参数类型常量
|
|
const (
|
|
ParamTypeString = "string"
|
|
ParamTypeInteger = "integer"
|
|
ParamTypeEnum = "enum"
|
|
ParamTypeFile = "file"
|
|
ParamTypeDirectory = "directory"
|
|
ParamTypeBoolean = "boolean"
|
|
)
|
|
|
|
// Application 表示一个参数化的 HPC 应用定义。
|
|
type Application struct {
|
|
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"` // 主键
|
|
Name string `gorm:"uniqueIndex;size:255;not null" json:"name"` // 应用名称(唯一)
|
|
Description string `gorm:"type:text" json:"description,omitempty"` // 应用描述
|
|
Icon string `gorm:"size:255" json:"icon,omitempty"` // 图标
|
|
Category string `gorm:"size:255" json:"category,omitempty"` // 分类
|
|
ScriptTemplate string `gorm:"type:text;not null" json:"script_template"` // 脚本模板
|
|
Parameters json.RawMessage `gorm:"type:json" json:"parameters,omitempty"` // 参数表单JSON
|
|
Environment json.RawMessage `gorm:"type:text" json:"environment,omitempty"` // 环境变量JSON
|
|
Scope string `gorm:"size:50;default:'system'" json:"scope,omitempty"` // 作用域(system/user)
|
|
CreatedBy int64 `json:"created_by,omitempty"` // 创建者ID
|
|
CreatedAt time.Time `json:"created_at"` // 创建时间
|
|
UpdatedAt time.Time `json:"updated_at"` // 更新时间
|
|
}
|
|
|
|
func (Application) TableName() string {
|
|
return "hpc_applications"
|
|
}
|
|
|
|
// ParameterSchema 定义应用表单中单个参数的格式。
|
|
type ParameterSchema struct {
|
|
Name string `json:"name"` // 参数名
|
|
Label string `json:"label,omitempty"` // 显示名称
|
|
Type string `json:"type"` // 参数类型
|
|
Required bool `json:"required,omitempty"` // 是否必填
|
|
Default string `json:"default,omitempty"` // 默认值
|
|
Options []string `json:"options,omitempty"` // 枚举选项列表
|
|
Description string `json:"description,omitempty"` // 参数说明
|
|
SchedulingMap string `json:"scheduling_map,omitempty"` // maps to a scheduling param
|
|
}
|
|
|
|
// CreateApplicationRequest 是创建应用的 API 请求。
|
|
type CreateApplicationRequest struct {
|
|
Name string `json:"name" binding:"required"` // 应用名称(必填)
|
|
Description string `json:"description,omitempty"` // 应用描述
|
|
Icon string `json:"icon,omitempty"` // 图标
|
|
Category string `json:"category,omitempty"` // 分类
|
|
ScriptTemplate string `json:"script_template" binding:"required"` // 脚本模板(必填)
|
|
Parameters json.RawMessage `json:"parameters,omitempty"` // 参数表单JSON
|
|
Environment map[string]string `json:"environment,omitempty"` // 环境变量
|
|
Scope string `json:"scope,omitempty"` // 作用域
|
|
}
|
|
|
|
// UpdateApplicationRequest 是更新应用的 API 请求。所有字段可选。
|
|
type UpdateApplicationRequest struct {
|
|
Name *string `json:"name,omitempty"` // 应用名称
|
|
Description *string `json:"description,omitempty"` // 应用描述
|
|
Icon *string `json:"icon,omitempty"` // 图标
|
|
Category *string `json:"category,omitempty"` // 分类
|
|
ScriptTemplate *string `json:"script_template,omitempty"` // 脚本模板
|
|
Parameters *json.RawMessage `json:"parameters,omitempty"` // 参数表单JSON
|
|
Environment *json.RawMessage `json:"environment,omitempty"` // 环境变量
|
|
Scope *string `json:"scope,omitempty"` // 作用域
|
|
}
|
|
|
|
// ApplicationSubmitRequest 是通过应用提交作业的 API 请求。
|
|
type ApplicationSubmitRequest struct {
|
|
Values map[string]string `json:"values" binding:"required"` // 脚本业务参数键值对
|
|
}
|