This is an automated email from the ASF dual-hosted git repository.

zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git


The following commit(s) were added to refs/heads/master by this push:
     new 14667dbe [horus] File parsing database initialization completed (#322)
14667dbe is described below

commit 14667dbe4e51aa954ed7c6947e2a6d620d7085b4
Author: mfordjody <[email protected]>
AuthorDate: Fri Sep 6 17:51:53 2024 +0800

    [horus] File parsing database initialization completed (#322)
    
    * [horus] MySQL data conversion
    
    * File parsing and database initialization completed
    
    * [horus] MySQL data conversion
    
    File parsing and database initialization completed
---
 app/horus/basic/config/file.go | 12 +++----
 app/horus/basic/config/flag.go |  2 +-
 app/horus/cmd/main.go          | 19 ++++++++---
 app/horus/core/db/db.go        | 74 ++++++++++++++++++++++++++++++++++++++++++
 app/horus/core/db/sql.tpl      | 53 ++++++++++++++++++++++++++++++
 deploy/horus/horus.yaml        | 21 ++++++++++++
 6 files changed, 170 insertions(+), 11 deletions(-)

diff --git a/app/horus/basic/config/file.go b/app/horus/basic/config/file.go
index 23f2f7dc..4cd24a27 100644
--- a/app/horus/basic/config/file.go
+++ b/app/horus/basic/config/file.go
@@ -16,12 +16,12 @@
 package config
 
 type Config struct {
-       HttpAddr string `yaml:"HttpAddr"`
-       Mysql    *Mysql `yaml:"Mysql"`
+       HttpAddr string              `yaml:"HttpAddr"`
+       Mysql    *MysqlConfiguration `yaml:"Mysql"`
 }
 
-type Mysql struct {
-       Name  string `yaml:"Name"`
-       Addr  string `yaml:"Addr"`
-       Debug bool   `yaml:"Debug"`
+type MysqlConfiguration struct {
+       Name  string `yaml:"name"`
+       Addr  string `yaml:"addr"`
+       Debug bool   `yaml:"debug"`
 }
diff --git a/app/horus/basic/config/flag.go b/app/horus/basic/config/flag.go
index a10eeeb6..8e65762d 100644
--- a/app/horus/basic/config/flag.go
+++ b/app/horus/basic/config/flag.go
@@ -37,7 +37,7 @@ func LoadFile(name string) (*Config, error) {
        }
        cfg, err := Load(string(bytes))
        if err != nil {
-               fmt.Printf("parsing YAML file err:%v", err)
+               fmt.Printf("parsing yaml file err:%v", err)
                return nil, err
        }
        return cfg, err
diff --git a/app/horus/cmd/main.go b/app/horus/cmd/main.go
index 98c631e9..ff53c77d 100644
--- a/app/horus/cmd/main.go
+++ b/app/horus/cmd/main.go
@@ -18,6 +18,7 @@ package main
 import (
        "flag"
        "github.com/apache/dubbo-kubernetes/app/horus/basic/config"
+       "github.com/apache/dubbo-kubernetes/app/horus/core/db"
        "k8s.io/klog/v2"
 )
 
@@ -27,15 +28,25 @@ var (
 )
 
 func main() {
-       flag.StringVar(&configFile, "configFile", "./horus.yaml", "horus config 
file")
-       flag.StringVar(&httpAddr, "httpAddr", "0.0.0.0:9089", "horus http addr")
+       flag.StringVar(&configFile, "configFile", "deploy/horus/horus.yaml", 
"horus config file")
+       flag.StringVar(&httpAddr, "httpAddr", "0.0.0.0:38089", "horus http 
addr")
+       klog.InitFlags(flag.CommandLine)
        flag.Parse()
 
        c, err := config.LoadFile(configFile)
        if err != nil {
-               klog.Infof("load config file success.")
+               klog.Errorf("load config file failed err:%+v", c)
+               return
        } else {
-               klog.Errorf("load config file failed err: %v", c)
+               klog.Infof("load config file success.")
+       }
+
+       err = db.InitDataBase(c.Mysql)
+       if err != nil {
+               klog.Errorf("horus db initial failed err:%v", err)
                return
+       } else {
+               klog.Infof("horus db initial success.")
        }
+
 }
diff --git a/app/horus/core/db/db.go b/app/horus/core/db/db.go
new file mode 100644
index 00000000..b350ef02
--- /dev/null
+++ b/app/horus/core/db/db.go
@@ -0,0 +1,74 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You 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 db
+
+import (
+       "fmt"
+       "github.com/apache/dubbo-kubernetes/app/horus/basic/config"
+       _ "github.com/go-sql-driver/mysql"
+       "xorm.io/xorm"
+       xlog "xorm.io/xorm/log"
+)
+
+type NodeDataInfo struct {
+       Id              uint32 `json:"id"`
+       NodeName        string `json:"nodeName"`
+       NodeIP          string `json:"nodeIP"`
+       Sn              string `json:"sn"`
+       ClusterName     string `json:"clusterName"`
+       ModuleName      string `json:"moduleName"`
+       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"`
+}
+
+type PodDataInfo struct {
+       Id              uint32 `json:"id"`
+       PodName         string `json:"podName"`
+       PodIP           string `json:"podIP"`
+       Sn              string `json:"sn"`
+       NodeName        string `json:"nodeName"`
+       ClusterName     string `json:"clusterName"`
+       ModuleName      string `json:"moduleName"`
+       Reason          string `json:"reason"`
+       Restart         int32  `json:"restart"`
+       Repair          int32  `json:"repair"`
+       RepairTicketUrl string `json:"repairTicketUrl"`
+       FirstDate       string `json:"firstDate"`
+       LastDate        string `json:"lastDate"`
+       CreateTime      string `json:"createTime"`
+       UpdateTime      string `json:"updateTime"`
+}
+
+var (
+       db *xorm.Engine
+)
+
+func InitDataBase(mc *config.MysqlConfiguration) error {
+       data, err := xorm.NewEngine("mysql", mc.Addr)
+       if err != nil {
+               fmt.Printf("Unable to connect to mysql server:\n  addr: %s\n  
err: %v\n", mc.Addr, err)
+       }
+       data.Logger().SetLevel(xlog.LOG_INFO)
+       data.ShowSQL(mc.Debug)
+       db = data
+       return nil
+}
diff --git a/app/horus/core/db/sql.tpl b/app/horus/core/db/sql.tpl
new file mode 100644
index 00000000..38c16864
--- /dev/null
+++ b/app/horus/core/db/sql.tpl
@@ -0,0 +1,53 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You 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.
+
+CREATE TABLE `node_data` (
+                             `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',
+                             `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 '模块名',
+                             `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 '更新时间',
+                             PRIMARY KEY (`id`) USING BTREE,
+                             UNIQUE INDEX `idx_unique_node_module` 
(`nodeName`, `moduleName`) USING BTREE
+) ENGINE=InnoDB AUTO_INCREMENT=3 CHARACTER SET=utf8mb3 
COLLATE=utf8mb3_general_ci ROW_FORMAT=Dynamic;
+
+CREATE TABLE `pod_data` (
+                                 `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地址',
+                                 `sn` varchar(255) CHARACTER SET utf8mb3 
COLLATE utf8mb3_general_ci NOT NULL COMMENT '序列号',
+                                 `nodeName` varchar(255) CHARACTER SET utf8mb3 
COLLATE utf8mb3_general_ci NOT NULL COMMENT '节点名',
+                                 `clusterName` varchar(255) CHARACTER SET 
utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '集群名',
+                                 `moduleName` varchar(255) CHARACTER SET 
utf8mb3 COLLATE utf8mb3_general_ci NOT NULL COMMENT '模块名',
+                                 `reason` varchar(255) CHARACTER SET utf8mb3 
COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '维护原因',
+                                 `restart` int DEFAULT NULL COMMENT '重启标志位',
+                                 `repair` int DEFAULT NULL COMMENT '修复标志位',
+                                 `repairTicketUrl` varchar(255) CHARACTER SET 
utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '修复单跳转 URL',
+                                 `firstDate` datetime DEFAULT NULL COMMENT 
'第一次维护日期',
+                                 `lastDate` datetime DEFAULT NULL COMMENT 
'最后维护日期',
+                                 `createTime` datetime DEFAULT 
CURRENT_TIMESTAMP COMMENT '创建日期',
+                                 `updateTime` datetime DEFAULT 
CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新日期',
+                                 PRIMARY KEY (`id`) USING BTREE,
+                                 UNIQUE KEY `idxUniqueName` (`podName`, 
`moduleName`) USING BTREE
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
\ No newline at end of file
diff --git a/deploy/horus/horus.yaml b/deploy/horus/horus.yaml
new file mode 100644
index 00000000..61079cbc
--- /dev/null
+++ b/deploy/horus/horus.yaml
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+
+HttpAddr: 0.0.0.0:38089
+
+Mysql:
+  Name: horus
+  Addr: "root:root@tcp(127.0.0.1:3306)/horus?charset=utf8&parseTime=True"
+  Debug: false
\ No newline at end of file

Reply via email to