|
|
|
@ -24,6 +24,7 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import com.tencent.cloud.common.util.JacksonUtils;
|
|
|
|
|
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
|
|
|
|
|
import com.tencent.cloud.polaris.contract.config.PolarisContractProperties;
|
|
|
|
|
import com.tencent.polaris.api.core.ProviderAPI;
|
|
|
|
|
import com.tencent.polaris.api.plugin.server.InterfaceDescriptor;
|
|
|
|
|
import com.tencent.polaris.api.plugin.server.ReportServiceContractRequest;
|
|
|
|
@ -53,25 +54,26 @@ public class PolarisContractReporter implements ApplicationListener<ApplicationR
|
|
|
|
|
private final Logger LOG = LoggerFactory.getLogger(PolarisContractReporter.class);
|
|
|
|
|
private final ServiceModelToSwagger2Mapper swagger2Mapper;
|
|
|
|
|
private final DocumentationCache documentationCache;
|
|
|
|
|
private final String groupName;
|
|
|
|
|
private final PolarisContractProperties polarisContractProperties;
|
|
|
|
|
|
|
|
|
|
private final ProviderAPI providerAPI;
|
|
|
|
|
|
|
|
|
|
private final PolarisDiscoveryProperties polarisDiscoveryProperties;
|
|
|
|
|
|
|
|
|
|
public PolarisContractReporter(DocumentationCache documentationCache, ServiceModelToSwagger2Mapper swagger2Mapper,
|
|
|
|
|
String groupName, ProviderAPI providerAPI, PolarisDiscoveryProperties polarisDiscoveryProperties) {
|
|
|
|
|
PolarisContractProperties polarisContractProperties, ProviderAPI providerAPI, PolarisDiscoveryProperties polarisDiscoveryProperties) {
|
|
|
|
|
this.swagger2Mapper = swagger2Mapper;
|
|
|
|
|
this.documentationCache = documentationCache;
|
|
|
|
|
this.groupName = groupName;
|
|
|
|
|
this.polarisContractProperties = polarisContractProperties;
|
|
|
|
|
this.providerAPI = providerAPI;
|
|
|
|
|
this.polarisDiscoveryProperties = polarisDiscoveryProperties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onApplicationEvent(@NonNull ApplicationReadyEvent applicationReadyEvent) {
|
|
|
|
|
if (polarisContractProperties.isReportEnabled()) {
|
|
|
|
|
try {
|
|
|
|
|
Documentation documentation = documentationCache.documentationByGroup(groupName);
|
|
|
|
|
Documentation documentation = documentationCache.documentationByGroup(polarisContractProperties.getGroup());
|
|
|
|
|
Swagger swagger = swagger2Mapper.mapDocumentation(documentation);
|
|
|
|
|
if (swagger != null) {
|
|
|
|
|
ReportServiceContractRequest request = new ReportServiceContractRequest();
|
|
|
|
@ -93,13 +95,14 @@ public class PolarisContractReporter implements ApplicationListener<ApplicationR
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LOG.warn("Swagger or json is null, documentationCache keys:{}, group:{}", documentationCache.all()
|
|
|
|
|
.keySet(), groupName);
|
|
|
|
|
.keySet(), polarisContractProperties.getGroup());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Throwable t) {
|
|
|
|
|
LOG.error("Report contract failed.", t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<InterfaceDescriptor> getInterfaceDescriptorFromSwagger(Swagger swagger) {
|
|
|
|
|
List<InterfaceDescriptor> interfaceDescriptorList = new ArrayList<>();
|
|
|
|
|