|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*
-
- 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
- }
|