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 fdapi
import (
"fmt"
"ascend-common/common-utils/hwlog"
fdol "ascend-faultdiag-online"
"ascend-faultdiag-online/pkg/core/context"
)
const (
controllerUrl = "feature/netfault/controller"
fdConfigPath = "/home/hwMindX/fdConfig.yaml"
startApi = "start"
stopApi = "stop"
reloadApi = "reload"
)
func StartFdOL() {
hwlog.RunLog.Info("start fd-ol")
fdol.StartFDOnline(fdConfigPath, []string{"slowNode", "netFault"}, "cluster")
}
func StartController() {
requestFD(context.FdCtx, startApi)
}
func StopController() {
requestFD(context.FdCtx, stopApi)
}
func ReloadController() {
requestFD(context.FdCtx, reloadApi)
}
func requestFD(fdCtx *context.FaultDiagContext, api string) {
if fdCtx == nil {
hwlog.RunLog.Errorf("fdCtx is nil")
return
}
url := fmt.Sprintf("%s/%s", controllerUrl, api)
resp, err := fdCtx.Request(url, "{}")
if err != nil {
hwlog.RunLog.Errorf("stop controller algorithm failed: %v", err)
return
}
hwlog.RunLog.Infof("the response of %s controller is %v", api, resp)
}