3 Star 2 Fork 0

info-superbahn-ict / superbahn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
handler_strategy.go 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
tangshibo 提交于 2022-01-07 10:26 . update
package nervous_apis
import (
"encoding/json"
"fmt"
"gitee.com/info-superbahn-ict/superbahn/internal/supbmanager/v3_test/modules/nervous-apis/clireq"
m2 "gitee.com/info-superbahn-ict/superbahn/pkg/supbmanager/v3_test/supb-modules/supbres/applications/model"
"gitee.com/info-superbahn-ict/superbahn/pkg/supbmanager/v3_test/supb-modules/supbres/types"
"net/http"
)
func (r *NervousServer) strategy(args ...interface{}) (interface{}, error) {
var req = &clireq.StrategyRequest{}
r.logger.Infof("STRATEGY")
if err := json.Unmarshal([]byte(args[0].(string)), req); err != nil {
return "", err
}
switch req.Op {
case clireq.StrategyControlInfo:
return r.strategyControlInfo(req.Key)
default:
return "", fmt.Errorf("unkown type")
}
}
func (r *NervousServer) strategyControlInfo(strategyKey string) (string, error) {
if r.supbStrategy == nil || r.supbResMgr == nil {
return "", fmt.Errorf("nil stratgy or resrouce mgr")
}
st, err := r.supbResMgr.GetStrategy(types.DynamicStrategy, strategyKey)
if err != nil {
return "", fmt.Errorf("[%v]",err)
}
apps, i := make([]*m2.SupbApplicationBaseInfo, len(st.StrategySlaves)), 0
for _, slave := range st.StrategySlaves {
app, err := r.supbResMgr.GetApplication(types.DynamicApplication, string(slave.SlaveKey))
if err != nil {
return "", err
}
apps[i] = app
i++
}
rData := clireq.Response{
Code: http.StatusOK,
Message: "succeed",
Data:apps,
}
resp,err := json.Marshal(rData)
if err != nil {
return "", err
}
return string(resp), err
}
Go
1
https://gitee.com/info-superbahn-ict/superbahn.git
git@gitee.com:info-superbahn-ict/superbahn.git
info-superbahn-ict
superbahn
superbahn
5fda629dab96

搜索帮助