Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
kafka-manager
提交
13641c00
K
kafka-manager
项目概览
DiDi
/
kafka-manager
8 个月 前同步成功
通知
58
Star
6372
Fork
1229
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kafka-manager
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
13641c00
编写于
4月 03, 2023
作者:
Z
ZQKC
提交者:
EricZeng
4月 04, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Bugfix]修复Broker元信息解析方法未调用导致接入集群失败的问题(#986)
上级
769c2c0f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
102 addition
and
27 deletion
+102
-27
km-persistence/src/main/java/com/xiaojukeji/know/streaming/km/persistence/kafka/zookeeper/service/impl/KafkaZKDAOImpl.java
...sistence/kafka/zookeeper/service/impl/KafkaZKDAOImpl.java
+3
-2
km-persistence/src/main/java/com/xiaojukeji/know/streaming/km/persistence/kafka/zookeeper/znode/brokers/BrokerMetadata.java
...istence/kafka/zookeeper/znode/brokers/BrokerMetadata.java
+99
-25
未找到文件。
km-persistence/src/main/java/com/xiaojukeji/know/streaming/km/persistence/kafka/zookeeper/service/impl/KafkaZKDAOImpl.java
浏览文件 @
13641c00
...
...
@@ -7,6 +7,7 @@ import com.xiaojukeji.know.streaming.km.common.bean.entity.broker.Broker;
import
com.xiaojukeji.know.streaming.km.common.bean.entity.kafkacontroller.KafkaController
;
import
com.xiaojukeji.know.streaming.km.common.bean.entity.result.ResultStatus
;
import
com.xiaojukeji.know.streaming.km.common.bean.entity.topic.Topic
;
import
com.xiaojukeji.know.streaming.km.common.constant.Constant
;
import
com.xiaojukeji.know.streaming.km.common.enums.topic.TopicTypeEnum
;
import
com.xiaojukeji.know.streaming.km.common.exception.AdminOperateException
;
import
com.xiaojukeji.know.streaming.km.common.exception.NotExistException
;
...
...
@@ -78,7 +79,7 @@ public class KafkaZKDAOImpl implements KafkaZKDAO {
try
{
BrokerMetadata
metadata
=
this
.
getData
(
kafkaZkClient
.
currentZooKeeper
(),
BrokerIdZNode
.
path
(
brokerId
),
false
,
BrokerMetadata
.
class
);
BrokerMetadata
.
parseAndUpdateBrokerMetadata
(
metadata
);
return
this
.
convert2Broker
(
clusterPhyId
,
brokerId
,
metadata
);
}
catch
(
KeeperException
ke
)
{
logger
.
error
(
"method=getBrokerMetadata||clusterPhyId={}||brokerId={}||errMsg=exception"
,
clusterPhyId
,
brokerId
,
ke
);
...
...
@@ -279,7 +280,7 @@ public class KafkaZKDAOImpl implements KafkaZKDAO {
metadata
.
setJmxPort
(
brokerMetadata
.
getJmxPort
());
metadata
.
setStartTimestamp
(
brokerMetadata
.
getTimestamp
());
metadata
.
setRack
(
brokerMetadata
.
getRack
());
metadata
.
setStatus
(
1
);
metadata
.
setStatus
(
Constant
.
ALIVE
);
metadata
.
setEndpointMap
(
brokerMetadata
.
getEndpointMap
());
return
metadata
;
}
...
...
km-persistence/src/main/java/com/xiaojukeji/know/streaming/km/persistence/kafka/zookeeper/znode/brokers/BrokerMetadata.java
浏览文件 @
13641c00
package
com.xiaojukeji.know.streaming.km.persistence.kafka.zookeeper.znode.brokers
;
import
com.
fasterxml.jackson.annotation.JsonIgnore
;
import
com.
alibaba.fastjson.JSON
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.xiaojukeji.know.streaming.km.common.bean.entity.common.IpPortData
;
import
com.xiaojukeji.know.streaming.km.common.constant.KafkaConstant
;
import
com.xiaojukeji.know.streaming.km.common.utils.ConvertUtil
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.HashMap
;
...
...
@@ -51,7 +50,6 @@ import java.util.Map;
* }
*
*/
@Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
BrokerMetadata
implements
Serializable
{
private
static
final
long
serialVersionUID
=
3918113492423375809L
;
...
...
@@ -74,34 +72,92 @@ public class BrokerMetadata implements Serializable {
private
String
rack
;
@JsonIgnore
public
String
getExternalHost
()
{
if
(!
endpointMap
.
containsKey
(
KafkaConstant
.
EXTERNAL_KEY
))
{
// external如果不存在,就返回host
return
host
;
public
List
<
String
>
getEndpoints
()
{
return
endpoints
;
}
public
void
setEndpoints
(
List
<
String
>
endpoints
)
{
this
.
endpoints
=
endpoints
;
}
public
Map
<
String
,
IpPortData
>
getEndpointMap
()
{
if
(
endpointMap
==
null
)
{
this
.
parseBrokerMetadata
();
}
return
endpointMap
.
get
(
KafkaConstant
.
EXTERNAL_KEY
).
getIp
();
return
endpointMap
;
}
public
String
getHost
()
{
if
(
endpointMap
==
null
)
{
this
.
parseBrokerMetadata
();
}
return
host
;
}
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
@JsonIgnore
public
String
getInternalHost
()
{
if
(!
endpointMap
.
containsKey
(
KafkaConstant
.
INTERNAL_KEY
))
{
// internal如果不存在,就返回host
return
host
;
public
Integer
getPort
()
{
if
(
endpointMap
==
null
)
{
this
.
parseBrokerMetadata
();
}
return
endpointMap
.
get
(
KafkaConstant
.
INTERNAL_KEY
).
getIp
();
return
port
;
}
public
static
void
parseAndUpdateBrokerMetadata
(
BrokerMetadata
brokerMetadata
)
{
brokerMetadata
.
setEndpointMap
(
new
HashMap
<>());
public
void
setPort
(
Integer
port
)
{
this
.
port
=
port
;
}
public
Integer
getJmxPort
()
{
return
jmxPort
;
}
public
void
setJmxPort
(
Integer
jmxPort
)
{
this
.
jmxPort
=
jmxPort
;
}
public
Integer
getVersion
()
{
return
version
;
}
if
(
brokerMetadata
.
getEndpoints
().
isEmpty
())
{
public
void
setVersion
(
Integer
version
)
{
this
.
version
=
version
;
}
public
Long
getTimestamp
()
{
return
timestamp
;
}
public
void
setTimestamp
(
Long
timestamp
)
{
this
.
timestamp
=
timestamp
;
}
public
String
getRack
()
{
return
rack
;
}
public
void
setRack
(
String
rack
)
{
this
.
rack
=
rack
;
}
private
synchronized
void
parseBrokerMetadata
()
{
if
(
this
.
endpointMap
!=
null
)
{
return
;
}
if
(
this
.
endpoints
==
null
||
this
.
endpoints
.
isEmpty
())
{
this
.
endpointMap
=
new
HashMap
<>(
0
);
return
;
}
Map
<
String
,
IpPortData
>
tempEndpointMap
=
new
HashMap
<>();
// example EXTERNAL://10.179.162.202:7092
for
(
String
endpoint:
brokerMetadata
.
getEndpoints
()
)
{
for
(
String
endpoint:
this
.
endpoints
)
{
int
idx1
=
endpoint
.
indexOf
(
"://"
);
int
idx2
=
endpoint
.
lastIndexOf
(
":"
);
if
(
idx1
==
-
1
||
idx2
==
-
1
||
idx1
==
idx2
)
{
...
...
@@ -111,19 +167,37 @@ public class BrokerMetadata implements Serializable {
String
brokerHost
=
endpoint
.
substring
(
idx1
+
"://"
.
length
(),
idx2
);
String
brokerPort
=
endpoint
.
substring
(
idx2
+
1
);
brokerMetadata
.
getEndpointMap
()
.
put
(
endpoint
.
substring
(
0
,
idx1
),
new
IpPortData
(
brokerHost
,
brokerPort
));
tempEndpointMap
.
put
(
endpoint
.
substring
(
0
,
idx1
),
new
IpPortData
(
brokerHost
,
brokerPort
));
if
(
KafkaConstant
.
INTERNAL_KEY
.
equals
(
endpoint
.
substring
(
0
,
idx1
)))
{
// 优先使用internal的地址进行展示
brokerMetadata
.
setHost
(
brokerHost
)
;
brokerMetadata
.
setPort
(
ConvertUtil
.
string2Integer
(
brokerPort
)
);
this
.
host
=
brokerHost
;
this
.
port
=
ConvertUtil
.
string2Integer
(
brokerPort
);
}
if
(
null
==
brokerMetadata
.
getHost
()
)
{
brokerMetadata
.
setHost
(
brokerHost
)
;
brokerMetadata
.
setPort
(
ConvertUtil
.
string2Integer
(
brokerPort
)
);
if
(
null
==
this
.
host
)
{
this
.
host
=
brokerHost
;
this
.
port
=
ConvertUtil
.
string2Integer
(
brokerPort
);
}
}
this
.
endpointMap
=
tempEndpointMap
;
}
public
static
void
main
(
String
[]
args
)
{
String
str
=
"{\t\n"
+
"\t\"listener_security_protocol_map\":{\"EXTERNAL\":\"SASL_PLAINTEXT\",\"INTERNAL\":\"SASL_PLAINTEXT\"},\n"
+
"\t\"endpoints\":[\"EXTERNAL://10.179.162.202:7092\",\"INTERNAL://10.179.162.202:7093\"],\n"
+
"\t\"jmx_port\":8099,\n"
+
"\t\"host\":null,\n"
+
"\t\"timestamp\":\"1627289710439\",\n"
+
"\t\"port\":-1,\n"
+
"\t\"version\":4\n"
+
"}"
;
BrokerMetadata
bm
=
JSON
.
parseObject
(
str
,
BrokerMetadata
.
class
);
System
.
out
.
println
(
bm
.
getHost
());
System
.
out
.
println
(
JSON
.
toJSON
(
bm
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录