use of org.apache.ratis.thirdparty.io.grpc.netty.NettyChannelBuilder in project ozone by apache.
the class FollowerAppendLogEntryGenerator method call.
@Override
public Void call() throws Exception {
inFlightMessages = new LinkedBlockingQueue<>(inflightLimit);
timer = getMetrics().timer("append-entry");
byte[] data = RandomStringUtils.randomAscii(chunkSize).getBytes(StandardCharsets.UTF_8);
dataToWrite = ByteString.copyFrom(data);
OzoneConfiguration conf = createOzoneConfiguration();
setServerIdFromFile(conf);
Preconditions.assertTrue(getThreadNo() == 1, "This test should be executed from one thread");
// the raft identifier which is used by the freon
requestor = RaftPeerProto.newBuilder().setId(RaftPeerId.valueOf(FAKE_LEADER_ID).toByteString()).setAddress(FAKE_LEADER_ADDDRESS).build();
NettyChannelBuilder channelBuilder = NettyChannelBuilder.forTarget(serverAddress);
channelBuilder.negotiationType(NegotiationType.PLAINTEXT);
ManagedChannel build = channelBuilder.build();
stub = RaftServerProtocolServiceGrpc.newStub(build);
if (rateLimit != 0) {
rateLimiter = new TimedSemaphore(1, TimeUnit.SECONDS, rateLimit);
}
init();
sender = stub.appendEntries(this);
if (nextIndex == 0) {
// first: configure a new ratis group (one follower, one fake leader
// (freon))
configureGroup();
RequestVoteReplyProto vote = requestVote().get(1000, TimeUnit.SECONDS);
LOG.info("Datanode answered to the vote request: {}", vote);
if (!vote.getServerReply().getSuccess()) {
throw new RuntimeException("Datanode didn't vote to the fake freon leader.");
}
// send the first appendEntry. This one is special as it initialized the
// log.
long callId = callIdRandom.nextLong();
inFlightMessages.put(callId);
sender.onNext(createInitialLogEntry(callId));
nextIndex = 1L;
}
// We can generate as mach entry as we need.
runTests(this::sendAppendLogEntryRequest);
if (rateLimiter != null) {
rateLimiter.shutdown();
}
return null;
}
use of org.apache.ratis.thirdparty.io.grpc.netty.NettyChannelBuilder in project ozone by apache.
the class LeaderAppendLogEntryGenerator method call.
@Override
public Void call() throws Exception {
inFlightMessages = new LinkedBlockingQueue<>(inflightLimit);
OzoneConfiguration conf = createOzoneConfiguration();
byte[] data = RandomStringUtils.randomAscii(chunkSize).getBytes(StandardCharsets.UTF_8);
dataToWrite = ByteString.copyFrom(data);
setServerIdFromFile(conf);
requestor = RaftPeerProto.newBuilder().setId(RaftPeerId.valueOf(FAKE_FOLLOWER_ID1).toByteString()).setAddress(FAKE_LEADER_ADDDRESS1).build();
NettyChannelBuilder channelBuilder = NettyChannelBuilder.forTarget(serverAddress);
channelBuilder.negotiationType(NegotiationType.PLAINTEXT);
ManagedChannel build = channelBuilder.build();
stub = RaftServerProtocolServiceGrpc.newStub(build);
init();
if (nextIndex == 0) {
configureGroup();
}
Thread.sleep(3000L);
XceiverClientRatis client = createXceiverClient(conf);
client.connect();
long containerId = 1L;
System.out.println(client.sendCommand(createContainerRequest(containerId)));
timer = getMetrics().timer("append-entry");
runTests(step -> timer.time(() -> {
inFlightMessages.put(step);
XceiverClientReply xceiverClientReply = client.sendCommandAsync(createChunkWriteRequest(containerId, step));
xceiverClientReply.getResponse().thenApply(response -> inFlightMessages.remove(step));
return null;
}));
return null;
}
use of org.apache.ratis.thirdparty.io.grpc.netty.NettyChannelBuilder in project ozone by apache.
the class XceiverClientGrpc method connectToDatanode.
private synchronized void connectToDatanode(DatanodeDetails dn) throws IOException {
if (isConnected(dn)) {
return;
}
// read port from the data node, on failure use default configured
// port.
int port = dn.getPort(DatanodeDetails.Port.Name.STANDALONE).getValue();
if (port == 0) {
port = config.getInt(OzoneConfigKeys.DFS_CONTAINER_IPC_PORT, OzoneConfigKeys.DFS_CONTAINER_IPC_PORT_DEFAULT);
}
// Add credential context to the client call
if (LOG.isDebugEnabled()) {
LOG.debug("Nodes in pipeline : {}", pipeline.getNodes());
LOG.debug("Connecting to server : {}", dn.getIpAddress());
}
NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress(dn.getIpAddress(), port).usePlaintext().maxInboundMessageSize(OzoneConsts.OZONE_SCM_CHUNK_MAX_SIZE).intercept(new GrpcClientInterceptor());
if (secConfig.isGrpcTlsEnabled()) {
SslContextBuilder sslContextBuilder = GrpcSslContexts.forClient();
if (caCerts != null) {
sslContextBuilder.trustManager(caCerts);
}
if (secConfig.useTestCert()) {
channelBuilder.overrideAuthority("localhost");
}
channelBuilder.useTransportSecurity().sslContext(sslContextBuilder.build());
} else {
channelBuilder.usePlaintext();
}
ManagedChannel channel = channelBuilder.build();
XceiverClientProtocolServiceStub asyncStub = XceiverClientProtocolServiceGrpc.newStub(channel);
asyncStubs.put(dn.getUuid(), asyncStub);
channels.put(dn.getUuid(), channel);
}
use of org.apache.ratis.thirdparty.io.grpc.netty.NettyChannelBuilder in project ozone by apache.
the class SCMUpdateServiceGrpcClient method createChannel.
public void createChannel() {
NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress(host, port).usePlaintext().maxInboundMessageSize(OzoneConsts.OZONE_SCM_CHUNK_MAX_SIZE);
channel = channelBuilder.build();
updateClient = SCMUpdateServiceGrpc.newStub(channel);
subscribeClient = SCMUpdateServiceGrpc.newBlockingStub(channel);
}
Aggregations