Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the means to extract the contextual underlying channel from HttpChannel without excessive typecasting #11751

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Changed
- Mute the query profile IT with concurrent execution ([#9840](https://github.com/opensearch-project/OpenSearch/pull/9840))
- Force merge with `only_expunge_deletes` honors max segment size ([#10036](https://github.com/opensearch-project/OpenSearch/pull/10036))
- Add the means to extract the contextual properties from HttpChannel, TcpCChannel and TrasportChannel without excessive typecasting ([#10562](https://github.com/opensearch-project/OpenSearch/pull/10562))
- Add the means to extract the contextual properties from HttpChannel, TcpCChannel and TrasportChannel without excessive typecasting ([#10562](https://github.com/opensearch-project/OpenSearch/pull/10562)), ([#11751](https://github.com/opensearch-project/OpenSearch/pull/11751))
- Introduce new dynamic cluster setting to control slice computation for concurrent segment search ([#9107](https://github.com/opensearch-project/OpenSearch/pull/9107))
- Search pipelines now support asynchronous request and response processors to avoid blocking on a transport thread ([#10598](https://github.com/opensearch-project/OpenSearch/pull/10598))
- [Remote Store] Add Remote Store backpressure rejection stats to `_nodes/stats` ([#10524](https://github.com/opensearch-project/OpenSearch/pull/10524))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import io.netty.channel.ChannelPipeline;

public class Netty4HttpChannel implements HttpChannel {
private static final String CHANNEL_PROPERTY = "channel";

private final Channel channel;
private final CompletableContext<Void> closeContext = new CompletableContext<>();
Expand Down Expand Up @@ -102,6 +103,10 @@ public Channel getNettyChannel() {
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> get(String name, Class<T> clazz) {
if (CHANNEL_PROPERTY.equalsIgnoreCase(name) && clazz.isAssignableFrom(Channel.class)) {
return (Optional<T>) Optional.of(getNettyChannel());
}

Object handler = getNettyChannel().pipeline().get(name);

if (handler == null && inboundPipeline() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.http.netty4;

import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.transport.Netty4NioSocketChannel;
import org.junit.Before;

import java.util.Optional;

import io.netty.channel.Channel;
import io.netty.channel.ChannelOutboundInvoker;
import io.netty.channel.ServerChannel;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.sameInstance;

public class Netty4HttpChannelTests extends OpenSearchTestCase {
private Netty4HttpChannel netty4HttpChannel;
private Channel channel;

@Before
@Override
public void setUp() throws Exception {
super.setUp();
channel = new Netty4NioSocketChannel();
netty4HttpChannel = new Netty4HttpChannel(channel);
}

public void testChannelAttributeMatchesChannel() {
final Optional<Channel> channelOpt = netty4HttpChannel.get("channel", Channel.class);
assertThat(channelOpt.isPresent(), is(true));
assertThat(channelOpt.get(), sameInstance(channel));
}

public void testChannelAttributeMatchesChannelOutboundInvoker() {
final Optional<ChannelOutboundInvoker> channelOpt = netty4HttpChannel.get("channel", ChannelOutboundInvoker.class);
assertThat(channelOpt.isPresent(), is(true));
assertThat(channelOpt.get(), sameInstance(channel));
}

public void testChannelAttributeIsEmpty() {
final Optional<ServerChannel> channelOpt = netty4HttpChannel.get("channel", ServerChannel.class);
assertThat(channelOpt.isEmpty(), is(true));
}
}