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
25 changes: 14 additions & 11 deletions trpc-admin/trpc-admin-default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,20 @@
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-netty4</artifactId>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</exclusion>
<exclusion>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</exclusion>
</exclusions>
<artifactId>resteasy-undertow</artifactId>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-activation</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
Expand All @@ -76,5 +74,10 @@
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

/**
* Command Operation Management
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import com.tencent.trpc.admin.dto.ConfigOverviewDto;
import com.tencent.trpc.core.admin.spi.Admin;
import com.tencent.trpc.core.common.ConfigManager;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/cmds")
public class ConfigAdmin implements Admin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import com.tencent.trpc.admin.dto.VersionDto;
import com.tencent.trpc.core.admin.spi.Admin;
import com.tencent.trpc.core.common.Version;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/version")
public class FrameOverviewAdmin implements Admin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import org.apache.commons.lang3.EnumUtils;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import org.apache.commons.collections4.CollectionUtils;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/cmds/workerpool")
public class WorkerPoolAdmin implements Admin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
import com.tencent.trpc.core.stat.MetricStatFactory;
import java.util.Collection;
import java.util.List;
import javax.ws.rs.Path;
import io.undertow.Undertow;
import jakarta.ws.rs.Path;
import org.jboss.resteasy.core.ResteasyDeploymentImpl;
import org.jboss.resteasy.plugins.server.netty.NettyJaxrsServer;
import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer;
import org.jboss.resteasy.spi.Registry;

/**
Expand All @@ -36,9 +37,9 @@ public class DefaultAdminServiceImpl implements AdminService {

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAdminServiceImpl.class);
/**
* netty jar server
* undertow jaxrs server
*/
private NettyJaxrsServer adminRestServer;
private UndertowJaxrsServer adminRestServer;
private ServerConfig serverConfig;
/**
* Lifecycle class
Expand Down Expand Up @@ -70,19 +71,23 @@ protected class LifecycleObj extends LifecycleBase {
@Override
protected void initInternal() throws Exception {
super.initInternal();
adminRestServer = new NettyJaxrsServer();
AdminConfig adminConfig = serverConfig.getAdminConfig();
adminRestServer.setHostname(adminConfig.getAdminIp());
adminRestServer.setPort(adminConfig.getAdminPort());
adminRestServer.setDeployment(new ResteasyDeploymentImpl());
adminRestServer = new UndertowJaxrsServer();
}

@Override
protected void startInternal() {
try {
super.startInternal();
adminRestServer.start();
Registry registry = adminRestServer.getDeployment().getRegistry();
AdminConfig adminConfig = serverConfig.getAdminConfig();
adminRestServer.start(Undertow.builder()
.addHttpListener(adminConfig.getAdminPort(), adminConfig.getAdminIp()));
ResteasyDeploymentImpl deployment = new ResteasyDeploymentImpl();
deployment.start();
adminRestServer.deploy(adminRestServer.undertowDeployment(deployment)
.setContextPath("/")
.setDeploymentName("AdminService")
.setClassLoader(DefaultAdminServiceImpl.class.getClassLoader()));
Registry registry = deployment.getRegistry();
ExtensionLoader<Admin> extensionLoader = ExtensionLoader.getExtensionLoader(Admin.class);
Collection<ExtensionClass<Admin>> extensionClasses = extensionLoader.getAllExtensionClass();
for (ExtensionClass<Admin> extensionClass : extensionClasses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,35 @@
import com.tencent.trpc.core.common.config.AdminConfig;
import com.tencent.trpc.core.utils.JsonUtils;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@ActiveProfiles("admin")
@SpringBootTest(classes = TrpcServerApplication.class)
public class AdminIntegrationTest {

private String adminAddress;

@Before
@BeforeEach
public void before() {
final AdminConfig adminConfig = ConfigManager.getInstance().getServerConfig().getAdminConfig();
adminAddress = new StringBuffer(adminConfig.getAdminIp()).append(":").append(adminConfig.getAdminPort())
.toString();
System.out.println("adminAddress:" + adminAddress);
}

@Test
public void testVersion() {
String[] cmd = {"curl", "http://" + adminAddress + "/version"};
String versionInfo = ShellUtils.execute(cmd);
VersionDto versionDto = JsonUtils.fromJson(versionInfo, VersionDto.class);
Assert.assertEquals(Version.version(), versionDto.getVersion());
Assertions.assertEquals(Version.version(), versionDto.getVersion());
}

@Test
Expand All @@ -61,19 +62,19 @@ public void testUpdateLoglevel() {
String[] set2DebugCmd = {"curl", "-XPUT", "http://" + adminAddress + "/cmds/loglevel/ROOT", "-d",
"value=DEBUG"};
String set2DebugResult = ShellUtils.execute(set2DebugCmd);
System.out.println(set2DebugResult);
System.out.println("set2DebugResult: " + set2DebugResult);
final LoggerLevelRevisedDto levelDebugRevisedDto = JsonUtils.fromJson(set2DebugResult,
LoggerLevelRevisedDto.class);

Assert.assertEquals(CommonDto.SUCCESS, levelDebugRevisedDto.getErrorcode());
Assert.assertEquals("DEBUG", (levelDebugRevisedDto.getLevel()));
Assertions.assertEquals(CommonDto.SUCCESS, levelDebugRevisedDto.getErrorcode());
Assertions.assertEquals("DEBUG", (levelDebugRevisedDto.getLevel()));

//查看修改后的结果
String[] logLevelCmd = {"curl", "http://" + adminAddress + "/cmds/loglevel"};
String logLevelInfo = ShellUtils.execute(logLevelCmd);
LoggerLevelDto dto = JsonUtils.fromJson(logLevelInfo, LoggerLevelDto.class);
Assert.assertEquals(CommonDto.SUCCESS, dto.getErrorcode());
Assert.assertTrue(dto.getLogger().stream()
Assertions.assertEquals(CommonDto.SUCCESS, dto.getErrorcode());
Assertions.assertTrue(dto.getLogger().stream()
.anyMatch(log -> "ROOT".equals(log.getLoggerName()) && "DEBUG".equals(log.getLevel())));

//修改
Expand All @@ -82,63 +83,64 @@ public void testUpdateLoglevel() {
LoggerLevelRevisedDto levelInfoRevisedDto = JsonUtils.fromJson(set2InfoResult,
LoggerLevelRevisedDto.class);

Assert.assertEquals(CommonDto.SUCCESS, levelInfoRevisedDto.getErrorcode());
Assert.assertEquals("INFO", levelInfoRevisedDto.getLevel());
Assertions.assertEquals(CommonDto.SUCCESS, levelInfoRevisedDto.getErrorcode());
Assertions.assertEquals("INFO", levelInfoRevisedDto.getLevel());
}

@Test
public void testLogLevel() {
String[] cmd = {"curl", "http://" + adminAddress + "/cmds/loglevel"};
String logLevelInfo = ShellUtils.execute(cmd);
System.out.println(logLevelInfo);
LoggerLevelDto dto = JsonUtils.fromJson(logLevelInfo, LoggerLevelDto.class);
Assert.assertEquals(CommonDto.SUCCESS, dto.getErrorcode());
Assert.assertTrue(dto.getLogger().stream()
Assertions.assertEquals(CommonDto.SUCCESS, dto.getErrorcode());
Assertions.assertTrue(dto.getLogger().stream()
.anyMatch(log -> "ROOT".equals(log.getLoggerName()) && "INFO".equals(log.getLevel())));
}

@Test
public void testWorkerPool() {
String[] cmd = {"curl", "http://" + adminAddress + "/cmds/workerpool/info"};
String workPoolInfo = ShellUtils.execute(cmd);
Assert.assertTrue("{\"errorcode\":\"0\",\"message\":\"\",\"workerPoolInfo\":{}}".equals(workPoolInfo));
Assertions.assertTrue("{\"errorcode\":\"0\",\"message\":\"\",\"workerPoolInfo\":{}}".equals(workPoolInfo));
}

@Test
public void testConfig() {
String[] cmd = {"curl", "http://" + adminAddress + "/cmds/config"};
String configInfo = ShellUtils.execute(cmd);
ConfigOverviewDto configOverviewDto = JsonUtils.fromJson(configInfo, ConfigOverviewDto.class);
Assert.assertEquals(CommonDto.SUCCESS, configOverviewDto.getErrorcode());
Assert.assertEquals("integration-test-admin", configOverviewDto.getContent().getServer().getApp());
Assertions.assertEquals(CommonDto.SUCCESS, configOverviewDto.getErrorcode());
Assertions.assertEquals("integration-test-admin", configOverviewDto.getContent().getServer().getApp());
}

@Test
public void testStatRpc() {
String[] cmd = {"curl", "http://" + adminAddress + "/cmds/stats/rpc"};
String rpcStats = ShellUtils.execute(cmd);
RpcStatsDto rpcStatsDto = JsonUtils.fromJson(rpcStats, RpcStatsDto.class);
Assert.assertEquals(CommonDto.SUCCESS, rpcStatsDto.getErrorcode());
Assert.assertEquals(Version.version(), rpcStatsDto.getRpcVersion());
Assert.assertEquals(0, rpcStatsDto.getRpcServiceCount().intValue());
Assertions.assertEquals(CommonDto.SUCCESS, rpcStatsDto.getErrorcode());
Assertions.assertEquals(Version.version(), rpcStatsDto.getRpcVersion());
Assertions.assertEquals(0, rpcStatsDto.getRpcServiceCount().intValue());
}

@Test
public void testCustomAdmin() {
String[] cmd = {"curl", "http://" + adminAddress + "/cmds/test"};
String testInfo = ShellUtils.execute(cmd);
TestDto rpcStatsDto = JsonUtils.fromJson(testInfo, TestDto.class);
Assert.assertEquals(CommonDto.SUCCESS, rpcStatsDto.getErrorcode());
Assert.assertEquals("hello world!", rpcStatsDto.getTestResult());
Assertions.assertEquals(CommonDto.SUCCESS, rpcStatsDto.getErrorcode());
Assertions.assertEquals("hello world!", rpcStatsDto.getTestResult());
}

@Test
public void testCmds() {
String[] cmd = {"curl", "http://" + adminAddress + "/cmds"};
String cmdResult = ShellUtils.execute(cmd);
CommandDto commandDto = JsonUtils.fromJson(cmdResult, CommandDto.class);
Assert.assertEquals(CommonDto.SUCCESS, commandDto.getErrorcode());
Assertions.assertEquals(CommonDto.SUCCESS, commandDto.getErrorcode());
List<String> commands = commandDto.getCmds();
Assert.assertTrue(commands.contains("/cmds/loglevel") && commands.contains("/cmds/loglevel/{logname}")
Assertions.assertTrue(commands.contains("/cmds/loglevel") && commands.contains("/cmds/loglevel/{logname}")
&& commands.contains("/version") && commands.contains("/cmds") && commands.contains("/cmds/config")
&& commands.contains("/cmds/stats/rpc") && commands.contains("/cmds/workerpool/info")
&& commands.contains("/cmds/test"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
import com.tencent.trpc.core.exception.LifecycleException;
import com.tencent.trpc.core.extension.ExtensionClass;
import com.tencent.trpc.core.extension.ExtensionLoader;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AdminTest {

private static final String LOCAL_HOST = "127.0.0.1";

@After
@AfterEach
public void after() {
ExtensionLoader.destroyAllPlugin();
}
Expand Down Expand Up @@ -57,7 +57,7 @@ public void testStartFail() {
adminService2.stop();
}
}
Assert.assertTrue(exception != null && exception instanceof LifecycleException);
Assertions.assertTrue(exception != null && exception instanceof LifecycleException);
}

private AdminService getAdminService(String ip, int adminPort) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import com.tencent.trpc.admin.impl.CommandAdmin;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class CommandAdminTest {

Expand All @@ -27,9 +27,9 @@ public void test() {
CommandDto commandDto = commandAdmin.getCommands();
commandDto.toString();
commandDto.setCmds(commandDto.getCmds());
Assert.assertTrue(CommonDto.SUCCESS.equals(commandDto.getErrorcode()));
Assert.assertTrue(StringUtils.isEmpty(commandDto.getMessage()));
Assert.assertTrue(CollectionUtils.isNotEmpty(commandDto.getCmds()));
Assertions.assertTrue(CommonDto.SUCCESS.equals(commandDto.getErrorcode()));
Assertions.assertTrue(StringUtils.isEmpty(commandDto.getMessage()));
Assertions.assertTrue(CollectionUtils.isNotEmpty(commandDto.getCmds()));
}

}
Loading
Loading