use of io.grpc.channelz.v1.Socket in project grpc-java by grpc.
the class ChannelzProtoUtil method toSocket.
static Socket toSocket(InternalInstrumented<SocketStats> obj) {
SocketStats socketStats = getFuture(obj.getStats());
Socket.Builder builder = Socket.newBuilder().setRef(toSocketRef(obj)).setLocal(toAddress(socketStats.local));
if (socketStats.security != null) {
builder.setSecurity(toSecurity(socketStats.security));
}
// listen sockets do not have remote nor data
if (socketStats.remote != null) {
builder.setRemote(toAddress(socketStats.remote));
}
builder.setData(extractSocketData(socketStats));
return builder.build();
}
use of io.grpc.channelz.v1.Socket in project grpc-java by grpc.
the class ChannelzProtoUtilTest method socketSecurityTls.
@Test
public void socketSecurityTls() throws Exception {
Certificate local = mock(Certificate.class);
Certificate remote = mock(Certificate.class);
when(local.getEncoded()).thenReturn("localcert".getBytes(Charsets.UTF_8));
when(remote.getEncoded()).thenReturn("remotecert".getBytes(Charsets.UTF_8));
socket.security = new InternalChannelz.Security(new InternalChannelz.Tls("TLS_NULL_WITH_NULL_NULL", local, remote));
assertEquals(Security.newBuilder().setTls(Tls.newBuilder().setStandardName("TLS_NULL_WITH_NULL_NULL").setLocalCertificate(ByteString.copyFrom("localcert", Charsets.UTF_8)).setRemoteCertificate(ByteString.copyFrom("remotecert", Charsets.UTF_8))).build(), ChannelzProtoUtil.toSocket(socket).getSecurity());
socket.security = new InternalChannelz.Security(new InternalChannelz.Tls("TLS_NULL_WITH_NULL_NULL", /*localCert=*/
null, remote));
assertEquals(Security.newBuilder().setTls(Tls.newBuilder().setStandardName("TLS_NULL_WITH_NULL_NULL").setRemoteCertificate(ByteString.copyFrom("remotecert", Charsets.UTF_8))).build(), ChannelzProtoUtil.toSocket(socket).getSecurity());
socket.security = new InternalChannelz.Security(new InternalChannelz.Tls("TLS_NULL_WITH_NULL_NULL", local, /*remoteCert=*/
null));
assertEquals(Security.newBuilder().setTls(Tls.newBuilder().setStandardName("TLS_NULL_WITH_NULL_NULL").setLocalCertificate(ByteString.copyFrom("localcert", Charsets.UTF_8))).build(), ChannelzProtoUtil.toSocket(socket).getSecurity());
}
use of io.grpc.channelz.v1.Socket in project grpc-java by grpc.
the class ChannelzProtoUtilTest method toServer.
@Test
public void toServer() throws Exception {
// no listen sockets
assertEquals(serverProto, ChannelzProtoUtil.toServer(server));
// 1 listen socket
server.serverStats = toBuilder(server.serverStats).addListenSockets(ImmutableList.<InternalInstrumented<SocketStats>>of(listenSocket)).build();
assertEquals(serverProto.toBuilder().addListenSocket(listenSocketRef).build(), ChannelzProtoUtil.toServer(server));
// multiple listen sockets
TestListenSocket otherListenSocket = new TestListenSocket();
SocketRef otherListenSocketRef = ChannelzProtoUtil.toSocketRef(otherListenSocket);
server.serverStats = toBuilder(server.serverStats).addListenSockets(ImmutableList.<InternalInstrumented<SocketStats>>of(otherListenSocket)).build();
assertEquals(serverProto.toBuilder().addListenSocket(listenSocketRef).addListenSocket(otherListenSocketRef).build(), ChannelzProtoUtil.toServer(server));
}
use of io.grpc.channelz.v1.Socket in project grpc-java by grpc.
the class ChannelzService method getSocket.
/**
* Returns a socket.
*/
@Override
public void getSocket(GetSocketRequest request, StreamObserver<GetSocketResponse> responseObserver) {
InternalInstrumented<SocketStats> s = channelz.getSocket(request.getSocketId());
if (s == null) {
responseObserver.onError(Status.NOT_FOUND.withDescription("Can't find socket " + request.getSocketId()).asRuntimeException());
return;
}
GetSocketResponse resp;
try {
resp = GetSocketResponse.newBuilder().setSocket(ChannelzProtoUtil.toSocket(s)).build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
}
use of io.grpc.channelz.v1.Socket in project grpc-java by grpc.
the class ChannelzProtoUtilTest method socketSecurityOther.
@Test
public void socketSecurityOther() throws Exception {
// what is packed here is not important, just pick some proto message
Message contents = GetChannelRequest.newBuilder().setChannelId(1).build();
Any packed = Any.pack(contents);
socket.security = new InternalChannelz.Security(new InternalChannelz.OtherSecurity("other_security", packed));
assertEquals(Security.newBuilder().setOther(OtherSecurity.newBuilder().setName("other_security").setValue(packed)).build(), ChannelzProtoUtil.toSocket(socket).getSecurity());
}
Aggregations