From 5de399e34a872c0488fad6d21f15bbb5c810df93 Mon Sep 17 00:00:00 2001 From: zhouqunjie Date: Thu, 15 Jun 2023 17:27:30 +0800 Subject: [PATCH] ac list history job& pcm list cluster for compute center Former-commit-id: 94574bb5620a79dc75f145e57bc1498786ac080a --- adaptor/PCM-CORE/api/desc/core/pcm-core.api | 25 +++++ adaptor/PCM-CORE/api/desc/pcm.api | 3 + .../handler/core/listclusterhandler.go | 28 ++++++ .../PCM-CORE/api/internal/handler/routes.go | 5 + .../internal/logic/core/listclusterlogic.go | 55 +++++++++++ adaptor/PCM-CORE/api/internal/types/types.go | 77 ++++++++++++++-- adaptor/PCM-CORE/model/computeclustermodel.go | 24 +++++ .../PCM-CORE/model/computeclustermodel_gen.go | 91 +++++++++++++++++++ .../rpc/internal/logic/listhistoryjoblogic.go | 12 +-- 9 files changed, 307 insertions(+), 13 deletions(-) create mode 100644 adaptor/PCM-CORE/api/internal/handler/core/listclusterhandler.go create mode 100644 adaptor/PCM-CORE/api/internal/logic/core/listclusterlogic.go create mode 100644 adaptor/PCM-CORE/model/computeclustermodel.go create mode 100644 adaptor/PCM-CORE/model/computeclustermodel_gen.go diff --git a/adaptor/PCM-CORE/api/desc/core/pcm-core.api b/adaptor/PCM-CORE/api/desc/core/pcm-core.api index 17b6d3ee..457e79a9 100644 --- a/adaptor/PCM-CORE/api/desc/core/pcm-core.api +++ b/adaptor/PCM-CORE/api/desc/core/pcm-core.api @@ -271,6 +271,31 @@ type ( } ) + +type ( + listClusterReq { + CenterId int32 `json:"centerId"` + } + listClusterResp { + Code int32 `json:"code"` + Msg string `json:"msg"` + Data ClusterData `json:"data"` + } + ClusterData { + TotalCount int `json:"totalCount"` + Clusters []ComputeCluster `json:"clusters"` + } + ComputeCluster { + Id int64 `json:"id"` + Name string `json:"name"` + JcceDomainId int64 `json:"jcceDomainId"` + JcceDomainName string `json:"jcceDomainName"` + Longitude float64 `json:"longitude"` + Latitude float64 `json:"latitude"` + Description string `json:"description"` + } +) + type ( cpResp { POpsAtFp16 float32 `json:"pOpsAtFp16"` diff --git a/adaptor/PCM-CORE/api/desc/pcm.api b/adaptor/PCM-CORE/api/desc/pcm.api index 0b7434bc..71d6c9dd 100644 --- a/adaptor/PCM-CORE/api/desc/pcm.api +++ b/adaptor/PCM-CORE/api/desc/pcm.api @@ -33,6 +33,9 @@ service pcm { @handler listCenterHandler get /core/listCenter () returns (listCenterResp) + @handler listClusterHandler + get /core/listCluster (listClusterReq) returns (listClusterResp) + @handler submitJobHandler post /core/submitJob (submitJobReq) returns (submitJobResp) diff --git a/adaptor/PCM-CORE/api/internal/handler/core/listclusterhandler.go b/adaptor/PCM-CORE/api/internal/handler/core/listclusterhandler.go new file mode 100644 index 00000000..c1102f9c --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/handler/core/listclusterhandler.go @@ -0,0 +1,28 @@ +package core + +import ( + "net/http" + + "PCM/adaptor/PCM-CORE/api/internal/logic/core" + "PCM/adaptor/PCM-CORE/api/internal/svc" + "PCM/adaptor/PCM-CORE/api/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func ListClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.ListClusterReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := core.NewListClusterLogic(r.Context(), svcCtx) + resp, err := l.ListCluster(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/adaptor/PCM-CORE/api/internal/handler/routes.go b/adaptor/PCM-CORE/api/internal/handler/routes.go index 7c999485..4cb1d2f6 100644 --- a/adaptor/PCM-CORE/api/internal/handler/routes.go +++ b/adaptor/PCM-CORE/api/internal/handler/routes.go @@ -37,6 +37,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/core/listCenter", Handler: core.ListCenterHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/core/listCluster", + Handler: core.ListClusterHandler(serverCtx), + }, { Method: http.MethodPost, Path: "/core/submitJob", diff --git a/adaptor/PCM-CORE/api/internal/logic/core/listclusterlogic.go b/adaptor/PCM-CORE/api/internal/logic/core/listclusterlogic.go new file mode 100644 index 00000000..c1afbef3 --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/logic/core/listclusterlogic.go @@ -0,0 +1,55 @@ +package core + +import ( + "PCM/adaptor/PCM-CORE/api/internal/svc" + "PCM/adaptor/PCM-CORE/api/internal/types" + "PCM/adaptor/PCM-CORE/model" + "context" + "github.com/zeromicro/go-zero/core/logx" +) + +type ListClusterLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewListClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListClusterLogic { + return &ListClusterLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *ListClusterLogic) ListCluster(req *types.ListClusterReq) (*types.ListClusterResp, error) { + + var clusters []types.ComputeCluster + var clustersModel *[]model.ComputeCluster + + //var centersModel []model.ComputeCenter + var resp types.ListClusterResp + + l.svcCtx.DbEngin.Raw("select * from compute_cluster").Scan(&clustersModel) + + var clustersModelV = *clustersModel + + for _, clusterModel := range clustersModelV { + var cluster types.ComputeCluster + cluster.Id = clusterModel.Id + cluster.Name = clusterModel.Name.String + cluster.JcceDomainId = clusterModel.JcceDomainId.Int64 + cluster.JcceDomainName = clusterModel.JcceDomainName.String + cluster.Longitude = clusterModel.Longitude.Float64 + cluster.Latitude = clusterModel.Latitude.Float64 + cluster.Description = clusterModel.Description.String + clusters = append(clusters, cluster) + } + + resp.Code = 200 + resp.Msg = "success" + resp.Data.TotalCount = len(clusters) + resp.Data.Clusters = clusters + return &resp, nil + +} diff --git a/adaptor/PCM-CORE/api/internal/types/types.go b/adaptor/PCM-CORE/api/internal/types/types.go index 7f4f7437..525ec950 100644 --- a/adaptor/PCM-CORE/api/internal/types/types.go +++ b/adaptor/PCM-CORE/api/internal/types/types.go @@ -249,6 +249,31 @@ type Center struct { HubCode int64 `json:"hubCode"` } +type ListClusterReq struct { + CenterId int32 `json:"centerId"` +} + +type ListClusterResp struct { + Code int32 `json:"code"` + Msg string `json:"msg"` + Data ClusterData `json:"data"` +} + +type ClusterData struct { + TotalCount int `json:"totalCount"` + Clusters []ComputeCluster `json:"clusters"` +} + +type ComputeCluster struct { + Id int64 `json:"id"` + Name string `json:"name"` + JcceDomainId int64 `json:"jcceDomainId"` + JcceDomainName string `json:"jcceDomainName"` + Longitude float64 `json:"longitude"` + Latitude float64 `json:"latitude"` + Description string `json:"description"` +} + type CpResp struct { POpsAtFp16 float32 `json:"pOpsAtFp16"` } @@ -1781,10 +1806,8 @@ type ConstraintCreateTraining struct { } type ParametersTrainJob struct { - Name string `json:"name,optional"` - Description string `json:"description,optional"` - Value string `json:"value,optional"` - ConstraintCreateTraining ConstraintCreateTraining `json:"constraint,optional"` + Name string `json:"name,optional"` + Value string `json:"value,optional"` } type PoliciesCreateTraining struct { @@ -1799,11 +1822,53 @@ type AlgorithmsCtRq struct { ParametersTrainJob []ParametersTrainJob `json:"parameters,optional"` PoliciesCreateTraining PoliciesCreateTraining `json:"policies,optional"` Command string `json:"command,optional"` + SubscriptionId string `json:"subscriptionId,optional"` + ItemVersionId string `json:"itemVersionId,optional"` + InputTra []InputTra `json:"inputs,optional"` + OutputTra []OutputTra `json:"outputs,optional"` + Environments Environments `json:"environments,optional"` +} + +type Environments struct { +} + +type InputTra struct { + Name string `json:"name,optional"` + AccessMethod string `json:"accessMethod,optional"` + RemoteIn RemoteTra `json:"remoteIn,optional"` +} + +type RemoteTra struct { + DatasetIn DatasetTra `json:"dataSet,optional"` +} + +type DatasetTra struct { + Id string `json:"id,optional"` + Name string `json:"name,optional"` + VersionName string `json:"versionName,optional"` + VersionId string `json:"versionId,optional"` +} + +type OutputTra struct { + Name string `json:"name,optional"` + AccessMethod string `json:"accessMethod,optional"` + PrefetchToLocal string `json:"prefetchToLocal,optional"` + RemoteOut RemoteOut `json:"remoteOut,optional"` +} + +type RemoteOut struct { + Obs ObsTra `json:"obs,optional"` +} + +type ObsTra struct { + ObsUrl string `json:"obsUrl,optional"` } type ResourceCreateTraining struct { - FlavorId string `json:"flavorId,optional"` - NodeCount int32 `json:"nodeCount,optional"` + FlavorId string `json:"flavorId,optional"` + NodeCount int32 `json:"nodeCount,optional"` + Policy string `json:"policy,optional"` + FlavorLabel string `json:"flavorLabel,optional"` } type LogExportPathCreateTrainingJob struct { diff --git a/adaptor/PCM-CORE/model/computeclustermodel.go b/adaptor/PCM-CORE/model/computeclustermodel.go new file mode 100644 index 00000000..552ccb7b --- /dev/null +++ b/adaptor/PCM-CORE/model/computeclustermodel.go @@ -0,0 +1,24 @@ +package model + +import "github.com/zeromicro/go-zero/core/stores/sqlx" + +var _ ComputeClusterModel = (*customComputeClusterModel)(nil) + +type ( + // ComputeClusterModel is an interface to be customized, add more methods here, + // and implement the added methods in customComputeClusterModel. + ComputeClusterModel interface { + computeClusterModel + } + + customComputeClusterModel struct { + *defaultComputeClusterModel + } +) + +// NewComputeClusterModel returns a model for the database table. +func NewComputeClusterModel(conn sqlx.SqlConn) ComputeClusterModel { + return &customComputeClusterModel{ + defaultComputeClusterModel: newComputeClusterModel(conn), + } +} diff --git a/adaptor/PCM-CORE/model/computeclustermodel_gen.go b/adaptor/PCM-CORE/model/computeclustermodel_gen.go new file mode 100644 index 00000000..f6ad2f2a --- /dev/null +++ b/adaptor/PCM-CORE/model/computeclustermodel_gen.go @@ -0,0 +1,91 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +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 ( + computeClusterFieldNames = builder.RawFieldNames(&ComputeCluster{}) + computeClusterRows = strings.Join(computeClusterFieldNames, ",") + computeClusterRowsExpectAutoSet = strings.Join(stringx.Remove(computeClusterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") + computeClusterRowsWithPlaceHolder = strings.Join(stringx.Remove(computeClusterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" +) + +type ( + computeClusterModel interface { + Insert(ctx context.Context, data *ComputeCluster) (sql.Result, error) + FindOne(ctx context.Context, id int64) (*ComputeCluster, error) + Update(ctx context.Context, data *ComputeCluster) error + Delete(ctx context.Context, id int64) error + } + + defaultComputeClusterModel struct { + conn sqlx.SqlConn + table string + } + + ComputeCluster struct { + Id int64 `db:"id"` // 集群id + Name sql.NullString `db:"name"` // 集群名 + CenterId sql.NullInt64 `db:"center_id"` // 数据中心id + CenterName sql.NullString `db:"center_name"` // 数据中心名称 + JcceDomainId sql.NullInt64 `db:"jcce_domain_id"` // JCCE侧域ID + JcceDomainName sql.NullString `db:"jcce_domain_name"` // JCCE侧域名 + Longitude sql.NullFloat64 `db:"longitude"` // 经度 + Latitude sql.NullFloat64 `db:"latitude"` // 纬度 + Description sql.NullString `db:"description"` // 描述 + } +) + +func newComputeClusterModel(conn sqlx.SqlConn) *defaultComputeClusterModel { + return &defaultComputeClusterModel{ + conn: conn, + table: "`compute_cluster`", + } +} + +func (m *defaultComputeClusterModel) Delete(ctx context.Context, id int64) error { + query := fmt.Sprintf("delete from %s where `id` = ?", m.table) + _, err := m.conn.ExecCtx(ctx, query, id) + return err +} + +func (m *defaultComputeClusterModel) FindOne(ctx context.Context, id int64) (*ComputeCluster, error) { + query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", computeClusterRows, m.table) + var resp ComputeCluster + err := m.conn.QueryRowCtx(ctx, &resp, query, id) + switch err { + case nil: + return &resp, nil + case sqlc.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} + +func (m *defaultComputeClusterModel) Insert(ctx context.Context, data *ComputeCluster) (sql.Result, error) { + query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, computeClusterRowsExpectAutoSet) + ret, err := m.conn.ExecCtx(ctx, query, data.Name, data.CenterId, data.CenterName, data.JcceDomainId, data.JcceDomainName, data.Longitude, data.Latitude, data.Description) + return ret, err +} + +func (m *defaultComputeClusterModel) Update(ctx context.Context, data *ComputeCluster) error { + query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, computeClusterRowsWithPlaceHolder) + _, err := m.conn.ExecCtx(ctx, query, data.Name, data.CenterId, data.CenterName, data.JcceDomainId, data.JcceDomainName, data.Longitude, data.Latitude, data.Description, data.Id) + return err +} + +func (m *defaultComputeClusterModel) tableName() string { + return m.table +} diff --git a/adaptor/PCM-HPC/PCM-AC/rpc/internal/logic/listhistoryjoblogic.go b/adaptor/PCM-HPC/PCM-AC/rpc/internal/logic/listhistoryjoblogic.go index 63b14232..2a68c0a5 100644 --- a/adaptor/PCM-HPC/PCM-AC/rpc/internal/logic/listhistoryjoblogic.go +++ b/adaptor/PCM-HPC/PCM-AC/rpc/internal/logic/listhistoryjoblogic.go @@ -32,7 +32,7 @@ func NewListHistoryJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Li func (l *ListHistoryJobLogic) ListHistoryJob(in *hpcAC.ListHistoryJobReq) (*hpcAC.ListHistoryJobResp, error) { var resp hpcAC.ListHistoryJobResp - //historyJobUrl := "hpc/openapi/v2/historyjobs?" + historyJobUrl := "hpc/openapi/v2/historyjobs?" getTokenLogic := NewGetACTokenLogic(l.ctx, l.svcCtx) tokenResp, _ := getTokenLogic.GetACToken(&hpcAC.ACTokenReq{}) @@ -45,22 +45,20 @@ func (l *ListHistoryJobLogic) ListHistoryJob(in *hpcAC.ListHistoryJobReq) (*hpcA c := http.Client{Timeout: time.Duration(3) * time.Second} params := url.Values{} - params.Add("strClusterIDList", strconv.FormatInt(clusterId, 10)) + params.Add("strClusterNameList", strconv.FormatInt(clusterId, 10)) params.Add("startTime", in.StartTime) params.Add("endTime", in.EndTime) params.Add("timeType", in.TimeType) - params.Add("start", string(in.Start)) - params.Add("limit", string(in.Limit)) + params.Add("start", strconv.FormatInt(int64(in.Start), 10)) + params.Add("limit", strconv.FormatInt(int64(in.Limit), 10)) params.Add("isQueryByQueueTime", in.IsQueryByQueueTime) - //reqUrl, err := http.NewRequest("GET", "https://api01.hpccube.com:65106/"+historyJobUrl+params.Encode(), nil) - reqUrl, err := http.NewRequest("GET", "https://api01.hpccube.com:65106/hpc/openapi/v2/historyjobs?strClusterNameList=1638523853&startTime=2022-12-05+01%3A01%3A01&endTime=2023-12-08+01%3A01%3A01&timeType=CUSTOM&start=0&limit=25&isQueryByQueueTime=true", nil) + reqUrl, err := http.NewRequest("GET", "https://api01.hpccube.com:65106/"+historyJobUrl+params.Encode(), nil) if err != nil { log.Fatal(err) } reqUrl.Header.Add("token", token) - respUrl, err := c.Do(reqUrl) if err != nil {