1
0
mirror of https://github.com/apache/dubbo.git synced 2024-10-23 07:04:37 +08:00

Fix native image compile failure and run binary package failure (#11066)

* fix native image failed

Signed-off-by: crazyhzm <crazyhzm@gmail.com>

* fix native image failed

Signed-off-by: crazyhzm <crazyhzm@gmail.com>

* remove import

Signed-off-by: crazyhzm <crazyhzm@gmail.com>

Signed-off-by: crazyhzm <crazyhzm@gmail.com>
This commit is contained in:
huazhongming 2022-12-05 11:56:37 +08:00 committed by GitHub
parent 93e60093c5
commit c5815be7b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 263 additions and 29 deletions

6
.gitignore vendored
View File

@ -48,3 +48,9 @@ dubbo-demo/dubbo-demo-triple/build/*
# global registry center
.tmp
dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/src/main/resources/META-INF/native-image
dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/src/main/generated
dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/src/main/resources/META-INF/native-image
dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/src/main/generated

View File

@ -743,7 +743,12 @@ public abstract class AbstractConfig implements Serializable {
&& ClassUtils.isTypeMatch(method.getParameterTypes()[0], value)
&& !isIgnoredAttribute(obj.getClass(), propertyName)) {
value = environment.resolvePlaceholders(value);
method.invoke(obj, ClassUtils.convertPrimitive(ScopeModelUtil.getFrameworkModel(getScopeModel()), method.getParameterTypes()[0], value));
if (StringUtils.hasText(value)) {
Object arg = ClassUtils.convertPrimitive(ScopeModelUtil.getFrameworkModel(getScopeModel()), method.getParameterTypes()[0], value);
if (arg != null) {
method.invoke(obj, arg);
}
}
}
} catch (Exception e) {
logger.info("Failed to override the property " + method.getName() + " in " +

View File

@ -85,6 +85,16 @@
<artifactId>dubbo-remoting-http</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-native</artifactId>
</dependency>
</dependencies>
<profiles>
@ -184,11 +194,20 @@
--initialize-at-run-time=io.netty.channel.unix.Limits
--initialize-at-run-time=io.netty.channel.unix.Socket
--initialize-at-run-time=io.netty.channel.ChannelHandlerMask
--initialize-at-run-time=io.netty.internal.tcnative.CertificateVerifier
--initialize-at-run-time=io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod
--initialize-at-run-time=io.netty.handler.ssl.ReferenceCountedOpenSslEngine
--initialize-at-run-time=io.netty.handler.ssl.OpenSslPrivateKeyMethod
--initialize-at-run-time=io.netty.internal.tcnative.CertificateVerifier
--initialize-at-run-time=io.netty.internal.tcnative.SSL
--initialize-at-run-time=io.netty.handler.ssl.OpenSslAsyncPrivateKeyMethod
--initialize-at-run-time=io.netty.internal.tcnative.SSLPrivateKeyMethod
--report-unsupported-elements-at-runtime
--allow-incomplete-classpath
--enable-url-protocols=http
-H:+ReportExceptionStackTraces
-H:+AllowJRTFileSystem
</buildArgs>
</configuration>
</plugin>

View File

@ -33,6 +33,7 @@ public class Application {
public static void main(String[] args) {
System.setProperty("dubbo.application.logger", "log4j");
System.setProperty("native", "true");
System.setProperty("dubbo.json-framework.prefer","fastjson");
if (isClassic(args)) {
runWithRefer();
} else {
@ -45,11 +46,8 @@ public class Application {
}
private static void runWithBootstrap() {
ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
reference.setInterface(DemoService.class);
reference.setGeneric("false");
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-api-consumer");
applicationConfig.setQosEnable(false);
applicationConfig.setCompiler("jdk");
@ -57,6 +55,10 @@ public class Application {
m.put("proxy", "jdk");
applicationConfig.setParameters(m);
ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
reference.setInterface(DemoService.class);
reference.setGeneric("false");
bootstrap.application(applicationConfig)
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.DUBBO, -1))

View File

@ -79,6 +79,17 @@
<artifactId>dubbo-remoting-http</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-native</artifactId>
</dependency>
</dependencies>
@ -180,11 +191,20 @@
--initialize-at-run-time=io.netty.channel.unix.Limits
--initialize-at-run-time=io.netty.channel.unix.Socket
--initialize-at-run-time=io.netty.channel.ChannelHandlerMask
--initialize-at-run-time=io.netty.internal.tcnative.CertificateVerifier
--initialize-at-run-time=io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod
--initialize-at-run-time=io.netty.handler.ssl.ReferenceCountedOpenSslEngine
--initialize-at-run-time=io.netty.handler.ssl.OpenSslPrivateKeyMethod
--initialize-at-run-time=io.netty.internal.tcnative.CertificateVerifier
--initialize-at-run-time=io.netty.internal.tcnative.SSL
--initialize-at-run-time=io.netty.handler.ssl.OpenSslAsyncPrivateKeyMethod
--initialize-at-run-time=io.netty.internal.tcnative.SSLPrivateKeyMethod
--report-unsupported-elements-at-runtime
--allow-incomplete-classpath
--enable-url-protocols=http
-H:+ReportExceptionStackTraces
-H:+AllowJRTFileSystem
</buildArgs>
</configuration>
</plugin>

View File

@ -24,6 +24,7 @@ import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apace.dubbo.graalvm.demo.DemoService;
import org.apache.dubbo.rpc.model.ModuleModel;
import java.util.HashMap;
import java.util.Map;
@ -34,6 +35,7 @@ public class Application {
public static void main(String[] args) throws Exception {
System.setProperty("dubbo.application.logger", "log4j");
System.setProperty("native", "true");
System.setProperty("dubbo.json-framework.prefer","fastjson");
if (isClassic(args)) {
startWithExport();
} else {
@ -47,32 +49,30 @@ public class Application {
}
private static void startWithBootstrap() {
ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-api-provider");
ApplicationConfig applicationConfig = new ApplicationConfig( "dubbo-demo-api-provider");
applicationConfig.setQosEnable(false);
applicationConfig.setCompiler("jdk");
Map<String, String> m = new HashMap<>(1);
m.put("proxy", "jdk");
applicationConfig.setParameters(m);
ServiceConfig<DemoService> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
bootstrap.application(applicationConfig)
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.DUBBO, -1))
.service(service)
.start()
.await();
System.out.println("dubbo service started");
}
private static void startWithExport() throws InterruptedException {
ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-api-provider");
applicationConfig.setQosEnable(false);
applicationConfig.setCompiler("jdk");
@ -81,6 +81,13 @@ public class Application {
m.put("proxy", "jdk");
applicationConfig.setParameters(m);
ModuleModel moduleModel = applicationConfig.getApplicationModel().newModule();
ServiceConfig<DemoService> service = new ServiceConfig<>(moduleModel);
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setApplication(applicationConfig);
service.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
service.export();

View File

@ -1107,7 +1107,7 @@
"methods": [
{
"name": "<init>",
"parameterTypes": []
"parameterTypes": ["org.apache.dubbo.rpc.model.ApplicationModel"]
}
]
},
@ -1332,7 +1332,13 @@
},
{
"name": "org.apache.dubbo.config.deploy.DefaultApplicationDeployer",
"allPublicConstructors": true
"allPublicConstructors": true,
"methods": [
{
"name": "<init>",
"parameterTypes": ["org.apache.dubbo.rpc.model.ApplicationModel"]
}
]
},
{
"name": "org.apache.dubbo.config.deploy.DefaultModuleDeployer",
@ -1481,7 +1487,7 @@
"methods": [
{
"name": "<init>",
"parameterTypes": []
"parameterTypes": ["org.apache.dubbo.rpc.model.ApplicationModel"]
}
]
},
@ -2062,7 +2068,13 @@
{
"name": "org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter",
"allPublicMethods": true,
"allPublicConstructors": true
"allPublicConstructors": true,
"methods": [
{
"name": "<init>",
"parameterTypes": []
}
]
},
{
"name": "org.apache.dubbo.rpc.cluster.filter.support.ZoneAwareFilter"
@ -2347,9 +2359,6 @@
{
"name": "org.apache.dubbo.rpc.filter.CompatibleFilter"
},
{
"name": "org.apache.dubbo.rpc.filter.ContextFilter"
},
{
"name": "org.apache.dubbo.rpc.filter.DeprecatedFilter"
},
@ -2671,5 +2680,97 @@
"parameterTypes": []
}
]
},
{
"name": "org.apache.dubbo.rpc.cluster.router.RouterSnapshotSwitcher",
"allPublicMethods": true,
"methods": [
{
"name": "<init>",
"parameterTypes": []
}
]
},
{
"name": "org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository",
"allPublicMethods": true,
"methods": [
{
"name": "<init>",
"parameterTypes": []
}
]
},
{
"name": "org.apache.dubbo.common.convert.ConverterUtil",
"allPublicMethods": true,
"methods": [
{
"name": "<init>",
"parameterTypes": ["org.apache.dubbo.rpc.model.FrameworkModel"]
}
]
},
{
"name": "org.apache.dubbo.rpc.cluster.router.mesh.route.MeshRuleManager",
"allPublicMethods": true,
"methods": [
{
"name": "<init>",
"parameterTypes": ["org.apache.dubbo.rpc.model.ModuleModel"]
}
]
},
{
"name": "org.apache.dubbo.config.context.ModuleConfigManager",
"allPublicMethods": true,
"methods": [
{
"name": "<init>",
"parameterTypes": ["org.apache.dubbo.rpc.model.ModuleModel"]
}
]
},
{
"name": "org.apache.dubbo.common.store.support.SimpleDataStore",
"allPublicMethods": true,
"methods": [
{
"name": "<init>",
"parameterTypes": []
}
]
},
{
"name": "org.apache.dubbo.common.metrics.collector.DefaultMetricsCollector",
"allPublicMethods": true,
"methods": [
{
"name": "<init>",
"parameterTypes": ["org.apache.dubbo.rpc.model.ApplicationModel"]
}
]
},
{
"name": "org.apache.dubbo.config.deploy.DefaultMetricsServiceExporter",
"allPublicMethods": true,
"methods": [
{
"name": "<init>",
"parameterTypes": []
}
]
},
{
"name": "com.alibaba.fastjson.JSON",
"allPublicMethods": true
},
{
"name": "java.util.Collections$UnmodifiableMap",
"allPublicMethods": true
},
{
"name": "java.util.Collections$UnmodifiableCollection",
"allPublicMethods": true
}
]

View File

@ -153,6 +153,12 @@
},
{
"pattern": "\\Qorg/apache/dubbo/remoting/exchange/Exchangers.class\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.store.DataStore\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.metrics.service.MetricsServiceExporter\\E"
}
]
},

View File

@ -0,0 +1,30 @@
/*
* 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.dubbo.common.metrics;
import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ScopeModelUtil;
public class MetricsReporterFactory$Adaptive implements org.apache.dubbo.common.metrics.MetricsReporterFactory {
public org.apache.dubbo.common.metrics.MetricsReporter createMetricsReporter(org.apache.dubbo.common.URL arg0) {
if (arg0 == null) throw new IllegalArgumentException("url == null");
org.apache.dubbo.common.URL url = arg0;
String extName = ( url.getProtocol() == null ? "nop" : url.getProtocol() );
if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.common.metrics.MetricsReporterFactory) name from url (" + url.toString() + ") use keys([protocol])");
ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), org.apache.dubbo.common.metrics.MetricsReporterFactory.class);
org.apache.dubbo.common.metrics.MetricsReporterFactory extension = (org.apache.dubbo.common.metrics.MetricsReporterFactory)scopeModel.getExtensionLoader(org.apache.dubbo.common.metrics.MetricsReporterFactory.class).getExtension(extName);
return extension.createMetricsReporter(arg0);
}
}

View File

@ -27,7 +27,7 @@ throw new UnsupportedOperationException("The method public abstract java.lang.St
public org.apache.dubbo.common.serialize.ObjectInput deserialize(org.apache.dubbo.common.URL arg0, java.io.InputStream arg1) throws java.io.IOException {
if (arg0 == null) throw new IllegalArgumentException("url == null");
org.apache.dubbo.common.URL url = arg0;
String extName = url.getParameter("serialization", "hessian2");
String extName = url.getParameter("serialization", "adaptive");
if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.common.serialize.Serialization) name from url (" + url.toString() + ") use keys([serialization])");
ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), org.apache.dubbo.common.serialize.Serialization.class);
org.apache.dubbo.common.serialize.Serialization extension = (org.apache.dubbo.common.serialize.Serialization)scopeModel.getExtensionLoader(org.apache.dubbo.common.serialize.Serialization.class).getExtension(extName);
@ -36,7 +36,7 @@ return extension.deserialize(arg0, arg1);
public org.apache.dubbo.common.serialize.ObjectOutput serialize(org.apache.dubbo.common.URL arg0, java.io.OutputStream arg1) throws java.io.IOException {
if (arg0 == null) throw new IllegalArgumentException("url == null");
org.apache.dubbo.common.URL url = arg0;
String extName = url.getParameter("serialization", "hessian2");
String extName = url.getParameter("serialization", "adaptive");
if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.common.serialize.Serialization) name from url (" + url.toString() + ") use keys([serialization])");
ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), org.apache.dubbo.common.serialize.Serialization.class);
org.apache.dubbo.common.serialize.Serialization extension = (org.apache.dubbo.common.serialize.Serialization)scopeModel.getExtensionLoader(org.apache.dubbo.common.serialize.Serialization.class).getExtension(extName);

View File

@ -28,6 +28,6 @@ org.apache.dubbo.metadata.report.MetadataReportFactory extension = (org.apache.d
return extension.getMetadataReport(arg0);
}
public void destroy() {
throw new UnsupportedOperationException("The method public abstract void org.apache.dubbo.metadata.report.MetadataReportFactory.destroy() of interface org.apache.dubbo.metadata.report.MetadataReportFactory is not adaptive method!");
throw new UnsupportedOperationException("The method public default void org.apache.dubbo.metadata.report.MetadataReportFactory.destroy() of interface org.apache.dubbo.metadata.report.MetadataReportFactory is not adaptive method!");
}
}

View File

@ -21,7 +21,7 @@ public class RegistryFactory$Adaptive implements org.apache.dubbo.registry.Regis
public org.apache.dubbo.registry.Registry getRegistry(org.apache.dubbo.common.URL arg0) {
if (arg0 == null) throw new IllegalArgumentException("url == null");
org.apache.dubbo.common.URL url = arg0;
String extName = ( url.getProtocol() == null ? "dubbo" : url.getProtocol() );
String extName = ( url.getProtocol() == null ? "adaptive" : url.getProtocol() );
if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.registry.RegistryFactory) name from url (" + url.toString() + ") use keys([protocol])");
ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), org.apache.dubbo.registry.RegistryFactory.class);
org.apache.dubbo.registry.RegistryFactory extension = (org.apache.dubbo.registry.RegistryFactory)scopeModel.getExtensionLoader(org.apache.dubbo.registry.RegistryFactory.class).getExtension(extName);

View File

@ -0,0 +1,39 @@
/*
* 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.dubbo.remoting.api.pu;
import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ScopeModelUtil;
public class PortUnificationTransporter$Adaptive implements org.apache.dubbo.remoting.api.pu.PortUnificationTransporter {
public org.apache.dubbo.remoting.Client connect(org.apache.dubbo.common.URL arg0, org.apache.dubbo.remoting.ChannelHandler arg1) throws org.apache.dubbo.remoting.RemotingException {
if (arg0 == null) throw new IllegalArgumentException("url == null");
org.apache.dubbo.common.URL url = arg0;
String extName = url.getParameter("client", url.getParameter("transporter", "netty4"));
if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter) name from url (" + url.toString() + ") use keys([client, transporter])");
ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class);
org.apache.dubbo.remoting.api.pu.PortUnificationTransporter extension = (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter)scopeModel.getExtensionLoader(org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class).getExtension(extName);
return extension.connect(arg0, arg1);
}
public org.apache.dubbo.remoting.api.pu.AbstractPortUnificationServer bind(org.apache.dubbo.common.URL arg0, org.apache.dubbo.remoting.ChannelHandler arg1) throws org.apache.dubbo.remoting.RemotingException {
if (arg0 == null) throw new IllegalArgumentException("url == null");
org.apache.dubbo.common.URL url = arg0;
String extName = url.getParameter("server", url.getParameter("transporter", "netty4"));
if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter) name from url (" + url.toString() + ") use keys([server, transporter])");
ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class);
org.apache.dubbo.remoting.api.pu.PortUnificationTransporter extension = (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter)scopeModel.getExtensionLoader(org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class).getExtension(extName);
return extension.bind(arg0, arg1);
}
}

View File

@ -15,17 +15,16 @@
* limitations under the License.
*/
package org.apache.dubbo.rpc.cluster.router.state;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ScopeModelUtil;
public class StateRouterFactory$Adaptive implements org.apache.dubbo.rpc.cluster.router.state.StateRouterFactory {
public <T> org.apache.dubbo.rpc.cluster.router.state.StateRouter<T> getRouter(Class<T> arg0, URL arg1) {
if (arg0 == null) throw new IllegalArgumentException("url == null");
public org.apache.dubbo.rpc.cluster.router.state.StateRouter getRouter(java.lang.Class arg0, org.apache.dubbo.common.URL arg1) {
if (arg1 == null) throw new IllegalArgumentException("url == null");
org.apache.dubbo.common.URL url = arg1;
String extName = ( url.getProtocol() == null ? "adaptive" : url.getProtocol() );
if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.rpc.cluster.router.state.StateRouterFactory) name from url (" + url.toString() + ") use keys([protocol])");
ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), org.apache.dubbo.rpc.cluster.router.state.StateRouterFactory.class);
org.apache.dubbo.rpc.cluster.router.state.StateRouterFactory extension = (org.apache.dubbo.rpc.cluster.router.state.StateRouterFactory)scopeModel.getExtensionLoader(org.apache.dubbo.rpc.cluster.router.state.StateRouterFactory.class).getExtension(extName);
return extension.getRouter(arg0,arg1);
return extension.getRouter(arg0, arg1);
}
}