Merge branch 'master' of https://gitlink.org.cn/JointCloud/pcm-coordinator
# Conflicts: # api/internal/types/types.go Former-commit-id: 7b326c485e64d3e86f26839eff6f59de03fbd032
This commit is contained in:
commit
56851224ad
|
@ -93,6 +93,28 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
type (
|
||||
GeneralTaskReq {
|
||||
Name string `json:"name"`
|
||||
ComputeType string `json:"computeType"`
|
||||
TemplateId string `json:"templateId"`
|
||||
AdapterId string `json:"adapterId"`
|
||||
ClusterIds []string `json:"clusterIds"`
|
||||
Strategy Strategy `json:"strategy"`
|
||||
ReqBody []string `json:"reqBody"`
|
||||
}
|
||||
|
||||
Strategy {
|
||||
Name string `json:"name"`
|
||||
StaticWeightList []StaticWeightList `json:"staticWeightList"`
|
||||
}
|
||||
|
||||
StaticWeightList {
|
||||
ClusterName string `json:"clusterName"`
|
||||
Weight int `json:"weight"`
|
||||
}
|
||||
)
|
||||
|
||||
type deleteTaskReq {
|
||||
Id int64 `path:"id"`
|
||||
}
|
||||
|
@ -875,6 +897,9 @@ type (
|
|||
PageNum int `json:"pageNum,omitempty"`
|
||||
PageSize int `json:"pageSize,omitempty"`
|
||||
}
|
||||
ListResult{
|
||||
List interface{} `json:"list,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
|
|
|
@ -12,7 +12,7 @@ type (
|
|||
commitHpcTaskReq {
|
||||
Name string `json:"name"` // paratera:jobName
|
||||
Description string `json:"description,optional"`
|
||||
tenantId int64 `json:"tenantId,optional"`
|
||||
TenantId int64 `json:"tenantId,optional"`
|
||||
TaskId int64 `json:"taskId,optional"`
|
||||
AdapterId string `json:"adapterId,optional"`
|
||||
MatchLabels map[string]string `json:"matchLabels,optional"`
|
||||
|
@ -99,15 +99,15 @@ type (
|
|||
HPCResource HPCResource `json:"hpcResource"`
|
||||
}
|
||||
HPCResource {
|
||||
GPUCardsTotal int32 `json:"gpuCoresTotal"`
|
||||
CPUCoresTotal int32 `json:"cpuCoresTotal"`
|
||||
RAMTotal int32 `json:"ramTotal"`
|
||||
GPUCardsUsed int32 `json:"gpuCoresUsed"`
|
||||
CPUCoresUsed int32 `json:"cpuCoresUsed"`
|
||||
RAMUsed int32 `json:"ramUsed"`
|
||||
GPURate float32 `json:"gpuRate"`
|
||||
CPURate float32 `json:"cpuRate"`
|
||||
RAMRate float32 `json:"ramRate"`
|
||||
GPUCardsTotal float64 `json:"gpuCoresTotal"`
|
||||
CPUCoresTotal float64 `json:"cpuCoresTotal"`
|
||||
RAMTotal float64 `json:"ramTotal"`
|
||||
GPUCardsUsed float64 `json:"gpuCoresUsed"`
|
||||
CPUCoresUsed float64 `json:"cpuCoresUsed"`
|
||||
RAMUsed float64 `json:"ramUsed"`
|
||||
GPURate float64 `json:"gpuRate"`
|
||||
CPURate float64 `json:"cpuRate"`
|
||||
RAMRate float64 `json:"ramRate"`
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -133,6 +133,10 @@ service pcm {
|
|||
@doc "paging queries the task list"
|
||||
@handler pageListTaskHandler
|
||||
get /core/task/list (pageTaskReq) returns(PageResult)
|
||||
|
||||
@doc "Statistical task status"
|
||||
@handler countTaskStatus
|
||||
get /core/task/countTaskStatus () returns(ListResult)
|
||||
}
|
||||
|
||||
//hpc二级接口
|
||||
|
@ -203,6 +207,10 @@ service pcm {
|
|||
@doc "Obtain cluster list information according to adapterId"
|
||||
@handler getClusterListHandler
|
||||
get /core/clusterList (getClusterListReq) returns (getClusterListResp)
|
||||
|
||||
@doc "Create cloud computing common tasks"
|
||||
@handler commitGeneralTask
|
||||
post /cloud/task/create (GeneralTaskReq) returns()
|
||||
}
|
||||
|
||||
//智算二级接口
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package cloud
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/cloud"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func CommitGeneralTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GeneralTaskReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := cloud.NewCommitGeneralTaskLogic(r.Context(), svcCtx)
|
||||
err := l.CommitGeneralTask(&req)
|
||||
result.HttpResult(r, w, nil, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/core"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func CountTaskStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := core.NewCountTaskStatusLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CountTaskStatus()
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -160,6 +160,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/core/task/list",
|
||||
Handler: core.PageListTaskHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/core/task/countTaskStatus",
|
||||
Handler: core.CountTaskStatusHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/pcm/v1"),
|
||||
)
|
||||
|
@ -242,6 +247,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/core/clusterList",
|
||||
Handler: cloud.GetClusterListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/cloud/task/create",
|
||||
Handler: cloud.CommitGeneralTaskHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/pcm/v1"),
|
||||
)
|
||||
|
|
|
@ -27,9 +27,9 @@ func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.PageR
|
|||
offset := req.PageSize * (req.PageNum - 1)
|
||||
resp = &types.PageResult{}
|
||||
var list []types.ClusterInfo
|
||||
db := l.svcCtx.DbEngin.Model(&types.AdapterInfo{}).Table("t_adapter")
|
||||
db := l.svcCtx.DbEngin.Model(&types.AdapterInfo{}).Table("t_cluster")
|
||||
|
||||
db = db.Joins("left join t_cluster on t_adapter.id = t_cluster.adapter_id").
|
||||
db = db.Joins("left join t_adapter on t_adapter.id = t_cluster.adapter_id").
|
||||
Where("t_cluster.deleted_at is null")
|
||||
if req.Name != "" {
|
||||
db = db.Where("t_cluster.name LIKE ?", "%"+req.Name+"%")
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
package cloud
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models/cloud"
|
||||
"io"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
syaml "k8s.io/apimachinery/pkg/runtime/serializer/yaml"
|
||||
kyaml "k8s.io/apimachinery/pkg/util/yaml"
|
||||
"sigs.k8s.io/yaml"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CommitGeneralTaskLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCommitGeneralTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitGeneralTaskLogic {
|
||||
return &CommitGeneralTaskLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) error {
|
||||
var yamlStr []string
|
||||
for _, s := range req.ReqBody {
|
||||
j2, err := yaml.YAMLToJSON([]byte(s))
|
||||
if err != nil {
|
||||
logx.Errorf("Failed to convert yaml to JSON, err: %v", err)
|
||||
return err
|
||||
}
|
||||
yamlStr = append(yamlStr, string(j2))
|
||||
}
|
||||
result := strings.Join(yamlStr, ",")
|
||||
//TODO The namespace is fixed to ns-admin for the time being. Later, the namespace is obtained based on the user
|
||||
taskModel := models.Task{
|
||||
Status: constants.Saved,
|
||||
Name: req.Name,
|
||||
CommitTime: time.Now(),
|
||||
NsID: "ns-admin",
|
||||
YamlString: "[" + result + "]",
|
||||
}
|
||||
// Save the task data to the database
|
||||
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
var clusters []*models.CloudModel
|
||||
err := l.svcCtx.DbEngin.Raw("SELECT * FROM `t_cluster` where adapter_id = ? and id in ?", req.AdapterId, req.ClusterIds).Scan(&clusters).Error
|
||||
if err != nil {
|
||||
logx.Errorf("CommitGeneralTask() => sql execution error: %v", err)
|
||||
return errors.Errorf("the cluster does not match the drive resources. Check the data")
|
||||
}
|
||||
taskCloud := cloud.TaskCloudModel{}
|
||||
//TODO 执行策略返回集群跟 Replica
|
||||
for _, c := range clusters {
|
||||
for _, s := range req.ReqBody {
|
||||
sStruct := UnMarshalK8sStruct(s)
|
||||
unString, _ := sStruct.MarshalJSON()
|
||||
taskCloud.TaskId = uint(taskModel.Id)
|
||||
taskCloud.AdapterId = c.AdapterId
|
||||
taskCloud.ClusterId = c.Id
|
||||
taskCloud.ClusterName = c.Name
|
||||
taskCloud.Status = "Saved"
|
||||
taskCloud.YamlString = string(unString)
|
||||
taskCloud.Kind = sStruct.GetKind()
|
||||
taskCloud.Namespace = sStruct.GetNamespace()
|
||||
tx = l.svcCtx.DbEngin.Create(&taskCloud)
|
||||
if tx.Error != nil {
|
||||
logx.Errorf("CommitGeneralTask() create taskCloud => sql execution error: %v", err)
|
||||
return tx.Error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func UnMarshalK8sStruct(yamlString string) *unstructured.Unstructured {
|
||||
unstructuredObj := &unstructured.Unstructured{}
|
||||
d := kyaml.NewYAMLOrJSONDecoder(bytes.NewBufferString(yamlString), 4096)
|
||||
var err error
|
||||
for {
|
||||
var rawObj runtime.RawExtension
|
||||
err = d.Decode(&rawObj)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
obj := &unstructured.Unstructured{}
|
||||
syaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(rawObj.Raw, nil, obj)
|
||||
unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
|
||||
if err != nil {
|
||||
logx.Errorf("UnMarshalK8sStruct() => Execution failure err:%v", err)
|
||||
}
|
||||
unstructuredObj = &unstructured.Unstructured{Object: unstructuredMap}
|
||||
// 命名空间为空 设置默认值
|
||||
if len(unstructuredObj.GetNamespace()) == 0 {
|
||||
unstructuredObj.SetNamespace("default")
|
||||
}
|
||||
}
|
||||
return unstructuredObj
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CountTaskStatusLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCountTaskStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CountTaskStatusLogic {
|
||||
return &CountTaskStatusLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
type taskStatus struct {
|
||||
Quantity string `json:"quantity"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func (l *CountTaskStatusLogic) CountTaskStatus() (resp *types.ListResult, err error) {
|
||||
resp = &types.ListResult{}
|
||||
var taskStatusList []*taskStatus
|
||||
err = l.svcCtx.DbEngin.Raw("select count(*) quantity, status from task group by status").Scan(&taskStatusList).Error
|
||||
if err != nil {
|
||||
logx.Errorf("CountTaskStatus() => sql execution error: %v", err)
|
||||
return nil, errors.Errorf("Description Failed to collect statistics on the status of a task. Please try again later")
|
||||
}
|
||||
resp.List = &taskStatusList
|
||||
return
|
||||
}
|
|
@ -54,7 +54,7 @@ func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.Pa
|
|||
return resp, err
|
||||
}
|
||||
db = db.Limit(limit).Offset(offset)
|
||||
err = db.Order("create_time desc").Find(&dictList).Error
|
||||
err = db.Order("sort_order").Find(&dictList).Error
|
||||
|
||||
resp.List = dictList
|
||||
resp.PageSize = req.PageSize
|
||||
|
|
|
@ -2,7 +2,6 @@ package hpc
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||
|
||||
|
@ -25,24 +24,35 @@ func NewResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Resource
|
|||
|
||||
func (l *ResourceLogic) Resource(req *types.HpcResourceReq) (resp *types.HpcResourceResp, err error) {
|
||||
|
||||
l.svcCtx.DbEngin.Raw("SELECT th.NAME as job_name,t.description as job_desc,t.commit_time as submit_time,th.STATUS as job_status,ta.name as adapter_name,tc.name as cluster_name,tc.label as cluster_type FROM task_hpc th LEFT JOIN task t ON t.id = th.task_id JOIN t_cluster tc on th.cluster_id = tc.id JOIN t_adapter ta on tc.adapter_id = ta.id")
|
||||
type hpcResourceOV struct {
|
||||
CpuAvail float64 `json:"cpu_avail"`
|
||||
CpuTotal float64 `json:"cpu_total"`
|
||||
MemAvail float64 `json:"mem_avail"`
|
||||
MemTotal float64 `json:"mem_total"`
|
||||
DiskAvail float64 `json:"disk_avail"`
|
||||
DiskTotal float64 `json:"disk_total"`
|
||||
GpuAvail float64 `json:"gpu_avail"`
|
||||
GpuTotal float64 `json:"gpu_total"`
|
||||
}
|
||||
var hrov hpcResourceOV
|
||||
l.svcCtx.DbEngin.Raw("SELECT sum(cpu_avail) as cpu_avail,sum(cpu_total) as cpu_total,sum(mem_avail) as mem_avail,sum(mem_total) as mem_total,sum(disk_avail) as disk_avail,sum(disk_total) as disk_total,sum(gpu_avail) as gpu_avail,sum(gpu_total) as gpu_total FROM t_cluster_resource where cluster_type = 2").Scan(&hrov)
|
||||
|
||||
hpcResource := types.HPCResource{
|
||||
GPUCardsTotal: 0,
|
||||
CPUCoresTotal: 0,
|
||||
RAMTotal: 0,
|
||||
GPUCardsUsed: 0,
|
||||
CPUCoresUsed: 0,
|
||||
RAMUsed: 0,
|
||||
GPURate: 0,
|
||||
CPURate: 0,
|
||||
RAMRate: 0,
|
||||
GPUCardsTotal: hrov.GpuTotal,
|
||||
CPUCoresTotal: hrov.CpuTotal,
|
||||
RAMTotal: hrov.MemTotal,
|
||||
GPUCardsUsed: hrov.GpuTotal - hrov.GpuAvail,
|
||||
CPUCoresUsed: hrov.CpuTotal - hrov.CpuAvail,
|
||||
RAMUsed: hrov.MemTotal - hrov.MemAvail,
|
||||
GPURate: (hrov.GpuTotal - hrov.GpuAvail) / hrov.GpuTotal,
|
||||
CPURate: (hrov.CpuTotal - hrov.CpuAvail) / hrov.CpuTotal,
|
||||
RAMRate: (hrov.MemTotal - hrov.MemAvail) / hrov.MemTotal,
|
||||
}
|
||||
|
||||
resp = &types.HpcResourceResp{
|
||||
Code: 200,
|
||||
Msg: "success",
|
||||
HPCResource: hpcResource,
|
||||
Data: hpcResource,
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -850,6 +850,10 @@ type PageResult struct {
|
|||
PageSize int `json:"pageSize,omitempty"`
|
||||
}
|
||||
|
||||
type ListResult struct {
|
||||
List interface{} `json:"list,omitempty"`
|
||||
}
|
||||
|
||||
type HpcInfo struct {
|
||||
Id int64 `json:"id"` // id
|
||||
TaskId int64 `json:"task_id"` // 任务id
|
||||
|
@ -1114,19 +1118,19 @@ type HpcResourceReq struct {
|
|||
type HpcResourceResp struct {
|
||||
Code int32 `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
HPCResource HPCResource `json:"hpcResource"`
|
||||
Data HPCResource `json:"data"`
|
||||
}
|
||||
|
||||
type HPCResource struct {
|
||||
GPUCardsTotal int32 `json:"gpuCoresTotal"`
|
||||
CPUCoresTotal int32 `json:"cpuCoresTotal"`
|
||||
RAMTotal int32 `json:"ramTotal"`
|
||||
GPUCardsUsed int32 `json:"gpuCoresUsed"`
|
||||
CPUCoresUsed int32 `json:"cpuCoresUsed"`
|
||||
RAMUsed int32 `json:"ramUsed"`
|
||||
GPURate float32 `json:"gpuRate"`
|
||||
CPURate float32 `json:"cpuRate"`
|
||||
RAMRate float32 `json:"ramRate"`
|
||||
GPUCardsTotal float64 `json:"gpuCoresTotal"`
|
||||
CPUCoresTotal float64 `json:"cpuCoresTotal"`
|
||||
RAMTotal float64 `json:"ramTotal"`
|
||||
GPUCardsUsed float64 `json:"gpuCoresUsed"`
|
||||
CPUCoresUsed float64 `json:"cpuCoresUsed"`
|
||||
RAMUsed float64 `json:"ramUsed"`
|
||||
GPURate float64 `json:"gpuRate"`
|
||||
CPURate float64 `json:"cpuRate"`
|
||||
RAMRate float64 `json:"ramRate"`
|
||||
}
|
||||
|
||||
type QueueAssetsResp struct {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package base
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type BaseModel struct {
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` // 删除时间
|
||||
CreatedBy uint `gorm:"created_by;comment:创建人" json:"createdBy"` //创建人
|
||||
CreatedTime time.Time `gorm:"comment:创建时间" json:"-"` // 创建时间
|
||||
UpdatedBy uint `gorm:"updated_by;comment:更新人" json:"UpdatedBy"` //创建人
|
||||
UpdatedTime time.Time `gorm:"comment:更新时间" json:"-"` // 更新时间
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package cloud
|
||||
|
||||
import (
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models/base"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TaskCloudModel struct {
|
||||
Id uint `json:"id" gorm:"primarykey;not null;comment:id"`
|
||||
TaskId uint `json:"taskId" gorm:"not null;comment:task表id"`
|
||||
AdapterId uint `json:"adapterId" gorm:"not null;comment:适配器id"`
|
||||
ClusterId uint `json:"clusterId" gorm:"not null;comment:集群id"`
|
||||
ClusterName string `json:"clusterName" gorm:"not null;comment:集群名称"`
|
||||
Kind string `json:"kind" gorm:"comment:种类"`
|
||||
Status string `json:"status" gorm:"comment:状态"`
|
||||
StartTime time.Time `json:"startTime" gorm:"comment:开始时间"`
|
||||
YamlString string `json:"yamlString" gorm:"not null;comment:入参"`
|
||||
Result string `json:"result" gorm:"comment:运行结果"`
|
||||
Namespace string `json:"namespace" gorm:"comment:命名空间"`
|
||||
Replica int `json:"replica" gorm:"not null;comment:副本数"`
|
||||
base.BaseModel
|
||||
}
|
||||
|
||||
func (TaskCloudModel) TableName() string {
|
||||
return "task_cloud"
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package models
|
||||
|
||||
import "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models/base"
|
||||
|
||||
type CloudModel struct {
|
||||
Id uint `json:"id,omitempty" gorm:"id"`
|
||||
AdapterId uint `json:"adapterId,omitempty" gorm:"adapter_id"`
|
||||
Name string `json:"name,omitempty" gorm:"name"`
|
||||
Nickname string `json:"nickname,omitempty" gorm:"nickname"`
|
||||
Description string `json:"description,omitempty" gorm:"description"`
|
||||
Server string `json:"server,omitempty" gorm:"server"`
|
||||
MonitorServer string `json:"monitorServer,omitempty" gorm:"monitor_server"`
|
||||
Username string `json:"username,omitempty" gorm:"username"`
|
||||
Password string `json:"password,omitempty" gorm:"password"`
|
||||
Token string `json:"token,omitempty" gorm:"token"`
|
||||
Ak string `json:"ak,omitempty" gorm:"ak"`
|
||||
Sk string `json:"sk,omitempty" gorm:"sk"`
|
||||
Region string `json:"region,omitempty" gorm:"region"`
|
||||
ProjectId string `json:"projectId,omitempty" gorm:"project_id"`
|
||||
Version string `json:"version,omitempty" gorm:"version"`
|
||||
Label string `json:"label,omitempty" gorm:"label"`
|
||||
OwnerId uint `json:"ownerId,omitempty" gorm:"owner_id"`
|
||||
AuthType int `json:"authType,omitempty" gorm:"auth_type"`
|
||||
ProducerDict string `json:"producerDict,omitempty" gorm:"producer_dict"`
|
||||
RegionDict string `json:"regionDict,omitempty" gorm:"region_dict"`
|
||||
base.BaseModel
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package models
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ TClusterResourceModel = (*customTClusterResourceModel)(nil)
|
||||
|
||||
type (
|
||||
// TClusterResourceModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customTClusterResourceModel.
|
||||
TClusterResourceModel interface {
|
||||
tClusterResourceModel
|
||||
withSession(session sqlx.Session) TClusterResourceModel
|
||||
}
|
||||
|
||||
customTClusterResourceModel struct {
|
||||
*defaultTClusterResourceModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewTClusterResourceModel returns a model for the database table.
|
||||
func NewTClusterResourceModel(conn sqlx.SqlConn) TClusterResourceModel {
|
||||
return &customTClusterResourceModel{
|
||||
defaultTClusterResourceModel: newTClusterResourceModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customTClusterResourceModel) withSession(session sqlx.Session) TClusterResourceModel {
|
||||
return NewTClusterResourceModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
tClusterResourceFieldNames = builder.RawFieldNames(&TClusterResource{})
|
||||
tClusterResourceRows = strings.Join(tClusterResourceFieldNames, ",")
|
||||
tClusterResourceRowsExpectAutoSet = strings.Join(stringx.Remove(tClusterResourceFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
tClusterResourceRowsWithPlaceHolder = strings.Join(stringx.Remove(tClusterResourceFieldNames, "`cluster_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
tClusterResourceModel interface {
|
||||
Insert(ctx context.Context, data *TClusterResource) (sql.Result, error)
|
||||
FindOne(ctx context.Context, clusterId int64) (*TClusterResource, error)
|
||||
Update(ctx context.Context, data *TClusterResource) error
|
||||
Delete(ctx context.Context, clusterId int64) error
|
||||
}
|
||||
|
||||
defaultTClusterResourceModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
TClusterResource struct {
|
||||
ClusterId int64 `db:"cluster_id"`
|
||||
ClusterName string `db:"cluster_name"`
|
||||
ClusterType int64 `db:"cluster_type"` // 类型0->容器,1->智算,2->超算,3-虚拟机
|
||||
CpuAvail float64 `db:"cpu_avail"`
|
||||
CpuTotal float64 `db:"cpu_total"`
|
||||
MemAvail float64 `db:"mem_avail"`
|
||||
MemTotal float64 `db:"mem_total"`
|
||||
DiskAvail float64 `db:"disk_avail"`
|
||||
DiskTotal float64 `db:"disk_total"`
|
||||
GpuAvail float64 `db:"gpu_avail"`
|
||||
GpuTotal float64 `db:"gpu_total"`
|
||||
}
|
||||
)
|
||||
|
||||
func newTClusterResourceModel(conn sqlx.SqlConn) *defaultTClusterResourceModel {
|
||||
return &defaultTClusterResourceModel{
|
||||
conn: conn,
|
||||
table: "`t_cluster_resource`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTClusterResourceModel) Delete(ctx context.Context, clusterId int64) error {
|
||||
query := fmt.Sprintf("delete from %s where `cluster_id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, clusterId)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultTClusterResourceModel) FindOne(ctx context.Context, clusterId int64) (*TClusterResource, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `cluster_id` = ? limit 1", tClusterResourceRows, m.table)
|
||||
var resp TClusterResource
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, clusterId)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTClusterResourceModel) Insert(ctx context.Context, data *TClusterResource) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, tClusterResourceRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.ClusterId, data.ClusterName, data.ClusterType, data.CpuAvail, data.CpuTotal, data.MemAvail, data.MemTotal, data.DiskAvail, data.DiskTotal, data.GpuAvail, data.GpuTotal)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultTClusterResourceModel) Update(ctx context.Context, data *TClusterResource) error {
|
||||
query := fmt.Sprintf("update %s set %s where `cluster_id` = ?", m.table, tClusterResourceRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.ClusterName, data.ClusterType, data.CpuAvail, data.CpuTotal, data.MemAvail, data.MemTotal, data.DiskAvail, data.DiskTotal, data.GpuAvail, data.GpuTotal, data.ClusterId)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultTClusterResourceModel) tableName() string {
|
||||
return m.table
|
||||
}
|
Loading…
Reference in New Issue