From 6e2fd619257f5d723e4a42189cde3e82da589e5a Mon Sep 17 00:00:00 2001 From: bizhiyuan Date: Tue, 10 Dec 2024 14:15:23 +0800 Subject: [PATCH] Optimize OperationClusterAction functions --- models/cluster.go | 21 +++++++++++---------- models/heartbeat.go | 7 +++++++ utils/command.go | 2 ++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/models/cluster.go b/models/cluster.go index d154c02..f764e9a 100644 --- a/models/cluster.go +++ b/models/cluster.go @@ -1,6 +1,6 @@ /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * ha-api licensed under the Mulan Permissive Software License, Version 2. + * ha-api licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. * Author: yangzhao_kl * Date: Fri Jan 8 20:56:40 2021 +0800 @@ -366,6 +366,12 @@ func getClusterPropertyFromXml(e *etree.Element) map[string]interface{} { func OperationClusterAction(action string) map[string]interface{} { result := map[string]interface{}{} + if action == "" { + result["action"] = false + result["error"] = gettext.Gettext("Action on node failed") + return result + } + if action == "start" { utils.RunCommand(utils.CmdStartCluster) } @@ -376,15 +382,10 @@ func OperationClusterAction(action string) map[string]interface{} { utils.RunCommand(utils.CmdStopClusterLocal) utils.RunCommand(utils.CmdStartCluster) } - if action == "" { - result["action"] = false - result["error"] = gettext.Gettext("Action on node failed") - return result - } else { - result["action"] = true - result["info"] = gettext.Gettext("Action on node success") - return result - } + + result["action"] = true + result["info"] = gettext.Gettext("Action on node success") + return result } func getResourceStickiness() int { diff --git a/models/heartbeat.go b/models/heartbeat.go index 845522d..b916858 100644 --- a/models/heartbeat.go +++ b/models/heartbeat.go @@ -194,6 +194,13 @@ func AddLink(linkIds string) error { return err } +func EditLinks(hbInfo map[string]string, linkId string) error { + hbInfoStr := GenerateLinkStr(hbInfo) + cmd := fmt.Sprintf(utils.CmdUpdateLinkForce, hbInfoStr, linkId) + _, err := utils.RunCommand(cmd) + return err +} + func GenerateLinkStr(data map[string]string) string { var linkStr strings.Builder for k, v := range data { diff --git a/utils/command.go b/utils/command.go index 858f37d..2d0ac6e 100644 --- a/utils/command.go +++ b/utils/command.go @@ -95,6 +95,8 @@ const ( CmdAddLinkForce = "pcs cluster link add %s --force" CmdAddLinksWithLinkNum = "pcs cluster link add %s options linknumber=%s --force" CmdHbStatus = "corosync-cfgtool -n" + CmdUpdateLink = "pcs cluster link update %s %s" + CmdUpdateLinkForce = CmdUpdateLink + " --force" ) // RunCommand runs the command and get the result -- Gitee