/* 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 GetComputingPowerLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewGetComputingPowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetComputingPowerLogic { return &GetComputingPowerLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } type client struct { } func (c *client) getComputingPower(cp computingPower, l *GetComputingPowerLogic) float32 { return cp.GetComputing(l) } type OctopusComputingPower struct { } type AcComputingPower struct { } type computingPower interface { GetComputing(l *GetComputingPowerLogic) float32 } // 启智章鱼资源算力 func (cp OctopusComputingPower) GetComputing(l *GetComputingPowerLogic) float32 { octopusCpReq := &octopus.ResourceReq{} octopusCpResp, err := l.svcCtx.OctopusRpc.GetComputingPower(l.ctx, octopusCpReq) if err != nil { log.Println("OctopusRpc 算力请求失败", err) } return octopusCpResp.POpsAtFp16 } // 曙光账号算力 func (cp AcComputingPower) GetComputing(l *GetComputingPowerLogic) float32 { acCpReq := &hpcAC.ResourceReq{} acCpResp, err := l.svcCtx.ACRpc.GetComputingPower(l.ctx, acCpReq) if err != nil { log.Println("ACRpc 算力请求失败", err) } return acCpResp.POpsAtFp16 } func (l *GetComputingPowerLogic) GetComputingPower() (resp *types.CpResp, err error) { apiResp := types.CpResp{} c := client{} ot := OctopusComputingPower{} ac := AcComputingPower{} a := c.getComputingPower(ot, l) b := c.getComputingPower(ac, l) apiResp.POpsAtFp16 = a + b ////启智章鱼资源算力 //octopusCpReq := &octopus.ResourceReq{} //octopusCpResp, err := l.svcCtx.OctopusRpc.GetComputingPower(l.ctx, octopusCpReq) //if err != nil { // log.Println("OctopusRpc 算力请求失败", err) //} // ////曙光账号算力 //acCpReq := &hpcAC.ResourceReq{} //acCpResp, err := l.svcCtx.ACRpc.GetComputingPower(l.ctx, acCpReq) //if err != nil { // log.Println("ACRpc 算力请求失败", err) //} // //computingPowerAggregated := acCpResp.POpsAtFp16 + octopusCpResp.POpsAtFp16 //apiResp.POpsAtFp16 = computingPowerAggregated return &apiResp, nil }