Skip to content

Commit

Permalink
Add the means to extract the contextual properties from HttpChannel, …
Browse files Browse the repository at this point in the history
…TcpCChannel and TrasportChannel without excessive typecasting

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta committed Oct 11, 2023
1 parent 9bcd7ea commit c84c736
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 0 deletions.
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 @@ -98,6 +98,22 @@ public Channel getNettyChannel() {
return channel;
}

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

Check warning on line 104 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#L104

Added line #L104 was not covered by tests

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

Check warning on line 107 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#L107

Added line #L107 was not covered by tests
}

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

Check warning on line 111 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#L111

Added line #L111 was not covered by tests
}

return null;

Check warning on line 114 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#L114

Added line #L114 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 @@ -164,6 +164,18 @@ public void sendMessage(BytesReference reference, ActionListener<Void> listener)
}
}

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

Check warning on line 170 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#L170

Added line #L170 was not covered by tests

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

Check warning on line 173 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#L173

Added line #L173 was not covered by tests
}

return null;

Check warning on line 176 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#L176

Added line #L176 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 @@ -72,4 +72,18 @@ default void handleException(Exception ex) {}
*/
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.
* {@code null} if there's no such property or the expected type is not compatible.
*/
default <T> T get(String name, Class<T> clazz) {
return null;

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 @@ -92,4 +92,9 @@ public InetSocketAddress getLocalAddress() {
public InetSocketAddress getRemoteAddress() {
return delegate.getRemoteAddress();
}

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

Check warning on line 98 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#L98

Added line #L98 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ public void sendResponse(Exception exception) throws IOException {
public Version getVersion() {
return delegate.getVersion();
}

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

Check warning on line 115 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#L115

Added line #L115 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,9 @@ public Version getVersion() {
public TransportChannel getChannel() {
return channel;
}

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

Check warning on line 95 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#L95

Added line #L95 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 @@ -96,6 +96,21 @@ public interface TcpChannel extends CloseableChannel {
*/
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.
* {@code null} if there's no such property or the expected type is not compatible.
*/
default <T> T get(String name, Class<T> clazz) {
return null;

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 @@ -130,4 +130,8 @@ public Version getVersion() {
return version;
}

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

Check warning on line 135 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#L135

Added line #L135 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,19 @@ static void sendErrorResponse(TransportChannel channel, String actionName, Trans
);
}
}

/**
* 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.
* {@code null} if there's no such property or the expected type is not compatible.
*/
default <T> T get(String name, Class<T> clazz) {
return null;

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
}
}

0 comments on commit c84c736

Please sign in to comment.