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 properties from HttpChannel, TcpChannel and TrasportChannel without excessive typecasting #10562

Merged
merged 2 commits into from
Oct 11, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Remote Store] Add support to reload repository metadata inplace ([#9569](https://github.com/opensearch-project/OpenSearch/pull/9569))
- [Metrics Framework] Add Metrics framework. ([#10241](https://github.com/opensearch-project/OpenSearch/pull/10241))
- Updating the separator for RemoteStoreLockManager since underscore is allowed in base64UUID url charset ([#10379](https://github.com/opensearch-project/OpenSearch/pull/10379))
- 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))

### Deprecated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.opensearch.transport.netty4.Netty4TcpChannel;

import java.net.InetSocketAddress;
import java.util.Optional;

import io.netty.channel.Channel;
import io.netty.channel.ChannelPipeline;
Expand Down Expand Up @@ -98,6 +99,22 @@
return channel;
}

@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> get(String name, Class<T> clazz) {
Object handler = getNettyChannel().pipeline().get(name);

Check warning on line 105 in modules/transport-netty4/src/main/java/org/opensearch/http/netty4/Netty4HttpChannel.java

View check run for this annotation

Codecov / codecov/patch

modules/transport-netty4/src/main/java/org/opensearch/http/netty4/Netty4HttpChannel.java#L105

Added line #L105 was not covered by tests

if (handler == null && inboundPipeline() != null) {
handler = inboundPipeline().get(name);

Check warning on line 108 in modules/transport-netty4/src/main/java/org/opensearch/http/netty4/Netty4HttpChannel.java

View check run for this annotation

Codecov / codecov/patch

modules/transport-netty4/src/main/java/org/opensearch/http/netty4/Netty4HttpChannel.java#L108

Added line #L108 was not covered by tests
}

if (handler != null && clazz.isInstance(handler) == true) {
return Optional.of((T) handler);

Check warning on line 112 in modules/transport-netty4/src/main/java/org/opensearch/http/netty4/Netty4HttpChannel.java

View check run for this annotation

Codecov / codecov/patch

modules/transport-netty4/src/main/java/org/opensearch/http/netty4/Netty4HttpChannel.java#L112

Added line #L112 was not covered by tests
}

return Optional.empty();

Check warning on line 115 in modules/transport-netty4/src/main/java/org/opensearch/http/netty4/Netty4HttpChannel.java

View check run for this annotation

Codecov / codecov/patch

modules/transport-netty4/src/main/java/org/opensearch/http/netty4/Netty4HttpChannel.java#L115

Added line #L115 was not covered by tests
}

@Override
public String toString() {
return "Netty4HttpChannel{" + "localAddress=" + getLocalAddress() + ", remoteAddress=" + getRemoteAddress() + '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.opensearch.transport.TransportException;

import java.net.InetSocketAddress;
import java.util.Optional;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
Expand Down Expand Up @@ -164,6 +165,18 @@
}
}

@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> get(String name, Class<T> clazz) {
final Object handler = getNettyChannel().pipeline().get(name);

Check warning on line 171 in modules/transport-netty4/src/main/java/org/opensearch/transport/netty4/Netty4TcpChannel.java

View check run for this annotation

Codecov / codecov/patch

modules/transport-netty4/src/main/java/org/opensearch/transport/netty4/Netty4TcpChannel.java#L171

Added line #L171 was not covered by tests

if (handler != null && clazz.isInstance(handler) == true) {
return Optional.of((T) handler);

Check warning on line 174 in modules/transport-netty4/src/main/java/org/opensearch/transport/netty4/Netty4TcpChannel.java

View check run for this annotation

Codecov / codecov/patch

modules/transport-netty4/src/main/java/org/opensearch/transport/netty4/Netty4TcpChannel.java#L174

Added line #L174 was not covered by tests
}

return Optional.empty();

Check warning on line 177 in modules/transport-netty4/src/main/java/org/opensearch/transport/netty4/Netty4TcpChannel.java

View check run for this annotation

Codecov / codecov/patch

modules/transport-netty4/src/main/java/org/opensearch/transport/netty4/Netty4TcpChannel.java#L177

Added line #L177 was not covered by tests
}

public Channel getNettyChannel() {
return channel;
}
Expand Down
14 changes: 14 additions & 0 deletions server/src/main/java/org/opensearch/http/HttpChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.opensearch.core.action.ActionListener;

import java.net.InetSocketAddress;
import java.util.Optional;

/**
* Represents an HTTP comms channel
Expand Down Expand Up @@ -72,4 +73,17 @@
*/
InetSocketAddress getRemoteAddress();

/**
* Returns the contextual property associated with this specific HTTP channel (the
* implementation of how such properties are managed depends on the the particular
* transport engine).
*
* @param name the name of the property
* @param clazz the expected type of the property
*
* @return the value of the property
*/
default <T> Optional<T> get(String name, Class<T> clazz) {
return Optional.empty();

Check warning on line 87 in server/src/main/java/org/opensearch/http/HttpChannel.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/http/HttpChannel.java#L87

Added line #L87 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.net.InetSocketAddress;
import java.util.Objects;
import java.util.Optional;

/**
* Tracer wrapped {@link HttpChannel}
Expand Down Expand Up @@ -92,4 +93,9 @@
public InetSocketAddress getRemoteAddress() {
return delegate.getRemoteAddress();
}

@Override
public <T> Optional<T> get(String name, Class<T> clazz) {
return delegate.get(name, clazz);

Check warning on line 99 in server/src/main/java/org/opensearch/telemetry/tracing/channels/TraceableHttpChannel.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/telemetry/tracing/channels/TraceableHttpChannel.java#L99

Added line #L99 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.opensearch.transport.TransportChannel;

import java.io.IOException;
import java.util.Optional;

/**
* Tracer wrapped {@link TransportChannel}
Expand Down Expand Up @@ -109,4 +110,9 @@
public Version getVersion() {
return delegate.getVersion();
}

@Override
public <T> Optional<T> get(String name, Class<T> clazz) {
return delegate.get(name, clazz);

Check warning on line 116 in server/src/main/java/org/opensearch/telemetry/tracing/channels/TraceableTcpTransportChannel.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/telemetry/tracing/channels/TraceableTcpTransportChannel.java#L116

Added line #L116 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.opensearch.core.transport.TransportResponse;

import java.io.IOException;
import java.util.Optional;

/**
* Transport channel for tasks
Expand Down Expand Up @@ -89,4 +90,9 @@
public TransportChannel getChannel() {
return channel;
}

@Override
public <T> Optional<T> get(String name, Class<T> clazz) {
return getChannel().get(name, clazz);

Check warning on line 96 in server/src/main/java/org/opensearch/transport/TaskTransportChannel.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/transport/TaskTransportChannel.java#L96

Added line #L96 was not covered by tests
}
}
15 changes: 15 additions & 0 deletions server/src/main/java/org/opensearch/transport/TcpChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.opensearch.core.common.bytes.BytesReference;

import java.net.InetSocketAddress;
import java.util.Optional;

/**
* This is a tcp channel representing a single channel connection to another node. It is the base channel
Expand Down Expand Up @@ -96,6 +97,20 @@
*/
ChannelStats getChannelStats();

/**
* Returns the contextual property associated with this specific TCP channel (the
* implementation of how such properties are managed depends on the the particular
* transport engine).
*
* @param name the name of the property
* @param clazz the expected type of the property
*
* @return the value of the property
*/
default <T> Optional<T> get(String name, Class<T> clazz) {
return Optional.empty();

Check warning on line 111 in server/src/main/java/org/opensearch/transport/TcpChannel.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/transport/TcpChannel.java#L111

Added line #L111 was not covered by tests
}

/**
* Channel statistics
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.opensearch.search.query.QuerySearchResult;

import java.io.IOException;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -130,4 +131,8 @@
return version;
}

@Override
public <T> Optional<T> get(String name, Class<T> clazz) {
return getChannel().get(name, clazz);

Check warning on line 136 in server/src/main/java/org/opensearch/transport/TcpTransportChannel.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/transport/TcpTransportChannel.java#L136

Added line #L136 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.opensearch.core.transport.TransportResponse;

import java.io.IOException;
import java.util.Optional;

/**
* A transport channel allows to send a response to a request on the channel.
Expand Down Expand Up @@ -78,4 +79,18 @@
);
}
}

/**
* Returns the contextual property associated with this specific transport channel (the
* implementation of how such properties are managed depends on the the particular
* transport engine).
*
* @param name the name of the property
* @param clazz the expected type of the property
*
* @return the value of the property.
*/
default <T> Optional<T> get(String name, Class<T> clazz) {
return Optional.empty();

Check warning on line 94 in server/src/main/java/org/opensearch/transport/TransportChannel.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/transport/TransportChannel.java#L94

Added line #L94 was not covered by tests
}
}
Loading