Skip to content

Commit

Permalink
[horus] Fixing database fields (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfordjody authored Sep 15, 2024
1 parent ac4bf26 commit cba3490
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 46 deletions.
50 changes: 21 additions & 29 deletions app/horus/basic/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@ import (

type NodeDataInfo struct {
Id int64 `json:"id"`
NodeName string `json:"nodeName"`
NodeIP string `json:"nodeIP"`
NodeName string `json:"node_name" xorm:"node_name"`
NodeIP string `json:"node_ip" xorm:"node_ip"`
Sn string `json:"sn"`
ClusterName string `json:"clusterName"`
ModuleName string `json:"moduleName"`
ClusterName string `json:"cluster_name" xorm:"cluster_name"`
ModuleName string `json:"module_name" xorm:"module_name"`
Reason string `json:"reason"`
Restart uint32 `json:"restart"`
Repair uint32 `json:"repair"`
RepairTicketUrl string `json:"repairTicketUrl"`
FirstDate string `json:"firstDate"`
LastDate string `json:"lastDate"`
CreateTime string `json:"createTime" xorm:"createTime created"`
UpdateTime string `json:"updateTime" xorm:"updateTime updated"`
RecoveryMark int64 `json:"recoveryMark"`
RecoveryQL string `json:"recoveryQL"`
RepairTicketUrl string `json:"repair_ticket_url" xorm:"repair_ticket_url"`
FirstDate string `json:"first_date" xorm:"first_date"`
CreateTime string `json:"create_time" xorm:"create_time created"`
UpdateTime string `json:"update_time" xorm:"update_time updated"`
RecoveryMark int64 `json:"recovery_mark" xorm:"recovery_mark"`
RecoveryQL string `json:"recovery_ql" xorm:"recovery_ql"`
}

type PodDataInfo struct {
Expand Down Expand Up @@ -77,24 +76,8 @@ func InitDataBase(mc *config.MysqlConfiguration) error {
}

func (n *NodeDataInfo) Add() (int64, error) {
exist, err := db.Exist(n)
if err != nil {
return 0, err
}
if exist {
return n.Id, nil
}

affected, err := db.Insert(n)
if err != nil {
return 0, err
}

if affected > 0 {
return n.Id, nil
}

return 0, fmt.Errorf("failed to insert record")
row, err := db.Insert(n)
return row, err
}

func (n *NodeDataInfo) Get() (*NodeDataInfo, error) {
Expand Down Expand Up @@ -126,3 +109,12 @@ func (n *NodeDataInfo) Check() (bool, error) {
exist, err := db.Exist(n)
return exist, err
}

func (n *NodeDataInfo) AddOrGet() (int64, error) {
exist, _ := n.Check()
if exist {
return n.Id, nil
}
row, err := n.Add()
return row, err
}
4 changes: 0 additions & 4 deletions app/horus/basic/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,4 @@ func TestDataBase(t *testing.T) {
data.NodeName = "002"
id, err := data.Add()
t.Logf("test.add id:%v err:%v", id, err)
query, err := data.Get()
t.Logf("test.get query:%v err:%v", query, err)
update, err := data.Update()
t.Logf("test.update %v err: %v", update, err)
}
23 changes: 11 additions & 12 deletions app/horus/basic/db/sql.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.

CREATE TABLE `node_data` (
CREATE TABLE `node_data_info` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`nodeName` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL COMMENT '节点名',
`nodeIP` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL COMMENT '节点IP',
`node_name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL COMMENT '节点名',
`node_ip` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL COMMENT '节点IP',
`sn` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL COMMENT '序列号',
`clusterName` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL COMMENT '集群名',
`moduleName` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL COMMENT '模块名',
`cluster_name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL COMMENT '集群名',
`module_name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL COMMENT '模块名',
`reason` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL COMMENT '维护原因',
`restart` int(10) UNSIGNED NULL DEFAULT NULL COMMENT '重启标志',
`repair` int(10) UNSIGNED NULL DEFAULT NULL COMMENT '修复标志',
`repairTicketUrl` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL COMMENT '修复单跳转 URL',
`firstDate` datetime(0) NULL DEFAULT NULL COMMENT '最早开始维护时间',
`lastDate` datetime(0) DEFAULT NULL COMMENT '最后维护日期',
`createTime` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
`updateTime` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
`repair_ticket_url` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL COMMENT '修复单跳转 URL',
`first_date` datetime(0) NULL DEFAULT NULL COMMENT '最早开始维护时间',
`create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
`update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `idx_unique_node_module` (`nodeName`, `moduleName`) USING BTREE
UNIQUE INDEX `idx_unique_node_module` (`node_name`, `module_name`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 CHARACTER SET=utf8mb3 COLLATE=utf8mb3_general_ci ROW_FORMAT=Dynamic;

CREATE TABLE `pod_data` (
CREATE TABLE `pod_data_info` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`podName` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL COMMENT 'Pod 名',
`podIP` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT 'ip地址',
Expand Down
2 changes: 1 addition & 1 deletion app/horus/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
)

func main() {
flag.StringVar(&configFile, "configFile", "deploy/horus/horus.yaml", "horus config file")
flag.StringVar(&configFile, "configFile", "../../deploy/horus/horus.yaml", "horus config file")
flag.StringVar(&address, "address", "0.0.0.0:38089", "horus address")
klog.InitFlags(flag.CommandLine)
flag.Parse()
Expand Down

0 comments on commit cba3490

Please sign in to comment.