Copyright(C)2025. Huawei Technologies Co.,Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
Package pingmesh a series of function handle ping mesh configmap create/update/delete.
*/
package pingmesh
import (
"encoding/json"
"ascend-common/api"
"ascend-common/common-utils/hwlog"
"clusterd/pkg/common/constant"
)
func handlerSuperPodRoce(res map[int]string) {
superPodIds := filterA5SuperPodIDFromMap(res)
if len(superPodIds) == 0 {
hwlog.RunLog.Info("no Super Pod Npu in this cluster, can't create super-pod-roce dir")
return
}
listData := &constant.CrossSuperPodListData{
SuperPodList: make([]int, 0),
}
listData.SuperPodList = append(listData.SuperPodList, superPodIds...)
ConfigPingMeshInst.RLock()
if _, exist := ConfigPingMeshInst.configCMInfo[constant.RasRoceKey]; !exist {
hwlog.RunLog.Warnf("the roce config is not exist")
ConfigPingMeshInst.RUnlock()
return
}
ConfigPingMeshInst.RUnlock()
cfg := ConfigPingMeshInst.getRasConfigBySuperPodId(constant.RasRoceKey)
hwlog.RunLog.Infof("these super-pod list<%v> will write to file", listData.SuperPodList)
b, err := json.MarshalIndent(listData, "", jsonIndent)
if err != nil || len(b) == 0 {
hwlog.RunLog.Errorf("marshal bytes illegal, SuperPodID=%s, err=%v", constant.RasRoceKey, err)
return
}
if errWrite := writeJsonDataByteToFile(constant.RasRoceKey, b); errWrite != nil {
hwlog.RunLog.Errorf("write json data to file failed, err: %v", errWrite)
return
}
err = saveConfigToFile(constant.RasRoceKey, cfg)
if err != nil {
hwlog.RunLog.Errorf("save config to file failed, err=%v, superPodID=%s", err, constant.RasRoceKey)
return
}
}
func filterA5SuperPodIDFromMap(resMap map[int]string) []int {
res := make([]int, 0, len(resMap))
for id, acceleratorType := range resMap {
if acceleratorType != api.A5PodType {
hwlog.RunLog.Infof("the superPodID<%d> is not NPU Super Pod and do not append to list", id)
continue
}
res = append(res, id)
}
return res
}