Skip to content

Commit ca83c69

Browse files
Aias00eye-gu
andauthored
Fix RocketMQ logging e2e bootstrap startup (#6379)
* feat(api-doc): support request parameter parsing for RPC types (Dubbo/SOFA/TARS/gRPC) * fix license * fix checkstyle exclude generated source * fix checkstyle * fix review * Fix Protobuf field schema parsing logic * fix use common version * chore: trigger CI retest * Recover RocketMQ e2e bootstrap after delayed admin health The RocketMQ logging e2e script runs three sync modes in sequence. In the zookeeper round, Docker Compose can return before shenyu-admin has recovered from an initial unhealthy state, leaving shenyu-bootstrap created but not started. The script previously ignored both that compose failure and later healthcheck failures, so Maven reported the gateway as unavailable instead of recovering the service stack first. Constraint: CI builds the required latest Docker images before this script runs Rejected: Increase fixed sleeps only | it would hide the dependency failure without ensuring bootstrap starts Confidence: medium Scope-risk: narrow Directive: Keep bootstrap startup gated on admin health for this e2e script Tested: bash -n e2e-logging-rocketmq-compose.sh; e2e RocketMQ test-compile; RocketMQ logging plugin test-compile; docker compose config for zookeeper, RocketMQ, and HTTP example compose files; git diff --check Not-tested: Full Docker Compose e2e locally because CI-built apache/shenyu-admin:latest, apache/shenyu-bootstrap:latest, and shenyu-examples-http:latest images are not present --------- Co-authored-by: eye-gu <734164350@qq.com>
1 parent 75a23bb commit ca83c69

18 files changed

Lines changed: 2002 additions & 202 deletions

File tree

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
<maven-shade-plugin.version>3.5.1</maven-shade-plugin.version>
104104
<docker-maven-plugin.version>0.40.1</docker-maven-plugin.version>
105105
<maven-assembly-plugin.version>3.5.0</maven-assembly-plugin.version>
106+
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
107+
<os-maven-plugin.version>1.6.2</os-maven-plugin.version>
106108
<!-- maven plugin version end -->
107109

108110
<!-- dependency version start -->
@@ -735,7 +737,7 @@
735737
<configLocation>/script/shenyu_checkstyle.xml</configLocation>
736738
<headerLocation>/script/checkstyle-header.txt</headerLocation>
737739
<includeTestSourceDirectory>true</includeTestSourceDirectory>
738-
<excludes>**/transfer/**/*</excludes>
740+
<excludes>**/transfer/**/*,**/generated*/**/*</excludes>
739741
</configuration>
740742
<executions>
741743
<execution>

shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import org.apache.commons.collections4.CollectionUtils;
2323
import org.apache.commons.lang3.StringUtils;
24+
import java.util.Objects;
2425
import org.apache.shenyu.admin.disruptor.RegisterClientServerDisruptorPublisher;
2526
import org.apache.shenyu.admin.mapper.ApiMapper;
2627
import org.apache.shenyu.admin.mapper.TagMapper;
@@ -40,7 +41,6 @@
4041
import org.apache.shenyu.admin.model.vo.RuleVO;
4142
import org.apache.shenyu.admin.model.vo.TagVO;
4243
import org.apache.shenyu.admin.service.ApiService;
43-
import org.apache.shenyu.common.enums.ApiSourceEnum;
4444
import org.apache.shenyu.common.enums.PluginEnum;
4545
import org.apache.shenyu.common.utils.JsonUtils;
4646
import org.apache.shenyu.common.utils.ListUtil;
@@ -243,12 +243,14 @@ public ApiVO findById(final String id) {
243243
tagVOs = tagDOS.stream().map(TagVO::buildTagVO).collect(Collectors.toList());
244244
}
245245
ApiVO apiVO = ApiVO.buildApiVO(item, tagVOs);
246-
if (apiVO.getApiSource().equals(ApiSourceEnum.SWAGGER.getValue())) {
246+
if (StringUtils.isNotBlank(apiVO.getDocument())) {
247247
DocItem docItem = JsonUtils.jsonToObject(apiVO.getDocument(), DocItem.class);
248-
apiVO.setRequestHeaders(docItem.getRequestHeaders());
249-
apiVO.setRequestParameters(docItem.getRequestParameters());
250-
apiVO.setResponseParameters(docItem.getResponseParameters());
251-
apiVO.setBizCustomCodeList(docItem.getBizCodeList());
248+
if (Objects.nonNull(docItem)) {
249+
apiVO.setRequestHeaders(docItem.getRequestHeaders());
250+
apiVO.setRequestParameters(docItem.getRequestParameters());
251+
apiVO.setResponseParameters(docItem.getResponseParameters());
252+
apiVO.setBizCustomCodeList(docItem.getBizCodeList());
253+
}
252254
}
253255
return apiVO;
254256

shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ApiServiceTest.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,60 @@ public void testFindById() {
108108
assertNotNull(byId);
109109
}
110110

111+
@Test
112+
public void testFindByIdWithDocumentNotBlank() {
113+
String id = "456";
114+
ApiDTO apiDTO = new ApiDTO();
115+
apiDTO.setId(id);
116+
apiDTO.setContextPath("string");
117+
apiDTO.setApiPath("string");
118+
apiDTO.setHttpMethod(0);
119+
apiDTO.setConsume("string");
120+
apiDTO.setProduce("string");
121+
apiDTO.setVersion("string");
122+
apiDTO.setRpcType("string");
123+
apiDTO.setState(0);
124+
apiDTO.setApiOwner("string");
125+
apiDTO.setApiDesc("string");
126+
apiDTO.setApiSource(0);
127+
apiDTO.setDocument("{\"module\":\"test-module\",\"requestParameters\":[],\"responseParameters\":[]}");
128+
ApiDO apiDO = ApiDO.buildApiDO(apiDTO);
129+
Timestamp now = Timestamp.valueOf(LocalDateTime.now());
130+
apiDO.setDateCreated(now);
131+
apiDO.setDateUpdated(now);
132+
given(this.apiMapper.selectByPrimaryKey(eq(id))).willReturn(apiDO);
133+
ApiVO byId = this.apiService.findById(id);
134+
assertNotNull(byId);
135+
assertNotNull(byId.getRequestParameters());
136+
assertNotNull(byId.getResponseParameters());
137+
}
138+
139+
@Test
140+
public void testFindByIdWithBlankDocument() {
141+
String id = "789";
142+
ApiDTO apiDTO = new ApiDTO();
143+
apiDTO.setId(id);
144+
apiDTO.setContextPath("string");
145+
apiDTO.setApiPath("string");
146+
apiDTO.setHttpMethod(0);
147+
apiDTO.setConsume("string");
148+
apiDTO.setProduce("string");
149+
apiDTO.setVersion("string");
150+
apiDTO.setRpcType("string");
151+
apiDTO.setState(0);
152+
apiDTO.setApiOwner("string");
153+
apiDTO.setApiDesc("string");
154+
apiDTO.setApiSource(0);
155+
apiDTO.setDocument("");
156+
ApiDO apiDO = ApiDO.buildApiDO(apiDTO);
157+
Timestamp now = Timestamp.valueOf(LocalDateTime.now());
158+
apiDO.setDateCreated(now);
159+
apiDO.setDateUpdated(now);
160+
given(this.apiMapper.selectByPrimaryKey(eq(id))).willReturn(apiDO);
161+
ApiVO byId = this.apiService.findById(id);
162+
assertNotNull(byId);
163+
}
164+
111165
@Test
112166
public void testListByPage() {
113167
PageParameter pageParameter = new PageParameter();

shenyu-client/shenyu-client-core/pom.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,55 @@
8181
<artifactId>spring-boot-starter-tomcat</artifactId>
8282
<scope>test</scope>
8383
</dependency>
84+
<dependency>
85+
<groupId>com.google.protobuf</groupId>
86+
<artifactId>protobuf-java</artifactId>
87+
<scope>test</scope>
88+
</dependency>
89+
<dependency>
90+
<groupId>io.grpc</groupId>
91+
<artifactId>grpc-stub</artifactId>
92+
<scope>test</scope>
93+
</dependency>
8494
</dependencies>
95+
96+
<build>
97+
<extensions>
98+
<extension>
99+
<groupId>kr.motd.maven</groupId>
100+
<artifactId>os-maven-plugin</artifactId>
101+
<version>${os-maven-plugin.version}</version>
102+
</extension>
103+
</extensions>
104+
<plugins>
105+
<plugin>
106+
<groupId>org.xolstice.maven.plugins</groupId>
107+
<artifactId>protobuf-maven-plugin</artifactId>
108+
<version>${protobuf-maven-plugin.version}</version>
109+
<extensions>true</extensions>
110+
<configuration>
111+
<protocArtifact>com.google.protobuf:protoc:${protobuf-java.version}:exe:${os.detected.classifier}</protocArtifact>
112+
<protoSourceRoot>${project.basedir}/src/test/proto</protoSourceRoot>
113+
<outputDirectory>${project.build.directory}/generated-test-sources/protobuf/java</outputDirectory>
114+
<clearOutputDirectory>false</clearOutputDirectory>
115+
</configuration>
116+
<executions>
117+
<execution>
118+
<goals>
119+
<goal>test-compile</goal>
120+
</goals>
121+
</execution>
122+
</executions>
123+
</plugin>
124+
<plugin>
125+
<groupId>org.apache.maven.plugins</groupId>
126+
<artifactId>maven-checkstyle-plugin</artifactId>
127+
<configuration>
128+
<testSourceDirectories>
129+
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
130+
</testSourceDirectories>
131+
</configuration>
132+
</plugin>
133+
</plugins>
134+
</build>
85135
</project>

shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.apache.shenyu.client.core.client;
1919

20-
import com.google.common.collect.ImmutableMap;
2120
import com.google.common.collect.Lists;
2221
import org.apache.commons.collections4.MapUtils;
2322
import org.apache.commons.lang3.StringUtils;
@@ -213,7 +212,7 @@ private List<ApiDocRegisterDTO> buildApiDocDTO(final Object bean, final Method m
213212
String apiPath = pathJoin(contextPath, superPath, value);
214213
ApiHttpMethodEnum[] value3 = sextet.getValue3();
215214
for (ApiHttpMethodEnum apiHttpMethodEnum : value3) {
216-
String documentJson = buildDocumentJson(pairs.getRight(), apiPath, method);
215+
String documentJson = buildDocumentJson(pairs.getRight(), apiPath, method, sextet.getValue4());
217216
String extJson = buildExtJson(method);
218217
ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
219218
.consume(sextet.getValue1())
@@ -258,15 +257,8 @@ protected ApiDocRegisterDTO.ApiExt customApiDocExt(final ApiDocRegisterDTO.ApiEx
258257
return ext;
259258
}
260259

261-
private String buildDocumentJson(final List<String> tags, final String path, final Method method) {
262-
Map<String, Object> documentMap = ImmutableMap.<String, Object>builder()
263-
.put("tags", tags)
264-
.put("operationId", path)
265-
.put("parameters", OpenApiUtils.generateDocumentParameters(path, method))
266-
.put("responses", OpenApiUtils.generateDocumentResponse(path))
267-
.put("responseType", Collections.singletonList(OpenApiUtils.parseReturnType(method)))
268-
.build();
269-
return GsonUtils.getInstance().toJson(documentMap);
260+
private String buildDocumentJson(final List<String> tags, final String path, final Method method, final RpcTypeEnum rpcTypeEnum) {
261+
return OpenApiUtils.buildDocumentJson(tags, path, method, rpcTypeEnum);
270262
}
271263

272264
protected abstract Sextet<String[], String, String, ApiHttpMethodEnum[], RpcTypeEnum, String> buildApiDocSextet(Method method, Annotation annotation, Map<String, T> beans);

shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/AbstractApiDocRegistrar.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.apache.shenyu.client.core.register.registrar;
1919

20-
import com.google.common.collect.ImmutableMap;
2120
import com.google.common.collect.Lists;
2221
import org.apache.commons.lang3.StringUtils;
2322
import org.apache.shenyu.client.apidocs.annotations.ApiDoc;
@@ -42,9 +41,7 @@
4241
import java.lang.reflect.Method;
4342
import java.util.ArrayList;
4443
import java.util.Arrays;
45-
import java.util.Collections;
4644
import java.util.List;
47-
import java.util.Map;
4845

4946
public abstract class AbstractApiDocRegistrar extends AbstractApiRegistrar<ApiDocRegisterDTO> {
5047

@@ -128,14 +125,7 @@ protected List<ApiDocRegisterDTO> parse(final ApiBean.ApiDefinition apiDefinitio
128125
}
129126

130127
private String buildDocumentJson(final List<String> tags, final String path, final Method method) {
131-
Map<String, Object> documentMap = ImmutableMap.<String, Object>builder()
132-
.put("tags", tags)
133-
.put("operationId", path)
134-
.put("parameters", OpenApiUtils.generateDocumentParameters(path, method))
135-
.put("responses", OpenApiUtils.generateDocumentResponse(path))
136-
.put("responseType", Collections.singletonList(OpenApiUtils.parseReturnType(method)))
137-
.build();
138-
return GsonUtils.getInstance().toJson(documentMap);
128+
return OpenApiUtils.buildDocumentJson(tags, path, method, rpcTypeEnum);
139129
}
140130

141131
private String buildExtJson(final ApiBean.ApiDefinition apiDefinition) {

shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/ApiDocRegistrarImpl.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.apache.shenyu.client.core.register.registrar;
1919

20-
import com.google.common.collect.ImmutableMap;
2120
import org.apache.commons.lang3.StringUtils;
2221
import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
2322
import org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher;
@@ -38,7 +37,6 @@
3837
import java.util.Arrays;
3938
import java.util.Collections;
4039
import java.util.List;
41-
import java.util.Map;
4240
import java.util.Objects;
4341
import java.util.stream.Collectors;
4442

@@ -132,14 +130,9 @@ private String getDocument(final ApiBean.ApiDefinition api) {
132130
return document;
133131
}
134132
final String path = getPath(api);
135-
final Map<String, Object> documentMap = ImmutableMap.<String, Object>builder()
136-
.put("tags", buildTags(api))
137-
.put("operationId", path)
138-
.put("parameters", OpenApiUtils.generateDocumentParameters(path, api.getApiMethod()))
139-
.put("responses", OpenApiUtils.generateDocumentResponse(path))
140-
.put("responseType", Collections.singletonList(OpenApiUtils.parseReturnType(api.getApiMethod())))
141-
.build();
142-
return GsonUtils.getInstance().toJson(documentMap);
133+
final String rpcType = getRpcType(api);
134+
RpcTypeEnum rpcTypeEnum = RpcTypeEnum.acquireByName(rpcType);
135+
return OpenApiUtils.buildDocumentJson(buildTags(api), path, api.getApiMethod(), rpcTypeEnum);
143136
}
144137

145138
private String getRpcType(final ApiBean.ApiDefinition api) {

0 commit comments

Comments
 (0)