You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/04/04 14:23:18 UTC

[GitHub] [rocketmq-client-go] francisoliverlee opened a new pull request, #798: add some admin tool apis

francisoliverlee opened a new pull request, #798:
URL: https://github.com/apache/rocketmq-client-go/pull/798

   add some admin tool api
   1. FetchAllTopicList
   2. GetBrokerClusterInfo
   3. FetchPublishMessageQueues


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq-client-go] ShannonDing commented on a diff in pull request #798: add some admin tool apis

Posted by GitBox <gi...@apache.org>.
ShannonDing commented on code in PR #798:
URL: https://github.com/apache/rocketmq-client-go/pull/798#discussion_r928667694


##########
internal/cluster.go:
##########
@@ -0,0 +1,119 @@
+package internal
+
+import (
+	"encoding/json"
+	"github.com/apache/rocketmq-client-go/v2/rlog"
+	"github.com/pkg/errors"
+	"github.com/tidwall/gjson"
+	"gopkg.in/yaml.v2"
+	"strings"
+)
+
+type ClusterInfo struct {
+	BrokerAddrTable  map[string]BrokerData `json:"brokerAddrTable"`
+	ClusterAddrTable map[string][]string   `json:"clusterAddrTable"`
+}
+
+type ClusterInfoMap struct {
+	BrokerAddrTable  map[string]string `json:"brokerAddrTable"`
+	ClusterAddrTable map[string]string `json:"clusterAddrTable"`
+}
+
+func ParseClusterInfo(jsonString string) (cluster *ClusterInfo, errResult error) {
+	var brokerAddrTableResult = gjson.Get(jsonString, "brokerAddrTable")
+	if !brokerAddrTableResult.Exists() {
+		return nil, errors.New("json key for brokerAddrTable not exist")
+	}
+	var clusterAddrTableResult = gjson.Get(jsonString, "clusterAddrTable")
+	if !clusterAddrTableResult.Exists() {
+		return nil, errors.New("json key for clusterAddrTable not exist")
+	}
+
+	var mapAndArray, err = ParseClusterAddrTable(clusterAddrTableResult.String())
+	if err != nil {
+		return nil, err
+	}
+
+	if len(mapAndArray) <= 0 {
+		return nil, nil
+	}
+
+	var clusterInfo = &ClusterInfo{}
+	clusterInfo.ClusterAddrTable, errResult = ParseClusterAddrTable(clusterAddrTableResult.String())
+	if errResult != nil {
+		return nil, errResult
+	}
+	clusterInfo.BrokerAddrTable, errResult = ParseBrokerAddrTable(brokerAddrTableResult.String(), clusterInfo.ClusterAddrTable)
+	if errResult != nil {
+		return nil, errResult
+	}
+	return clusterInfo, nil
+}
+
+// parse broker addr table
+// input like : {"broker-a":{"brokerAddrs":{0:"127.0.0.1:10911"},"brokerName":"broker-a","cluster":"DefaultCluster"}}
+// result.key = broker name, result.value=BrokerData
+func ParseBrokerAddrTable(jsonString string, clusterAndBrokerNamesMap map[string][]string) (map[string]BrokerData, error) {
+	var brokerMap = make(map[string]BrokerData)
+	for _, brokerNames := range clusterAndBrokerNamesMap {
+		for _, brokerName := range brokerNames {
+			var brokerInfo = gjson.Get(jsonString, brokerName).String()
+			var brokerAddrsString = gjson.Get(brokerInfo, "brokerAddrs").String() // {0:"x.x.x.x:10911"}
+			var brokerName1 = gjson.Get(brokerInfo, "brokerName").String()
+			var cluster = gjson.Get(brokerInfo, "cluster").String()
+
+			bd := BrokerData{
+				Cluster:         cluster,
+				BrokerName:      brokerName1,
+				BrokerAddresses: ParseBrokerAddrs(brokerAddrsString),
+			}
+
+			brokerMap[brokerName1] = bd
+		}
+	}
+
+	return brokerMap, nil
+}
+
+// input like : "{0:"127.0.0.1:10911"}" to map directly,can't parse, so get one by one
+// result.key = broker id , result.value = broker address and port
+func ParseBrokerAddrs1(jsonString string) map[int64]string {
+	var resultMap = make(map[int64]string)
+	var broker0Addr = gjson.Get(jsonString, "0")
+	if broker0Addr.Exists() {
+		resultMap[0] = broker0Addr.String()
+	}
+	var broker1Addr = gjson.Get(jsonString, "1")
+	if broker1Addr.Exists() {
+		resultMap[1] = broker1Addr.String()
+	}
+	return resultMap
+}
+
+// input like : "{0:"127.0.0.1:10911"}" to map directly,can't parse, so get one by one
+// result.key = broker id , result.value = broker address and port
+func ParseBrokerAddrs(jsonString string) map[int64]string {
+	// for yaml parse, do replace
+	jsonString = strings.ReplaceAll(jsonString, "0:", "0: ")

Review Comment:
   not support in go 1.12



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq-client-go] francisoliverlee closed pull request #798: add some admin tool apis

Posted by "francisoliverlee (via GitHub)" <gi...@apache.org>.
francisoliverlee closed pull request #798: add some admin tool apis
URL: https://github.com/apache/rocketmq-client-go/pull/798


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org