You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2021/11/25 10:35:25 UTC
[ignite-3] branch main updated: IGNITE-15132 Reuse Netty infrastructure from network module in REST module (#469)
This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new c60b8f5 IGNITE-15132 Reuse Netty infrastructure from network module in REST module (#469)
c60b8f5 is described below
commit c60b8f57fdbc79ceb4f32ba6793d84202a8ce414
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Thu Nov 25 13:35:20 2021 +0300
IGNITE-15132 Reuse Netty infrastructure from network module in REST module (#469)
---
modules/rest/pom.xml | 5 +++
.../java/org/apache/ignite/rest/RestModule.java | 47 ++++++----------------
.../org/apache/ignite/internal/app/IgniteImpl.java | 2 +-
3 files changed, 18 insertions(+), 36 deletions(-)
diff --git a/modules/rest/pom.xml b/modules/rest/pom.xml
index cb665f2..f4942bc 100644
--- a/modules/rest/pom.xml
+++ b/modules/rest/pom.xml
@@ -43,6 +43,11 @@
<artifactId>ignite-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.ignite</groupId>
+ <artifactId>ignite-network</artifactId>
+ </dependency>
+
<!-- 3rd party dependencies -->
<dependency>
<groupId>com.google.code.gson</groupId>
diff --git a/modules/rest/src/main/java/org/apache/ignite/rest/RestModule.java b/modules/rest/src/main/java/org/apache/ignite/rest/RestModule.java
index 159fa72..076c209 100644
--- a/modules/rest/src/main/java/org/apache/ignite/rest/RestModule.java
+++ b/modules/rest/src/main/java/org/apache/ignite/rest/RestModule.java
@@ -24,11 +24,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelFutureListener;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import java.net.BindException;
@@ -41,6 +36,7 @@ import org.apache.ignite.internal.configuration.ConfigurationRegistry;
import org.apache.ignite.internal.manager.IgniteComponent;
import org.apache.ignite.lang.IgniteException;
import org.apache.ignite.lang.IgniteLogger;
+import org.apache.ignite.network.NettyBootstrapFactory;
import org.apache.ignite.rest.netty.RestApiHttpRequest;
import org.apache.ignite.rest.netty.RestApiHttpResponse;
import org.apache.ignite.rest.netty.RestApiInitializer;
@@ -79,23 +75,29 @@ public class RestModule implements IgniteComponent {
/** Presentation of cluster configuration. */
private final ConfigurationPresentation<String> clusterCfgPresentation;
+ /** Netty bootstrap factory. */
+ private final NettyBootstrapFactory bootstrapFactory;
+
/** Netty channel. */
private volatile Channel channel;
/**
* Creates a new instance of REST module.
*
- * @param nodeCfgMgr Node configuration manager.
- * @param clusterCfgMgr Cluster configuration manager.
+ * @param nodeCfgMgr Node configuration manager.
+ * @param clusterCfgMgr Cluster configuration manager.
+ * @param bootstrapFactory Netty bootstrap factory.
*/
public RestModule(
ConfigurationManager nodeCfgMgr,
- ConfigurationManager clusterCfgMgr
- ) {
+ ConfigurationManager clusterCfgMgr,
+ NettyBootstrapFactory bootstrapFactory) {
nodeCfgRegistry = nodeCfgMgr.configurationRegistry();
nodeCfgPresentation = new HoconPresentation(nodeCfgMgr.configurationRegistry());
clusterCfgPresentation = new HoconPresentation(clusterCfgMgr.configurationRegistry());
+
+ this.bootstrapFactory = bootstrapFactory;
}
/** {@inheritDoc} */
@@ -155,16 +157,9 @@ public class RestModule implements IgniteComponent {
Channel ch = null;
- EventLoopGroup parentGrp = new NioEventLoopGroup();
- EventLoopGroup childGrp = new NioEventLoopGroup();
-
var hnd = new RestApiInitializer(router);
- // TODO: IGNITE-15132 Rest module must reuse netty infrastructure from network module
- ServerBootstrap b = new ServerBootstrap()
- .option(ChannelOption.SO_BACKLOG, 1024)
- .group(parentGrp, childGrp)
- .channel(NioServerSocketChannel.class)
+ ServerBootstrap b = bootstrapFactory.createServerBootstrap()
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(hnd);
@@ -173,24 +168,9 @@ public class RestModule implements IgniteComponent {
if (bindRes.isSuccess()) {
ch = bindRes.channel();
-
- ch.closeFuture().addListener(new ChannelFutureListener() {
- /** {@inheritDoc} */
- @Override
- public void operationComplete(ChannelFuture fut) {
- parentGrp.shutdownGracefully();
- childGrp.shutdownGracefully();
-
- log.error("REST component was stopped", fut.cause());
- }
- });
-
port = portCandidate;
break;
} else if (!(bindRes.cause() instanceof BindException)) {
- parentGrp.shutdownGracefully();
- childGrp.shutdownGracefully();
-
throw new RuntimeException(bindRes.cause());
}
}
@@ -201,9 +181,6 @@ public class RestModule implements IgniteComponent {
log.error(msg);
- parentGrp.shutdownGracefully();
- childGrp.shutdownGracefully();
-
throw new RuntimeException(msg);
}
diff --git a/modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java b/modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java
index 6794556..52ef6f2 100644
--- a/modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java
+++ b/modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java
@@ -224,7 +224,7 @@ public class IgniteImpl implements Ignite {
distributedTblMgr
);
- restModule = new RestModule(nodeCfgMgr, clusterCfgMgr);
+ restModule = new RestModule(nodeCfgMgr, clusterCfgMgr, nettyBootstrapFactory);
clientHandlerModule = new ClientHandlerModule(
qryEngine,