You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/04/19 18:27:33 UTC
[GitHub] [geode] jdeppe-pivotal opened a new pull request #6346: GEODE-9172: Add Junit rule to start docker-based redis cluster
jdeppe-pivotal opened a new pull request #6346:
URL: https://github.com/apache/geode/pull/6346
The fun part here is that some redis commands will respond with internal
IP addresses which need to be rewritten so that clients are able to make
use of them. Currently CLUSTER SLOTS and CLUSTER NODES are implemented
with this functionality. If docker could do host networking on Mac OS, all these
shenanigans could be avoided.
Thank you for submitting a contribution to Apache Geode.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
- [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
- [ ] Is your initial contribution a single, squashed commit?
- [ ] Does `gradlew build` run cleanly?
- [ ] Have you written or updated unit tests to verify your changes?
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
### Note:
Please ensure that once the PR is submitted, check Concourse for build issues and
submit an update to your PR as soon as possible. If you need help, please send an
email to dev@geode.apache.org.
--
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
[GitHub] [geode] sabbey37 commented on a change in pull request #6346: GEODE-9172: Add Junit rule to start docker-based redis cluster
Posted by GitBox <gi...@apache.org>.
sabbey37 commented on a change in pull request #6346:
URL: https://github.com/apache/geode/pull/6346#discussion_r616792137
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxyInboundHandler.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Map;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.codec.redis.ArrayRedisMessage;
+import io.netty.handler.codec.redis.FullBulkStringRedisMessage;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import io.netty.util.CharsetUtil;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+public class RedisProxyInboundHandler extends ChannelInboundHandlerAdapter {
+
+ private static final Logger logger = LogService.getLogger();
+ private final String remoteHost;
+ private final int remotePort;
+ private final Map<HostPort, HostPort> mappings;
+ private Channel outboundChannel;
+ private RedisProxyOutboundHandler outboundHandler;
+ private final ClusterSlotsResponseProcessor slotsResponseProcessor;
+ private final ClusterNodesResponseProcessor nodesResponseProcessor;
+ private MovedResponseHandler movedResponseHandler;
+
+ public RedisProxyInboundHandler(String remoteHost, int remotePort,
+ Map<HostPort, HostPort> mappings) {
+ this.remoteHost = remoteHost;
+ this.remotePort = remotePort;
+ this.mappings = mappings;
+ this.slotsResponseProcessor = new ClusterSlotsResponseProcessor(mappings);
+ this.nodesResponseProcessor = new ClusterNodesResponseProcessor(mappings);
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) {
+ Channel inboundChannel = ctx.channel();
+ outboundHandler = new RedisProxyOutboundHandler(inboundChannel);
+ movedResponseHandler = new MovedResponseHandler(inboundChannel, mappings);
+
+ // Start the connection attempt.
+ Bootstrap b = new Bootstrap();
+ b.group(inboundChannel.eventLoop())
+ .channel(ctx.channel().getClass())
+ .handler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
Review comment:
I don't think we need the `throws Exception` here any longer.
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/MovedResponseHandler.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Map;
+
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.handler.codec.redis.ErrorRedisMessage;
+
+public class MovedResponseHandler extends ChannelInboundHandlerAdapter {
+
+ private final Map<HostPort, HostPort> mappings;
+ private final Channel inboundChannel;
+
+ public MovedResponseHandler(Channel inboundChannel, Map<HostPort, HostPort> mappings) {
+ this.inboundChannel = inboundChannel;
+ this.mappings = mappings;
+ }
+
+ @Override
+ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
Review comment:
I don't think we need the `throws Exception` here any longer.
--
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
[GitHub] [geode] jdeppe-pivotal commented on a change in pull request #6346: GEODE-9172: Add Junit rule to start docker-based redis cluster
Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6346:
URL: https://github.com/apache/geode/pull/6346#discussion_r616791038
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxy.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+/**
+ * This proxy handles mangling Redis responses in whatever way is necessary. In the case of
+ * creating a docker-based redis cluster, we need to translate internal addresses into external
+ * addresses - see {@link RedisProxyInboundHandler#channelRead(ChannelHandlerContext, Object)}.
+ */
+public final class RedisProxy {
+
+ private static final Logger logger = LogService.getLogger();
+
+ private static final int LOCAL_PORT = Integer.parseInt(System.getProperty("localPort", "5379"));
+ private static final String REMOTE_HOST = System.getProperty("remoteHost", "localhost");
+ private static final int REMOTE_PORT = Integer.parseInt(System.getProperty("remotePort", "6379"));
Review comment:
Removed
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxy.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+/**
+ * This proxy handles mangling Redis responses in whatever way is necessary. In the case of
+ * creating a docker-based redis cluster, we need to translate internal addresses into external
+ * addresses - see {@link RedisProxyInboundHandler#channelRead(ChannelHandlerContext, Object)}.
+ */
+public final class RedisProxy {
+
+ private static final Logger logger = LogService.getLogger();
+
+ private static final int LOCAL_PORT = Integer.parseInt(System.getProperty("localPort", "5379"));
+ private static final String REMOTE_HOST = System.getProperty("remoteHost", "localhost");
+ private static final int REMOTE_PORT = Integer.parseInt(System.getProperty("remotePort", "6379"));
+
+ private final EventLoopGroup bossGroup;
+ private final EventLoopGroup workerGroup;
+ private final int exposedPort;
+ private final Map<HostPort, HostPort> mappings = new HashMap<>();
+
+ public RedisProxy(int targetPort) {
+ bossGroup = new NioEventLoopGroup(1);
+ workerGroup = new NioEventLoopGroup(1);
+
+ ChannelFuture future = new ServerBootstrap().group(bossGroup, workerGroup)
+ .channel(NioServerSocketChannel.class)
+ .childHandler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
+ ChannelPipeline p = ch.pipeline();
+ // p.addLast(new LoggingHandler(LogLevel.INFO));
Review comment:
Removed
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxyInboundHandler.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Map;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.codec.redis.ArrayRedisMessage;
+import io.netty.handler.codec.redis.FullBulkStringRedisMessage;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import io.netty.util.CharsetUtil;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+public class RedisProxyInboundHandler extends ChannelInboundHandlerAdapter {
+
+ private static final Logger logger = LogService.getLogger();
+ private final String remoteHost;
+ private final int remotePort;
+ private final Map<HostPort, HostPort> mappings;
+ private Channel outboundChannel;
+ private RedisProxyOutboundHandler outboundHandler;
+ private final ClusterSlotsResponseProcessor slotsResponseProcessor;
+ private final ClusterNodesResponseProcessor nodesResponseProcessor;
+ private MovedResponseHandler movedResponseHandler;
+
+ public RedisProxyInboundHandler(String remoteHost, int remotePort,
+ Map<HostPort, HostPort> mappings) {
+ this.remoteHost = remoteHost;
+ this.remotePort = remotePort;
+ this.mappings = mappings;
+ this.slotsResponseProcessor = new ClusterSlotsResponseProcessor(mappings);
+ this.nodesResponseProcessor = new ClusterNodesResponseProcessor(mappings);
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) {
+ Channel inboundChannel = ctx.channel();
+ outboundHandler = new RedisProxyOutboundHandler(inboundChannel);
+ movedResponseHandler = new MovedResponseHandler(inboundChannel, mappings);
+
+ // Start the connection attempt.
+ Bootstrap b = new Bootstrap();
+ b.group(inboundChannel.eventLoop())
+ .channel(ctx.channel().getClass())
+ .handler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
+ ChannelPipeline p = ch.pipeline();
+ // p.addLast(new LoggingHandler(LogLevel.INFO));
Review comment:
Removed
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxyInboundHandler.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Map;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.codec.redis.ArrayRedisMessage;
+import io.netty.handler.codec.redis.FullBulkStringRedisMessage;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import io.netty.util.CharsetUtil;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+public class RedisProxyInboundHandler extends ChannelInboundHandlerAdapter {
+
+ private static final Logger logger = LogService.getLogger();
+ private final String remoteHost;
+ private final int remotePort;
+ private final Map<HostPort, HostPort> mappings;
+ private Channel outboundChannel;
+ private RedisProxyOutboundHandler outboundHandler;
+ private final ClusterSlotsResponseProcessor slotsResponseProcessor;
+ private final ClusterNodesResponseProcessor nodesResponseProcessor;
+ private MovedResponseHandler movedResponseHandler;
+
+ public RedisProxyInboundHandler(String remoteHost, int remotePort,
+ Map<HostPort, HostPort> mappings) {
+ this.remoteHost = remoteHost;
+ this.remotePort = remotePort;
+ this.mappings = mappings;
+ this.slotsResponseProcessor = new ClusterSlotsResponseProcessor(mappings);
+ this.nodesResponseProcessor = new ClusterNodesResponseProcessor(mappings);
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) {
+ Channel inboundChannel = ctx.channel();
+ outboundHandler = new RedisProxyOutboundHandler(inboundChannel);
+ movedResponseHandler = new MovedResponseHandler(inboundChannel, mappings);
+
+ // Start the connection attempt.
+ Bootstrap b = new Bootstrap();
+ b.group(inboundChannel.eventLoop())
+ .channel(ctx.channel().getClass())
+ .handler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
+ ChannelPipeline p = ch.pipeline();
+ // p.addLast(new LoggingHandler(LogLevel.INFO));
+ p.addLast(new RedisEncoder());
+ p.addLast(new RedisDecoder());
+ p.addLast(new RedisBulkStringAggregator());
+ p.addLast(new RedisArrayAggregator());
+ p.addLast(movedResponseHandler);
+ p.addLast(outboundHandler);
+ }
+ });
+ // .option(ChannelOption.AUTO_READ, false);
Review comment:
Removed
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxyInboundHandler.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Map;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.codec.redis.ArrayRedisMessage;
+import io.netty.handler.codec.redis.FullBulkStringRedisMessage;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import io.netty.util.CharsetUtil;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+public class RedisProxyInboundHandler extends ChannelInboundHandlerAdapter {
+
+ private static final Logger logger = LogService.getLogger();
+ private final String remoteHost;
+ private final int remotePort;
+ private final Map<HostPort, HostPort> mappings;
+ private Channel outboundChannel;
+ private RedisProxyOutboundHandler outboundHandler;
+ private final ClusterSlotsResponseProcessor slotsResponseProcessor;
+ private final ClusterNodesResponseProcessor nodesResponseProcessor;
+ private MovedResponseHandler movedResponseHandler;
+
+ public RedisProxyInboundHandler(String remoteHost, int remotePort,
+ Map<HostPort, HostPort> mappings) {
+ this.remoteHost = remoteHost;
+ this.remotePort = remotePort;
+ this.mappings = mappings;
+ this.slotsResponseProcessor = new ClusterSlotsResponseProcessor(mappings);
+ this.nodesResponseProcessor = new ClusterNodesResponseProcessor(mappings);
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) {
+ Channel inboundChannel = ctx.channel();
+ outboundHandler = new RedisProxyOutboundHandler(inboundChannel);
+ movedResponseHandler = new MovedResponseHandler(inboundChannel, mappings);
+
+ // Start the connection attempt.
+ Bootstrap b = new Bootstrap();
+ b.group(inboundChannel.eventLoop())
+ .channel(ctx.channel().getClass())
+ .handler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
+ ChannelPipeline p = ch.pipeline();
+ // p.addLast(new LoggingHandler(LogLevel.INFO));
+ p.addLast(new RedisEncoder());
+ p.addLast(new RedisDecoder());
+ p.addLast(new RedisBulkStringAggregator());
+ p.addLast(new RedisArrayAggregator());
+ p.addLast(movedResponseHandler);
+ p.addLast(outboundHandler);
+ }
+ });
+ // .option(ChannelOption.AUTO_READ, false);
+ ChannelFuture f = b.connect(remoteHost, remotePort);
+ outboundChannel = f.channel();
+ f.addListener((ChannelFutureListener) future -> {
+ if (future.isSuccess()) {
+ // connection complete start to read first data
+ inboundChannel.read();
+ } else {
+ logger.error("Failed to connect", future.cause());
+ inboundChannel.close();
+ }
+ });
+ }
+
+ /**
+ * Any redis commands which return an IP or port which needs to be translated into an external
+ * IP/port need to be added to this method and an appropriate {@link RedisResponseProcessor}
+ * needs to be implemented.
+ * <p/>
+ * Note that each inbound command has an explicit outbound processor associated. Commands that
+ * do not need any processing are simply handled by a {@link NoopRedisResponseProcessor}.
+ */
+ @Override
+ public void channelRead(final ChannelHandlerContext ctx, Object msg) {
+ if (outboundChannel.isActive()) {
+ // Commands always consist of an array of bulk strings
+ ArrayRedisMessage rMessage = (ArrayRedisMessage) msg;
+ String command = getArg(rMessage, 0);
+
+ // logger.info("--- {}", command);
Review comment:
Removed
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxyOutboundHandler.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Queue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+public class RedisProxyOutboundHandler extends ChannelInboundHandlerAdapter {
+
+ private static final Logger logger = LogService.getLogger();
+ private final Queue<RedisResponseProcessor> processors = new LinkedBlockingQueue<>();
+ private final Channel inboundChannel;
+
+ public RedisProxyOutboundHandler(Channel inboundChannel) {
+ this.inboundChannel = inboundChannel;
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) {
+ ctx.read();
+ }
+
+ @Override
+ public void channelRead(final ChannelHandlerContext ctx, Object msg) {
+ RedisResponseProcessor processor = processors.poll();
+ if (processor == null) {
+ logger.warn("No processor queued - will use default noop processor");
+ processor = NoopRedisResponseProcessor.INSTANCE;
+ }
+
+ inboundChannel.writeAndFlush(processor.process(msg, ctx.channel()))
+ .addListener((ChannelFutureListener) future -> {
+ if (future.isSuccess()) {
+ inboundChannel.read();
+ // ctx.channel().read();
Review comment:
Removed
--
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
[GitHub] [geode] jdeppe-pivotal commented on a change in pull request #6346: GEODE-9172: Add Junit rule to start docker-based redis cluster
Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6346:
URL: https://github.com/apache/geode/pull/6346#discussion_r616798719
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/MovedResponseHandler.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Map;
+
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.handler.codec.redis.ErrorRedisMessage;
+
+public class MovedResponseHandler extends ChannelInboundHandlerAdapter {
+
+ private final Map<HostPort, HostPort> mappings;
+ private final Channel inboundChannel;
+
+ public MovedResponseHandler(Channel inboundChannel, Map<HostPort, HostPort> mappings) {
+ this.inboundChannel = inboundChannel;
+ this.mappings = mappings;
+ }
+
+ @Override
+ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
Review comment:
Cleaned up.
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxyInboundHandler.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Map;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.codec.redis.ArrayRedisMessage;
+import io.netty.handler.codec.redis.FullBulkStringRedisMessage;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import io.netty.util.CharsetUtil;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+public class RedisProxyInboundHandler extends ChannelInboundHandlerAdapter {
+
+ private static final Logger logger = LogService.getLogger();
+ private final String remoteHost;
+ private final int remotePort;
+ private final Map<HostPort, HostPort> mappings;
+ private Channel outboundChannel;
+ private RedisProxyOutboundHandler outboundHandler;
+ private final ClusterSlotsResponseProcessor slotsResponseProcessor;
+ private final ClusterNodesResponseProcessor nodesResponseProcessor;
+ private MovedResponseHandler movedResponseHandler;
+
+ public RedisProxyInboundHandler(String remoteHost, int remotePort,
+ Map<HostPort, HostPort> mappings) {
+ this.remoteHost = remoteHost;
+ this.remotePort = remotePort;
+ this.mappings = mappings;
+ this.slotsResponseProcessor = new ClusterSlotsResponseProcessor(mappings);
+ this.nodesResponseProcessor = new ClusterNodesResponseProcessor(mappings);
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) {
+ Channel inboundChannel = ctx.channel();
+ outboundHandler = new RedisProxyOutboundHandler(inboundChannel);
+ movedResponseHandler = new MovedResponseHandler(inboundChannel, mappings);
+
+ // Start the connection attempt.
+ Bootstrap b = new Bootstrap();
+ b.group(inboundChannel.eventLoop())
+ .channel(ctx.channel().getClass())
+ .handler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
Review comment:
Cleaned up.
--
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
[GitHub] [geode] jdeppe-pivotal merged pull request #6346: GEODE-9172: Add Junit rule to start docker-based redis cluster
Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal merged pull request #6346:
URL: https://github.com/apache/geode/pull/6346
--
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
[GitHub] [geode] sabbey37 commented on a change in pull request #6346: GEODE-9172: Add Junit rule to start docker-based redis cluster
Posted by GitBox <gi...@apache.org>.
sabbey37 commented on a change in pull request #6346:
URL: https://github.com/apache/geode/pull/6346#discussion_r616779833
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxy.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+/**
+ * This proxy handles mangling Redis responses in whatever way is necessary. In the case of
+ * creating a docker-based redis cluster, we need to translate internal addresses into external
+ * addresses - see {@link RedisProxyInboundHandler#channelRead(ChannelHandlerContext, Object)}.
+ */
+public final class RedisProxy {
+
+ private static final Logger logger = LogService.getLogger();
+
+ private static final int LOCAL_PORT = Integer.parseInt(System.getProperty("localPort", "5379"));
+ private static final String REMOTE_HOST = System.getProperty("remoteHost", "localhost");
+ private static final int REMOTE_PORT = Integer.parseInt(System.getProperty("remotePort", "6379"));
+
+ private final EventLoopGroup bossGroup;
+ private final EventLoopGroup workerGroup;
+ private final int exposedPort;
+ private final Map<HostPort, HostPort> mappings = new HashMap<>();
+
+ public RedisProxy(int targetPort) {
+ bossGroup = new NioEventLoopGroup(1);
+ workerGroup = new NioEventLoopGroup(1);
+
+ ChannelFuture future = new ServerBootstrap().group(bossGroup, workerGroup)
+ .channel(NioServerSocketChannel.class)
+ .childHandler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
+ ChannelPipeline p = ch.pipeline();
+ // p.addLast(new LoggingHandler(LogLevel.INFO));
Review comment:
Do we still need this?
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxy.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+/**
+ * This proxy handles mangling Redis responses in whatever way is necessary. In the case of
+ * creating a docker-based redis cluster, we need to translate internal addresses into external
+ * addresses - see {@link RedisProxyInboundHandler#channelRead(ChannelHandlerContext, Object)}.
+ */
+public final class RedisProxy {
+
+ private static final Logger logger = LogService.getLogger();
+
+ private static final int LOCAL_PORT = Integer.parseInt(System.getProperty("localPort", "5379"));
+ private static final String REMOTE_HOST = System.getProperty("remoteHost", "localhost");
+ private static final int REMOTE_PORT = Integer.parseInt(System.getProperty("remotePort", "6379"));
Review comment:
It doesn't seem like these are being used.
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxyInboundHandler.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Map;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.codec.redis.ArrayRedisMessage;
+import io.netty.handler.codec.redis.FullBulkStringRedisMessage;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import io.netty.util.CharsetUtil;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+public class RedisProxyInboundHandler extends ChannelInboundHandlerAdapter {
+
+ private static final Logger logger = LogService.getLogger();
+ private final String remoteHost;
+ private final int remotePort;
+ private final Map<HostPort, HostPort> mappings;
+ private Channel outboundChannel;
+ private RedisProxyOutboundHandler outboundHandler;
+ private final ClusterSlotsResponseProcessor slotsResponseProcessor;
+ private final ClusterNodesResponseProcessor nodesResponseProcessor;
+ private MovedResponseHandler movedResponseHandler;
+
+ public RedisProxyInboundHandler(String remoteHost, int remotePort,
+ Map<HostPort, HostPort> mappings) {
+ this.remoteHost = remoteHost;
+ this.remotePort = remotePort;
+ this.mappings = mappings;
+ this.slotsResponseProcessor = new ClusterSlotsResponseProcessor(mappings);
+ this.nodesResponseProcessor = new ClusterNodesResponseProcessor(mappings);
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) {
+ Channel inboundChannel = ctx.channel();
+ outboundHandler = new RedisProxyOutboundHandler(inboundChannel);
+ movedResponseHandler = new MovedResponseHandler(inboundChannel, mappings);
+
+ // Start the connection attempt.
+ Bootstrap b = new Bootstrap();
+ b.group(inboundChannel.eventLoop())
+ .channel(ctx.channel().getClass())
+ .handler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
+ ChannelPipeline p = ch.pipeline();
+ // p.addLast(new LoggingHandler(LogLevel.INFO));
+ p.addLast(new RedisEncoder());
+ p.addLast(new RedisDecoder());
+ p.addLast(new RedisBulkStringAggregator());
+ p.addLast(new RedisArrayAggregator());
+ p.addLast(movedResponseHandler);
+ p.addLast(outboundHandler);
+ }
+ });
+ // .option(ChannelOption.AUTO_READ, false);
+ ChannelFuture f = b.connect(remoteHost, remotePort);
+ outboundChannel = f.channel();
+ f.addListener((ChannelFutureListener) future -> {
+ if (future.isSuccess()) {
+ // connection complete start to read first data
+ inboundChannel.read();
+ } else {
+ logger.error("Failed to connect", future.cause());
+ inboundChannel.close();
+ }
+ });
+ }
+
+ /**
+ * Any redis commands which return an IP or port which needs to be translated into an external
+ * IP/port need to be added to this method and an appropriate {@link RedisResponseProcessor}
+ * needs to be implemented.
+ * <p/>
+ * Note that each inbound command has an explicit outbound processor associated. Commands that
+ * do not need any processing are simply handled by a {@link NoopRedisResponseProcessor}.
+ */
+ @Override
+ public void channelRead(final ChannelHandlerContext ctx, Object msg) {
+ if (outboundChannel.isActive()) {
+ // Commands always consist of an array of bulk strings
+ ArrayRedisMessage rMessage = (ArrayRedisMessage) msg;
+ String command = getArg(rMessage, 0);
+
+ // logger.info("--- {}", command);
Review comment:
Do we still need this?
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxyInboundHandler.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Map;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.codec.redis.ArrayRedisMessage;
+import io.netty.handler.codec.redis.FullBulkStringRedisMessage;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import io.netty.util.CharsetUtil;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+public class RedisProxyInboundHandler extends ChannelInboundHandlerAdapter {
+
+ private static final Logger logger = LogService.getLogger();
+ private final String remoteHost;
+ private final int remotePort;
+ private final Map<HostPort, HostPort> mappings;
+ private Channel outboundChannel;
+ private RedisProxyOutboundHandler outboundHandler;
+ private final ClusterSlotsResponseProcessor slotsResponseProcessor;
+ private final ClusterNodesResponseProcessor nodesResponseProcessor;
+ private MovedResponseHandler movedResponseHandler;
+
+ public RedisProxyInboundHandler(String remoteHost, int remotePort,
+ Map<HostPort, HostPort> mappings) {
+ this.remoteHost = remoteHost;
+ this.remotePort = remotePort;
+ this.mappings = mappings;
+ this.slotsResponseProcessor = new ClusterSlotsResponseProcessor(mappings);
+ this.nodesResponseProcessor = new ClusterNodesResponseProcessor(mappings);
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) {
+ Channel inboundChannel = ctx.channel();
+ outboundHandler = new RedisProxyOutboundHandler(inboundChannel);
+ movedResponseHandler = new MovedResponseHandler(inboundChannel, mappings);
+
+ // Start the connection attempt.
+ Bootstrap b = new Bootstrap();
+ b.group(inboundChannel.eventLoop())
+ .channel(ctx.channel().getClass())
+ .handler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
+ ChannelPipeline p = ch.pipeline();
+ // p.addLast(new LoggingHandler(LogLevel.INFO));
Review comment:
Do we still need this?
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxyInboundHandler.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Map;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.codec.redis.ArrayRedisMessage;
+import io.netty.handler.codec.redis.FullBulkStringRedisMessage;
+import io.netty.handler.codec.redis.RedisArrayAggregator;
+import io.netty.handler.codec.redis.RedisBulkStringAggregator;
+import io.netty.handler.codec.redis.RedisDecoder;
+import io.netty.handler.codec.redis.RedisEncoder;
+import io.netty.util.CharsetUtil;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+public class RedisProxyInboundHandler extends ChannelInboundHandlerAdapter {
+
+ private static final Logger logger = LogService.getLogger();
+ private final String remoteHost;
+ private final int remotePort;
+ private final Map<HostPort, HostPort> mappings;
+ private Channel outboundChannel;
+ private RedisProxyOutboundHandler outboundHandler;
+ private final ClusterSlotsResponseProcessor slotsResponseProcessor;
+ private final ClusterNodesResponseProcessor nodesResponseProcessor;
+ private MovedResponseHandler movedResponseHandler;
+
+ public RedisProxyInboundHandler(String remoteHost, int remotePort,
+ Map<HostPort, HostPort> mappings) {
+ this.remoteHost = remoteHost;
+ this.remotePort = remotePort;
+ this.mappings = mappings;
+ this.slotsResponseProcessor = new ClusterSlotsResponseProcessor(mappings);
+ this.nodesResponseProcessor = new ClusterNodesResponseProcessor(mappings);
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) {
+ Channel inboundChannel = ctx.channel();
+ outboundHandler = new RedisProxyOutboundHandler(inboundChannel);
+ movedResponseHandler = new MovedResponseHandler(inboundChannel, mappings);
+
+ // Start the connection attempt.
+ Bootstrap b = new Bootstrap();
+ b.group(inboundChannel.eventLoop())
+ .channel(ctx.channel().getClass())
+ .handler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
+ ChannelPipeline p = ch.pipeline();
+ // p.addLast(new LoggingHandler(LogLevel.INFO));
+ p.addLast(new RedisEncoder());
+ p.addLast(new RedisDecoder());
+ p.addLast(new RedisBulkStringAggregator());
+ p.addLast(new RedisArrayAggregator());
+ p.addLast(movedResponseHandler);
+ p.addLast(outboundHandler);
+ }
+ });
+ // .option(ChannelOption.AUTO_READ, false);
Review comment:
Do we still need this?
##########
File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxyOutboundHandler.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.geode.redis.internal.proxy;
+
+import java.util.Queue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+public class RedisProxyOutboundHandler extends ChannelInboundHandlerAdapter {
+
+ private static final Logger logger = LogService.getLogger();
+ private final Queue<RedisResponseProcessor> processors = new LinkedBlockingQueue<>();
+ private final Channel inboundChannel;
+
+ public RedisProxyOutboundHandler(Channel inboundChannel) {
+ this.inboundChannel = inboundChannel;
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) {
+ ctx.read();
+ }
+
+ @Override
+ public void channelRead(final ChannelHandlerContext ctx, Object msg) {
+ RedisResponseProcessor processor = processors.poll();
+ if (processor == null) {
+ logger.warn("No processor queued - will use default noop processor");
+ processor = NoopRedisResponseProcessor.INSTANCE;
+ }
+
+ inboundChannel.writeAndFlush(processor.process(msg, ctx.channel()))
+ .addListener((ChannelFutureListener) future -> {
+ if (future.isSuccess()) {
+ inboundChannel.read();
+ // ctx.channel().read();
Review comment:
Do we still need this?
--
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