Skip to content

Commit

Permalink
remove unnecessary brackets & revert em-dashboard-pom.xml & move Rock…
Browse files Browse the repository at this point in the history
…etmqProperties to core.dto
  • Loading branch information
scwlkq committed Mar 22, 2024
1 parent f02261f commit 4280c6f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ public ResponseEntity<Object> preflight() {
}

@CrossOrigin
@GetMapping()
@GetMapping
public Result<List<TopicProperties>> getList() {
List<TopicProperties> topicList = topicCore.getTopics();
return Result.success(topicList);
}

@CrossOrigin
@PostMapping()
@PostMapping
public Result<Object> create(@RequestBody CreateTopicRequest createTopicRequest) {
String topicName = createTopicRequest.getName();
topicCore.createTopic(topicName);
return Result.success();
}

@CrossOrigin
@DeleteMapping()
@DeleteMapping
public Result<Object> delete(@RequestBody DeleteTopicRequest deleteTopicRequest) {
String topicName = deleteTopicRequest.getName();
topicCore.deleteTopic(topicName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package org.apache.eventmesh.dashboard.core.store;

import org.apache.eventmesh.dashboard.common.properties.RocketmqProperties;
import org.apache.eventmesh.dashboard.core.function.SDK.SDKManager;
import org.apache.eventmesh.dashboard.core.function.SDK.SDKTypeEnum;
import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateSDKConfig;
import org.apache.eventmesh.dashboard.service.dto.RocketmqProperties;
import org.apache.eventmesh.dashboard.service.dto.TopicProperties;
import org.apache.eventmesh.dashboard.service.store.TopicCore;

Expand Down Expand Up @@ -65,18 +65,18 @@ public RocketmqTopicCore(RocketmqProperties rocketmqProperties) {

@Override
public Boolean createTopic(String topicName) {
String brokerUrl = rocketmqProperties.getBrokerUrl();
String namesrvAddr = rocketmqProperties.getNamesrvAddr();
long requestTimeoutMillis = rocketmqProperties.getRequestTimeoutMillis();
int readQueueNums = rocketmqProperties.getReadQueueNums();
int writeQueueNums = rocketmqProperties.getReadQueueNums();
if (StringUtils.isEmpty(brokerUrl)) {
if (StringUtils.isEmpty(namesrvAddr)) {
log.info("RocketmqTopicCore-createTopic failed, missing brokerUrl");
return Boolean.FALSE;
}

RemotingClient remotingClient = (RemotingClient) SDKManager.getInstance().getClient(SDKTypeEnum.STORAGE_ROCKETMQ_REMOTING, brokerUrl);
RemotingClient remotingClient = (RemotingClient) SDKManager.getInstance().getClient(SDKTypeEnum.STORAGE_ROCKETMQ_REMOTING, namesrvAddr);
if (remotingClient == null) {
remotingClient = createRemotingClient(brokerUrl);
remotingClient = createRemotingClient(namesrvAddr);
}
try {
CreateTopicRequestHeader requestHeader = new CreateTopicRequestHeader();
Expand All @@ -87,7 +87,7 @@ public Boolean createTopic(String topicName) {
requestHeader.setPerm(PermName.PERM_READ | PermName.PERM_WRITE);

RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_AND_CREATE_TOPIC, requestHeader);
RemotingCommand response = remotingClient.invokeSync(brokerUrl, request, requestTimeoutMillis);
RemotingCommand response = remotingClient.invokeSync(namesrvAddr, request, requestTimeoutMillis);
log.info("Rocketmq create topic result:" + response.toString());
return response.getCode() == 0;
} catch (Exception e) {
Expand All @@ -98,21 +98,21 @@ public Boolean createTopic(String topicName) {

@Override
public List<TopicProperties> getTopics() {
String brokerUrl = rocketmqProperties.getBrokerUrl();
String namesrvAddr = rocketmqProperties.getNamesrvAddr();
long requestTimeoutMillis = rocketmqProperties.getRequestTimeoutMillis();
if (StringUtils.isEmpty(brokerUrl)) {
if (StringUtils.isEmpty(namesrvAddr)) {
log.info("RocketmqTopicCore-getTopics failed, missing brokerUrl");
return new ArrayList<>();
}

RemotingClient remotingClient = (RemotingClient) SDKManager.getInstance().getClient(SDKTypeEnum.STORAGE_ROCKETMQ_REMOTING, brokerUrl);
RemotingClient remotingClient = (RemotingClient) SDKManager.getInstance().getClient(SDKTypeEnum.STORAGE_ROCKETMQ_REMOTING, namesrvAddr);
if (remotingClient == null) {
remotingClient = createRemotingClient(brokerUrl);
remotingClient = createRemotingClient(namesrvAddr);
}
List<TopicConfig> topicConfigList = new ArrayList<>();
try {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, (CommandCustomHeader) null);
RemotingCommand response = remotingClient.invokeSync(brokerUrl, request, requestTimeoutMillis);
RemotingCommand response = remotingClient.invokeSync(namesrvAddr, request, requestTimeoutMillis);
TopicConfigSerializeWrapper allTopicConfig = TopicConfigSerializeWrapper.decode(response.getBody(), TopicConfigSerializeWrapper.class);
ConcurrentMap<String, TopicConfig> topicConfigTable = allTopicConfig.getTopicConfigTable();
topicConfigList = new ArrayList<>(topicConfigTable.values());
Expand All @@ -125,22 +125,22 @@ public List<TopicProperties> getTopics() {

@Override
public Boolean deleteTopic(String topicName) {
String brokerUrl = rocketmqProperties.getBrokerUrl();
String namesrvAddr = rocketmqProperties.getNamesrvAddr();
long requestTimeoutMillis = rocketmqProperties.getRequestTimeoutMillis();
if (StringUtils.isEmpty(brokerUrl)) {
if (StringUtils.isEmpty(namesrvAddr)) {
log.info("RocketmqTopicCore-deleteTopic failed, missing brokerUrl");
return Boolean.FALSE;
}

RemotingClient remotingClient = (RemotingClient) SDKManager.getInstance().getClient(SDKTypeEnum.STORAGE_ROCKETMQ_REMOTING, brokerUrl);
RemotingClient remotingClient = (RemotingClient) SDKManager.getInstance().getClient(SDKTypeEnum.STORAGE_ROCKETMQ_REMOTING, namesrvAddr);
if (remotingClient == null) {
remotingClient = createRemotingClient(brokerUrl);
remotingClient = createRemotingClient(namesrvAddr);
}
try {
DeleteTopicRequestHeader deleteTopicRequestHeader = new DeleteTopicRequestHeader();
deleteTopicRequestHeader.setTopic(topicName);
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.DELETE_TOPIC_IN_BROKER, null);
RemotingCommand response = remotingClient.invokeSync(brokerUrl, request, requestTimeoutMillis);
RemotingCommand response = remotingClient.invokeSync(namesrvAddr, request, requestTimeoutMillis);

log.info("Rocketmq delete topic result:" + response.toString());
return response.getCode() == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.common.properties;
package org.apache.eventmesh.dashboard.service.dto;

import lombok.Data;

Expand All @@ -26,8 +26,6 @@ public class RocketmqProperties {

private String clusterName;

private String brokerUrl;

private int writeQueueNums = 8;

private int readQueueNums = 8;
Expand Down
4 changes: 0 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
Expand Down

0 comments on commit 4280c6f

Please sign in to comment.