This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new b85cb6a4b fix(topic): answer a topic create with the stored perm,
cluster and type (#6009)
b85cb6a4b is described below
commit b85cb6a4b243c8da9e93afe78b9609a55b1e9bbe
Author: 烤化の初雪 <[email protected]>
AuthorDate: Fri Nov 27 12:12:32 2026 +0800
fix(topic): answer a topic create with the stored perm, cluster and type
(#6009)
---
.../provider/apache/RocketMQAdminClientImpl.java | 28 ++++++++++++++++++++++
.../apache/RocketMQAdminClientImplTest.java | 25 +++++++++++++++++++
2 files changed, 53 insertions(+)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQAdminClientImpl.java
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQAdminClientImpl.java
index 97f04ae8b..1e5c400cc 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQAdminClientImpl.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQAdminClientImpl.java
@@ -370,6 +370,10 @@ public class RocketMQAdminClientImpl implements
AdminClient {
topic.setId(entity.getId());
topic.setWriteQueues(writeQueues);
topic.setReadQueues(readQueues);
+ // Report what was persisted: the create path applies defaults
the request may omit
+ // (perm RW, the resolved cluster, type NORMAL), so echoing
the request told every
+ // client the topic has no perm, no cluster and no type.
+ applyStoredTopicProjection(topic, entity);
return topic;
} catch (BusinessException e) {
recordAudit("CREATE_TOPIC", topicName, e.getMessage(),
"FAILED");
@@ -480,6 +484,7 @@ public class RocketMQAdminClientImpl implements AdminClient
{
// Report the persisted remark so a clear or an omitted
remark cannot be
// mistaken for a value the update did not write.
topic.setRemark(existing.getRemark());
+ applyStoredTopicProjection(topic, existing);
}
return topic;
} catch (BusinessException e) {
@@ -1661,6 +1666,29 @@ public class RocketMQAdminClientImpl implements
AdminClient {
return 6;
}
+ /**
+ * Copies the persisted columns an omitted request field would otherwise
hide from the response
+ * (the applied permission, the resolved cluster and the stored type).
+ */
+ private void applyStoredTopicProjection(TopicVO topic, RmqTopic entity) {
+ topic.setClusterId(entity.getClusterId());
+ topic.setPerm(fromRocketMQPerm(entity.getPerm()));
+ if (topic.getType() == null) {
+ topic.setType(parseStoredTopicType(entity.getTopicType()));
+ }
+ }
+
+ private static TopicType parseStoredTopicType(String type) {
+ if (!StringUtils.hasText(type)) {
+ return TopicType.NORMAL;
+ }
+ try {
+ return TopicType.valueOf(type);
+ } catch (IllegalArgumentException ignored) {
+ return TopicType.NORMAL;
+ }
+ }
+
private TopicPerm fromRocketMQPerm(Integer perm) {
if (perm != null && perm == 4) {
return TopicPerm.RO;
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQAdminClientImplTest.java
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQAdminClientImplTest.java
index 6f7f710c8..b8ba62a66 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQAdminClientImplTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQAdminClientImplTest.java
@@ -881,6 +881,31 @@ class RocketMQAdminClientImplTest {
}
}
+ @Test
+ void createTopicShouldAnswerWithTheStoredPermClusterAndTypeTest() throws
Exception {
+ TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new
MybatisConfiguration(), ""), RmqTopic.class);
+
when(adminExt.examineBrokerClusterInfo()).thenReturn(clusterInfoWithMaster());
+ when(topicMapper.selectOne(any())).thenReturn(null);
+ doNothing().when(adminExt).createAndUpdateTopicConfig(anyString(),
any(TopicConfig.class));
+ when(topicMapper.insert(any(RmqTopic.class))).thenAnswer(invocation ->
{
+ RmqTopic entity = invocation.getArgument(0);
+ entity.setId(9L);
+ return 1;
+ });
+
+ TopicVO topic = new TopicVO();
+ topic.setInstanceId("open-source-local");
+ topic.setName("orders");
+ // perm, clusterId and type are omitted: the provider applies RW / the
resolved cluster /
+ // NORMAL, and the response used to echo the request (all three null).
+ TopicVO created = adminClient.createTopic(topic);
+
+ assertThat(created.getId()).isEqualTo(9L);
+
assertThat(created.getPerm()).isEqualTo(org.apache.rocketmq.studio.common.domain.enums.TopicPerm.RW);
+ assertThat(created.getClusterId()).isNotBlank();
+
assertThat(created.getType()).isEqualTo(org.apache.rocketmq.studio.common.domain.enums.TopicType.NORMAL);
+ }
+
@Test
void
createTopicShouldOnlyWriteTargetClusterBrokersInMultiClusterTopology() throws
Exception {
TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new
MybatisConfiguration(), ""), RmqTopic.class);