fit:超算概览两个查询接口
This commit is contained in:
parent
8bb1fed88a
commit
f104476a89
|
@ -15,6 +15,7 @@ import "idl_common/slurmdb_wckey.proto";
|
|||
import "idl_common/slurm_job.proto";
|
||||
import "idl_common/slurm_diag.proto";
|
||||
import "idl_common/slurmdb_job.proto";
|
||||
import "idl_common/slurm_region.proto";
|
||||
|
||||
// Slurm Services
|
||||
service SlurmService {
|
||||
|
@ -117,4 +118,8 @@ service SlurmService {
|
|||
|
||||
// add qos to slurmdb
|
||||
rpc AddQos(AddQosReq) returns (AddQosResp);
|
||||
|
||||
rpc ListRegions(ListRegionSlurmReq) returns (ListRegionSlurmResp);
|
||||
|
||||
rpc GetRegion(GetRegionSlurmReq) returns (GetRegionSlurmResp);
|
||||
}
|
|
@ -81,3 +81,7 @@ http:
|
|||
get: "/apis/slurm/getQos/{name}"
|
||||
- selector: slurmCommon.SlurmService.AddQos
|
||||
post: "/apis/slurm/addQos"
|
||||
- selector: slurmCommon.SlurmService.ListRegions
|
||||
get: "/apis/slurm/listRegions"
|
||||
- selector: slurmCommon.SlurmService.GetRegion
|
||||
get: "/apis/slurm/getRegion"
|
|
@ -11,13 +11,21 @@ message RegionSlurmInfo{
|
|||
int32 adaptorInterfaceSum=4;
|
||||
}
|
||||
|
||||
message RegionSlurmSumInfo {
|
||||
int32 regionSum =1;
|
||||
int32 softStackSum =2;
|
||||
}
|
||||
|
||||
//List
|
||||
message ListRegionSlurmReq{
|
||||
SlurmVersion slurm_version = 1;
|
||||
}
|
||||
|
||||
|
||||
message ListRegionSlurmResp{
|
||||
repeated RegionSlurmInfo regionSlurmInfo = 1;
|
||||
string code = 1;
|
||||
string msg = 2;
|
||||
repeated RegionSlurmInfo regionSlurmInfo = 3;
|
||||
}
|
||||
|
||||
//Get
|
||||
|
@ -26,5 +34,8 @@ message GetRegionSlurmReq{
|
|||
string region_name = 2;
|
||||
}
|
||||
message GetRegionSlurmResp{
|
||||
repeated RegionSlurmInfo RegionSlurmInfo = 1;
|
||||
string code = 1;
|
||||
int32 regionSum =2;
|
||||
int32 softStackSum =3;
|
||||
repeated RegionSlurmSumInfo regionSlurmSumInfo =4;
|
||||
}
|
|
@ -51,3 +51,21 @@ func (s *Server) ListDbJobs(ctx context.Context, req *slurmCommon.ListDbJobsReq)
|
|||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *Server) ListRegions(ctx context.Context, req *slurmCommon.ListRegionSlurmReq) (*slurmCommon.ListRegionSlurmResp, error) {
|
||||
resp, err := ListRegions(ctx, req)
|
||||
if err != nil {
|
||||
glog.Errorf("List db jobs error %+v", err)
|
||||
return nil, status.Errorf(codes.Internal, err.Error())
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetRegion(ctx context.Context, req *slurmCommon.GetRegionSlurmReq) (*slurmCommon.GetRegionSlurmResp, error) {
|
||||
resp, err := GetRegion(ctx, req)
|
||||
if err != nil {
|
||||
glog.Errorf("List db jobs error %+v", err)
|
||||
return nil, status.Errorf(codes.Internal, err.Error())
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -41,3 +41,21 @@ func ListDbJobs(ctx context.Context, req *slurmCommon.ListDbJobsReq) (*slurmComm
|
|||
resp, _ := slurm.ListDbJobs(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func ListRegions(ctx context.Context, req *slurmCommon.ListRegionSlurmReq) (*slurmCommon.ListRegionSlurmResp, error) {
|
||||
slurm, _ := slurmer.SelectSlurmVersion(slurmCommon.SlurmVersion_common)
|
||||
if slurm == nil {
|
||||
return nil, nil
|
||||
}
|
||||
resp, _ := slurm.ListRegions(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func GetRegion(ctx context.Context, req *slurmCommon.GetRegionSlurmReq) (*slurmCommon.GetRegionSlurmResp, error) {
|
||||
slurm, _ := slurmer.SelectSlurmVersion(slurmCommon.SlurmVersion_common)
|
||||
if slurm == nil {
|
||||
return nil, nil
|
||||
}
|
||||
resp, _ := slurm.GetRegion(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -39,3 +39,13 @@ func (s SlurmStruct) ListDbJobs(ctx context.Context, req *slurmCommon.ListDbJobs
|
|||
resp = ListDbJobs(*req)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s SlurmStruct) ListRegions(ctx context.Context, req *slurmCommon.ListRegionSlurmReq) (resp *slurmCommon.ListRegionSlurmResp, err error) {
|
||||
resp = ListRegions()
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s SlurmStruct) GetRegion(ctx context.Context, req *slurmCommon.GetRegionSlurmReq) (resp *slurmCommon.GetRegionSlurmResp, err error) {
|
||||
resp = GetRegion()
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -7,16 +7,29 @@ import (
|
|||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
type RegionSlurmInfo struct {
|
||||
/*type RegionSlurmInfo struct {
|
||||
regionName string
|
||||
softStack string
|
||||
slurmNum int
|
||||
adaptorInterfaceSum int
|
||||
}
|
||||
|
||||
func ListRegions() slurmCommon.ListRegionSlurmResp {
|
||||
type RegionSlurmSumInfo struct {
|
||||
regionSum int
|
||||
softStackSum int
|
||||
}*/
|
||||
|
||||
func ListRegions() *slurmCommon.ListRegionSlurmResp {
|
||||
//"用户名:密码@[连接方式](主机名:端口号)/数据库名"
|
||||
db, _ := sql.Open("mysql", "root:uJpLd6u-J?HC1@(106.53.150.192:3306)/region") // 设置连接数据库的参数
|
||||
db, _ := sql.Open("mysql", "root:uJpLd6u-J?HC1@(106.53.150.192:3306)/slurm") // 设置连接数据库的参数
|
||||
//设置数据库最大连接数
|
||||
db.SetConnMaxLifetime(100)
|
||||
//设置上数据库最大闲置连接数
|
||||
db.SetMaxIdleConns(10)
|
||||
//验证连接
|
||||
if err := db.Ping(); err != nil {
|
||||
fmt.Println("open database fail")
|
||||
}
|
||||
defer db.Close() //关闭数据库
|
||||
err := db.Ping() //连接数据库
|
||||
if err != nil {
|
||||
|
@ -25,16 +38,51 @@ func ListRegions() slurmCommon.ListRegionSlurmResp {
|
|||
fmt.Println("数据库连接成功")
|
||||
}
|
||||
|
||||
var regionList []*slurmCommon.RegionSlurmInfo
|
||||
|
||||
//多行查询
|
||||
rows, _ := db.Query("select * from region") //获取所有数据
|
||||
|
||||
var r RegionSlurmInfo
|
||||
regions := slurmCommon.ListRegionSlurmResp{}
|
||||
rows, err := db.Query(`select RegionName,SlurmNum,SoftStack,AdaptorInterfaceSum from region_slurm`) //获取所有数据
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println(rows)
|
||||
resp := slurmCommon.ListRegionSlurmResp{}
|
||||
//var ListRegionResp []*slurmCommon.ListRegionSlurmResp
|
||||
for rows.Next() {
|
||||
rows.Scan(&r.regionName, &r.slurmNum, &r.softStack, &r.adaptorInterfaceSum)
|
||||
fmt.Println(r)
|
||||
//regions.RegionSlurmInfo = append(regions.RegionSlurmInfo, r)
|
||||
var r slurmCommon.RegionSlurmInfo
|
||||
rows.Scan(&r.RegionName, &r.SlurmNum, &r.SoftStack, &r.AdaptorInterfaceSum)
|
||||
regionList = append(regionList, &r)
|
||||
fmt.Println(regionList)
|
||||
}
|
||||
resp.Code = "200"
|
||||
resp.RegionSlurmInfo = regionList
|
||||
return &resp
|
||||
}
|
||||
|
||||
return regions
|
||||
func GetRegion() *slurmCommon.GetRegionSlurmResp {
|
||||
db, _ := sql.Open("mysql", "root:uJpLd6u-J?HC1@(106.53.150.192:3306)/slurm") // 设置连接数据库的参数
|
||||
defer db.Close() //关闭数据库
|
||||
err := db.Ping() //连接数据库
|
||||
if err != nil {
|
||||
fmt.Println("数据库连接失败")
|
||||
} else {
|
||||
fmt.Println("数据库连接成功")
|
||||
}
|
||||
var r *slurmCommon.RegionSlurmSumInfo
|
||||
errRegionSum := db.QueryRow(`SELECT count(t.RegionName) as RegionSum FROM region_slurm t`).Scan(&r.RegionSum) //获取所有数据
|
||||
if errRegionSum != nil {
|
||||
fmt.Println(errRegionSum)
|
||||
}
|
||||
|
||||
errSoftStackSum := db.QueryRow(`SELECT count(t.SoftStack) as SoftStackSum FROM region_slurm t`).Scan(&r.SoftStackSum) //获取所有数据
|
||||
if errSoftStackSum != nil {
|
||||
fmt.Println(errSoftStackSum)
|
||||
}
|
||||
fmt.Println(r)
|
||||
|
||||
resp := slurmCommon.GetRegionSlurmResp{}
|
||||
resp.Code = "200"
|
||||
resp.RegionSum = r.RegionSum
|
||||
resp.SoftStackSum = r.SoftStackSum
|
||||
return &resp
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ type Slurmer interface {
|
|||
SubmitJob(ctx context.Context, req *slurmCommon.SubmitJobReq) (resp *slurmCommon.SubmitJobResp, err error)
|
||||
ListJobs(ctx context.Context, req *slurmCommon.ListJobsReq) (resp *slurmCommon.ListJobsResp, err error)
|
||||
ListDbJobs(ctx context.Context, req *slurmCommon.ListDbJobsReq) (resp *slurmCommon.ListDbJobsResp, err error)
|
||||
ListRegions(ctx context.Context, req *slurmCommon.ListRegionSlurmReq) (resp *slurmCommon.ListRegionSlurmResp, err error)
|
||||
GetRegion(ctx context.Context, req *slurmCommon.GetRegionSlurmReq) (resp *slurmCommon.GetRegionSlurmResp, err error)
|
||||
}
|
||||
|
||||
func SelectSlurmVersion(slurmVersion slurmCommon.SlurmVersion) (slurmer Slurmer, err error) {
|
||||
|
|
Loading…
Reference in New Issue