Former-commit-id: f7e3262935
pull/105/head
| @@ -133,6 +133,8 @@ type ( | |||
| MatchLabels map[string]string `json:"matchLabels,optional"` | |||
| servers []ServerCommit `json:"servers,optional"` | |||
| platform string `json:"platform,optional"` | |||
| AdapterId string `json:"adapterId,optional"` | |||
| ClusterType string `json:"clusterType,optional"` | |||
| } | |||
| ServerCommit { | |||
| allCardRunTime string `json:"allCardRunTime"` | |||
| @@ -159,7 +161,10 @@ type ( | |||
| } | |||
| commitVmTaskResp { | |||
| VmTask []VmTask `json:"vmTask" copier:"VmTask"` | |||
| // VmTask []VmTask `json:"vmTask" copier:"VmTask"` | |||
| TaskId int64 `json:"taskId"` | |||
| Code int32 `json:"code"` | |||
| Msg string `json:"msg"` | |||
| } | |||
| VmTask{ | |||
| Id string `json:"id" copier:"Id"` | |||
| @@ -43,10 +43,6 @@ service pcm { | |||
| @handler commitVmTaskHandler | |||
| post /core/commitVmTask (commitVmTaskReq) returns (commitVmTaskResp) | |||
| @doc "提交虚拟机任务临时" | |||
| @handler commitVmTaskTempHandler | |||
| post /core/commitVmTaskTemp (commitVmTaskReq) returns (commitVmTaskResp) | |||
| @doc "删除任务" | |||
| @handler deleteTaskHandler | |||
| delete /core/deleteTask/:id (deleteTaskReq) | |||
| @@ -385,10 +381,14 @@ service pcm { | |||
| @handler GetNetworkNumHandler | |||
| get /vm/getNetworkNum (ListNetworksReq) returns (NetworkNum) | |||
| @doc "查询镜像列表" | |||
| @doc "查询镜像数量" | |||
| @handler getImageNumHandler | |||
| get /vm/getImageNum (ListImagesReq) returns (ImageNum) | |||
| @doc "查询虚拟机概览数据" | |||
| @handler getOpenstackOverviewHandler | |||
| get /vm/getOpenstackOverview (OpenstackOverviewReq) returns (OpenstackOverviewResp) | |||
| @doc "查询虚拟机列表" | |||
| @handler ListServerHandler | |||
| get /vm/listServer (ListServersReq) returns (ListServersResp) | |||
| @@ -75,6 +75,22 @@ type ( | |||
| Msg string `json:"msg,omitempty"` | |||
| ErrorMsg string `json:"errorMsg,omitempty"` | |||
| } | |||
| OpenstackOverviewReq { | |||
| Platform string `form:"platform,optional"` | |||
| } | |||
| OpenstackOverviewResp { | |||
| Data OpenstackOverview `json:"data"` | |||
| Code int32 `json:"code,omitempty"` | |||
| Msg string `json:"msg,omitempty"` | |||
| ErrorMsg string `json:"errorMsg,omitempty"` | |||
| } | |||
| OpenstackOverview { | |||
| max_total_cores int32 `json:"max_total_cores"` | |||
| max_total_ram_size int32 `json:"max_total_ram_size"` | |||
| max_total_volumes int32 `json:"max_total_volumes"` | |||
| } | |||
| ) | |||
| /****************** servers start*************************/ | |||
| type ( | |||
| @@ -45,11 +45,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | |||
| Path: "/core/commitVmTask", | |||
| Handler: core.CommitVmTaskHandler(serverCtx), | |||
| }, | |||
| { | |||
| Method: http.MethodPost, | |||
| Path: "/core/commitVmTaskTemp", | |||
| Handler: core.CommitVmTaskTempHandler(serverCtx), | |||
| }, | |||
| { | |||
| Method: http.MethodDelete, | |||
| Path: "/core/deleteTask/:id", | |||
| @@ -456,6 +451,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | |||
| Path: "/vm/getImageNum", | |||
| Handler: vm.GetImageNumHandler(serverCtx), | |||
| }, | |||
| { | |||
| Method: http.MethodGet, | |||
| Path: "/vm/getOpenstackOverview", | |||
| Handler: vm.GetOpenstackOverviewHandler(serverCtx), | |||
| }, | |||
| { | |||
| Method: http.MethodGet, | |||
| Path: "/vm/listServer", | |||
| @@ -1,24 +1,24 @@ | |||
| package core | |||
| package vm | |||
| import ( | |||
| "net/http" | |||
| "github.com/zeromicro/go-zero/rest/httpx" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/core" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/vm" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" | |||
| ) | |||
| func CommitVmTaskTempHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||
| func GetOpenstackOverviewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||
| return func(w http.ResponseWriter, r *http.Request) { | |||
| var req types.CommitVmTaskReq | |||
| var req types.OpenstackOverviewReq | |||
| if err := httpx.Parse(r, &req); err != nil { | |||
| httpx.ErrorCtx(r.Context(), w, err) | |||
| return | |||
| } | |||
| l := core.NewCommitVmTaskTempLogic(r.Context(), svcCtx) | |||
| resp, err := l.CommitVmTaskTemp(&req) | |||
| l := vm.NewGetOpenstackOverviewLogic(r.Context(), svcCtx) | |||
| resp, err := l.GetOpenstackOverview(&req) | |||
| if err != nil { | |||
| httpx.ErrorCtx(r.Context(), w, err) | |||
| } else { | |||
| @@ -42,6 +42,14 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type | |||
| if tx.Error != nil { | |||
| return nil, tx.Error | |||
| } | |||
| var clusterIds []int64 | |||
| l.svcCtx.DbEngin.Raw("SELECT id FROM `t_cluster` where adapter_id = ? and label = ?", req.AdapterId, req.ClusterType).Scan(&clusterIds) | |||
| if len(clusterIds) == 0 || clusterIds == nil { | |||
| return nil, nil | |||
| } | |||
| vm := models.Vm{} | |||
| tool.Convert(req, &vm) | |||
| mqInfo := response.TaskInfo{ | |||
| @@ -52,5 +60,11 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type | |||
| } | |||
| //req.TaskId = taskModel.Id | |||
| mqs.InsQueue.Beta.Add(&mqInfo) | |||
| return | |||
| tx = l.svcCtx.DbEngin.Create(&mqInfo) | |||
| resp = &types.CommitVmTaskResp{ | |||
| Code: 200, | |||
| Msg: "success", | |||
| TaskId: taskModel.Id, | |||
| } | |||
| return resp, nil | |||
| } | |||
| @@ -1,49 +0,0 @@ | |||
| package core | |||
| import ( | |||
| "context" | |||
| "github.com/jinzhu/copier" | |||
| "github.com/pkg/errors" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/helper/xerr" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" | |||
| "gitlink.org.cn/JointCloud/pcm-openstack/openstack" | |||
| "k8s.io/apimachinery/pkg/util/json" | |||
| "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 CommitVmTaskTempLogic struct { | |||
| logx.Logger | |||
| ctx context.Context | |||
| svcCtx *svc.ServiceContext | |||
| } | |||
| func NewCommitVmTaskTempLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitVmTaskTempLogic { | |||
| return &CommitVmTaskTempLogic{ | |||
| Logger: logx.WithContext(ctx), | |||
| ctx: ctx, | |||
| svcCtx: svcCtx, | |||
| } | |||
| } | |||
| func (l *CommitVmTaskTempLogic) CommitVmTaskTemp(req *types.CommitVmTaskReq) (resp *types.CommitVmTaskResp, err error) { | |||
| // todo: add your logic here and delete this line | |||
| CreateServerReq := &openstack.CreateServerReq{} | |||
| err = copier.CopyWithOption(CreateServerReq, req, copier.Option{Converters: utils.Converters}) | |||
| CreateServerResp, err := l.svcCtx.OpenstackRpc.CreateServer(l.ctx, CreateServerReq) | |||
| if err != nil { | |||
| return nil, errors.Wrapf(xerr.NewErrMsg("Failed to get Servers list"), "Failed to get db Servers list err : %v ,req:%+v", err, req) | |||
| } | |||
| marshal, err := json.Marshal(&CreateServerResp) | |||
| if err != nil { | |||
| return nil, result.NewDefaultError(err.Error()) | |||
| } | |||
| json.Unmarshal(marshal, &resp) | |||
| err = copier.CopyWithOption(&resp, &CreateServerResp, copier.Option{Converters: utils.Converters}) | |||
| return resp, err | |||
| return | |||
| } | |||
| @@ -0,0 +1,35 @@ | |||
| package vm | |||
| import ( | |||
| "context" | |||
| "github.com/zeromicro/go-zero/core/logx" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" | |||
| ) | |||
| type GetOpenstackOverviewLogic struct { | |||
| logx.Logger | |||
| ctx context.Context | |||
| svcCtx *svc.ServiceContext | |||
| } | |||
| func NewGetOpenstackOverviewLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOpenstackOverviewLogic { | |||
| return &GetOpenstackOverviewLogic{ | |||
| Logger: logx.WithContext(ctx), | |||
| ctx: ctx, | |||
| svcCtx: svcCtx, | |||
| } | |||
| } | |||
| func (l *GetOpenstackOverviewLogic) GetOpenstackOverview(req *types.OpenstackOverviewReq) (resp *types.OpenstackOverviewResp, err error) { | |||
| // todo: add your logic here and delete this line | |||
| var openstackOverview types.OpenstackOverview | |||
| sqlStr := "SELECT t.max_total_cores,t.max_total_ram_size,t.max_total_volumes FROM `vm_openstack_overview` t left join t_cluster tc on t.cluster_id=tc.id where tc.`name` = ?" | |||
| l.svcCtx.DbEngin.Raw(sqlStr, req.Platform).Scan(&openstackOverview) | |||
| resp = &types.OpenstackOverviewResp{ | |||
| Code: 200, | |||
| Msg: "success", | |||
| Data: openstackOverview, | |||
| } | |||
| return resp, err | |||
| } | |||
| @@ -118,6 +118,8 @@ type CommitVmTaskReq struct { | |||
| MatchLabels map[string]string `json:"matchLabels,optional"` | |||
| Servers []ServerCommit `json:"servers,optional"` | |||
| Platform string `json:"platform,optional"` | |||
| AdapterId string `json:"adapterId,optional"` | |||
| ClusterType string `json:"clusterType,optional"` | |||
| } | |||
| type ServerCommit struct { | |||
| @@ -147,7 +149,9 @@ type Block_device_mapping_v2Commit struct { | |||
| } | |||
| type CommitVmTaskResp struct { | |||
| VmTask []VmTask `json:"vmTask" copier:"VmTask"` | |||
| TaskId int64 `json:"taskId"` | |||
| Code int32 `json:"code"` | |||
| Msg string `json:"msg"` | |||
| } | |||
| type VmTask struct { | |||
| @@ -2692,6 +2696,23 @@ type GetVolumeLimitsResp struct { | |||
| ErrorMsg string `json:"errorMsg,omitempty"` | |||
| } | |||
| type OpenstackOverviewReq struct { | |||
| Platform string `form:"platform,optional"` | |||
| } | |||
| type OpenstackOverviewResp struct { | |||
| Data OpenstackOverview `json:"data"` | |||
| Code int32 `json:"code,omitempty"` | |||
| Msg string `json:"msg,omitempty"` | |||
| ErrorMsg string `json:"errorMsg,omitempty"` | |||
| } | |||
| type OpenstackOverview struct { | |||
| Max_total_cores int32 `json:"max_total_cores"` | |||
| Max_total_ram_size int32 `json:"max_total_ram_size"` | |||
| Max_total_volumes int32 `json:"max_total_volumes"` | |||
| } | |||
| type ListServersReq struct { | |||
| Limit int32 `form:"limit,optional"` | |||
| OffSet int32 `form:"offSet,optional"` | |||
| @@ -5311,6 +5332,123 @@ type AiAlgorithmsResp struct { | |||
| Algorithms []string `json:"algorithms"` | |||
| } | |||
| type PullTaskInfoReq struct { | |||
| AdapterId int64 `form:"adapterId"` | |||
| } | |||
| type PullTaskInfoResp struct { | |||
| HpcInfoList []*HpcInfo `json:"HpcInfoList,omitempty"` | |||
| CloudInfoList []*CloudInfo `json:"CloudInfoList,omitempty"` | |||
| AiInfoList []*AiInfo `json:"AiInfoList,omitempty"` | |||
| VmInfoList []*VmInfo `json:"VmInfoList,omitempty"` | |||
| } | |||
| type HpcInfo struct { | |||
| Id int64 `json:"id"` // id | |||
| TaskId int64 `json:"task_id"` // 任务id | |||
| JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id) | |||
| AdapterId int64 `json:"adapter_id"` // 执行任务的适配器id | |||
| ClusterId int64 `json:"cluster_id"` // 执行任务的集群id | |||
| ClusterType string `json:"cluster_type"` // 执行任务的集群类型 | |||
| Name string `json:"name"` // 名称 | |||
| Status string `json:"status"` // 状态 | |||
| CmdScript string `json:"cmd_script"` | |||
| StartTime string `json:"start_time"` // 开始时间 | |||
| RunningTime int64 `json:"running_time"` // 运行时间 | |||
| DerivedEs string `json:"derived_es"` | |||
| Cluster string `json:"cluster"` | |||
| BlockId int64 `json:"block_id"` | |||
| AllocNodes int64 `json:"alloc_nodes"` | |||
| AllocCpu int64 `json:"alloc_cpu"` | |||
| CardCount int64 `json:"card_count"` // 卡数 | |||
| Version string `json:"version"` | |||
| Account string `json:"account"` | |||
| WorkDir string `json:"work_dir"` // 工作路径 | |||
| AssocId int64 `json:"assoc_id"` | |||
| ExitCode int64 `json:"exit_code"` | |||
| WallTime string `json:"wall_time"` // 最大运行时间 | |||
| Result string `json:"result"` // 运行结果 | |||
| DeletedAt string `json:"deleted_at"` // 删除时间 | |||
| YamlString string `json:"yaml_string"` | |||
| AppType string `json:"app_type"` // 应用类型 | |||
| AppName string `json:"app_name"` // 应用名称 | |||
| Queue string `json:"queue"` // 队列名称 | |||
| SubmitType string `json:"submit_type"` // cmd(命令行模式) | |||
| NNode string `json:"n_node"` // 节点个数(当指定该参数时,GAP_NODE_STRING必须为"") | |||
| StdOutFile string `json:"std_out_file"` // 工作路径/std.err.%j | |||
| StdErrFile string `json:"std_err_file"` // 工作路径/std.err.%j | |||
| StdInput string `json:"std_input"` | |||
| Environment string `json:"environment"` | |||
| DeletedFlag int64 `json:"deleted_flag"` // 是否删除(0-否,1-是) | |||
| CreatedBy int64 `json:"created_by"` // 创建人 | |||
| CreatedTime string `json:"created_time"` // 创建时间 | |||
| UpdatedBy int64 `json:"updated_by"` // 更新人 | |||
| UpdatedTime string `json:"updated_time"` // 更新时间 | |||
| } | |||
| type CloudInfo struct { | |||
| Participant int64 `json:"participant,omitempty"` | |||
| Id int64 `json:"id,omitempty"` | |||
| TaskId int64 `json:"taskId,omitempty"` | |||
| ApiVersion string `json:"apiVersion,omitempty"` | |||
| Kind string `json:"kind,omitempty"` | |||
| Namespace string `json:"namespace,omitempty"` | |||
| Name string `json:"name,omitempty"` | |||
| Status string `json:"status,omitempty"` | |||
| StartTime string `json:"startTime,omitempty"` | |||
| RunningTime int64 `json:"runningTime,omitempty"` | |||
| Result string `json:"result,omitempty"` | |||
| YamlString string `json:"yamlString,omitempty"` | |||
| } | |||
| type AiInfo struct { | |||
| ParticipantId int64 `json:"participantId,omitempty"` | |||
| TaskId int64 `json:"taskId,omitempty"` | |||
| ProjectId string `json:"project_id,omitempty"` | |||
| Name string `json:"name,omitempty"` | |||
| Status string `json:"status,omitempty"` | |||
| StartTime string `json:"startTime,omitempty"` | |||
| RunningTime int64 `json:"runningTime,omitempty"` | |||
| Result string `json:"result,omitempty"` | |||
| JobId string `json:"jobId,omitempty"` | |||
| CreateTime string `json:"createTime,omitempty"` | |||
| ImageUrl string `json:"imageUrl,omitempty"` | |||
| Command string `json:"command,omitempty"` | |||
| FlavorId string `json:"flavorId,omitempty"` | |||
| SubscriptionId string `json:"subscriptionId,omitempty"` | |||
| ItemVersionId string `json:"itemVersionId,omitempty"` | |||
| } | |||
| type VmInfo struct { | |||
| ParticipantId int64 `json:"participantId,omitempty"` | |||
| TaskId int64 `json:"taskId,omitempty"` | |||
| Name string `json:"name,omitempty"` | |||
| FlavorRef string `json:"flavor_ref,omitempty"` | |||
| ImageRef string `json:"image_ref,omitempty"` | |||
| NetworkUuid string `json:"network_uuid,omitempty"` | |||
| BlockUuid string `json:"block_uuid,omitempty"` | |||
| SourceType string `json:"source_type,omitempty"` | |||
| DeleteOnTermination bool `json:"delete_on_termination,omitempty"` | |||
| State string `json:"state,omitempty"` | |||
| } | |||
| type PushTaskInfoReq struct { | |||
| AdapterId int64 `json:"adapterId"` | |||
| HpcInfoList []*HpcInfo `json:"hpcInfoList"` | |||
| CloudInfoList []*CloudInfo `json:"cloudInfoList"` | |||
| AiInfoList []*AiInfo `json:"aiInfoList"` | |||
| VmInfoList []*VmInfo `json:"vmInfoList"` | |||
| } | |||
| type PushTaskInfoResp struct { | |||
| Code int64 `json:"code"` | |||
| Msg string `json:"msg"` | |||
| } | |||
| type PushResourceInfoReq struct { | |||
| AdapterId int64 `json:"adapterId"` | |||
| } | |||
| type CreateAlertRuleReq struct { | |||
| ClusterName string `json:"clusterName"` | |||
| Namespace string `json:"namespace"` | |||