Skip to content

Commit

Permalink
feat: set openim lint (#329)
Browse files Browse the repository at this point in the history
Signed-off-by: Xinwei Xiong(cubxxw) <[email protected]>
  • Loading branch information
cubxxw authored Dec 19, 2023
1 parent 1a349a4 commit 53c4eff
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions deployments/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ envs:
zookeeper:
schema: openim # ZOOKEEPER_SCHEMA, the schema to use in Zookeeper
zkAddr:
- 127.28.0.1:12181 # ZOOKEEPER_ADDRESS and ZOOKEEPER_PORT, Zookeeper address and port
- 172.28.0.1:12181 # ZOOKEEPER_ADDRESS and ZOOKEEPER_PORT, Zookeeper address and port
username: "" # ZOOKEEPER_USERNAME, Username for Zookeeper authentication
password: "" # ZOOKEEPER_PASSWORD, Password for Zookeeper authentication

Expand Down Expand Up @@ -51,7 +51,7 @@ rpcRegisterName:

# MySQL database configuration - used for storing OpenIM data
mysql:
address: [ 127.0.0.1:13306 ] # MYSQL_ADDRESS and MYSQL_PORT, MySQL server address and port
address: [ 172.28.0.1:13306 ] # MYSQL_ADDRESS and MYSQL_PORT, MySQL server address and port
username: root # MYSQL_USERNAME, Username for MySQL
password: openIM123 # MYSQL_PASSWORD, Password for MySQL
database: openIM_v3 # MYSQL_DATABASE, Database name
Expand Down Expand Up @@ -118,10 +118,10 @@ adminList:
imAdmin: openIMAdmin

# URL for OpenIM server
openIMUrl: "127.0.0.1:10002" # OPENIM_SERVER_ADDRESS:API_OPENIM_PORT, URL of the OpenIM server
openIMUrl: "172.28.0.1:10002" # OPENIM_SERVER_ADDRESS:API_OPENIM_PORT, URL of the OpenIM server

# Redis configuration - used for caching and session management
redis:
address: [ 127.0.0.1:16379 ] # REDIS_ADDRESS and REDIS_PORT, Redis server address and port
address: [ 172.28.0.1:16379 ] # REDIS_ADDRESS and REDIS_PORT, Redis server address and port
username: # REDIS_USERNAME, Username for Redis authentication
password: openIM123 # REDIS_PASSWORD, Password for Redis
2 changes: 1 addition & 1 deletion pkg/common/config/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.3.1
v3.3.5
26 changes: 17 additions & 9 deletions tools/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ package component

import (
"fmt"
"github.com/OpenIMSDK/protocol/constant"
"os"
"time"

"github.com/OpenIMSDK/protocol/constant"

"github.com/OpenIMSDK/chat/pkg/common/config"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/log"
Expand All @@ -28,6 +29,10 @@ import (
"gopkg.in/yaml.v3"
)

var (
MaxConnectTimes = 100
)

func initCfg(cfgPath string) error {
file, err := os.ReadFile(cfgPath)
if err != nil {
Expand All @@ -47,15 +52,14 @@ func ComponentCheck(cfgPath string, hide bool) error {
return err
}
if config.Config.Envs.Discovery != "k8s" {
var zkConn *zk.Conn
if zkConn, err = checkNewZkClient(hide); err != nil {
errorPrint(fmt.Sprintf("%v.Please check if your openIM server has started", err.Error()), hide)
return err
}
if err = checkGetCfg(zkConn, hide); err != nil {
if _, err := checkNewZkClient(hide); err != nil {
errorPrint(fmt.Sprintf("%v.Please check if your openIM server has started", err.Error()), hide)
return err
}
// if err = checkGetCfg(zkConn, hide); err != nil {
// errorPrint(fmt.Sprintf("%v.Please check if your openIM server has started", err.Error()), hide)
// return err
// }
}

return nil
Expand All @@ -76,7 +80,9 @@ func successPrint(s string, hide bool) {
func newZkClient() (*zk.Conn, error) {
var c *zk.Conn
c, _, err := zk.Connect(config.Config.Zookeeper.ZkAddr, time.Second, zk.WithLogger(log.NewZkLogger()))
fmt.Println("zk addr=", config.Config.Zookeeper.ZkAddr)
if err != nil {
fmt.Println("zookeeper connect error:", err)
return nil, errs.Wrap(err)
} else {
if config.Config.Zookeeper.Username != "" && config.Config.Zookeeper.Password != "" {
Expand All @@ -89,7 +95,7 @@ func newZkClient() (*zk.Conn, error) {
}

func checkNewZkClient(hide bool) (*zk.Conn, error) {
for i := 0; i < 100; i++ {
for i := 0; i < MaxConnectTimes; i++ {
if i != 0 {
time.Sleep(3 * time.Second)
}
Expand All @@ -108,13 +114,15 @@ func checkNewZkClient(hide bool) (*zk.Conn, error) {
}

func checkGetCfg(conn *zk.Conn, hide bool) error {
for i := 0; i < 100; i++ {
for i := 0; i < MaxConnectTimes; i++ {
if i != 0 {
time.Sleep(3 * time.Second)
}
path := "/" + config.Config.Zookeeper.Schema + "/" + constant.OpenIMCommonConfigKey

zkConfig, _, err := conn.Get(path)
if err != nil {
fmt.Println("path =", path, "zkConfig is:", zkConfig)
errorPrint(fmt.Sprintf("! get zk config [%d] error: %v\n", i, err), hide)
continue
} else if len(zkConfig) == 0 {
Expand Down

0 comments on commit 53c4eff

Please sign in to comment.