You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/06/08 19:35:49 UTC

[GitHub] [ozone] adoroszlai commented on a change in pull request #2315: HDDS-5237. Add SSL support to the Ozone streaming API

adoroszlai commented on a change in pull request #2315:
URL: https://github.com/apache/ozone/pull/2315#discussion_r647729493



##########
File path: hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/stream/StreamingServer.java
##########
@@ -47,35 +48,54 @@
 
   private EventLoopGroup workerGroup;
 
+  private SslContext sslContext;
+
   public StreamingServer(
-          StreamingSource source, int port
+      StreamingSource source, int port
+  ) {
+    this(source, port, null);
+  }
+
+  public StreamingServer(
+      StreamingSource source, int port, SslContext sslContext
   ) {
     this.port = port;
     this.source = source;
+    this.sslContext = sslContext;
   }
 
-  public void start() throws InterruptedException {
-    ServerBootstrap b = new ServerBootstrap();
-    bossGroup = new NioEventLoopGroup(100);
-    workerGroup = new NioEventLoopGroup(100);
-
-    b.group(bossGroup, workerGroup)
-            .channel(NioServerSocketChannel.class)
-            .option(ChannelOption.SO_BACKLOG, 100)
-            .childHandler(new ChannelInitializer<SocketChannel>() {
-              @Override
-              public void initChannel(SocketChannel ch) throws Exception {
-                ch.pipeline().addLast(
-                        new ChunkedWriteHandler(),
-                        new DirstreamServerHandler(source));
+  public void start() {
+    try {
+      ServerBootstrap b = new ServerBootstrap();
+      bossGroup = new NioEventLoopGroup(100);
+      workerGroup = new NioEventLoopGroup(100);
+
+      b.group(bossGroup, workerGroup)
+          .channel(NioServerSocketChannel.class)
+          .option(ChannelOption.SO_BACKLOG, 100)
+
+          .childHandler(new ChannelInitializer<SocketChannel>() {
+            @Override
+            public void initChannel(SocketChannel ch) throws Exception {
+              if (sslContext != null) {
+                ch.pipeline().addLast(sslContext.newHandler(ch.alloc()));
               }
-            });
+              ch.pipeline().addLast(
+                  new ChunkedWriteHandler(),
+                  new DirstreamServerHandler(source));
+
+
+            }
+          });
 
-    ChannelFuture f = b.bind(port).sync();
-    final InetSocketAddress socketAddress =
-            (InetSocketAddress) f.channel().localAddress();
-    port = socketAddress.getPort();
-    LOG.info("Started streaming server on " + port);
+      ChannelFuture f = b.bind(port).sync();
+      final InetSocketAddress socketAddress =
+          (InetSocketAddress) f.channel().localAddress();
+      port = socketAddress.getPort();
+      LOG.info("Started streaming server on " + port);

Review comment:
       ```suggestion
         LOG.info("Started streaming server on {}", port);
   ```

##########
File path: hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/stream/package-info.java
##########
@@ -0,0 +1,18 @@
+/**

Review comment:
       ```suggestion
   /*
   ```

##########
File path: hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/stream/StreamingServer.java
##########
@@ -47,35 +48,54 @@
 
   private EventLoopGroup workerGroup;
 
+  private SslContext sslContext;
+
   public StreamingServer(
-          StreamingSource source, int port
+      StreamingSource source, int port
+  ) {
+    this(source, port, null);
+  }
+
+  public StreamingServer(
+      StreamingSource source, int port, SslContext sslContext
   ) {
     this.port = port;
     this.source = source;
+    this.sslContext = sslContext;
   }
 
-  public void start() throws InterruptedException {
-    ServerBootstrap b = new ServerBootstrap();
-    bossGroup = new NioEventLoopGroup(100);
-    workerGroup = new NioEventLoopGroup(100);
-
-    b.group(bossGroup, workerGroup)
-            .channel(NioServerSocketChannel.class)
-            .option(ChannelOption.SO_BACKLOG, 100)
-            .childHandler(new ChannelInitializer<SocketChannel>() {
-              @Override
-              public void initChannel(SocketChannel ch) throws Exception {
-                ch.pipeline().addLast(
-                        new ChunkedWriteHandler(),
-                        new DirstreamServerHandler(source));
+  public void start() {
+    try {
+      ServerBootstrap b = new ServerBootstrap();
+      bossGroup = new NioEventLoopGroup(100);
+      workerGroup = new NioEventLoopGroup(100);
+
+      b.group(bossGroup, workerGroup)
+          .channel(NioServerSocketChannel.class)
+          .option(ChannelOption.SO_BACKLOG, 100)
+
+          .childHandler(new ChannelInitializer<SocketChannel>() {
+            @Override
+            public void initChannel(SocketChannel ch) throws Exception {
+              if (sslContext != null) {
+                ch.pipeline().addLast(sslContext.newHandler(ch.alloc()));
               }
-            });
+              ch.pipeline().addLast(
+                  new ChunkedWriteHandler(),
+                  new DirstreamServerHandler(source));
+
+
+            }
+          });
 
-    ChannelFuture f = b.bind(port).sync();
-    final InetSocketAddress socketAddress =
-            (InetSocketAddress) f.channel().localAddress();
-    port = socketAddress.getPort();
-    LOG.info("Started streaming server on " + port);
+      ChannelFuture f = b.bind(port).sync();
+      final InetSocketAddress socketAddress =
+          (InetSocketAddress) f.channel().localAddress();
+      port = socketAddress.getPort();
+      LOG.info("Started streaming server on " + port);
+    } catch (InterruptedException ex) {
+      throw new RuntimeException(ex);

Review comment:
       Can we keep `throws InterruptedException` instead?  I think it's better for clarity.

##########
File path: hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/stream/package-info.java
##########
@@ -0,0 +1,18 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.container.stream;
+// Unit tests for streaming.

Review comment:
       ```suggestion
   /**
    * Unit tests for streaming.
    */
   package org.apache.hadoop.ozone.container.stream;
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org