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_job.proto";
|
||||||
import "idl_common/slurm_diag.proto";
|
import "idl_common/slurm_diag.proto";
|
||||||
import "idl_common/slurmdb_job.proto";
|
import "idl_common/slurmdb_job.proto";
|
||||||
|
import "idl_common/slurm_region.proto";
|
||||||
|
|
||||||
// Slurm Services
|
// Slurm Services
|
||||||
service SlurmService {
|
service SlurmService {
|
||||||
|
@ -117,4 +118,8 @@ service SlurmService {
|
||||||
|
|
||||||
// add qos to slurmdb
|
// add qos to slurmdb
|
||||||
rpc AddQos(AddQosReq) returns (AddQosResp);
|
rpc AddQos(AddQosReq) returns (AddQosResp);
|
||||||
|
|
||||||
|
rpc ListRegions(ListRegionSlurmReq) returns (ListRegionSlurmResp);
|
||||||
|
|
||||||
|
rpc GetRegion(GetRegionSlurmReq) returns (GetRegionSlurmResp);
|
||||||
}
|
}
|
|
@ -80,4 +80,8 @@ http:
|
||||||
- selector: slurmCommon.SlurmService.GetQos
|
- selector: slurmCommon.SlurmService.GetQos
|
||||||
get: "/apis/slurm/getQos/{name}"
|
get: "/apis/slurm/getQos/{name}"
|
||||||
- selector: slurmCommon.SlurmService.AddQos
|
- selector: slurmCommon.SlurmService.AddQos
|
||||||
post: "/apis/slurm/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;
|
int32 adaptorInterfaceSum=4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message RegionSlurmSumInfo {
|
||||||
|
int32 regionSum =1;
|
||||||
|
int32 softStackSum =2;
|
||||||
|
}
|
||||||
|
|
||||||
//List
|
//List
|
||||||
message ListRegionSlurmReq{
|
message ListRegionSlurmReq{
|
||||||
SlurmVersion slurm_version = 1;
|
SlurmVersion slurm_version = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
message ListRegionSlurmResp{
|
message ListRegionSlurmResp{
|
||||||
repeated RegionSlurmInfo regionSlurmInfo = 1;
|
string code = 1;
|
||||||
|
string msg = 2;
|
||||||
|
repeated RegionSlurmInfo regionSlurmInfo = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get
|
//Get
|
||||||
|
@ -26,5 +34,8 @@ message GetRegionSlurmReq{
|
||||||
string region_name = 2;
|
string region_name = 2;
|
||||||
}
|
}
|
||||||
message GetRegionSlurmResp{
|
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
|
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)
|
resp, _ := slurm.ListDbJobs(ctx, req)
|
||||||
return resp, nil
|
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)
|
resp = ListDbJobs(*req)
|
||||||
return resp, nil
|
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,34 +7,82 @@ import (
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RegionSlurmInfo struct {
|
/*type RegionSlurmInfo struct {
|
||||||
regionName string
|
regionName string
|
||||||
softStack string
|
softStack string
|
||||||
slurmNum int
|
slurmNum int
|
||||||
adaptorInterfaceSum 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") // 设置连接数据库的参数
|
||||||
defer db.Close() //关闭数据库
|
//设置数据库最大连接数
|
||||||
err := db.Ping() //连接数据库
|
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 {
|
if err != nil {
|
||||||
fmt.Println("数据库连接失败")
|
fmt.Println("数据库连接失败")
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("数据库连接成功")
|
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() {
|
for rows.Next() {
|
||||||
rows.Scan(&r.regionName, &r.slurmNum, &r.softStack, &r.adaptorInterfaceSum)
|
var r slurmCommon.RegionSlurmInfo
|
||||||
fmt.Println(r)
|
rows.Scan(&r.RegionName, &r.SlurmNum, &r.SoftStack, &r.AdaptorInterfaceSum)
|
||||||
//regions.RegionSlurmInfo = append(regions.RegionSlurmInfo, r)
|
regionList = append(regionList, &r)
|
||||||
|
fmt.Println(regionList)
|
||||||
|
}
|
||||||
|
resp.Code = "200"
|
||||||
|
resp.RegionSlurmInfo = regionList
|
||||||
|
return &resp
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
return regions
|
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)
|
SubmitJob(ctx context.Context, req *slurmCommon.SubmitJobReq) (resp *slurmCommon.SubmitJobResp, err error)
|
||||||
ListJobs(ctx context.Context, req *slurmCommon.ListJobsReq) (resp *slurmCommon.ListJobsResp, 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)
|
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) {
|
func SelectSlurmVersion(slurmVersion slurmCommon.SlurmVersion) (slurmer Slurmer, err error) {
|
||||||
|
|
Loading…
Reference in New Issue