Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,28 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<guava.version>29.0-jre</guava.version>
<commons-digester.version>2.1</commons-digester.version>
<commons-lang.version>2.6</commons-lang.version>
<commons-io.version>2.4</commons-io.version>
<commons-cli.version>1.2</commons-cli.version>
<commons-collections.version>3.2.2</commons-collections.version>
<rocketmq.version>5.1.0</rocketmq.version>
<rocketmq.version>5.3.3</rocketmq.version>
<surefire.version>2.19.1</surefire.version>
<aspectj.version>1.9.6</aspectj.version>
<lombok.version>1.18.22</lombok.version>
<main.basedir>${basedir}/../..</main.basedir>
<docker.image.prefix>apacherocketmq</docker.image.prefix>
<spring.boot.version>2.6.0</spring.boot.version>
<spring.boot.version>3.4.5</spring.boot.version>
<mockito-inline.version>3.3.3</mockito-inline.version>
<jaxb-api.version>2.3.1</jaxb-api.version>
<jakarta.xml.bind-api.version>4.0.0</jakarta.xml.bind-api.version>
<commons-pool2.version>2.4.3</commons-pool2.version>
<easyexcel.version>2.2.10</easyexcel.version>
<asm.version>4.2</asm.version>
<junit.version>4.12</junit.version>
<snakeyaml.version>1.32</snakeyaml.version>
<snakeyaml.version>2.0</snakeyaml.version>
<cglib.version>2.2.2</cglib.version>
<joor.version>0.9.6</joor.version>
<bcpkix-jdk15on.version>1.68</bcpkix-jdk15on.version>
Expand All @@ -115,6 +114,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -235,9 +240,9 @@
<version>${bcpkix-jdk15on.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>${jakarta.xml.bind-api.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down Expand Up @@ -282,7 +287,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>3.11.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
Expand All @@ -296,19 +301,22 @@
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>repackage</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
</plugin>
<!-- Use dockerfile-maven instead, https://github.com/spotify/dockerfile-maven -->
<plugin>
Expand Down Expand Up @@ -384,9 +392,9 @@
<version>4.3.0</version>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>${jakarta.xml.bind-api.version}</version>
</dependency>
</dependencies>
</plugin>
Expand Down Expand Up @@ -418,7 +426,7 @@
<artifactId>frontend-maven-plugin</artifactId>
<version>1.11.3</version>
<configuration>
<workingDirectory>frontend</workingDirectory>
<workingDirectory>frontend-new</workingDirectory>
<installDirectory>target</installDirectory>
</configuration>
<executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

package org.apache.rocketmq.dashboard.admin;

import org.apache.rocketmq.tools.admin.MQAdminExt;

@FunctionalInterface
public interface MQAdminExtCallback<T> {
T doInMQAdminExt(MQAdminExt mqAdminExt) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.rocketmq.dashboard.admin;

import java.util.concurrent.atomic.AtomicLong;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.acl.common.AclClientRPCHook;
Expand All @@ -26,6 +25,8 @@
import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
import org.apache.rocketmq.tools.admin.MQAdminExt;

import java.util.concurrent.atomic.AtomicLong;

@Slf4j
public class MQAdminFactory {
private RMQConfigure rmqConfigure;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* 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.
*/
package org.apache.rocketmq.dashboard.admin;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.apache.rocketmq.client.ClientConfig;
import org.apache.rocketmq.dashboard.config.RMQConfigure;
import org.apache.rocketmq.tools.admin.MQAdminExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@Component
@Slf4j
public class UserMQAdminPoolManager {


private final ConcurrentMap<String/* userAk */, GenericObjectPool<MQAdminExt>> userPools = new ConcurrentHashMap<>();

private final ClientConfig baseClientConfig;

@Autowired
public UserMQAdminPoolManager(RMQConfigure rmqConfigure) {
this.baseClientConfig = new ClientConfig();
this.baseClientConfig.setNamesrvAddr(rmqConfigure.getNamesrvAddr());
this.baseClientConfig.setClientCallbackExecutorThreads(rmqConfigure.getClientCallbackExecutorThreads());
this.baseClientConfig.setVipChannelEnabled(Boolean.parseBoolean(rmqConfigure.getIsVIPChannel()));
this.baseClientConfig.setUseTLS(rmqConfigure.isUseTLS());
log.info("UserMQAdminPoolManager initialized with baseClientConfig for NameServer: {}", rmqConfigure.getNamesrvAddr());
}


public MQAdminExt borrowMQAdminExt(String userAk, String userSk) throws Exception {
GenericObjectPool<MQAdminExt> userPool = userPools.get(userAk);

if (userPool == null) {
log.info("Creating new MQAdminExt pool for user: {}", userAk);
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
poolConfig.setMaxIdle(1);
poolConfig.setMinIdle(0);
poolConfig.setTestWhileIdle(true);
poolConfig.setTimeBetweenEvictionRunsMillis(20000);
poolConfig.setMaxWaitMillis(10000);

UserSpecificMQAdminPooledObjectFactory factory =
new UserSpecificMQAdminPooledObjectFactory(baseClientConfig, userAk, userSk);

GenericObjectPool<MQAdminExt> newUserPool = new GenericObjectPool<>(factory, poolConfig);

GenericObjectPool<MQAdminExt> existingPool = userPools.putIfAbsent(userAk, newUserPool);
if (existingPool != null) {
log.warn("Another thread concurrently created MQAdminExt pool for user {}. Shutting down redundant pool.", userAk);
newUserPool.close();
userPool = existingPool;
} else {
userPool = newUserPool;
log.info("Successfully created and registered MQAdminExt pool for user: {}", userAk);
}
}

return userPool.borrowObject();
}

public void returnMQAdminExt(String userAk, MQAdminExt mqAdminExt) {
GenericObjectPool<MQAdminExt> userPool = userPools.get(userAk);
if (userPool != null) {
try {
userPool.returnObject(mqAdminExt);
log.debug("Returned MQAdminExt object ({}) to pool for user: {}", mqAdminExt, userAk);
} catch (Exception e) {
log.error("Failed to return MQAdminExt object ({}) for user {}: {}", mqAdminExt, userAk, e.getMessage(), e);
if (mqAdminExt != null) {
try {
mqAdminExt.shutdown();
} catch (Exception se) {
log.warn("Error shutting down MQAdminExt after failed return: {}", se.getMessage());
}
}
}
} else {
log.warn("Attempted to return MQAdminExt for non-existent user pool: {}. Shutting down the object directly.", userAk);
if (mqAdminExt != null) {
try {
mqAdminExt.shutdown();
} catch (Exception se) {
log.warn("Error shutting down MQAdminExt for non-existent pool: {}", se.getMessage());
}
}
}
}

public void shutdownUserPool(String userAk) {
GenericObjectPool<MQAdminExt> userPool = userPools.remove(userAk);
if (userPool != null) {
userPool.close();
log.info("Shutdown and removed MQAdminExt pool for user: {}", userAk);
} else {
log.warn("Attempted to shut down non-existent user pool: {}", userAk);
}
}

@PreDestroy
public void shutdownAllPools() {
log.info("Shutting down all MQAdminExt user pools...");
userPools.forEach((userAk, pool) -> {
pool.close();
log.info("Shutdown MQAdminExt pool for user: {}", userAk);
});
userPools.clear();
log.info("All MQAdminExt user pools have been shut down.");
}
}
Loading