This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.1 by this push:
new 638e11ad2f Add Support For Istio-Agent (#10567)
638e11ad2f is described below
commit 638e11ad2fcde79a304f7f6525b1e15827aa0849
Author: chenyanlann <[email protected]>
AuthorDate: Fri Sep 9 11:23:53 2022 +0800
Add Support For Istio-Agent (#10567)
---
dubbo-dependencies-bom/pom.xml | 2 +-
.../dubbo/registry/xds/util/PilotExchanger.java | 1 -
.../apache/dubbo/registry/xds/util/XdsChannel.java | 48 +++++++++++++++-------
.../xds/util/bootstrap/BootstrapInfoImpl.java | 2 +-
.../registry/xds/util/bootstrap/Bootstrapper.java | 8 ++--
.../xds/util/bootstrap/BootstrapperImpl.java | 2 +-
.../xds/util/bootstrap/ServerInfoImpl.java | 2 +-
.../xds/util/bootstrap/BootstrapperTest.java | 11 +++++
8 files changed, 52 insertions(+), 24 deletions(-)
diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml
index 2070914081..34d116c82f 100644
--- a/dubbo-dependencies-bom/pom.xml
+++ b/dubbo-dependencies-bom/pom.xml
@@ -139,7 +139,7 @@
<tomcat_embed_version>8.5.69</tomcat_embed_version>
<jetcd_version>0.5.3</jetcd_version>
<nacos_version>2.1.0</nacos_version>
- <grpc.version>1.44.0</grpc.version>
+ <grpc.version>1.47.0</grpc.version>
<grpc_contrib_verdion>0.8.1</grpc_contrib_verdion>
<jprotoc_version>1.2.1</jprotoc_version>
<!-- Log libs -->
diff --git
a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/PilotExchanger.java
b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/PilotExchanger.java
index 15295fef90..dbb30e7586 100644
---
a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/PilotExchanger.java
+++
b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/PilotExchanger.java
@@ -67,7 +67,6 @@ public class PilotExchanger {
if (CollectionUtils.isNotEmpty(listenerResult.getRouteConfigNames())) {
this.observeRouteRequest.set(createRouteObserve());
}
-
// Observe LDS updated
ldsProtocol.observeListeners((newListener) -> {
// update local cache
diff --git
a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/XdsChannel.java
b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/XdsChannel.java
index 4f4d8c759c..9019d38018 100644
--- a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/XdsChannel.java
+++ b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/XdsChannel.java
@@ -16,24 +16,27 @@
*/
package org.apache.dubbo.registry.xds.util;
+import io.grpc.ManagedChannel;
+import io.grpc.netty.shaded.io.netty.channel.epoll.EpollDomainSocketChannel;
+import io.grpc.netty.shaded.io.netty.channel.epoll.EpollEventLoopGroup;
+import io.grpc.netty.shaded.io.netty.channel.unix.DomainSocketAddress;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.url.component.URLAddress;
import org.apache.dubbo.registry.xds.XdsCertificateSigner;
-
import io.envoyproxy.envoy.service.discovery.v3.AggregatedDiscoveryServiceGrpc;
import io.envoyproxy.envoy.service.discovery.v3.DeltaDiscoveryRequest;
import io.envoyproxy.envoy.service.discovery.v3.DeltaDiscoveryResponse;
import io.envoyproxy.envoy.service.discovery.v3.DiscoveryRequest;
import io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse;
-import io.grpc.ManagedChannel;
import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext;
import
io.grpc.netty.shaded.io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.grpc.stub.StreamObserver;
-
-import javax.net.ssl.SSLException;
+import org.apache.dubbo.registry.xds.util.bootstrap.Bootstrapper;
+import org.apache.dubbo.registry.xds.util.bootstrap.BootstrapperImpl;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
@@ -41,22 +44,37 @@ public class XdsChannel {
private static final Logger logger =
LoggerFactory.getLogger(XdsChannel.class);
+ private static final String USE_AGENT = "use-agent";
+
private final ManagedChannel channel;
protected XdsChannel(URL url) {
ManagedChannel managedChannel = null;
try {
- XdsCertificateSigner signer =
url.getOrDefaultApplicationModel().getExtensionLoader(XdsCertificateSigner.class)
- .getExtension(url.getParameter("signer", "istio"));
- XdsCertificateSigner.CertPair certPair = signer.GenerateCert(url);
- SslContext context = GrpcSslContexts.forClient()
- .trustManager(InsecureTrustManagerFactory.INSTANCE)
- .keyManager(new
ByteArrayInputStream(certPair.getPublicKey().getBytes(StandardCharsets.UTF_8)),
- new
ByteArrayInputStream(certPair.getPrivateKey().getBytes(StandardCharsets.UTF_8)))
- .build();
- managedChannel = NettyChannelBuilder.forAddress(url.getHost(),
url.getPort()).sslContext(context)
- .build();
- } catch (SSLException e) {
+ if(!url.getParameter(USE_AGENT,false)) {
+ XdsCertificateSigner signer =
url.getOrDefaultApplicationModel().getExtensionLoader(XdsCertificateSigner.class)
+ .getExtension(url.getParameter("signer", "istio"));
+ XdsCertificateSigner.CertPair certPair =
signer.GenerateCert(url);
+ SslContext context = GrpcSslContexts.forClient()
+ .trustManager(InsecureTrustManagerFactory.INSTANCE)
+ .keyManager(new
ByteArrayInputStream(certPair.getPublicKey().getBytes(StandardCharsets.UTF_8)),
+ new
ByteArrayInputStream(certPair.getPrivateKey().getBytes(StandardCharsets.UTF_8)))
+ .build();
+ managedChannel = NettyChannelBuilder.forAddress(url.getHost(),
url.getPort()).sslContext(context)
+ .build();
+ }
+ else {
+ BootstrapperImpl bootstrapper = new BootstrapperImpl();
+ Bootstrapper.BootstrapInfo bootstrapInfo =
bootstrapper.bootstrap();
+ URLAddress address
=URLAddress.parse(bootstrapInfo.servers().get(0).target(),null, false);
+ EpollEventLoopGroup elg = new EpollEventLoopGroup();
+ managedChannel = NettyChannelBuilder.forAddress(new
DomainSocketAddress("/" + address.getPath()))
+ .eventLoopGroup(elg)
+ .channelType(EpollDomainSocketChannel.class)
+ .usePlaintext()
+ .build();
+ }
+ } catch (Exception e) {
logger.error("Error occurred when creating gRPC channel to control
panel.", e);
}
channel = managedChannel;
diff --git
a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapInfoImpl.java
b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapInfoImpl.java
index 4946166265..a4e4451891 100644
---
a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapInfoImpl.java
+++
b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapInfoImpl.java
@@ -23,7 +23,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-final class BootstrapInfoImpl extends Bootstrapper.BootstrapInfo {
+public final class BootstrapInfoImpl extends Bootstrapper.BootstrapInfo {
private final List<Bootstrapper.ServerInfo> servers;
diff --git
a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/Bootstrapper.java
b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/Bootstrapper.java
index 68473be5af..5e018c45a6 100644
---
a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/Bootstrapper.java
+++
b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/Bootstrapper.java
@@ -32,8 +32,8 @@ public abstract class Bootstrapper {
throw new UnsupportedOperationException();
}
- abstract static class ServerInfo {
- abstract String target();
+ public abstract static class ServerInfo {
+ public abstract String target();
abstract ChannelCredentials channelCredentials();
@@ -50,9 +50,9 @@ public abstract class Bootstrapper {
}
public abstract static class BootstrapInfo {
- abstract List<ServerInfo> servers();
+ public abstract List<ServerInfo> servers();
- abstract Map<String, CertificateProviderInfo> certProviders();
+ public abstract Map<String, CertificateProviderInfo> certProviders();
public abstract Node node();
diff --git
a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapperImpl.java
b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapperImpl.java
index ce6490bc3c..d9e299763f 100644
---
a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapperImpl.java
+++
b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapperImpl.java
@@ -34,7 +34,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-class BootstrapperImpl extends Bootstrapper {
+public class BootstrapperImpl extends Bootstrapper {
static final String BOOTSTRAP_PATH_SYS_ENV_VAR = "GRPC_XDS_BOOTSTRAP";
static String bootstrapPathFromEnvVar =
System.getenv(BOOTSTRAP_PATH_SYS_ENV_VAR);
diff --git
a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/ServerInfoImpl.java
b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/ServerInfoImpl.java
index de0402e965..001008a455 100644
---
a/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/ServerInfoImpl.java
+++
b/dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/bootstrap/ServerInfoImpl.java
@@ -36,7 +36,7 @@ final class ServerInfoImpl extends Bootstrapper.ServerInfo {
}
@Override
- String target() {
+ public String target() {
return target;
}
diff --git
a/dubbo-xds/src/test/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapperTest.java
b/dubbo-xds/src/test/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapperTest.java
index e1a871d1e2..180e260ca5 100644
---
a/dubbo-xds/src/test/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapperTest.java
+++
b/dubbo-xds/src/test/java/org/apache/dubbo/registry/xds/util/bootstrap/BootstrapperTest.java
@@ -16,6 +16,9 @@
*/
package org.apache.dubbo.registry.xds.util.bootstrap;
+import io.grpc.netty.shaded.io.netty.channel.unix.DomainSocketAddress;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.url.component.URLAddress;
import org.apache.dubbo.registry.xds.XdsInitializationException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -125,6 +128,14 @@ public class BootstrapperTest {
Bootstrapper.BootstrapInfo info = bootstrapper.bootstrap();
List<Bootstrapper.ServerInfo> serverInfoList = info.servers();
Assertions.assertEquals(serverInfoList.get(0).target(),
"unix:///etc/istio/proxy/XDS");
+ URLAddress address
=URLAddress.parse(serverInfoList.get(0).target(),null, false);
+ Assertions.assertEquals(new
DomainSocketAddress(address.getPath()).path(), "etc/istio/proxy/XDS");
+ }
+
+ @Test
+ public void testUrl() {
+ URL url =
URL.valueOf("dubbo://127.0.0.1:23456/TestService?useAgent=true");
+ Assertions.assertTrue(url.getParameter("useAgent", false));
}
private static BootstrapperImpl.FileReader createFileReader(final String
rawData) {