Java Code Examples for org.apache.ratis.protocol.RaftPeer#getId()
The following examples show how to use
org.apache.ratis.protocol.RaftPeer#getId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupManagementBaseTest.java From incubator-ratis with Apache License 2.0 | 6 votes |
@Test public void testGroupAlreadyExists() throws Exception { final MiniRaftCluster cluster = getCluster(1); cluster.start(); final RaftPeer peer = cluster.getPeers().get(0); final RaftPeerId peerId = peer.getId(); final RaftGroup group = RaftGroup.valueOf(cluster.getGroupId(), peer); try (final RaftClient client = cluster.createClient()) { Assert.assertEquals(group, cluster.getRaftServerImpl(peerId).getGroup()); try { client.groupAdd(group, peer.getId()); } catch (IOException ex) { // HadoopRPC throws RemoteException, which makes it hard to check if // the exception is instance of AlreadyExistsException Assert.assertTrue(ex.toString().contains(AlreadyExistsException.class.getCanonicalName())); } Assert.assertEquals(group, cluster.getRaftServerImpl(peerId).getGroup()); cluster.shutdown(); } }
Example 2
Source File: GrpcServerProtocolClient.java From incubator-ratis with Apache License 2.0 | 5 votes |
public GrpcServerProtocolClient(RaftPeer target, int flowControlWindow, TimeDuration requestTimeoutDuration, GrpcTlsConfig tlsConfig) { raftPeerId = target.getId(); NettyChannelBuilder channelBuilder = NettyChannelBuilder.forTarget(target.getAddress()); if (tlsConfig!= null) { SslContextBuilder sslContextBuilder = GrpcSslContexts.forClient(); if (tlsConfig.isFileBasedConfig()) { sslContextBuilder.trustManager(tlsConfig.getTrustStoreFile()); } else { sslContextBuilder.trustManager(tlsConfig.getTrustStore()); } if (tlsConfig.getMtlsEnabled()) { if (tlsConfig.isFileBasedConfig()) { sslContextBuilder.keyManager(tlsConfig.getCertChainFile(), tlsConfig.getPrivateKeyFile()); } else { sslContextBuilder.keyManager(tlsConfig.getPrivateKey(), tlsConfig.getCertChain()); } } try { channelBuilder.useTransportSecurity().sslContext(sslContextBuilder.build()); } catch (Exception ex) { throw new IllegalArgumentException("Failed to build SslContext, peerId=" + raftPeerId + ", tlsConfig=" + tlsConfig, ex); } } else { channelBuilder.negotiationType(NegotiationType.PLAINTEXT); } channel = channelBuilder.flowControlWindow(flowControlWindow).build(); blockingStub = RaftServerProtocolServiceGrpc.newBlockingStub(channel); asyncStub = RaftServerProtocolServiceGrpc.newStub(channel); this.requestTimeoutDuration = requestTimeoutDuration; }
Example 3
Source File: PeerConfiguration.java From incubator-ratis with Apache License 2.0 | 5 votes |
PeerConfiguration(Iterable<RaftPeer> peers) { Objects.requireNonNull(peers); Map<RaftPeerId, RaftPeer> map = new HashMap<>(); for(RaftPeer p : peers) { final RaftPeer previous = map.putIfAbsent(p.getId(), p); if (previous != null) { throw new IllegalArgumentException("Found duplicated ids " + p.getId() + " in peers " + peers); } } this.peers = Collections.unmodifiableMap(map); }
Example 4
Source File: FollowerInfo.java From incubator-ratis with Apache License 2.0 | 5 votes |
FollowerInfo(RaftGroupMemberId id, RaftPeer peer, Timestamp lastRpcTime, long nextIndex, boolean attendVote, int rpcSlownessTimeoutMs) { this.name = id + "->" + peer.getId(); this.infoIndexChange = s -> LOG.info("{}: {}", name, s); this.debugIndexChange = s -> LOG.debug("{}: {}", name, s); this.peer = peer; this.lastRpcResponseTime = new AtomicReference<>(lastRpcTime); this.lastRpcSendTime = new AtomicReference<>(lastRpcTime); this.nextIndex = new RaftLogIndex("nextIndex", nextIndex); this.attendVote = attendVote; this.rpcSlownessTimeoutMs = rpcSlownessTimeoutMs; }
Example 5
Source File: FollowerInfo.java From ratis with Apache License 2.0 | 5 votes |
FollowerInfo(RaftPeerId id, RaftPeer peer, Timestamp lastRpcTime, long nextIndex, boolean attendVote, int rpcSlownessTimeoutMs) { this.name = id + "->" + peer.getId(); this.infoIndexChange = s -> LOG.info("{}: {}", name, s); this.debugIndexChange = s -> LOG.debug("{}: {}", name, s); this.peer = peer; this.lastRpcResponseTime = new AtomicReference<>(lastRpcTime); this.lastRpcSendTime = new AtomicReference<>(lastRpcTime); this.nextIndex = new RaftLogIndex("nextIndex", nextIndex); this.attendVote = attendVote; this.rpcSlownessTimeoutMs = rpcSlownessTimeoutMs; }