Feature/cpm client autoconfig
- [ ] I have read the CONTRIBUTING.md guidelines.
- [ ] I have registered the PR changes.
Ⅰ. Describe what this PR did
Automated Configuration
1.Enabling Connection Pool Monitoring
1)Modification
seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataProperties.java
Purpose: Add a configuration field to enable or disable the connection pool monitoring feature.
/**
* enable connection pool metrics
*/
private boolean enableConnectionPoolMetrics = false;
spring/src/main/java/org/apache/seata/spring/annotation/GlobalTransactionScanner.java
Purpose: Configure whether to enable the connection pool monitoring feature and initialize the client HTTP port.
// init enableConnectionPoolMetrics / httpPort
try {
if (applicationContext != null) {
String enableConnectionPoolMetricsStr =
applicationContext.getEnvironment().getProperty("seata.enableConnectionPoolMetrics");
if (enableConnectionPoolMetricsStr != null
&& !enableConnectionPoolMetricsStr.trim().isEmpty()) {
boolean enableConnectionPoolMetrics = Boolean.parseBoolean(enableConnectionPoolMetricsStr);
RmNettyRemotingClient.getInstance().setEnableConnectionPoolMetrics(enableConnectionPoolMetrics);
}
String portStr = applicationContext.getEnvironment().getProperty("server.port");
if (portStr != null && !portStr.trim().isEmpty()) {
try {
int port = Integer.parseInt(portStr.trim());
RmNettyRemotingClient.getInstance().setHttpPort(port);
} catch (NumberFormatException e) {
LOGGER.debug("Invalid server.port in Spring Environment: {}", portStr);
}
}
}
} catch (Throwable t) {
LOGGER.debug("Failed to resolve server.port from Spring Environment", t);
}
2.Loading Client Endpoint Configuration
1)Modification
seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/SeataSpringFenceAutoConfiguration.java
Purpose: Load the client-side endpoint (ClientConnectionPoolController), which provides the ability to update connection pool configurations.
@Bean
@ConditionalOnProperty(name = "seata.enableConnectionPoolMetrics", havingValue = "true")
@ConditionalOnClass(name = "org.springframework.web.bind.annotation.RestController")
public ClientConnectionPoolController connectionPoolController() {
return new ClientConnectionPoolController();
}
Same-Port Hosting
namingserver/src/main/java/org/apache/seata/namingserver/controller/SpaController.java
Purpose:: Add a new front-end entry controller SpaController, forwarding GET /cpmto forward:/cpm/index.html
namingserver/pom.xml
Purpose:
- Use
frontend-maven-pluginto runnpm ciandnpm run buildwithin the front-end directory at build time. - Use
maven-resources-pluginto copycpm/build/*intonamingservertarget/classes/static/cpm/, so it can be packaged into the executable JAR.
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.12.1</version>
<configuration>
<workingDirectory>${project.basedir}/../console/src/main/resources/static/cpm</workingDirectory>
</configuration>
<executions>
<execution>
<id>install-node</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v18.18.0</nodeVersion>
</configuration>
</execution>
<execution>
<id>npm-ci</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>ci --no-audit --no-fund</arguments>
</configuration>
</execution>
<execution>
<id>npm-build</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-cpm-build</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/static/cpm</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/../console/src/main/resources/static/cpm/build</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>