forked from JointCloud/pcm-coordinator
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
/*
|
|
|
|
Copyright (c) [2023] [pcm]
|
|
[pcm-coordinator] is licensed under Mulan PSL v2.
|
|
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
You may obtain a copy of Mulan PSL v2 at:
|
|
http://license.coscl.org.cn/MulanPSL2
|
|
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
See the Mulan PSL v2 for more details.
|
|
|
|
*/
|
|
|
|
package core
|
|
|
|
import (
|
|
"context"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"gitlink.org.cn/JointCloud/pcm-ac/hpcAC"
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
|
"gitlink.org.cn/JointCloud/pcm-octopus/octopus"
|
|
"log"
|
|
)
|
|
|
|
type GetGeneralInfoLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetGeneralInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGeneralInfoLogic {
|
|
return &GetGeneralInfoLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetGeneralInfoLogic) GetGeneralInfo() (resp *types.GiResp, err error) {
|
|
apiResp := types.GiResp{}
|
|
|
|
//启智章鱼资源统计
|
|
octopusGiReq := &octopus.ResourceReq{}
|
|
octopusGiResp, err := l.svcCtx.OctopusRpc.GetGeneralInfo(l.ctx, octopusGiReq)
|
|
if err != nil {
|
|
log.Println("OctopusRpc 资源请求失败", err)
|
|
}
|
|
|
|
//曙光账号资源统计
|
|
acGiReq := &hpcAC.ResourceReq{}
|
|
acGiResp, err := l.svcCtx.ACRpc.GetGeneralInfo(l.ctx, acGiReq)
|
|
if err != nil {
|
|
log.Println("ACRpc 资源请求失败", err)
|
|
}
|
|
|
|
cpu := octopusGiResp.CpuCoreNum + acGiResp.CpuCoreNum
|
|
storage := acGiResp.StorageInGib
|
|
mem := octopusGiResp.MemoryInGib + acGiResp.MemoryInGib
|
|
|
|
apiResp.StorageInGib = storage
|
|
apiResp.CpuNum = cpu
|
|
apiResp.MemoryInGib = mem
|
|
|
|
return &apiResp, nil
|
|
}
|