Browse Source

ac list history job& pcm list cluster for compute center

Former-commit-id: 94574bb562
pull/9/head
zhouqunjie 2 years ago
parent
commit
5de399e34a
9 changed files with 307 additions and 13 deletions
  1. +25
    -0
      adaptor/PCM-CORE/api/desc/core/pcm-core.api
  2. +3
    -0
      adaptor/PCM-CORE/api/desc/pcm.api
  3. +28
    -0
      adaptor/PCM-CORE/api/internal/handler/core/listclusterhandler.go
  4. +5
    -0
      adaptor/PCM-CORE/api/internal/handler/routes.go
  5. +55
    -0
      adaptor/PCM-CORE/api/internal/logic/core/listclusterlogic.go
  6. +71
    -6
      adaptor/PCM-CORE/api/internal/types/types.go
  7. +24
    -0
      adaptor/PCM-CORE/model/computeclustermodel.go
  8. +91
    -0
      adaptor/PCM-CORE/model/computeclustermodel_gen.go
  9. +5
    -7
      adaptor/PCM-HPC/PCM-AC/rpc/internal/logic/listhistoryjoblogic.go

+ 25
- 0
adaptor/PCM-CORE/api/desc/core/pcm-core.api View File

@@ -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 ( type (
cpResp { cpResp {
POpsAtFp16 float32 `json:"pOpsAtFp16"` POpsAtFp16 float32 `json:"pOpsAtFp16"`


+ 3
- 0
adaptor/PCM-CORE/api/desc/pcm.api View File

@@ -33,6 +33,9 @@ service pcm {
@handler listCenterHandler @handler listCenterHandler
get /core/listCenter () returns (listCenterResp) get /core/listCenter () returns (listCenterResp)
@handler listClusterHandler
get /core/listCluster (listClusterReq) returns (listClusterResp)
@handler submitJobHandler @handler submitJobHandler
post /core/submitJob (submitJobReq) returns (submitJobResp) post /core/submitJob (submitJobReq) returns (submitJobResp)


+ 28
- 0
adaptor/PCM-CORE/api/internal/handler/core/listclusterhandler.go View File

@@ -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)
}
}
}

+ 5
- 0
adaptor/PCM-CORE/api/internal/handler/routes.go View File

@@ -37,6 +37,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/core/listCenter", Path: "/core/listCenter",
Handler: core.ListCenterHandler(serverCtx), Handler: core.ListCenterHandler(serverCtx),
}, },
{
Method: http.MethodGet,
Path: "/core/listCluster",
Handler: core.ListClusterHandler(serverCtx),
},
{ {
Method: http.MethodPost, Method: http.MethodPost,
Path: "/core/submitJob", Path: "/core/submitJob",


+ 55
- 0
adaptor/PCM-CORE/api/internal/logic/core/listclusterlogic.go View File

@@ -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

}

+ 71
- 6
adaptor/PCM-CORE/api/internal/types/types.go View File

@@ -249,6 +249,31 @@ type Center struct {
HubCode int64 `json:"hubCode"` 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 { type CpResp struct {
POpsAtFp16 float32 `json:"pOpsAtFp16"` POpsAtFp16 float32 `json:"pOpsAtFp16"`
} }
@@ -1781,10 +1806,8 @@ type ConstraintCreateTraining struct {
} }


type ParametersTrainJob 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 { type PoliciesCreateTraining struct {
@@ -1799,11 +1822,53 @@ type AlgorithmsCtRq struct {
ParametersTrainJob []ParametersTrainJob `json:"parameters,optional"` ParametersTrainJob []ParametersTrainJob `json:"parameters,optional"`
PoliciesCreateTraining PoliciesCreateTraining `json:"policies,optional"` PoliciesCreateTraining PoliciesCreateTraining `json:"policies,optional"`
Command string `json:"command,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 { 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 { type LogExportPathCreateTrainingJob struct {


+ 24
- 0
adaptor/PCM-CORE/model/computeclustermodel.go View File

@@ -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),
}
}

+ 91
- 0
adaptor/PCM-CORE/model/computeclustermodel_gen.go View File

@@ -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
}

+ 5
- 7
adaptor/PCM-HPC/PCM-AC/rpc/internal/logic/listhistoryjoblogic.go View File

@@ -32,7 +32,7 @@ func NewListHistoryJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Li
func (l *ListHistoryJobLogic) ListHistoryJob(in *hpcAC.ListHistoryJobReq) (*hpcAC.ListHistoryJobResp, error) { func (l *ListHistoryJobLogic) ListHistoryJob(in *hpcAC.ListHistoryJobReq) (*hpcAC.ListHistoryJobResp, error) {


var resp hpcAC.ListHistoryJobResp var resp hpcAC.ListHistoryJobResp
//historyJobUrl := "hpc/openapi/v2/historyjobs?"
historyJobUrl := "hpc/openapi/v2/historyjobs?"


getTokenLogic := NewGetACTokenLogic(l.ctx, l.svcCtx) getTokenLogic := NewGetACTokenLogic(l.ctx, l.svcCtx)
tokenResp, _ := getTokenLogic.GetACToken(&hpcAC.ACTokenReq{}) 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} c := http.Client{Timeout: time.Duration(3) * time.Second}


params := url.Values{} params := url.Values{}
params.Add("strClusterIDList", strconv.FormatInt(clusterId, 10))
params.Add("strClusterNameList", strconv.FormatInt(clusterId, 10))
params.Add("startTime", in.StartTime) params.Add("startTime", in.StartTime)
params.Add("endTime", in.EndTime) params.Add("endTime", in.EndTime)
params.Add("timeType", in.TimeType) 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) 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 { if err != nil {
log.Fatal(err) log.Fatal(err)
} }


reqUrl.Header.Add("token", token) reqUrl.Header.Add("token", token)

respUrl, err := c.Do(reqUrl) respUrl, err := c.Do(reqUrl)


if err != nil { if err != nil {


Loading…
Cancel
Save